Skip to content

Commit 14f54b7

Browse files
author
Philip Guo
committed
started some refactorings to prepare for Online Python Tutor 2.0!
1 parent 83a1d9a commit 14f54b7

4 files changed

Lines changed: 40 additions & 8 deletions

File tree

edu-python.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ table.listTbl td.listElt {
274274
}
275275

276276
table.tupleTbl {
277-
/*background-color: #dddddd;*/ /* must match .frameDataViz background-color */
277+
background-color: #dddddd; /* must match .frameDataViz background-color */
278278
border-spacing: 0px;
279279
color: black;
280280

edu-python.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,27 @@ function updateOutput() {
232232
$("#pyStdout").scrollTop($("#pyStdout").attr('scrollHeight'));
233233

234234

235+
// finally, render all the data structures!!!
236+
renderDataStructures(curEntry, "#dataViz");
237+
}
238+
239+
// Renders the current trace entry (curEntry) into the div named by vizDiv
240+
function renderDataStructures(curEntry, vizDiv) {
241+
renderDataStructuresVersion1(curEntry, vizDiv);
242+
243+
// Version 2.0 forthcoming!
244+
//renderDataStructuresVersion2(curEntry, vizDiv);
245+
}
246+
247+
248+
// The ORIGINAL "1.0" version of renderDataStructures, which renders
249+
// variables and values INLINE within each stack frame without any
250+
// explicit representation of data structure aliasing.
251+
//
252+
// This version was originally created in January 2010
253+
function renderDataStructuresVersion1(curEntry, vizDiv) {
235254
// render data structures:
236-
$("#dataViz").html(''); // CLEAR IT!
255+
$(vizDiv).html(''); // CLEAR IT!
237256

238257

239258
// render locals on stack:
@@ -242,7 +261,7 @@ function updateOutput() {
242261
var funcName = htmlspecialchars(frame[0]); // might contain '<' or '>' for weird names like <genexpr>
243262
var localVars = frame[1];
244263

245-
$("#dataViz").append('<div class="vizFrame">Local variables for <span style="font-family: Andale mono, monospace;">' + funcName + '</span>:</div>');
264+
$(vizDiv).append('<div class="vizFrame">Local variables for <span style="font-family: Andale mono, monospace;">' + funcName + '</span>:</div>');
246265

247266
// render locals in alphabetical order for tidiness:
248267
var orderedVarnames = [];
@@ -255,7 +274,7 @@ function updateOutput() {
255274
orderedVarnames.sort();
256275

257276
if (orderedVarnames.length > 0) {
258-
$("#dataViz .vizFrame:last").append('<br/><table class="frameDataViz"></table>');
277+
$(vizDiv + " .vizFrame:last").append('<br/><table class="frameDataViz"></table>');
259278
var tbl = $("#pyOutputPane table:last");
260279
$.each(orderedVarnames, function(i, varname) {
261280
var val = localVars[varname];
@@ -274,15 +293,15 @@ function updateOutput() {
274293
tbl.find("tr:last").find("td.val").css('border-bottom', '0px');
275294
}
276295
else {
277-
$("#dataViz .vizFrame:last").append(' <i>none</i>');
296+
$(vizDiv + " .vizFrame:last").append(' <i>none</i>');
278297
}
279298
});
280299
}
281300

282301

283302
// render globals LAST:
284303

285-
$("#dataViz").append('<div class="vizFrame">Global variables:</div>');
304+
$(vizDiv).append('<div class="vizFrame">Global variables:</div>');
286305

287306
var nonEmptyGlobals = false;
288307
var curGlobalFields = {};
@@ -296,7 +315,7 @@ function updateOutput() {
296315
}
297316

298317
if (nonEmptyGlobals) {
299-
$("#dataViz .vizFrame:last").append('<br/><table class="frameDataViz"></table>');
318+
$(vizDiv + " .vizFrame:last").append('<br/><table class="frameDataViz"></table>');
300319

301320
// render all global variables IN THE ORDER they were created by the program,
302321
// in order to ensure continuity:
@@ -349,11 +368,21 @@ function updateOutput() {
349368
tbl.find("tr:last").find("td.val").css('border-bottom', '0px');
350369
}
351370
else {
352-
$("#dataViz .vizFrame:last").append(' <i>none</i>');
371+
$(vizDiv + " .vizFrame:last").append(' <i>none</i>');
353372
}
354373

355374
}
356375

376+
377+
// The "2.0" version of renderDataStructures, which renders variables in
378+
// a stack and values in a separate heap, with data structure aliasing
379+
// explicitly represented via line connectors.
380+
//
381+
// This version was originally created in September 2011
382+
function renderDataStructuresVersion2(curEntry, vizDiv) {
383+
384+
}
385+
357386
// render the JS data object obj inside of jDomElt,
358387
// which is a jQuery wrapped DOM object
359388
// (obj is in a format encoded by cgi-bin/pg_encoder.py)

index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
<script type="text/javascript" src="jquery.autogrow.js"></script>
5050
-->
5151

52+
<!-- jsPlumb library for rendering connectors -->
53+
<script type="text/javascript" src="jquery.jsPlumb-1.3.3-all-min.js "></script>
5254

5355
<!-- my own code -->
5456
<script type="text/javascript" src="edu-python.js"></script>

jquery.jsPlumb-1.3.3-all-min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)