Skip to content

Commit a0ccaff

Browse files
committed
YAHHH
1 parent 7922e48 commit a0ccaff

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

PyTutorGAE/js/pytutor.js

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,23 +1560,48 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
15601560
}
15611561

15621562

1563+
// holy cow, the d3 code for stack rendering is ABSOLUTELY NUTS!
15631564

15641565
var stackDiv = myViz.domRootD3.select('#stack');
15651566

1567+
// VERY IMPORTANT for selectAll selector to be SUPER specific here!
15661568
var stackFrameDiv = stackDiv.selectAll('div.stackFrame,div.zombieStackFrame')
15671569
.data(curEntry.stack_to_render, function(frame) {
15681570
// VERY VERY VERY IMPORTANT for properly handling closures and nested functions
15691571
// (see the backend code for more details)
15701572
return frame.unique_hash;
15711573
});
15721574

1573-
stackFrameDiv.enter()
1575+
var sfdEnter = stackFrameDiv.enter()
15741576
.append('div')
15751577
.attr('class', function(d, i) {return d.is_zombie ? 'zombieStackFrame' : 'stackFrame';})
15761578
.attr('id', function(d, i) {return d.is_zombie ? myViz.generateID("zombie_stack" + i)
15771579
: myViz.generateID("stack" + i);
15781580
})
15791581
.each(function(frame, i) {console.log('NEW STACK FRAME', frame.unique_hash);})
1582+
1583+
sfdEnter
1584+
.append('div')
1585+
.attr('class', 'stackFrameHeader')
1586+
.html(function(frame, i) {
1587+
var funcName = htmlspecialchars(frame.func_name); // might contain '<' or '>' for weird names like <genexpr>
1588+
var headerLabel = funcName + '()';
1589+
1590+
var frameID = frame.frame_id; // optional (btw, this isn't a CSS id)
1591+
if (frameID) {
1592+
headerLabel = 'f' + frameID + ': ' + headerLabel;
1593+
}
1594+
1595+
// optional (btw, this isn't a CSS id)
1596+
if (frame.parent_frame_id_list.length > 0) {
1597+
var parentFrameID = frame.parent_frame_id_list[0];
1598+
headerLabel = headerLabel + ' [parent=f' + parentFrameID + ']';
1599+
}
1600+
1601+
return headerLabel;
1602+
})
1603+
1604+
sfdEnter
15801605
.append('table')
15811606
.attr('class', 'stackFrameVarTable');
15821607

@@ -1614,12 +1639,10 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
16141639
var frame = d.frame;
16151640

16161641
if (i == 0) {
1617-
if (varname == '__return__' && !frame.is_zombie) {
1642+
if (varname == '__return__' && !frame.is_zombie)
16181643
$(this).html('<span class="retval">Return value</span>');
1619-
}
1620-
else {
1644+
else
16211645
$(this).html(varname);
1622-
}
16231646
}
16241647
else {
16251648
var val = frame.encoded_locals[varname];
@@ -1676,33 +1699,6 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
16761699
.remove();
16771700

16781701

1679-
// render stack frame headers in a "brute force" way by
1680-
// first clearing all of them ...
1681-
myViz.domRoot.find('#stack').find('.stackFrame,.zombieStackFrame').find('.stackFrameHeader').remove();
1682-
1683-
// ... and then rendering all of them again in one fell swoop
1684-
myViz.domRootD3.select('#stack').selectAll('.stackFrame,.zombieStackFrame')
1685-
.data(curEntry.stack_to_render)
1686-
.insert('div', ':first-child') // prepend before first child
1687-
.attr('class', 'stackFrameHeader')
1688-
.html(function(frame, i) {
1689-
var funcName = htmlspecialchars(frame.func_name); // might contain '<' or '>' for weird names like <genexpr>
1690-
var headerLabel = funcName + '()';
1691-
1692-
var frameID = frame.frame_id; // optional (btw, this isn't a CSS id)
1693-
if (frameID) {
1694-
headerLabel = 'f' + frameID + ': ' + headerLabel;
1695-
}
1696-
1697-
// optional (btw, this isn't a CSS id)
1698-
if (frame.parent_frame_id_list.length > 0) {
1699-
var parentFrameID = frame.parent_frame_id_list[0];
1700-
headerLabel = headerLabel + ' [parent=f' + parentFrameID + ']';
1701-
}
1702-
1703-
return headerLabel;
1704-
})
1705-
17061702

17071703
// finally add all the connectors!
17081704
connectionEndpointIDs.forEach(function(varID, valueID) {

0 commit comments

Comments
 (0)