Skip to content

Commit 8afb861

Browse files
committed
Add params 'highlightLines', 'arrowLines'
to determine what is highlighted by visualizer, and no-arg URL param 'highlightLines' for iframe js
1 parent dd29d0a commit 8afb861

3 files changed

Lines changed: 131 additions & 81 deletions

File tree

‎v3/css/pytutor.css‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,3 +693,14 @@ div.ExecutionVisualizer div#vizHeader {
693693
max-width: 700px;
694694
}
695695

696+
div.ExecutionVisualizer .highlight-curr {
697+
background-color: #FFFF66;
698+
}
699+
700+
div.ExecutionVisualizer .highlight-prev {
701+
background-color: #F0F0EA;
702+
}
703+
704+
div.ExecutionVisualizer .highlight-legend {
705+
padding: 2px;
706+
}

‎v3/js/iframe-embed.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ $(document).ready(function() {
140140
drawParentPointers: drawParentPointerBool,
141141
textualMemoryLabels: textRefsBool,
142142
showOnlyOutputs: showOnlyOutputsBool,
143+
highlightLines: typeof $.bbq.getState("highlightLines") !== undefined
143144
});
144145
if (resizeContainer) resizeContainerNow();
145146
}

‎v3/js/pytutor.js‎

Lines changed: 119 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,23 @@ function ExecutionVisualizer(domRootID, dat, params) {
135135
this.params = {}; // make it an empty object by default
136136
}
137137

138+
if (!this.params.arrowLines && !this.params.highlightLines) {
139+
this.params.highlightLines = false;
140+
this.params.arrowLines = true;
141+
}
142+
else if (this.params.arrowLines) {
143+
this.params.arrowLines = (this.params.arrowLines == true);
144+
this.params.highlightLines = !(this.params.arrowLines);
145+
}
146+
else if (this.params.highlightLines) {
147+
this.params.highlightLines = (this.params.highlightLines == true);
148+
this.params.arrowLines = !(this.params.highlightLines);
149+
}
150+
else {
151+
this.params.arrowLines = (this.params.arrowLines == true);
152+
this.params.highlightLines = (this.params.highlightLines == true);
153+
}
154+
138155
// needs to be unique!
139156
this.visualizerID = curVisualizerID;
140157
curVisualizerID++;
@@ -304,19 +321,26 @@ ExecutionVisualizer.prototype.render = function() {
304321
this.domRoot.find('#vizLayoutTdFirst').append(outputsHTML);
305322
}
306323

307-
this.domRoot.find('#legendDiv')
308-
.append('<svg id="prevLegendArrowSVG"/> line that has just executed')
309-
.append('<p style="margin-top: 4px"><svg id="curLegendArrowSVG"/> next line to execute</p>');
310-
311-
myViz.domRootD3.select('svg#prevLegendArrowSVG')
312-
.append('polygon')
313-
.attr('points', SVG_ARROW_POLYGON)
314-
.attr('fill', lightArrowColor);
315-
316-
myViz.domRootD3.select('svg#curLegendArrowSVG')
317-
.append('polygon')
318-
.attr('points', SVG_ARROW_POLYGON)
319-
.attr('fill', darkArrowColor);
324+
if (this.params.arrowLines) {
325+
this.domRoot.find('#legendDiv')
326+
.append('<svg id="prevLegendArrowSVG"/> line that has just executed')
327+
.append('<p style="margin-top: 4px"><svg id="curLegendArrowSVG"/> next line to execute</p>');
328+
329+
myViz.domRootD3.select('svg#prevLegendArrowSVG')
330+
.append('polygon')
331+
.attr('points', SVG_ARROW_POLYGON)
332+
.attr('fill', lightArrowColor);
333+
334+
myViz.domRootD3.select('svg#curLegendArrowSVG')
335+
.append('polygon')
336+
.attr('points', SVG_ARROW_POLYGON)
337+
.attr('fill', darkArrowColor);
338+
}
339+
else if (this.params.highlightLines) {
340+
myViz.domRoot.find('#legendDiv')
341+
.append('<span class="highlight-legend highlight-prev">line that has just executed</span> ')
342+
.append('<span class="highlight-legend highlight-curr">next line to execute</span>')
343+
}
320344

321345

322346
if (this.params.editCodeBaseURL) {
@@ -1031,22 +1055,23 @@ ExecutionVisualizer.prototype.renderPyCodeOutput = function() {
10311055

10321056
// create a left-most gutter td that spans ALL rows ...
10331057
// (NB: valign="top" is CRUCIAL for this to work in IE)
1034-
myViz.domRoot.find('#pyCodeOutput tr:first')
1035-
.prepend('<td id="gutterTD" valign="top" rowspan="' + this.codeOutputLines.length + '"><svg id="leftCodeGutterSVG"/></td>');
1036-
1037-
// create prevLineArrow and curLineArrow
1038-
myViz.domRootD3.select('svg#leftCodeGutterSVG')
1039-
.append('polygon')
1040-
.attr('id', 'prevLineArrow')
1041-
.attr('points', SVG_ARROW_POLYGON)
1042-
.attr('fill', lightArrowColor);
1043-
1044-
myViz.domRootD3.select('svg#leftCodeGutterSVG')
1045-
.append('polygon')
1046-
.attr('id', 'curLineArrow')
1047-
.attr('points', SVG_ARROW_POLYGON)
1048-
.attr('fill', darkArrowColor);
1049-
1058+
if (myViz.params.arrowLines) {
1059+
myViz.domRoot.find('#pyCodeOutput tr:first')
1060+
.prepend('<td id="gutterTD" valign="top" rowspan="' + this.codeOutputLines.length + '"><svg id="leftCodeGutterSVG"/></td>');
1061+
1062+
// create prevLineArrow and curLineArrow
1063+
myViz.domRootD3.select('svg#leftCodeGutterSVG')
1064+
.append('polygon')
1065+
.attr('id', 'prevLineArrow')
1066+
.attr('points', SVG_ARROW_POLYGON)
1067+
.attr('fill', lightArrowColor);
1068+
1069+
myViz.domRootD3.select('svg#leftCodeGutterSVG')
1070+
.append('polygon')
1071+
.attr('id', 'curLineArrow')
1072+
.attr('points', SVG_ARROW_POLYGON)
1073+
.attr('fill', darkArrowColor);
1074+
}
10501075

10511076
// 2012-09-05: Disable breakpoints for now to simplify UX
10521077
/*
@@ -1129,7 +1154,7 @@ ExecutionVisualizer.prototype.updateOutput = function(smoothTransition) {
11291154
// (we often can't do this earlier since the entire pane
11301155
// might be invisible and hence returns a height of zero or NaN
11311156
// -- the exact format depends on browser)
1132-
if (!myViz.leftGutterSvgInitialized) {
1157+
if (!myViz.leftGutterSvgInitialized && myViz.params.arrowLines) {
11331158
// set the gutter's height to match that of its parent
11341159
gutterSVG.height(gutterSVG.parent().height());
11351160

@@ -1159,9 +1184,11 @@ ExecutionVisualizer.prototype.updateOutput = function(smoothTransition) {
11591184
myViz.leftGutterSvgInitialized = true;
11601185
}
11611186

1162-
assert(myViz.arrowOffsetY !== undefined);
1163-
assert(myViz.codeRowHeight !== undefined);
1164-
assert(0 <= myViz.arrowOffsetY && myViz.arrowOffsetY <= myViz.codeRowHeight);
1187+
if (myViz.params.arrowLines) {
1188+
assert(myViz.arrowOffsetY !== undefined);
1189+
assert(myViz.codeRowHeight !== undefined);
1190+
assert(0 <= myViz.arrowOffsetY && myViz.arrowOffsetY <= myViz.codeRowHeight);
1191+
}
11651192

11661193
// call the callback if necessary (BEFORE rendering)
11671194
if (this.params.updateOutputCallback) {
@@ -1287,55 +1314,56 @@ ExecutionVisualizer.prototype.updateOutput = function(smoothTransition) {
12871314
}
12881315
}
12891316

1290-
if (prevLineNumber) {
1291-
var pla = myViz.domRootD3.select('#prevLineArrow');
1292-
var translatePrevCmd = 'translate(0, ' + (((prevLineNumber - 1) * myViz.codeRowHeight) + myViz.arrowOffsetY + prevVerticalNudge) + ')';
1293-
1294-
if (smoothTransition) {
1295-
pla
1296-
.transition()
1297-
.duration(200)
1298-
.attr('fill', 'white')
1299-
.each('end', function() {
1300-
pla
1301-
.attr('transform', translatePrevCmd)
1302-
.attr('fill', lightArrowColor);
1303-
1304-
gutterSVG.find('#prevLineArrow').show(); // show at the end to avoid flickering
1305-
});
1306-
}
1307-
else {
1308-
pla.attr('transform', translatePrevCmd)
1309-
gutterSVG.find('#prevLineArrow').show();
1310-
}
1311-
1312-
}
1313-
else {
1314-
gutterSVG.find('#prevLineArrow').hide();
1315-
}
1316-
1317-
if (curLineNumber) {
1318-
var cla = myViz.domRootD3.select('#curLineArrow');
1319-
var translateCurCmd = 'translate(0, ' + (((curLineNumber - 1) * myViz.codeRowHeight) + myViz.arrowOffsetY + curVerticalNudge) + ')';
1320-
1321-
if (smoothTransition) {
1322-
cla
1323-
.transition()
1324-
.delay(200)
1325-
.duration(250)
1326-
.attr('transform', translateCurCmd);
1327-
}
1328-
else {
1329-
cla.attr('transform', translateCurCmd);
1330-
}
1331-
1332-
gutterSVG.find('#curLineArrow').show();
1333-
}
1334-
else {
1335-
gutterSVG.find('#curLineArrow').hide();
1317+
if (myViz.params.arrowLines) {
1318+
if (prevLineNumber) {
1319+
var pla = myViz.domRootD3.select('#prevLineArrow');
1320+
var translatePrevCmd = 'translate(0, ' + (((prevLineNumber - 1) * myViz.codeRowHeight) + myViz.arrowOffsetY + prevVerticalNudge) + ')';
1321+
1322+
if (smoothTransition) {
1323+
pla
1324+
.transition()
1325+
.duration(200)
1326+
.attr('fill', 'white')
1327+
.each('end', function() {
1328+
pla
1329+
.attr('transform', translatePrevCmd)
1330+
.attr('fill', lightArrowColor);
1331+
1332+
gutterSVG.find('#prevLineArrow').show(); // show at the end to avoid flickering
1333+
});
1334+
}
1335+
else {
1336+
pla.attr('transform', translatePrevCmd)
1337+
gutterSVG.find('#prevLineArrow').show();
1338+
}
1339+
1340+
}
1341+
else {
1342+
gutterSVG.find('#prevLineArrow').hide();
1343+
}
1344+
1345+
if (curLineNumber) {
1346+
var cla = myViz.domRootD3.select('#curLineArrow');
1347+
var translateCurCmd = 'translate(0, ' + (((curLineNumber - 1) * myViz.codeRowHeight) + myViz.arrowOffsetY + curVerticalNudge) + ')';
1348+
1349+
if (smoothTransition) {
1350+
cla
1351+
.transition()
1352+
.delay(200)
1353+
.duration(250)
1354+
.attr('transform', translateCurCmd);
1355+
}
1356+
else {
1357+
cla.attr('transform', translateCurCmd);
1358+
}
1359+
1360+
gutterSVG.find('#curLineArrow').show();
1361+
}
1362+
else {
1363+
gutterSVG.find('#curLineArrow').hide();
1364+
}
13361365
}
13371366

1338-
13391367
myViz.domRootD3.selectAll('#pyCodeOutputDiv td.cod')
13401368
.style('border-top', function(d) {
13411369
if (hasError && (d.lineNumber == curEntry.line)) {
@@ -1382,12 +1410,22 @@ ExecutionVisualizer.prototype.updateOutput = function(smoothTransition) {
13821410
pcod.animate({scrollTop: (ST + (LO - PO - (Math.round(H / 2))))}, 300);
13831411
}
13841412

1413+
if (myViz.params.highlightLines) {
1414+
myViz.domRoot.find('#pyCodeOutputDiv td.cod').removeClass('highlight-prev');
1415+
myViz.domRoot.find('#pyCodeOutputDiv td.cod').removeClass('highlight-curr');
1416+
if (curLineNumber)
1417+
myViz.domRoot.find('#'+myViz.generateID('cod'+curLineNumber)).addClass('highlight-curr');
1418+
if (prevLineNumber)
1419+
myViz.domRoot.find('#'+myViz.generateID('cod'+prevLineNumber)).addClass('highlight-prev');
1420+
}
1421+
13851422

13861423
// smoothly scroll code display
13871424
if (!isOutputLineVisible(curEntry.line)) {
13881425
scrollCodeOutputToLine(curEntry.line);
13891426
}
1390-
}
1427+
1428+
} // end of highlightCodeLine
13911429

13921430

13931431
// render code output:

0 commit comments

Comments
 (0)