@@ -153,6 +153,9 @@ function highlightCodeLine(curLine, visitedLinesSet, hasError, isTerminated) {
153153
154154// relies on curTrace and curInstr globals
155155function updateOutput ( ) {
156+ // update based on experimental checkbox ...
157+ useJsPlumbRendering = $ ( "#useJsPlumbCheckbox" ) . prop ( "checked" ) ;
158+
156159 var curEntry = curTrace [ curInstr ] ;
157160 var hasError = false ;
158161
@@ -388,10 +391,20 @@ function renderDataStructuresVersion1(curEntry, vizDiv) {
388391
389392// The "2.0" version of renderDataStructures, which renders variables in
390393// a stack and values in a separate heap, with data structure aliasing
391- // explicitly represented via line connectors.
394+ // explicitly represented via line connectors (thanks to jsPlumb lib) .
392395//
393396// This version was originally created in September 2011
394397function renderDataStructuresVersion2 ( curEntry , vizDiv ) {
398+
399+ // before we wipe out the old state of the visualization, CLEAR all
400+ // the click listeners first
401+ $ ( ".stackFrameHeader" ) . unbind ( ) ;
402+
403+ // VERY VERY IMPORTANT --- and reset ALL jsPlumb state to prevent
404+ // weird mis-behavior!!!
405+ jsPlumb . reset ( ) ;
406+
407+
395408 $ ( vizDiv ) . html ( '' ) ; // CLEAR IT!
396409
397410 // create a tabular layout for stack and heap side-by-side
@@ -567,6 +580,7 @@ function renderDataStructuresVersion2(curEntry, vizDiv) {
567580 // from bottom to top, so that we can hopefully prevent objects from
568581 // jumping around
569582
583+
570584 orderedGlobals . reverse ( ) ; // so that we can iterate backwards
571585
572586 $ . each ( orderedGlobals , function ( i , varname ) {
@@ -648,6 +662,7 @@ function renderDataStructuresVersion2(curEntry, vizDiv) {
648662 var enclosingStackFrameID = enclosingStackFrame . attr ( 'id' ) ;
649663
650664 var allConnections = jsPlumb . getConnections ( ) ;
665+ //console.log('allConnections: ' + allConnections);
651666 for ( var i = 0 ; i < allConnections . length ; i ++ ) {
652667 var c = allConnections [ i ] ;
653668
@@ -686,7 +701,7 @@ function renderDataStructuresVersion2(curEntry, vizDiv) {
686701
687702 // 'click' on the top-most stack frame if available,
688703 // or on "Global variables" otherwise
689- if ( curEntry . stack_locals != undefined && curEntry . stack_locals . length ) {
704+ if ( curEntry . stack_locals != undefined && curEntry . stack_locals . length > 0 ) {
690705 $ ( '#stack_header0' ) . trigger ( 'click' ) ;
691706 }
692707 else {
@@ -1008,6 +1023,7 @@ $(document).ready(function() {
10081023 $ ( "#editCodeLink" ) . click ( function ( ) {
10091024 $ ( "#pyInputPane" ) . show ( ) ;
10101025 $ ( "#pyInputPane" ) . css ( 'border-bottom' , '2px dashed #bbbbbb' ) ;
1026+ updateOutput ( ) ;
10111027 return false ; // to prevent page reload
10121028 } ) ;
10131029
@@ -1134,20 +1150,44 @@ $(document).ready(function() {
11341150 return false ;
11351151 } ) ;
11361152
1137- if ( useJsPlumbRendering ) {
1138- // set some sensible defaults
1139- jsPlumb . Defaults . Endpoint = [ "Dot" , { radius :3 } ] ;
1140- //jsPlumb.Defaults.Endpoint = ["Rectangle", {width:3, height:3}];
1141- jsPlumb . Defaults . EndpointStyle = { fillStyle : lightGray } ;
1142- jsPlumb . Defaults . Anchors = [ "RightMiddle" , "LeftMiddle" ] ;
1143- jsPlumb . Defaults . Connector = [ "Bezier" , { curviness :15 } ] ; /* too much 'curviness' causes lines to run together */
1144- jsPlumb . Defaults . PaintStyle = { lineWidth :1 , strokeStyle : lightGray } ;
1145-
1146- jsPlumb . Defaults . EndpointHoverStyle = { fillStyle : pinkish } ;
1147- jsPlumb . Defaults . HoverPaintStyle = { lineWidth :2 , strokeStyle : pinkish } ;
1148- }
1153+
1154+ // set some sensible jsPlumb defaults
1155+ jsPlumb . Defaults . Endpoint = [ "Dot" , { radius :3 } ] ;
1156+ //jsPlumb.Defaults.Endpoint = ["Rectangle", {width:3, height:3}];
1157+ jsPlumb . Defaults . EndpointStyle = { fillStyle : lightGray } ;
1158+ jsPlumb . Defaults . Anchors = [ "RightMiddle" , "LeftMiddle" ] ;
1159+ jsPlumb . Defaults . Connector = [ "Bezier" , { curviness :15 } ] ; /* too much 'curviness' causes lines to run together */
1160+ jsPlumb . Defaults . PaintStyle = { lineWidth :1 , strokeStyle : lightGray } ;
1161+
1162+ jsPlumb . Defaults . EndpointHoverStyle = { fillStyle : pinkish } ;
1163+ jsPlumb . Defaults . HoverPaintStyle = { lineWidth :2 , strokeStyle : pinkish } ;
1164+
11491165
11501166 // select an example on start-up:
11511167 $ ( "#tutorialExampleLink" ) . trigger ( 'click' ) ;
1168+
1169+
1170+ // disable controls initially ...
1171+ $ ( "#vcrControls #jmpFirstInstr" ) . attr ( "disabled" , true ) ;
1172+ $ ( "#vcrControls #jmpStepBack" ) . attr ( "disabled" , true ) ;
1173+ $ ( "#vcrControls #jmpStepFwd" ) . attr ( "disabled" , true ) ;
1174+ $ ( "#vcrControls #jmpLastInstr" ) . attr ( "disabled" , true ) ;
1175+
1176+
1177+ // set keyboard event listeners ...
1178+ $ ( document ) . keydown ( function ( k ) {
1179+ if ( k . keyCode == 37 ) { // left arrow
1180+ if ( ! $ ( "#vcrControls #jmpStepBack" ) . attr ( "disabled" ) ) {
1181+ $ ( "#jmpStepBack" ) . trigger ( 'click' ) ;
1182+ k . preventDefault ( ) ; // don't horizontally scroll the display
1183+ }
1184+ }
1185+ else if ( k . keyCode == 39 ) { // right arrow
1186+ if ( ! $ ( "#vcrControls #jmpStepFwd" ) . attr ( "disabled" ) ) {
1187+ $ ( "#jmpStepFwd" ) . trigger ( 'click' ) ;
1188+ k . preventDefault ( ) ; // don't horizontally scroll the display
1189+ }
1190+ }
1191+ } ) ;
11521192} ) ;
11531193
0 commit comments