Skip to content

Commit 16fd980

Browse files
committed
refactored getting heap object ID
1 parent 8d3b756 commit 16fd980

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

v3/js/pytutor.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ ExecutionVisualizer.prototype.resetJsPlumbManager = function() {
261261
// (for stack->heap connections) or heap object (for heap->heap connections)
262262
// the format is: '<this.visualizerID>__heap_pointer_src_<src id>'
263263
// Value: CSS ID of the div element representing the value rendered in the heap
264-
// (the format is: '<this.visualizerID>__heap_object_<id>')
264+
// (the format is given by generateHeapObjID())
265265
//
266266
// The reason we need to prepend this.visualizerID is because jsPlumb needs
267267
// GLOBALLY UNIQUE IDs for use as connector endpoints.
@@ -285,6 +285,13 @@ ExecutionVisualizer.prototype.generateID = function(original_id) {
285285
return 'v' + this.visualizerID + '__' + original_id;
286286
}
287287

288+
// create a unique CSS ID for a heap object, which should include both
289+
// its ID and the current step number. this is necessary if we want to
290+
// display the same heap object at multiple execution steps.
291+
ExecutionVisualizer.prototype.generateHeapObjID = function(objID, stepNum) {
292+
return this.generateID('heap_object_' + objID + '_s' + stepNum);
293+
}
294+
288295

289296
ExecutionVisualizer.prototype.render = function() {
290297
if (this.hasRendered) {
@@ -2283,7 +2290,7 @@ ExecutionVisualizer.prototype.renderDataStructures = function(curEntry, curTople
22832290
myViz.renderPrimitiveObject(val, $(this));
22842291
}
22852292
else {
2286-
var heapObjID = myViz.generateID('heap_object_' + getRefID(val));
2293+
var heapObjID = myViz.generateHeapObjID(getRefID(val), myViz.curInstr);
22872294

22882295
if (myViz.textualMemoryLabels) {
22892296
var labelID = varDivID + '_text_label';
@@ -2504,7 +2511,7 @@ ExecutionVisualizer.prototype.renderDataStructures = function(curEntry, curTople
25042511
myViz.renderPrimitiveObject(val, $(this));
25052512
}
25062513
else {
2507-
var heapObjID = myViz.generateID('heap_object_' + getRefID(val));
2514+
var heapObjID = myViz.generateHeapObjID(getRefID(val), myViz.curInstr);
25082515
if (myViz.textualMemoryLabels) {
25092516
var labelID = varDivID + '_text_label';
25102517
$(this).append('<div class="objectIdLabel" id="' + labelID + '">id' + getRefID(val) + '</div>');
@@ -2854,7 +2861,7 @@ function(objID, stepNum, d3DomElement, isTopLevel) {
28542861
var srcDivID = myViz.generateID('heap_pointer_src_' + myViz.jsPlumbManager.heap_pointer_src_id);
28552862
myViz.jsPlumbManager.heap_pointer_src_id++; // just make sure each source has a UNIQUE ID
28562863

2857-
var dstDivID = myViz.generateID('heap_object_' + objID);
2864+
var dstDivID = myViz.generateHeapObjID(objID, stepNum);
28582865

28592866
if (myViz.textualMemoryLabels) {
28602867
var labelID = srcDivID + '_text_label';
@@ -2889,7 +2896,7 @@ function(objID, stepNum, d3DomElement, isTopLevel) {
28892896
return; // early return!
28902897
}
28912898

2892-
var heapObjID = myViz.generateID('heap_object_' + objID);
2899+
var heapObjID = myViz.generateHeapObjID(objID, stepNum);
28932900

28942901

28952902
// wrap ALL compound objects in a heapObject div so that jsPlumb

0 commit comments

Comments
 (0)