Skip to content

Commit b06706f

Browse files
author
Philip Guo
committed
more preparation for annotation bubbles
1 parent c4880ea commit b06706f

3 files changed

Lines changed: 208 additions & 10 deletions

File tree

‎v3/css/pytutor.css‎

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,3 +514,129 @@ div.ExecutionVisualizer .ui-slider .ui-slider-handle {
514514
border: 1px solid #999;
515515
}
516516

517+
518+
/* for annotation bubbles */
519+
520+
/* For styling tricks, see: http://css-tricks.com/textarea-tricks/ */
521+
textarea.bubbleInputText {
522+
border: 1px solid #ccc;
523+
outline: none;
524+
overflow: auto; /* to look pretty on IE */
525+
526+
/* make sure textarea doesn't grow and stretch the enclosing bubble */
527+
resize: none;
528+
width: 225px;
529+
max-width: 225px;
530+
height: 35px;
531+
max-height: 35px;
532+
}
533+
534+
535+
.ui-tooltip-pgbootstrap,
536+
textarea.bubbleInputText {
537+
font-family: verdana, arial, helvetica, sans-serif;
538+
font-size: 9pt;
539+
line-height: 1.3em;
540+
}
541+
542+
543+
/* modified version of Twitter bootstrap style by Philip Guo */
544+
.ui-tooltip-pgbootstrap{
545+
color: #333;
546+
background-color: #ffffff;
547+
548+
max-width: 250px;
549+
min-width: 10px;
550+
551+
border: 2px solid #4284D3;
552+
553+
cursor: pointer;
554+
555+
*border-right-width: 2px;
556+
*border-bottom-width: 2px;
557+
558+
-webkit-border-radius: 5px;
559+
-moz-border-radius: 5px;
560+
border-radius: 5px;
561+
562+
/* way too poofy ...
563+
-webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
564+
-moz-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
565+
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
566+
*/
567+
568+
-webkit-box-shadow: 2px 2px 3px 0px rgba(0, 0, 0, 0.2);
569+
-moz-box-shadow: 2px 2px 3px 0px rgba(0, 0, 0, 0.2);
570+
box-shadow: 2px 2px 3px 0px rgba(0, 0, 0, 0.2);
571+
572+
-webkit-background-clip: padding-box;
573+
-moz-background-clip: padding;
574+
background-clip: padding-box;
575+
}
576+
577+
.ui-tooltip-pgbootstrap .ui-tooltip-titlebar{
578+
font-size: 18px;
579+
line-height: 22px;
580+
581+
border-bottom: 1px solid #ccc;
582+
background-color: transparent;
583+
}
584+
585+
.ui-tooltip-pgbootstrap .ui-tooltip-content{
586+
padding: 5px /* 5px is minimum or else it might look ugly */ 8px;
587+
}
588+
589+
590+
.ui-tooltip-pgbootstrap .ui-tooltip-titlebar .ui-state-default{
591+
right: 9px; top: 49%;
592+
border-style: none;
593+
}
594+
595+
.ui-tooltip-pgbootstrap .ui-tooltip-icon{
596+
background: white;
597+
}
598+
599+
.ui-tooltip-pgbootstrap .ui-tooltip-icon .ui-icon{
600+
width: auto;
601+
height: auto;
602+
float: right;
603+
font-size: 20px;
604+
font-weight: bold;
605+
line-height: 18px;
606+
color: #000000;
607+
text-shadow: 0 1px 0 #ffffff;
608+
opacity: 0.2;
609+
filter: alpha(opacity=20);
610+
}
611+
612+
.ui-tooltip-pgbootstrap .ui-tooltip-icon .ui-icon:hover{
613+
color: #000000;
614+
text-decoration: none;
615+
cursor: pointer;
616+
opacity: 0.4;
617+
filter: alpha(opacity=40);
618+
}
619+
620+
621+
/* Add rounded corners to your tooltips in: FF3+, Chrome 2+, Opera 10.6+, IE9+, Safari 2+ */
622+
.ui-tooltip-pgbootstrap{
623+
-moz-border-radius: 5px;
624+
-webkit-border-radius: 5px;
625+
border-radius: 5px;
626+
}
627+
628+
629+
.ui-tooltip-pgbootstrap-stub{
630+
border: 1px solid #999;
631+
632+
/*
633+
-webkit-box-shadow: none;
634+
-moz-box-shadow: none;
635+
box-shadow: none;
636+
*/
637+
}
638+
639+
.ui-tooltip-pgbootstrap-stub .ui-tooltip-content{
640+
padding: 6px 9px;
641+
}
642+

‎v3/js/opt-frontend.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ $(document).ready(function() {
190190
myVisualizer = new ExecutionVisualizer('pyOutputPane',
191191
dataFromBackend,
192192
{startingInstruction: startingInstruction,
193-
updateOutputCallback: function() {$('#urlOutput,#embedCodeOutput').val('');}
193+
updateOutputCallback: function() {$('#urlOutput,#embedCodeOutput').val('');},
194+
allowEditAnnotations: true,
194195
});
195196

196197

‎v3/js/pytutor.js‎

Lines changed: 80 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,31 +288,25 @@ ExecutionVisualizer.prototype.render = function() {
288288
}
289289

290290
myViz.editAnnotationMode = false;
291-
myViz.allAnnotationBubbles = [];
292291

293292
if (this.allowEditAnnotations) {
294293
var ab = this.domRoot.find('#annotateBtn');
295294

296295
ab.click(function() {
297296
if (myViz.editAnnotationMode) {
298297
ab.html('(rendering ...)');
299-
$.each(myViz.allAnnotationBubbles, function(i, e) {
300-
e.enterViewMode();
301-
});
298+
myViz.enterViewAnnotationsMode();
302299

303300
myViz.domRoot.find("#jmpFirstInstr,#jmpLastInstr,#jmpStepBack,#jmpStepFwd,#executionSlider").show();
304301
ab.html('Annotate this step');
305302
}
306303
else {
307304
ab.html('(rendering ...)');
308-
$.each(myViz.allAnnotationBubbles, function(i, e) {
309-
e.enterEditMode();
310-
});
305+
myViz.enterEditAnnotationsMode();
311306

312307
myViz.domRoot.find("#jmpFirstInstr,#jmpLastInstr,#jmpStepBack,#jmpStepFwd,#executionSlider").hide();
313308
ab.html('Done annotating');
314309
}
315-
myViz.editAnnotationMode = !myViz.editAnnotationMode;
316310
});
317311
}
318312
else {
@@ -435,6 +429,79 @@ ExecutionVisualizer.prototype.render = function() {
435429
this.hasRendered = true;
436430
}
437431

432+
ExecutionVisualizer.prototype.enterViewAnnotationsMode = function() {
433+
this.editAnnotationMode = false;
434+
435+
// TODO: grab all annotations bubbles from current trace entry
436+
/*
437+
$.each(myViz.allAnnotationBubbles, function(i, e) {
438+
e.enterViewMode();
439+
});
440+
*/
441+
}
442+
443+
ExecutionVisualizer.prototype.enterEditAnnotationsMode = function() {
444+
// TODO: check for memory leaks!!!
445+
446+
this.editAnnotationMode = true;
447+
448+
var myViz = this;
449+
450+
var codelineIDs = [];
451+
$.each(this.domRoot.find('#pyCodeOutput .cod'), function(i, e) {
452+
codelineIDs.push($(e).attr('id'));
453+
});
454+
455+
var heapObjectIDs = [];
456+
$.each(this.domRoot.find('.heapObject'), function(i, e) {
457+
heapObjectIDs.push($(e).attr('id'));
458+
});
459+
460+
var variableIDs = [];
461+
$.each(this.domRoot.find('.variableTr'), function(i, e) {
462+
variableIDs.push($(e).attr('id'));
463+
});
464+
465+
var frameIDs = [];
466+
$.each(this.domRoot.find('.stackFrame'), function(i, e) {
467+
frameIDs.push($(e).attr('id'));
468+
});
469+
470+
471+
var allAnnotationBubbles = [];
472+
473+
$.each(codelineIDs, function(i, e) {
474+
allAnnotationBubbles.push(new AnnotationBubble(myViz, 'codeline', e));
475+
});
476+
477+
$.each(heapObjectIDs, function(i, e) {
478+
allAnnotationBubbles.push(new AnnotationBubble(myViz, 'object', e));
479+
});
480+
481+
$.each(variableIDs, function(i, e) {
482+
allAnnotationBubbles.push(new AnnotationBubble(myViz, 'variable', e));
483+
});
484+
485+
$.each(frameIDs, function(i, e) {
486+
allAnnotationBubbles.push(new AnnotationBubble(myViz, 'frame', e));
487+
});
488+
489+
//this.allAnnotationBubbles = allAnnotationBubbles;
490+
491+
// TODO: this is badly placed ...
492+
this.domRoot.find('#pyCodeOutputDiv').scroll(function() {
493+
$.each(allAnnotationBubbles, function(i, e) {
494+
if (e.type == 'codeline') {
495+
e.redrawCodelineBubble();
496+
}
497+
});
498+
});
499+
500+
$.each(allAnnotationBubbles, function(i, e) {
501+
e.enterEditMode();
502+
});
503+
}
504+
438505

439506
// find the previous/next breakpoint to c or return -1 if it doesn't exist
440507
ExecutionVisualizer.prototype.findPrevBreakpoint = function() {
@@ -1875,6 +1942,7 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
18751942
globalVarTable
18761943
.enter()
18771944
.append('tr')
1945+
.attr('class', 'variableTr')
18781946
.attr('id', function(d, i) {
18791947
return myViz.generateID(varnameToCssID('global__' + d + '_tr')); // make globally unique (within the page)
18801948
});
@@ -2025,6 +2093,7 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
20252093
stackVarTable
20262094
.enter()
20272095
.append('tr')
2096+
.attr('class', 'variableTr')
20282097
.attr('id', function(d, i) {
20292098
return myViz.generateID(varnameToCssID(d.frame.unique_hash + '__' + d.varname + '_tr')); // make globally unique (within the page)
20302099
});
@@ -2400,7 +2469,9 @@ function createSpeechBubble(domID, my, at, htmlContent, isInput) {
24002469
// (as determined by the 'type' param)
24012470
//
24022471
// domID is the ID of the element to attach to (without the leading '#' sign)
2403-
function AnnotationBubble(type, domID) {
2472+
function AnnotationBubble(parentViz, type, domID) {
2473+
this.parentViz = parentViz;
2474+
24042475
this.domID = domID;
24052476
this.hashID = '#' + domID;
24062477

0 commit comments

Comments
 (0)