@@ -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,28 @@ 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 ( ! hasSameSubplots ) {
145+ gd . framework = makePlotFramework ;
146+ makePlotFramework ( gd ) ;
147+ }
148+ else if ( graphWasEmpty ) makePlotFramework ( gd ) ;
146149
147150 var fullLayout = gd . _fullLayout ;
148151
@@ -160,7 +163,7 @@ Plotly.plot = function(gd, data, layout, config) {
160163 }
161164
162165 // in case it has changed, attach fullData traces to calcdata
163- for ( var i = 0 ; i < gd . calcdata . length ; i ++ ) {
166+ for ( var i = 0 ; i < gd . calcdata . length ; i ++ ) {
164167 gd . calcdata [ i ] [ 0 ] . trace = gd . _fullData [ i ] ;
165168 }
166169
@@ -2144,8 +2147,12 @@ Plotly.relayout = function relayout(gd, astr, val) {
21442147 undoit [ ai ] = ( pleaf === 'reverse' ) ? vi : p . get ( ) ;
21452148
21462149 // 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 ) ; }
2150+ if ( hw . indexOf ( ai ) !== - 1 ) {
2151+ doextra ( 'autosize' , false ) ;
2152+ }
2153+ else if ( ai === 'autosize' ) {
2154+ doextra ( hw , undefined ) ;
2155+ }
21492156 else if ( pleafPlus . match ( / ^ [ x y z ] a x i s [ 0 - 9 ] * \. r a n g e ( \[ [ 0 | 1 ] \] ) ? $ / ) ) {
21502157 doextra ( ptrunk + '.autorange' , false ) ;
21512158 }
@@ -2165,6 +2172,10 @@ Plotly.relayout = function relayout(gd, astr, val) {
21652172 else if ( pleaf === 'tickmode' ) {
21662173 doextra ( [ ptrunk + '.tick0' , ptrunk + '.dtick' ] , undefined ) ;
21672174 }
2175+ else if ( / [ x y ] a x i s [ 0 - 9 ] * ?$ / . test ( pleaf ) && ! Object . keys ( vi || { } ) . length ) {
2176+ docalc = true ;
2177+ }
2178+
21682179 // toggling log without autorange: need to also recalculate ranges
21692180 // logical XOR (ie are we toggling log)
21702181 if ( pleaf === 'type' && ( ( parentFull . type === 'log' ) !== ( vi === 'log' ) ) ) {
@@ -2318,10 +2329,12 @@ Plotly.relayout = function relayout(gd, astr, val) {
23182329 seq . push ( function layoutReplot ( ) {
23192330 // force plot() to redo the layout
23202331 gd . layout = undefined ;
2332+
23212333 // force it to redo calcdata?
23222334 if ( docalc ) gd . calcdata = undefined ;
2335+
23232336 // replot with the modified layout
2324- return Plotly . plot ( gd , '' , layout ) ;
2337+ return Plotly . plot ( gd , '' , layout ) ;
23252338 } ) ;
23262339 }
23272340 else if ( ak . length ) {
0 commit comments