Skip to content

Commit 173ee30

Browse files
author
Philip Guo
committed
got more annotations stuff workin'
1 parent e323764 commit 173ee30

2 files changed

Lines changed: 53 additions & 15 deletions

File tree

‎v3/css/pytutor.css‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,12 @@ div.ExecutionVisualizer div#annotateLinkDiv {
155155
}
156156

157157
div.ExecutionVisualizer div#stepAnnotationDiv {
158-
margin-bottom: 20px;
158+
margin-bottom: 12px;
159159
}
160160

161-
div.ExecutionVisualizer textarea#stepAnnotation {
161+
div.ExecutionVisualizer textarea#stepAnnotationEditor {
162162
border: 1px solid #999999;
163-
font-size: 12pt;
164163
padding: 4px;
165-
font-family: Andale mono, monospace;
166164

167165
overflow: auto; /* to look pretty on IE */
168166
/* make sure textarea doesn't grow and stretch */
@@ -659,3 +657,10 @@ textarea.bubbleInputText {
659657
padding: 6px 9px;
660658
}
661659

660+
661+
.annotationText {
662+
font-family: verdana, arial, helvetica, sans-serif;
663+
font-size: 11pt;
664+
line-height: 1.5em;
665+
}
666+

‎v3/js/pytutor.js‎

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,11 @@ ExecutionVisualizer.prototype.render = function() {
198198
</div>\
199199
<div id="errorOutput"/>\
200200
<div id="legendDiv"/>\
201+
<div id="stepAnnotationDiv">\
202+
<textarea class="annotationText" id="stepAnnotationEditor" cols="60" rows="3"></textarea>\
203+
<div class="annotationText" id="stepAnnotationViewer"></div>\
204+
</div>\
201205
<div id="annotateLinkDiv"><button id="annotateBtn" type="button">Annotate this step</button></div>\
202-
<div id="stepAnnotationDiv"><textarea id="stepAnnotation" cols="50" rows="3" wrap="off"></textarea></div>\
203206
<div id="progOutputs">\
204207
Program output:<br/>\
205208
<textarea id="pyStdout" cols="50" rows="10" wrap="off" readonly></textarea>\
@@ -272,7 +275,7 @@ ExecutionVisualizer.prototype.render = function() {
272275
this.allowEditAnnotations = false;
273276
}
274277

275-
this.domRoot.find('#stepAnnotationDiv').hide();
278+
this.domRoot.find('#stepAnnotationEditor').hide();
276279

277280

278281
if (this.params.embeddedMode) {
@@ -299,15 +302,15 @@ ExecutionVisualizer.prototype.render = function() {
299302
if (myViz.editAnnotationMode) {
300303
myViz.enterViewAnnotationsMode();
301304

302-
myViz.domRoot.find("#jmpFirstInstr,#jmpLastInstr,#jmpStepBack,#jmpStepFwd,#executionSlider,#editCodeLinkDiv").show();
303-
myViz.domRoot.find('#stepAnnotationDiv').hide();
305+
myViz.domRoot.find("#jmpFirstInstr,#jmpLastInstr,#jmpStepBack,#jmpStepFwd,#executionSlider,#editCodeLinkDiv,#stepAnnotationViewer").show();
306+
myViz.domRoot.find('#stepAnnotationEditor').hide();
304307
ab.html('Annotate this step');
305308
}
306309
else {
307310
myViz.enterEditAnnotationsMode();
308311

309-
myViz.domRoot.find("#jmpFirstInstr,#jmpLastInstr,#jmpStepBack,#jmpStepFwd,#executionSlider,#editCodeLinkDiv").hide();
310-
myViz.domRoot.find('#stepAnnotationDiv').show();
312+
myViz.domRoot.find("#jmpFirstInstr,#jmpLastInstr,#jmpStepBack,#jmpStepFwd,#executionSlider,#editCodeLinkDiv,#stepAnnotationViewer").hide();
313+
myViz.domRoot.find('#stepAnnotationEditor').show();
311314
ab.html('Done annotating');
312315
}
313316
});
@@ -449,6 +452,18 @@ ExecutionVisualizer.prototype.destroyAllAnnotationBubbles = function() {
449452
myViz.allAnnotationBubbles = null;
450453
}
451454

455+
ExecutionVisualizer.prototype.initStepAnnotation = function() {
456+
var curEntry = this.curTrace[this.curInstr];
457+
if (curEntry.stepAnnotation) {
458+
this.domRoot.find("#stepAnnotationViewer").html(curEntry.stepAnnotation);
459+
this.domRoot.find("#stepAnnotationEditor").val(curEntry.stepAnnotation);
460+
}
461+
else {
462+
this.domRoot.find("#stepAnnotationViewer").html('');
463+
this.domRoot.find("#stepAnnotationEditor").val('');
464+
}
465+
}
466+
452467
ExecutionVisualizer.prototype.initAllAnnotationBubbles = function() {
453468
var myViz = this;
454469

@@ -505,13 +520,13 @@ ExecutionVisualizer.prototype.enterViewAnnotationsMode = function() {
505520
var myViz = this;
506521

507522
if (!myViz.allAnnotationBubbles) {
508-
if (curEntry.annotations) {
523+
if (curEntry.bubbleAnnotations) {
509524
// If there is an existing annotations object, then initiate all annotations bubbles
510525
// and display them in 'View' mode
511526
myViz.initAllAnnotationBubbles();
512527

513528
$.each(myViz.allAnnotationBubbles, function(i, e) {
514-
var txt = curEntry.annotations[e.domID];
529+
var txt = curEntry.bubbleAnnotations[e.domID];
515530
if (txt) {
516531
e.preseedText(txt);
517532
}
@@ -535,9 +550,18 @@ ExecutionVisualizer.prototype.enterViewAnnotationsMode = function() {
535550
// directly mapping domID -> text.
536551
//
537552
// NB: This scheme can break if the functions for generating domIDs are altered.
538-
curEntry.annotations = curAnnotations;
553+
curEntry.bubbleAnnotations = curAnnotations;
539554
}
540555

556+
var stepAnnotationEditorVal = myViz.domRoot.find("#stepAnnotationEditor").val().trim();
557+
if (stepAnnotationEditorVal) {
558+
curEntry.stepAnnotation = stepAnnotationEditorVal;
559+
}
560+
else {
561+
delete curEntry.stepAnnotation; // go as far as to DELETE this field entirely
562+
}
563+
564+
myViz.initStepAnnotation();
541565
}
542566

543567
ExecutionVisualizer.prototype.enterEditAnnotationsMode = function() {
@@ -546,6 +570,8 @@ ExecutionVisualizer.prototype.enterEditAnnotationsMode = function() {
546570
// TODO: check for memory leaks!!!
547571
var myViz = this;
548572

573+
var curEntry = this.curTrace[this.curInstr];
574+
549575
if (!myViz.allAnnotationBubbles) {
550576
myViz.initAllAnnotationBubbles();
551577
}
@@ -555,7 +581,12 @@ ExecutionVisualizer.prototype.enterEditAnnotationsMode = function() {
555581
});
556582

557583

558-
//myViz.domRoot.find("#stepAnnotation").val(<TODO: handle me>);
584+
if (curEntry.stepAnnotation) {
585+
myViz.domRoot.find("#stepAnnotationEditor").val(curEntry.stepAnnotation);
586+
}
587+
else {
588+
myViz.domRoot.find("#stepAnnotationEditor").val('');
589+
}
559590
}
560591

561592

@@ -961,7 +992,9 @@ ExecutionVisualizer.prototype.updateOutput = function(smoothTransition) {
961992
return;
962993
}
963994

964-
myViz.destroyAllAnnotationBubbles(); // TODO: is this a good place to put this function call?
995+
// crucial resets for annotations (TODO: kludgy)
996+
myViz.destroyAllAnnotationBubbles();
997+
myViz.initStepAnnotation();
965998

966999

9671000
var prevDataVizHeight = myViz.domRoot.find('#dataViz').height();

0 commit comments

Comments
 (0)