@@ -50,16 +50,13 @@ var xmlnsNamespaces = require('../constants/xmlns_namespaces');
50
50
Plotly . plot = function ( gd , data , layout , config ) {
51
51
Lib . markTime ( 'in plot' ) ;
52
52
53
-
54
53
gd = getGraphDiv ( gd ) ;
55
54
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
59
56
Events . init ( gd ) ;
60
57
61
58
var okToPlot = Events . triggerHandler ( gd , 'plotly_beforeplot' , [ data , layout , config ] ) ;
62
- if ( okToPlot === false ) return Promise . reject ( ) ;
59
+ if ( okToPlot === false ) return Promise . reject ( ) ;
63
60
64
61
// if there's no data or layout, and this isn't yet a plotly plot
65
62
// container, log a warning to help plotly.js users debug
@@ -89,22 +86,23 @@ Plotly.plot = function(gd, data, layout, config) {
89
86
// complete, and empty out the promise list again.
90
87
gd . _promises = [ ] ;
91
88
89
+ var graphWasEmpty = ( ( gd . data || [ ] ) . length === 0 && Array . isArray ( data ) ) ;
90
+
92
91
// if there is already data on the graph, append the new data
93
92
// if you only want to redraw, pass a non-array for data
94
- var graphwasempty = ( ( gd . data || [ ] ) . length === 0 && Array . isArray ( data ) ) ;
95
93
if ( Array . isArray ( data ) ) {
96
94
cleanData ( data , gd . data ) ;
97
95
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 ) ;
100
98
101
99
// for routines outside graph_obj that want a clean tab
102
100
// (rather than appending to an existing one) gd.empty
103
101
// is used to determine whether to make a new tab
104
- gd . empty = false ;
102
+ gd . empty = false ;
105
103
}
106
104
107
- if ( ! gd . layout || graphwasempty ) gd . layout = cleanLayout ( layout ) ;
105
+ if ( ! gd . layout || graphWasEmpty ) gd . layout = cleanLayout ( layout ) ;
108
106
109
107
// if the user is trying to drag the axes, allow new data and layout
110
108
// to come in but don't allow a replot.
@@ -126,23 +124,28 @@ Plotly.plot = function(gd, data, layout, config) {
126
124
// so we don't try to re-call Plotly.plot from inside
127
125
// legend and colorbar, if margins changed
128
126
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 ) ;
130
132
131
133
// Make or remake the framework (ie container and axes) if we need to
132
134
// note: if they container already exists and has data,
133
135
// the new layout gets ignored (as it should)
134
136
// but if there's no data there yet, it's just a placeholder...
135
137
// 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 ) {
141
140
gd . framework = makePlotFramework ;
142
141
makePlotFramework ( gd ) ;
143
142
}
144
143
}
145
- else if ( graphwasempty ) makePlotFramework ( gd ) ;
144
+ else if ( ! hasSameSubplots ) {
145
+ gd . framework = makePlotFramework ;
146
+ makePlotFramework ( gd ) ;
147
+ }
148
+ else if ( graphWasEmpty ) makePlotFramework ( gd ) ;
146
149
147
150
var fullLayout = gd . _fullLayout ;
148
151
@@ -160,7 +163,7 @@ Plotly.plot = function(gd, data, layout, config) {
160
163
}
161
164
162
165
// 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 ++ ) {
164
167
gd . calcdata [ i ] [ 0 ] . trace = gd . _fullData [ i ] ;
165
168
}
166
169
@@ -2144,8 +2147,12 @@ Plotly.relayout = function relayout(gd, astr, val) {
2144
2147
undoit [ ai ] = ( pleaf === 'reverse' ) ? vi : p . get ( ) ;
2145
2148
2146
2149
// 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
+ }
2149
2156
else if ( pleafPlus . match ( / ^ [ x y z ] a x i s [ 0 - 9 ] * \. r a n g e ( \[ [ 0 | 1 ] \] ) ? $ / ) ) {
2150
2157
doextra ( ptrunk + '.autorange' , false ) ;
2151
2158
}
@@ -2165,6 +2172,10 @@ Plotly.relayout = function relayout(gd, astr, val) {
2165
2172
else if ( pleaf === 'tickmode' ) {
2166
2173
doextra ( [ ptrunk + '.tick0' , ptrunk + '.dtick' ] , undefined ) ;
2167
2174
}
2175
+ else if ( / [ x y ] a x i s [ 0 - 9 ] * ?$ / . test ( pleaf ) && ! Object . keys ( vi || { } ) . length ) {
2176
+ docalc = true ;
2177
+ }
2178
+
2168
2179
// toggling log without autorange: need to also recalculate ranges
2169
2180
// logical XOR (ie are we toggling log)
2170
2181
if ( pleaf === 'type' && ( ( parentFull . type === 'log' ) !== ( vi === 'log' ) ) ) {
@@ -2318,10 +2329,12 @@ Plotly.relayout = function relayout(gd, astr, val) {
2318
2329
seq . push ( function layoutReplot ( ) {
2319
2330
// force plot() to redo the layout
2320
2331
gd . layout = undefined ;
2332
+
2321
2333
// force it to redo calcdata?
2322
2334
if ( docalc ) gd . calcdata = undefined ;
2335
+
2323
2336
// replot with the modified layout
2324
- return Plotly . plot ( gd , '' , layout ) ;
2337
+ return Plotly . plot ( gd , '' , layout ) ;
2325
2338
} ) ;
2326
2339
}
2327
2340
else if ( ak . length ) {
0 commit comments