@@ -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,24 @@ 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 ( graphWasEmpty ) makePlotFramework ( gd ) ;
146
145
147
146
var fullLayout = gd . _fullLayout ;
148
147
@@ -160,7 +159,7 @@ Plotly.plot = function(gd, data, layout, config) {
160
159
}
161
160
162
161
// 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 ++ ) {
164
163
gd . calcdata [ i ] [ 0 ] . trace = gd . _fullData [ i ] ;
165
164
}
166
165
@@ -2133,8 +2132,12 @@ Plotly.relayout = function relayout(gd, astr, val) {
2133
2132
undoit [ ai ] = ( pleaf === 'reverse' ) ? vi : p . get ( ) ;
2134
2133
2135
2134
// check autosize or autorange vs size and range
2136
- if ( hw . indexOf ( ai ) !== - 1 ) { doextra ( 'autosize' , false ) ; }
2137
- else if ( ai === 'autosize' ) { doextra ( hw , undefined ) ; }
2135
+ if ( hw . indexOf ( ai ) !== - 1 ) {
2136
+ doextra ( 'autosize' , false ) ;
2137
+ }
2138
+ else if ( ai === 'autosize' ) {
2139
+ doextra ( hw , undefined ) ;
2140
+ }
2138
2141
else if ( pleafPlus . match ( / ^ [ x y z ] a x i s [ 0 - 9 ] * \. r a n g e ( \[ [ 0 | 1 ] \] ) ? $ / ) ) {
2139
2142
doextra ( ptrunk + '.autorange' , false ) ;
2140
2143
}
@@ -2307,10 +2310,12 @@ Plotly.relayout = function relayout(gd, astr, val) {
2307
2310
seq . push ( function layoutReplot ( ) {
2308
2311
// force plot() to redo the layout
2309
2312
gd . layout = undefined ;
2313
+
2310
2314
// force it to redo calcdata?
2311
2315
if ( docalc ) gd . calcdata = undefined ;
2316
+
2312
2317
// replot with the modified layout
2313
- return Plotly . plot ( gd , '' , layout ) ;
2318
+ return Plotly . plot ( gd , '' , layout ) ;
2314
2319
} ) ;
2315
2320
}
2316
2321
else if ( ak . length ) {
0 commit comments