Skip to content

Commit 088550a

Browse files
committed
added custom labels for JS
1 parent fe6763f commit 088550a

3 files changed

Lines changed: 26 additions & 8 deletions

File tree

‎v4-cokapi/backends/javascript/jslogger.js‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ regarding the 'handle_' field of serialized objects ...
4646
4747
TODOs:
4848
49-
- get the frontend to display 'instance' as 'object', and 'list' as 'array'
50-
5149
5250
Low-priority TODOs:
5351

‎v4-cokapi/frontends/js/cokapi-frontend.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ function executeCode(forceStartingInstr, forceRawInputLst) {
5252
}
5353

5454
var backend_script = null;
55-
if ($('#pythonVersionSelector').val() == '2') {
55+
if ($('#pythonVersionSelector').val() === '2') {
5656
backend_script = '/exec_py2';
5757
}
58-
else if ($('#pythonVersionSelector').val() == '3') {
58+
else if ($('#pythonVersionSelector').val() === '3') {
5959
backend_script = '/exec_py3'
6060
}
61-
else if ($('#pythonVersionSelector').val() == 'js') {
61+
else if ($('#pythonVersionSelector').val() === 'js') {
6262
backend_script = '/exec_js';
6363
}
6464
else {
@@ -81,6 +81,7 @@ function executeCode(forceStartingInstr, forceRawInputLst) {
8181
textualMemoryLabels: ($('#textualMemoryLabelsSelector').val() == 'true'),
8282
showOnlyOutputs: ($('#showOnlyOutputsSelector').val() == 'true'),
8383
executeCodeWithRawInputFunc: executeCodeWithRawInput,
84+
lang: ($('#pythonVersionSelector').val() === 'js') ? 'js' : undefined,
8485

8586
// always use the same visualizer ID for all
8687
// instantiated ExecutionVisualizer objects,

‎v4-cokapi/frontends/js/pytutor.js‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ var curVisualizerID = 1; // global to uniquely identify each ExecutionVisualizer
115115
// granularity instead of line-level granularity (HIGHLY EXPERIMENTAL!)
116116
// hideCode - hide the code display and show only the data structure viz
117117
// tabularView - render a tabular view of ALL steps at once (EXPERIMENTAL)
118+
// lang - to render labels in a style appropriate for other languages.
119+
// e.g., 'js' for JavaScript, 'java' for Java [default is Python]
118120
// debugMode - some extra debugging printouts
119121
function ExecutionVisualizer(domRootID, dat, params) {
120122
this.curInputCode = dat.code.rtrim(); // kill trailing spaces
@@ -3215,10 +3217,10 @@ function(objID, stepNum, d3DomElement, isTopLevel) {
32153217

32163218
assert(obj.length >= 1);
32173219
if (obj.length == 1) {
3218-
d3DomElement.append('<div class="typeLabel">' + typeLabelPrefix + 'empty ' + label + '</div>');
3220+
d3DomElement.append('<div class="typeLabel">' + typeLabelPrefix + 'empty ' + myViz.getRealLabel(label) + '</div>');
32193221
}
32203222
else {
3221-
d3DomElement.append('<div class="typeLabel">' + typeLabelPrefix + label + '</div>');
3223+
d3DomElement.append('<div class="typeLabel">' + typeLabelPrefix + myViz.getRealLabel(label) + '</div>');
32223224
d3DomElement.append('<table class="' + label + 'Tbl"></table>');
32233225
var tbl = d3DomElement.children('table');
32243226

@@ -3292,7 +3294,11 @@ function(objID, stepNum, d3DomElement, isTopLevel) {
32923294
assert(obj.length >= headerLength);
32933295

32943296
if (isInstance) {
3295-
d3DomElement.append('<div class="typeLabel">' + typeLabelPrefix + obj[1] + ' instance</div>');
3297+
if (obj.length === headerLength) {
3298+
d3DomElement.append('<div class="typeLabel">' + typeLabelPrefix + obj[1] + 'empty ' + myViz.getRealLabel('instance') + '</div>');
3299+
} else {
3300+
d3DomElement.append('<div class="typeLabel">' + typeLabelPrefix + obj[1] + ' ' + myViz.getRealLabel('instance') + '</div>');
3301+
}
32963302
}
32973303
else {
32983304
var superclassStr = '';
@@ -3471,6 +3477,19 @@ ExecutionVisualizer.prototype.redrawConnectors = function() {
34713477
}
34723478

34733479

3480+
ExecutionVisualizer.prototype.getRealLabel = function(label) {
3481+
if (this.params.lang === 'js') {
3482+
if (label === 'list') {
3483+
return 'array';
3484+
} else if (label === 'instance') {
3485+
return 'object';
3486+
}
3487+
} else {
3488+
return label;
3489+
}
3490+
};
3491+
3492+
34743493
// Utilities
34753494

34763495

0 commit comments

Comments
 (0)