Skip to content

Commit 8f39ac7

Browse files
author
Philip Guo
committed
added embeddedMode param to ExecutionVisualizer
1 parent 0b563fc commit 8f39ac7

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

‎v3/js/pytutor.js‎

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ var curVisualizerID = 1; // global to uniquely identify each ExecutionVisualizer
5656
// hideOutput - hide "Program output" and "Generate URL" displays
5757
// codeDivHeight - maximum height of #pyCodeOutputDiv (in pixels)
5858
// editCodeBaseURL - the base URL to visit when the user clicks 'Edit code'
59+
// embeddedMode - make the widget narrower horizontally and disable breakpoints
5960
function ExecutionVisualizer(domRootID, dat, params) {
6061
this.curInputCode = dat.code.rtrim(); // kill trailing spaces
6162
this.curTrace = dat.trace;
@@ -159,9 +160,9 @@ ExecutionVisualizer.prototype.render = function() {
159160
<div id="executionSliderFooter"/>\
160161
<div id="vcrControls">\
161162
<button id="jmpFirstInstr", type="button">&lt;&lt; First</button>\
162-
<button id="jmpStepBack", type="button">&lt; Back</button>\
163+
<button id="jmpStepBack", type="button">&lt; Prev</button>\
163164
<span id="curInstr">Step ? of ?</span>\
164-
<button id="jmpStepFwd", type="button">Forward &gt;</button>\
165+
<button id="jmpStepFwd", type="button">Next &gt;</button>\
165166
<button id="jmpLastInstr", type="button">Last &gt;&gt;</button>\
166167
</div>\
167168
<div id="errorOutput"/>\
@@ -207,6 +208,23 @@ ExecutionVisualizer.prototype.render = function() {
207208
}
208209

209210

211+
if (this.params.embeddedMode) {
212+
this.params.hideOutput = true; // put this before hideOutput handler
213+
214+
this.domRoot.find('#executionSlider')
215+
.css('width', '320px')
216+
.css('margin', '6px auto');
217+
218+
this.domRoot.find('#executionSliderCaption').hide();
219+
this.domRoot.find('#jmpFirstInstr').hide();
220+
this.domRoot.find('#jmpLastInstr').hide();
221+
222+
this.domRoot.find('#pyCodeOutputDiv')
223+
.css('max-width', '350px');
224+
225+
}
226+
227+
210228
// create a persistent globals frame
211229
// (note that we need to keep #globals_area separate from #stack for d3 to work its magic)
212230
this.domRoot.find("#globals_area").append('<div class="stackFrame" id="'
@@ -648,7 +666,7 @@ ExecutionVisualizer.prototype.renderPyCodeOutput = function() {
648666
myViz.domRoot.find('#pyCodeOutputDiv').empty();
649667

650668
// maps this.codeOutputLines to both table columns
651-
this.domRootD3.select('#pyCodeOutputDiv')
669+
var codeOutputD3 = this.domRootD3.select('#pyCodeOutputDiv')
652670
.append('table')
653671
.attr('id', 'pyCodeOutput')
654672
.selectAll('tr')
@@ -658,10 +676,12 @@ ExecutionVisualizer.prototype.renderPyCodeOutput = function() {
658676
.data(function(d, i){return [d, d] /* map full data item down both columns */;})
659677
.enter().append('td')
660678
.attr('class', function(d, i) {return (i == 0) ? 'lineNo' : 'cod';})
661-
.style('cursor', function(d, i) {return 'pointer'})
662679
.html(function(d, i) {
663680
return (i == 0) ? d.lineNumber : htmlspecialchars(d.text);
664-
})
681+
});
682+
683+
if (!this.params.embeddedMode) {
684+
codeOutputD3.style('cursor', function(d, i) {return 'pointer'})
665685
.on('mouseover', function() {
666686
setHoverBreakpoint(this);
667687
})
@@ -696,8 +716,9 @@ ExecutionVisualizer.prototype.renderPyCodeOutput = function() {
696716
}
697717
});
698718

719+
renderSliderBreakpoints(); // renders breakpoints written in as code comments
720+
}
699721

700-
renderSliderBreakpoints(); // renders breakpoints written in as code comments
701722
}
702723

703724

0 commit comments

Comments
 (0)