@@ -39,18 +39,13 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3939 File "<string>", line 1
4040 x~=1
4141 ^
42- - for slower frontends, add an unobtrusive "running ..." indicator
43-
4442- make Ace editor resizable width-wise using jQuery resizable
4543 (stackoverflow has some tips for how to do that)
4644
4745- support pasting in code via URL, which will be important for
4846 transporting the user from regular OPT to live mode
4947 - add "Generate permanent link" button, but no need for iframe embed btn
5048
51- - make sure server logging works properly, esp. session and user IDs,
52- and slider interactions
53-
5449- if these Ace enhancements look good, then I can also use them for
5550 Codeopticon as well!
5651
@@ -103,6 +98,17 @@ var prevVisualizer = null; // the visualizer object from the previous execution
10398
10499var aceEditorWidth = '600px' ;
105100
101+ var hasSyntaxError = false ;
102+ function toggleSyntaxError ( x ) {
103+ if ( x ) {
104+ hasSyntaxError = true ;
105+ $ ( "#dataViz,#curInstr" ) . addClass ( 'dimmed' ) ; // dim the visualization until we fix the error
106+ } else {
107+ hasSyntaxError = false ;
108+ $ ( "#dataViz,#curInstr" ) . removeClass ( 'dimmed' ) ; // un-dim the visualization
109+ }
110+ }
111+
106112var allMarkerIds = [ ] ;
107113
108114function removeAllGutterDecorations ( ) {
@@ -130,7 +136,7 @@ function updateStepLabels() {
130136 var isLastInstr = myVisualizer . curInstr === ( totalInstrs - 1 ) ;
131137 if ( isLastInstr ) {
132138 if ( myVisualizer . promptForUserInput || myVisualizer . promptForMouseInput ) {
133- $ ( "#curInstr" ) . html ( '<b>< font color="' + brightRed + '">Enter user input: </font></b >' ) ;
139+ $ ( "#curInstr" ) . html ( '<font color="' + brightRed + '">input/raw_input not supported in live editor </font>' ) ;
134140 } else if ( myVisualizer . instrLimitReached ) {
135141 $ ( "#curInstr" ) . html ( "Instruction limit reached (" + String ( totalInstrs - 1 ) + " steps)" ) ;
136142 } else {
@@ -185,7 +191,7 @@ function optliveFinishSuccessfulExecution() {
185191 $ ( "#pyOutputPane" ) . show ( ) ;
186192 doneExecutingCode ( ) ;
187193
188- $ ( "#dataViz,#curInstr" ) . removeClass ( 'dimmed' ) ; // un-dim the visualization
194+ toggleSyntaxError ( false ) ;
189195
190196 // set up execution slider, code inspired by pytutor.js:
191197 var sliderDiv = $ ( '#executionSlider' ) ;
@@ -208,15 +214,6 @@ function optliveFinishSuccessfulExecution() {
208214 }
209215 } ) ;
210216
211- myVisualizer . add_pytutor_hook (
212- "end_updateOutput" ,
213- function ( args ) {
214- // PROGRAMMATICALLY change the value, so evt.originalEvent should be undefined
215- $ ( '#executionSlider' ) . slider ( 'value' , args . myViz . curInstr ) ;
216- return [ false ] ;
217- }
218- ) ;
219-
220217 // do this AFTER making #pyOutputPane visible, or else
221218 // jsPlumb connectors won't render properly
222219
@@ -239,16 +236,67 @@ function optliveFinishSuccessfulExecution() {
239236 }
240237
241238 updateStepLabels ( ) ; // do it once
239+
240+
241+ // initialize this at the VERY END after jumping to the proper initial step
242+ // above, perhaps using renderStep()
243+
244+ // copied from opt-frontend-common.js
245+ myVisualizer . creationTime = new Date ( ) . getTime ( ) ;
246+ // each element will be a two-element list consisting of:
247+ // [step number, timestamp]
248+ // (debounce entries that are less than 1 second apart to
249+ // compress the logs a bit when there's rapid scrubbing or scrolling)
250+ //
251+ // the first entry has a THIRD field:
252+ // [step number, timestamp, total # steps]
253+ //
254+ // subsequent entries don't need it since it will always be the same.
255+ // the invariant is that step number < total # steps (since it's
256+ // zero-indexed
257+ myVisualizer . updateHistory = [ ] ;
258+ myVisualizer . updateHistory . push ( [ myVisualizer . curInstr ,
259+ myVisualizer . creationTime ,
260+ myVisualizer . curTrace . length ] ) ;
261+
262+ // add this hook at the VERY END after jumping to the proper initial step
263+ // above, perhaps using renderStep()
264+ myVisualizer . add_pytutor_hook (
265+ "end_updateOutput" ,
266+ function ( args ) {
267+ // copied from opt-frontend-common.js
268+ if ( args . myViz . creationTime ) {
269+ var curTs = new Date ( ) . getTime ( ) ;
270+
271+ var uh = args . myViz . updateHistory ;
272+ assert ( uh . length > 0 ) ; // should already be seeded with an initial value
273+ if ( uh . length > 1 ) { // don't try to "compress" the very first entry
274+ var lastTs = uh [ uh . length - 1 ] [ 1 ] ;
275+ // (debounce entries that are less than 1 second apart to
276+ // compress the logs a bit when there's rapid scrubbing or scrolling)
277+ if ( ( curTs - lastTs ) < 1000 ) {
278+ uh . pop ( ) ; // get rid of last entry before pushing a new entry
279+ }
280+ }
281+ uh . push ( [ args . myViz . curInstr , curTs ] ) ;
282+ }
283+
284+ return [ false ] ;
285+ }
286+ ) ;
287+
288+ $ ( '#executionSlider' ) . slider ( 'value' , myVisualizer . curInstr ) ; // update slider
242289}
243290
291+ // a syntax-/compile-time error, rather than a runtime error
244292function optliveHandleUncaughtExceptionFunc ( trace ) {
245293 if ( trace . length == 1 && trace [ 0 ] . line ) {
246294 var errorLineNo = trace [ 0 ] . line - 1 ; /* CodeMirror lines are zero-indexed */
247295 if ( errorLineNo !== undefined && errorLineNo != NaN ) {
248296 removeAllGutterDecorations ( ) ;
249297
250298 if ( myVisualizer ) {
251- $ ( "#dataViz,#curInstr" ) . addClass ( 'dimmed' ) ; // dim the visualization until we fix the error
299+ toggleSyntaxError ( true ) ;
252300 myVisualizer . updateOutput ( ) ; // to update arrows
253301 }
254302
@@ -323,7 +371,6 @@ function optliveExecuteCodeAndCreateViz(codeToExec,
323371 function execCallback ( dataFromBackend ) {
324372 var trace = dataFromBackend . trace ;
325373
326- // don't enter visualize mode if there are killer errors:
327374 if ( ! trace ||
328375 ( trace . length == 0 ) ||
329376 ( trace [ trace . length - 1 ] . event == 'uncaught_exception' ) ) {
@@ -355,6 +402,8 @@ function optliveExecuteCodeAndCreateViz(codeToExec,
355402 clearFrontendError ( ) ;
356403 startExecutingCode ( ) ;
357404
405+ setFronendError ( [ 'Running your code ...' ] ) ;
406+
358407 jsonp_endpoint = null ;
359408
360409 // hacky!
@@ -385,6 +434,18 @@ function optliveExecuteCodeAndCreateViz(codeToExec,
385434 assert ( false ) ;
386435 }
387436
437+ // submit update history of the "previous" visualizer whenever you
438+ // run the code and hopefully get a new visualizer back
439+ //
440+ // don't bother if we're currently on a syntax error since the
441+ // displayed visualization is no longer relevant
442+ var prevUpdateHistoryJSON = undefined ;
443+ if ( myVisualizer && ! hasSyntaxError ) {
444+ var encodedUh = compressUpdateHistoryList ( myVisualizer ) ;
445+ prevUpdateHistoryJSON = JSON . stringify ( encodedUh ) ;
446+ console . log ( 'prevUpdateHistoryJSON' , prevUpdateHistoryJSON ) ;
447+ }
448+
388449 if ( backendScript === js_backend_script ||
389450 backendScript === ts_backend_script ||
390451 backendScript === java_backend_script ||
@@ -396,7 +457,9 @@ function optliveExecuteCodeAndCreateViz(codeToExec,
396457 { user_script : codeToExec ,
397458 options_json : JSON . stringify ( backendOptionsObj ) ,
398459 user_uuid : supports_html5_storage ( ) ? localStorage . getItem ( 'opt_uuid' ) : undefined ,
399- session_uuid : sessionUUID } ,
460+ session_uuid : sessionUUID ,
461+ prevUpdateHistoryJSON : prevUpdateHistoryJSON ,
462+ exeTime : new Date ( ) . getTime ( ) } ,
400463 function ( dat ) { } /* don't do anything since this is a dummy call */ , "text" ) ;
401464
402465 // the REAL call uses JSONP
@@ -418,7 +481,9 @@ function optliveExecuteCodeAndCreateViz(codeToExec,
418481 raw_input_json : rawInputLst . length > 0 ? JSON . stringify ( rawInputLst ) : '' ,
419482 options_json : JSON . stringify ( backendOptionsObj ) ,
420483 user_uuid : supports_html5_storage ( ) ? localStorage . getItem ( 'opt_uuid' ) : undefined ,
421- session_uuid : sessionUUID } ,
484+ session_uuid : sessionUUID ,
485+ prevUpdateHistoryJSON : prevUpdateHistoryJSON ,
486+ exeTime : new Date ( ) . getTime ( ) } ,
422487 execCallback , "json" ) ;
423488 }
424489}
0 commit comments