Skip to content

Commit 2e28be6

Browse files
author
Philip Guo
committed
add an option to have the stack grow both up and down
1 parent 768ad7b commit 2e28be6

3 files changed

Lines changed: 40 additions & 9 deletions

File tree

edu-python.css

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ table#pyCodeOutput {
147147
border-top: 1px solid #999999;
148148
padding-top: 3px;
149149
border-bottom: 1px solid #999999;
150-
margin-top: 5px;
150+
margin-top: 6px;
151151
}
152152

153153
/* don't wrap lines within code output ... FORCE scrollbars to appear */
@@ -512,15 +512,19 @@ div.heapObject {
512512
padding-left: 7px; /* leave some room for connector endpoints */
513513
}
514514

515-
div.stackHeader {
516-
margin-bottom: 10px;
515+
div#stackHeader {
516+
margin-bottom: 15px;
517517
text-align: right;
518-
color: #888888;
519518
}
520519

521-
div.heapHeader {
522-
margin-bottom: 10px;
523-
text-align: left;
524-
color: #888888;
520+
div#heapHeader {
521+
margin-top: 2px;
522+
margin-bottom: 13px;
523+
}
524+
525+
div#stackHeader,
526+
div#heapHeader {
527+
color: #333333;
528+
font-size: 10pt;
525529
}
526530

edu-python.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,29 @@ function renderDataStructuresVersion2(curEntry, vizDiv) {
414414
// TODO: figure out how to do this using CSS in a robust way!
415415
$(vizDiv).html('<table id="stackHeapTable"><tr><td id="stack_td"><div id="stack"></div></td><td id="heap_td"><div id="heap"></div></td></tr></table>');
416416

417+
$(vizDiv + " #stack").append('<div id="stackHeader">Stack grows <select id="stack_growth_selector"><option>down</option><option>up</option></select></div>');
418+
419+
// select a state based on stackGrowsDown global variable:
420+
if (stackGrowsDown) {
421+
$("#stack_growth_selector").val('down');
422+
}
423+
else {
424+
$("#stack_growth_selector").val('up');
425+
}
426+
427+
// add trigger
428+
$("#stack_growth_selector").change(function() {
429+
var v = $("#stack_growth_selector").val();
430+
if (v == 'down') {
431+
stackGrowsDown = true;
432+
}
433+
else {
434+
stackGrowsDown = false;
435+
}
436+
437+
updateOutput(); // refresh display!!!
438+
});
439+
417440

418441
var nonEmptyGlobals = false;
419442
var curGlobalFields = {};
@@ -710,6 +733,10 @@ function renderDataStructuresVersion2(curEntry, vizDiv) {
710733

711734
}
712735

736+
737+
// prepend heap header after all the dust settles:
738+
$(vizDiv + ' #heap').prepend('<div id="heapHeader">Heap</div>');
739+
713740

714741
// finally connect stack variables to heap objects via connectors
715742
for (varID in connectionEndpointIDs) {

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120

121121
<div id="pyCodeOutputDiv">
122122

123-
Use left and right arrow keys to single-step through this code:
123+
Use left and right arrow keys to step through this code:
124124
<table id="pyCodeOutput"></table>
125125

126126
</div>

0 commit comments

Comments
 (0)