@@ -312,7 +312,6 @@ proto.cameraChanged = function() {
312
312
} ;
313
313
314
314
proto . destroy = function ( ) {
315
-
316
315
var traces = this . traces ;
317
316
318
317
if ( traces ) {
@@ -336,10 +335,11 @@ proto.plot = function(fullData, calcData, fullLayout) {
336
335
var glplot = this . glplot ,
337
336
pixelRatio = this . pixelRatio ;
338
337
339
- var i , j , trace ;
338
+ var i ;
340
339
341
340
this . fullLayout = fullLayout ;
342
341
this . updateAxes ( fullLayout ) ;
342
+ this . updateTraces ( fullData , calcData ) ;
343
343
344
344
var width = fullLayout . width ,
345
345
height = fullLayout . height ,
@@ -353,34 +353,6 @@ proto.plot = function(fullData, calcData, fullLayout) {
353
353
canvas . height = pixelHeight ;
354
354
}
355
355
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
-
384
356
var options = this . glplotOptions ;
385
357
options . merge ( fullLayout ) ;
386
358
options . screenBox = [ 0 , 0 , width , height ] ;
@@ -406,12 +378,13 @@ proto.plot = function(fullData, calcData, fullLayout) {
406
378
bounds [ 0 ] = bounds [ 1 ] = Infinity ;
407
379
bounds [ 2 ] = bounds [ 3 ] = - Infinity ;
408
380
409
- traceIds = Object . keys ( this . traces ) ;
381
+ var traceIds = Object . keys ( this . traces ) ;
410
382
for ( i = 0 ; i < traceIds . length ; ++ i ) {
411
- trace = this . traces [ traceIds [ i ] ] ;
383
+ var traceObj = this . traces [ traceIds [ i ] ] ;
384
+
412
385
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 ] ) ;
415
388
}
416
389
}
417
390
@@ -441,6 +414,43 @@ proto.plot = function(fullData, calcData, fullLayout) {
441
414
this . glplot . draw ( ) ;
442
415
} ;
443
416
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
+
444
454
proto . draw = function ( ) {
445
455
if ( this . stopped ) return ;
446
456
0 commit comments