Skip to content

Commit 4086012

Browse files
committed
implement mouseover arrows when using text references
1 parent f7d7795 commit 4086012

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

v3/js/pytutor.js

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,8 +1900,23 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
19001900

19011901
function renderCompoundObject(objID, d3DomElement, isTopLevel) {
19021902
if (!isTopLevel && renderedObjectIDs.has(objID)) {
1903+
var srcDivID = myViz.generateID('heap_pointer_src_' + heap_pointer_src_id);
1904+
heap_pointer_src_id++; // just make sure each source has a UNIQUE ID
1905+
1906+
var dstDivID = myViz.generateID('heap_object_' + objID);
1907+
19031908
if (myViz.textualMemoryLabels) {
1904-
d3DomElement.append('<div class="objectIdLabel">id' + objID + '</div>');
1909+
var labelID = srcDivID + '_text_label';
1910+
d3DomElement.append('<div class="objectIdLabel" id="' + labelID + '">id' + objID + '</div>');
1911+
1912+
myViz.domRoot.find('div#' + labelID).hover(
1913+
function() {
1914+
myViz.jsPlumbInstance.connect({source: labelID, target: dstDivID,
1915+
scope: 'varValuePointer'});
1916+
},
1917+
function() {
1918+
myViz.jsPlumbInstance.reset(); // kill 'em all!
1919+
});
19051920
}
19061921
else {
19071922
// render jsPlumb arrow source since this heap object has already been rendered
@@ -1910,13 +1925,8 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
19101925
// add a stub so that we can connect it with a connector later.
19111926
// IE needs this div to be NON-EMPTY in order to properly
19121927
// render jsPlumb endpoints, so that's why we add an "&nbsp;"!
1913-
1914-
var srcDivID = myViz.generateID('heap_pointer_src_' + heap_pointer_src_id);
1915-
heap_pointer_src_id++; // just make sure each source has a UNIQUE ID
19161928
d3DomElement.append('<div id="' + srcDivID + '">&nbsp;</div>');
19171929

1918-
var dstDivID = myViz.generateID('heap_object_' + objID);
1919-
19201930
assert(!connectionEndpointIDs.has(srcDivID));
19211931
connectionEndpointIDs.set(srcDivID, dstDivID);
19221932
//console.log('HEAP->HEAP', srcDivID, dstDivID);
@@ -2216,8 +2226,19 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
22162226
renderPrimitiveObject(val, $(this));
22172227
}
22182228
else {
2229+
var heapObjID = myViz.generateID('heap_object_' + getRefID(val));
2230+
22192231
if (myViz.textualMemoryLabels) {
2220-
$(this).append('<div class="objectIdLabel">id' + getRefID(val) + '</div>');
2232+
var labelID = varDivID + '_text_label';
2233+
$(this).append('<div class="objectIdLabel" id="' + labelID + '">id' + getRefID(val) + '</div>');
2234+
$(this).find('div#' + labelID).hover(
2235+
function() {
2236+
myViz.jsPlumbInstance.connect({source: labelID, target: heapObjID,
2237+
scope: 'varValuePointer'});
2238+
},
2239+
function() {
2240+
myViz.jsPlumbInstance.reset(); // kill 'em all!
2241+
});
22212242
}
22222243
else {
22232244
// add a stub so that we can connect it with a connector later.
@@ -2226,7 +2247,6 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
22262247
$(this).append('<div class="stack_pointer" id="' + varDivID + '">&nbsp;</div>');
22272248

22282249
assert(!connectionEndpointIDs.has(varDivID));
2229-
var heapObjID = myViz.generateID('heap_object_' + getRefID(val));
22302250
connectionEndpointIDs.set(varDivID, heapObjID);
22312251
//console.log('STACK->HEAP', varDivID, heapObjID);
22322252
}
@@ -2423,8 +2443,18 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
24232443
renderPrimitiveObject(val, $(this));
24242444
}
24252445
else {
2446+
var heapObjID = myViz.generateID('heap_object_' + getRefID(val));
24262447
if (myViz.textualMemoryLabels) {
2427-
$(this).append('<div class="objectIdLabel">id' + getRefID(val) + '</div>');
2448+
var labelID = varDivID + '_text_label';
2449+
$(this).append('<div class="objectIdLabel" id="' + labelID + '">id' + getRefID(val) + '</div>');
2450+
$(this).find('div#' + labelID).hover(
2451+
function() {
2452+
myViz.jsPlumbInstance.connect({source: labelID, target: heapObjID,
2453+
scope: 'varValuePointer'});
2454+
},
2455+
function() {
2456+
myViz.jsPlumbInstance.reset(); // kill 'em all!
2457+
});
24282458
}
24292459
else {
24302460
// add a stub so that we can connect it with a connector later.
@@ -2433,7 +2463,6 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
24332463
$(this).append('<div class="stack_pointer" id="' + varDivID + '">&nbsp;</div>');
24342464

24352465
assert(!connectionEndpointIDs.has(varDivID));
2436-
var heapObjID = myViz.generateID('heap_object_' + getRefID(val));
24372466
connectionEndpointIDs.set(varDivID, heapObjID);
24382467
//console.log('STACK->HEAP', varDivID, heapObjID);
24392468
}

0 commit comments

Comments
 (0)