@@ -29,10 +29,20 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2929
3030var curVisualizerID = 1 ; // global to uniquely identify each ExecutionVisualizer instance
3131
32- function ExecutionVisualizer ( inputCode , traceData , startingInstruction , domRootID ) {
33- this . curInputCode = inputCode ;
34- this . curTrace = traceData ;
35- this . curInstr = startingInstruction ;
32+ // domRootID is the string ID of the root element where to render this instance
33+ // dat is data returned by the Python Tutor backend consisting of two fields:
34+ // code - string of executed code
35+ // trace - a full execution trace
36+ // startingInstruction is (optional) the execution point to display upon rendering (one-indexed)
37+ function ExecutionVisualizer ( domRootID , dat , startingInstruction /* optional */ ) {
38+ this . curInputCode = dat . code ;
39+ this . curTrace = dat . trace ;
40+
41+ this . curInstr = 0 ;
42+
43+ if ( startingInstruction ) {
44+ this . curInstr = ( startingInstruction - 1 ) ; // zero-indexed
45+ }
3646
3747 this . visualizerID = curVisualizerID ;
3848 curVisualizerID ++ ;
@@ -1103,9 +1113,7 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
11031113 // (the format is: '<this.visualizerID>__heap_object_<id>')
11041114 //
11051115 // The reason we need to prepend this.visualizerID is because jsPlumb needs
1106- // GLOBALLY UNIQUE IDs for use as connector endpoints. Actually this is no
1107- // longer true since we can use this.jsPlumbInstance, but still it's nice
1108- // to have unique div IDs
1116+ // GLOBALLY UNIQUE IDs for use as connector endpoints.
11091117 var connectionEndpointIDs = d3 . map ( ) ;
11101118 var heapConnectionEndpointIDs = d3 . map ( ) ; // subset of connectionEndpointIDs for heap->heap connections
11111119
@@ -1427,10 +1435,10 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
14271435 // render all global variables IN THE ORDER they were created by the program,
14281436 // in order to ensure continuity:
14291437 if ( curEntry . ordered_globals . length > 0 ) {
1430- this . domRoot . find ( "#stack" ) . append ( '<div class="stackFrame" id="globals "><div id="globals_header " class="stackFrameHeader">Global variables</div></div>' ) ;
1431- this . domRoot . find ( " #stack #globals" ) . append ( '<table class="stackFrameVarTable" id="global_table "></table>' ) ;
1438+ this . domRoot . find ( "#stack" ) . append ( '<div class="stackFrame" id="' + myViz . visualizerID + '__globals "><div id="' + myViz . visualizerID + '__globals_header " class="stackFrameHeader">Global variables</div></div>') ;
1439+ this . domRoot . find ( ' #stack #' + myViz . visualizerID + '__globals' ) . append ( '<table class="stackFrameVarTable" id="' + myViz . visualizerID + '__global_table "></table>') ;
14321440
1433- var tbl = this . domRoot . find ( "#global_table" ) ;
1441+ var tbl = this . domRoot . find ( '#' + myViz . visualizerID + '__global_table' ) ;
14341442
14351443 $ . each ( curEntry . ordered_globals , function ( i , varname ) {
14361444 var val = curEntry . globals [ varname ] ;
@@ -1449,7 +1457,7 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
14491457
14501458 // make sure varname doesn't contain any weird
14511459 // characters that are illegal for CSS ID's ...
1452- var varDivID = 'global__ ' + varnameToCssID ( varname ) ;
1460+ var varDivID = myViz . visualizerID + '__global__ ' + varnameToCssID ( varname ) ;
14531461 curTr . find ( "td.stackFrameValue" ) . append ( '<div id="' + varDivID + '"> </div>' ) ;
14541462
14551463 assert ( ! connectionEndpointIDs . has ( varDivID ) ) ;
@@ -1483,12 +1491,12 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
14831491 var divClass , divID , headerDivID ;
14841492 if ( is_zombie ) {
14851493 divClass = 'zombieStackFrame' ;
1486- divID = "zombie_stack " + ind ;
1494+ divID = myViz . visualizerID + "__zombie_stack " + ind ;
14871495 headerDivID = "zombie_stack_header" + ind ;
14881496 }
14891497 else {
14901498 divClass = 'stackFrame' ;
1491- divID = "stack " + ind ;
1499+ divID = myViz . visualizerID + "__stack " + ind ;
14921500 headerDivID = "stack_header" + ind ;
14931501 }
14941502
@@ -1605,13 +1613,13 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
16051613 var frame_already_highlighted = false ;
16061614 $ . each ( curEntry . stack_to_render , function ( i , e ) {
16071615 if ( e . is_highlighted ) {
1608- highlight_frame ( 'stack ' + i ) ;
1616+ highlight_frame ( myViz . visualizerID + '__stack ' + i ) ;
16091617 frame_already_highlighted = true ;
16101618 }
16111619 } ) ;
16121620
16131621 if ( ! frame_already_highlighted ) {
1614- highlight_frame ( 'globals ') ;
1622+ highlight_frame ( myViz . visualizerID + '__globals ') ;
16151623 }
16161624
16171625}
0 commit comments