@@ -50,16 +50,13 @@ var xmlnsNamespaces = require('../constants/xmlns_namespaces');
5050Plotly . plot = function ( gd , data , layout , config ) {
5151 Lib . markTime ( 'in plot' ) ;
5252
53-
5453 gd = getGraphDiv ( gd ) ;
5554
56- /*
57- * Events.init is idempotent and bails early if gd has already been init'd
58- */
55+ // Events.init is idempotent and bails early if gd has already been init'd
5956 Events . init ( gd ) ;
6057
6158 var okToPlot = Events . triggerHandler ( gd , 'plotly_beforeplot' , [ data , layout , config ] ) ;
62- if ( okToPlot === false ) return Promise . reject ( ) ;
59+ if ( okToPlot === false ) return Promise . reject ( ) ;
6360
6461 // if there's no data or layout, and this isn't yet a plotly plot
6562 // container, log a warning to help plotly.js users debug
@@ -89,22 +86,23 @@ Plotly.plot = function(gd, data, layout, config) {
8986 // complete, and empty out the promise list again.
9087 gd . _promises = [ ] ;
9188
89+ var graphWasEmpty = ( ( gd . data || [ ] ) . length === 0 && Array . isArray ( data ) ) ;
90+
9291 // if there is already data on the graph, append the new data
9392 // if you only want to redraw, pass a non-array for data
94- var graphwasempty = ( ( gd . data || [ ] ) . length === 0 && Array . isArray ( data ) ) ;
9593 if ( Array . isArray ( data ) ) {
9694 cleanData ( data , gd . data ) ;
9795
98- if ( graphwasempty ) gd . data = data ;
99- else gd . data . push . apply ( gd . data , data ) ;
96+ if ( graphWasEmpty ) gd . data = data ;
97+ else gd . data . push . apply ( gd . data , data ) ;
10098
10199 // for routines outside graph_obj that want a clean tab
102100 // (rather than appending to an existing one) gd.empty
103101 // is used to determine whether to make a new tab
104- gd . empty = false ;
102+ gd . empty = false ;
105103 }
106104
107- if ( ! gd . layout || graphwasempty ) gd . layout = cleanLayout ( layout ) ;
105+ if ( ! gd . layout || graphWasEmpty ) gd . layout = cleanLayout ( layout ) ;
108106
109107 // if the user is trying to drag the axes, allow new data and layout
110108 // to come in but don't allow a replot.
@@ -126,23 +124,24 @@ Plotly.plot = function(gd, data, layout, config) {
126124 // so we don't try to re-call Plotly.plot from inside
127125 // legend and colorbar, if margins changed
128126 gd . _replotting = true ;
129- var hasData = gd . _fullData . length > 0 ;
127+ var hasData = gd . _fullData . length > 0 ;
128+
129+ var subplots = Plotly . Axes . getSubplots ( gd ) . join ( '' ) ,
130+ oldSubplots = Object . keys ( gd . _fullLayout . _plots || { } ) . join ( '' ) ,
131+ hasSameSubplots = ( oldSubplots === subplots ) ;
130132
131133 // Make or remake the framework (ie container and axes) if we need to
132134 // note: if they container already exists and has data,
133135 // the new layout gets ignored (as it should)
134136 // but if there's no data there yet, it's just a placeholder...
135137 // then it should destroy and remake the plot
136- if ( hasData ) {
137- var subplots = Plotly . Axes . getSubplots ( gd ) . join ( '' ) ,
138- oldSubplots = Object . keys ( gd . _fullLayout . _plots || { } ) . join ( '' ) ;
139-
140- if ( gd . framework !== makePlotFramework || graphwasempty || ( oldSubplots !== subplots ) ) {
138+ if ( hasData ) {
139+ if ( gd . framework !== makePlotFramework || graphWasEmpty || ! hasSameSubplots ) {
141140 gd . framework = makePlotFramework ;
142141 makePlotFramework ( gd ) ;
143142 }
144143 }
145- else if ( graphwasempty ) makePlotFramework ( gd ) ;
144+ else if ( graphWasEmpty ) makePlotFramework ( gd ) ;
146145
147146 var fullLayout = gd . _fullLayout ;
148147
@@ -160,7 +159,7 @@ Plotly.plot = function(gd, data, layout, config) {
160159 }
161160
162161 // in case it has changed, attach fullData traces to calcdata
163- for ( var i = 0 ; i < gd . calcdata . length ; i ++ ) {
162+ for ( var i = 0 ; i < gd . calcdata . length ; i ++ ) {
164163 gd . calcdata [ i ] [ 0 ] . trace = gd . _fullData [ i ] ;
165164 }
166165
@@ -2144,8 +2143,12 @@ Plotly.relayout = function relayout(gd, astr, val) {
21442143 undoit [ ai ] = ( pleaf === 'reverse' ) ? vi : p . get ( ) ;
21452144
21462145 // check autosize or autorange vs size and range
2147- if ( hw . indexOf ( ai ) !== - 1 ) { doextra ( 'autosize' , false ) ; }
2148- else if ( ai === 'autosize' ) { doextra ( hw , undefined ) ; }
2146+ if ( hw . indexOf ( ai ) !== - 1 ) {
2147+ doextra ( 'autosize' , false ) ;
2148+ }
2149+ else if ( ai === 'autosize' ) {
2150+ doextra ( hw , undefined ) ;
2151+ }
21492152 else if ( pleafPlus . match ( / ^ [ x y z ] a x i s [ 0 - 9 ] * \. r a n g e ( \[ [ 0 | 1 ] \] ) ? $ / ) ) {
21502153 doextra ( ptrunk + '.autorange' , false ) ;
21512154 }
@@ -2318,10 +2321,12 @@ Plotly.relayout = function relayout(gd, astr, val) {
23182321 seq . push ( function layoutReplot ( ) {
23192322 // force plot() to redo the layout
23202323 gd . layout = undefined ;
2324+
23212325 // force it to redo calcdata?
23222326 if ( docalc ) gd . calcdata = undefined ;
2327+
23232328 // replot with the modified layout
2324- return Plotly . plot ( gd , '' , layout ) ;
2329+ return Plotly . plot ( gd , '' , layout ) ;
23252330 } ) ;
23262331 }
23272332 else if ( ak . length ) {
0 commit comments