@@ -275,7 +275,9 @@ var relayoutCallback = function(scene) {
275275 yrange = scene . yaxis . range ;
276276
277277 // Update the layout on the DIV
278+ scene . graphDiv . layout . xaxis . autorange = scene . xaxis . autorange ;
278279 scene . graphDiv . layout . xaxis . range = xrange . slice ( 0 ) ;
280+ scene . graphDiv . layout . yaxis . autorange = scene . yaxis . autorange ;
279281 scene . graphDiv . layout . yaxis . range = yrange . slice ( 0 ) ;
280282
281283 // Make a meaningful value to be passed on to the possible 'plotly_relayout' subscriber(s)
@@ -310,7 +312,6 @@ proto.cameraChanged = function() {
310312} ;
311313
312314proto . destroy = function ( ) {
313-
314315 var traces = this . traces ;
315316
316317 if ( traces ) {
@@ -334,10 +335,9 @@ proto.plot = function(fullData, calcData, fullLayout) {
334335 var glplot = this . glplot ,
335336 pixelRatio = this . pixelRatio ;
336337
337- var i , j , trace ;
338-
339338 this . fullLayout = fullLayout ;
340339 this . updateAxes ( fullLayout ) ;
340+ this . updateTraces ( fullData , calcData ) ;
341341
342342 var width = fullLayout . width ,
343343 height = fullLayout . height ,
@@ -351,34 +351,6 @@ proto.plot = function(fullData, calcData, fullLayout) {
351351 canvas . height = pixelHeight ;
352352 }
353353
354- // update traces
355- for ( i = 0 ; i < fullData . length ; ++ i ) {
356- var fullTrace = fullData [ i ] ,
357- calcTrace = calcData [ i ] ;
358- trace = this . traces [ fullTrace . uid ] ;
359-
360- if ( trace ) trace . update ( fullTrace , calcTrace ) ;
361- else {
362- trace = fullTrace . _module . plot ( this , fullTrace , calcTrace ) ;
363- }
364-
365- this . traces [ fullTrace . uid ] = trace ;
366- }
367-
368- // remove empty traces
369- var traceIds = Object . keys ( this . traces ) ;
370-
371- trace_id_loop:
372- for ( i = 0 ; i < traceIds . length ; ++ i ) {
373- for ( j = 0 ; j < calcData . length ; ++ j ) {
374- if ( calcData [ j ] [ 0 ] . trace . uid === traceIds [ i ] ) continue trace_id_loop;
375- }
376-
377- trace = this . traces [ traceIds [ i ] ] ;
378- trace . dispose ( ) ;
379- delete this . traces [ traceIds [ i ] ] ;
380- }
381-
382354 var options = this . glplotOptions ;
383355 options . merge ( fullLayout ) ;
384356 options . screenBox = [ 0 , 0 , width , height ] ;
@@ -404,16 +376,18 @@ proto.plot = function(fullData, calcData, fullLayout) {
404376 bounds [ 0 ] = bounds [ 1 ] = Infinity ;
405377 bounds [ 2 ] = bounds [ 3 ] = - Infinity ;
406378
407- traceIds = Object . keys ( this . traces ) ;
379+ var traceIds = Object . keys ( this . traces ) ;
380+ var ax , i ;
381+
408382 for ( i = 0 ; i < traceIds . length ; ++ i ) {
409- trace = this . traces [ traceIds [ i ] ] ;
383+ var traceObj = this . traces [ traceIds [ i ] ] ;
384+
410385 for ( var k = 0 ; k < 2 ; ++ k ) {
411- bounds [ k ] = Math . min ( bounds [ k ] , trace . bounds [ k ] ) ;
412- 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 ] ) ;
413388 }
414389 }
415390
416- var ax ;
417391 for ( i = 0 ; i < 2 ; ++ i ) {
418392 if ( bounds [ i ] > bounds [ i + 2 ] ) {
419393 bounds [ i ] = - 1 ;
@@ -439,6 +413,43 @@ proto.plot = function(fullData, calcData, fullLayout) {
439413 this . glplot . draw ( ) ;
440414} ;
441415
416+ proto . updateTraces = function ( fullData , calcData ) {
417+ var traceIds = Object . keys ( this . traces ) ;
418+ var i , j , fullTrace ;
419+
420+ // remove empty traces
421+ trace_id_loop:
422+ for ( i = 0 ; i < traceIds . length ; i ++ ) {
423+ var oldUid = traceIds [ i ] ,
424+ oldTrace = this . traces [ oldUid ] ;
425+
426+ for ( j = 0 ; j < fullData . length ; j ++ ) {
427+ fullTrace = fullData [ j ] ;
428+
429+ if ( fullTrace . uid === oldUid && fullTrace . type === oldTrace . type ) {
430+ continue trace_id_loop;
431+ }
432+ }
433+
434+ oldTrace . dispose ( ) ;
435+ delete this . traces [ oldUid ] ;
436+ }
437+
438+ // update / create trace objects
439+ for ( i = 0 ; i < fullData . length ; i ++ ) {
440+ fullTrace = fullData [ i ] ;
441+
442+ var calcTrace = calcData [ i ] ,
443+ traceObj = this . traces [ fullTrace . uid ] ;
444+
445+ if ( traceObj ) traceObj . update ( fullTrace , calcTrace ) ;
446+ else {
447+ traceObj = fullTrace . _module . plot ( this , fullTrace , calcTrace ) ;
448+ this . traces [ fullTrace . uid ] = traceObj ;
449+ }
450+ }
451+ } ;
452+
442453proto . draw = function ( ) {
443454 if ( this . stopped ) return ;
444455
0 commit comments