@@ -312,7 +312,6 @@ proto.cameraChanged = function() {
312312} ;
313313
314314proto . destroy = function ( ) {
315-
316315 var traces = this . traces ;
317316
318317 if ( traces ) {
@@ -336,10 +335,11 @@ proto.plot = function(fullData, calcData, fullLayout) {
336335 var glplot = this . glplot ,
337336 pixelRatio = this . pixelRatio ;
338337
339- var i , j , trace ;
338+ var i ;
340339
341340 this . fullLayout = fullLayout ;
342341 this . updateAxes ( fullLayout ) ;
342+ this . updateTraces ( fullData , calcData ) ;
343343
344344 var width = fullLayout . width ,
345345 height = fullLayout . height ,
@@ -353,34 +353,6 @@ proto.plot = function(fullData, calcData, fullLayout) {
353353 canvas . height = pixelHeight ;
354354 }
355355
356- // update traces
357- for ( i = 0 ; i < fullData . length ; ++ i ) {
358- var fullTrace = fullData [ i ] ,
359- calcTrace = calcData [ i ] ;
360- trace = this . traces [ fullTrace . uid ] ;
361-
362- if ( trace ) trace . update ( fullTrace , calcTrace ) ;
363- else {
364- trace = fullTrace . _module . plot ( this , fullTrace , calcTrace ) ;
365- }
366-
367- this . traces [ fullTrace . uid ] = trace ;
368- }
369-
370- // remove empty traces
371- var traceIds = Object . keys ( this . traces ) ;
372-
373- trace_id_loop:
374- for ( i = 0 ; i < traceIds . length ; ++ i ) {
375- for ( j = 0 ; j < calcData . length ; ++ j ) {
376- if ( calcData [ j ] [ 0 ] . trace . uid === traceIds [ i ] ) continue trace_id_loop;
377- }
378-
379- trace = this . traces [ traceIds [ i ] ] ;
380- trace . dispose ( ) ;
381- delete this . traces [ traceIds [ i ] ] ;
382- }
383-
384356 var options = this . glplotOptions ;
385357 options . merge ( fullLayout ) ;
386358 options . screenBox = [ 0 , 0 , width , height ] ;
@@ -406,12 +378,13 @@ proto.plot = function(fullData, calcData, fullLayout) {
406378 bounds [ 0 ] = bounds [ 1 ] = Infinity ;
407379 bounds [ 2 ] = bounds [ 3 ] = - Infinity ;
408380
409- traceIds = Object . keys ( this . traces ) ;
381+ var traceIds = Object . keys ( this . traces ) ;
410382 for ( i = 0 ; i < traceIds . length ; ++ i ) {
411- trace = this . traces [ traceIds [ i ] ] ;
383+ var traceObj = this . traces [ traceIds [ i ] ] ;
384+
412385 for ( var k = 0 ; k < 2 ; ++ k ) {
413- bounds [ k ] = Math . min ( bounds [ k ] , trace . bounds [ k ] ) ;
414- bounds [ k + 2 ] = Math . max ( bounds [ k + 2 ] , trace . bounds [ k + 2 ] ) ;
386+ bounds [ k ] = Math . min ( bounds [ k ] , traceObj . bounds [ k ] ) ;
387+ bounds [ k + 2 ] = Math . max ( bounds [ k + 2 ] , traceObj . bounds [ k + 2 ] ) ;
415388 }
416389 }
417390
@@ -441,6 +414,43 @@ proto.plot = function(fullData, calcData, fullLayout) {
441414 this . glplot . draw ( ) ;
442415} ;
443416
417+ proto . updateTraces = function ( fullData , calcData ) {
418+ var traceIds = Object . keys ( this . traces ) ;
419+ var i , j , fullTrace ;
420+
421+ // remove empty traces
422+ trace_id_loop:
423+ for ( i = 0 ; i < traceIds . length ; i ++ ) {
424+ var oldUid = traceIds [ i ] ,
425+ oldTrace = this . traces [ oldUid ] ;
426+
427+ for ( j = 0 ; j < fullData . length ; j ++ ) {
428+ fullTrace = fullData [ j ] ;
429+
430+ if ( fullTrace . uid === oldUid && fullTrace . type === oldTrace . type ) {
431+ continue trace_id_loop;
432+ }
433+ }
434+
435+ oldTrace . dispose ( ) ;
436+ delete this . traces [ oldUid ] ;
437+ }
438+
439+ // update / create trace objects
440+ for ( i = 0 ; i < fullData . length ; i ++ ) {
441+ fullTrace = fullData [ i ] ;
442+
443+ var calcTrace = calcData [ i ] ,
444+ traceObj = this . traces [ fullTrace . uid ] ;
445+
446+ if ( traceObj ) traceObj . update ( fullTrace , calcTrace ) ;
447+ else {
448+ traceObj = fullTrace . _module . plot ( this , fullTrace , calcTrace ) ;
449+ this . traces [ fullTrace . uid ] = traceObj ;
450+ }
451+ }
452+ } ;
453+
444454proto . draw = function ( ) {
445455 if ( this . stopped ) return ;
446456
0 commit comments