@@ -89,12 +89,6 @@ function plot(gd, data, layout, config) {
89
89
'but this container doesn\'t yet have a plot.' , gd ) ;
90
90
}
91
91
92
- function addFrames ( ) {
93
- if ( frames ) {
94
- return exports . addFrames ( gd , frames ) ;
95
- }
96
- }
97
-
98
92
// transfer configuration options to gd until we move over to
99
93
// a more OO like model
100
94
setPlotContext ( gd , config ) ;
@@ -147,10 +141,6 @@ function plot(gd, data, layout, config) {
147
141
return plotLegacyPolar ( gd , data , layout ) ;
148
142
}
149
143
150
- // so we don't try to re-call Plotly.plot from inside
151
- // legend and colorbar, if margins changed
152
- fullLayout . _replotting = true ;
153
-
154
144
// make or remake the framework if we need to
155
145
if ( graphWasEmpty ) makePlotFramework ( gd ) ;
156
146
@@ -163,11 +153,6 @@ function plot(gd, data, layout, config) {
163
153
// clear gradient defs on each .plot call, because we know we'll loop through all traces
164
154
Drawing . initGradients ( gd ) ;
165
155
166
- // save initial show spikes once per graph
167
- if ( graphWasEmpty ) Axes . saveShowSpikeInitial ( gd ) ;
168
-
169
- // prepare the data and find the autorange
170
-
171
156
// generate calcdata, if we need to
172
157
// to force redoing calcdata, just delete it before calling Plotly.plot
173
158
var recalc = ! gd . calcdata || gd . calcdata . length !== ( gd . _fullData || [ ] ) . length ;
@@ -182,8 +167,9 @@ function plot(gd, data, layout, config) {
182
167
if ( gd . _context . responsive ) {
183
168
if ( ! gd . _responsiveChartHandler ) {
184
169
// Keep a reference to the resize handler to purge it down the road
185
- gd . _responsiveChartHandler = function ( ) { if ( ! Lib . isHidden ( gd ) ) Plots . resize ( gd ) ; } ;
186
-
170
+ gd . _responsiveChartHandler = function ( ) {
171
+ if ( ! Lib . isHidden ( gd ) ) Plots . resize ( gd ) ;
172
+ } ;
187
173
// Listen to window resize
188
174
window . addEventListener ( 'resize' , gd . _responsiveChartHandler ) ;
189
175
}
@@ -195,7 +181,11 @@ function plot(gd, data, layout, config) {
195
181
* start async-friendly code - now we're actually drawing things
196
182
*/
197
183
198
- var oldMargins = Lib . extendFlat ( { } , fullLayout . _size ) ;
184
+ function addFrames ( ) {
185
+ if ( frames ) {
186
+ return exports . addFrames ( gd , frames ) ;
187
+ }
188
+ }
199
189
200
190
// draw framework first so that margin-pushing
201
191
// components can position themselves correctly
@@ -210,19 +200,11 @@ function plot(gd, data, layout, config) {
210
200
}
211
201
212
202
if ( ! fullLayout . _glcanvas && fullLayout . _has ( 'gl' ) ) {
213
- fullLayout . _glcanvas = fullLayout . _glcontainer . selectAll ( '.gl-canvas' ) . data ( [ {
214
- key : 'contextLayer' ,
215
- context : true ,
216
- pick : false
217
- } , {
218
- key : 'focusLayer' ,
219
- context : false ,
220
- pick : false
221
- } , {
222
- key : 'pickLayer' ,
223
- context : false ,
224
- pick : true
225
- } ] , function ( d ) { return d . key ; } ) ;
203
+ fullLayout . _glcanvas = fullLayout . _glcontainer . selectAll ( '.gl-canvas' ) . data ( [
204
+ { key : 'contextLayer' , context : true , pick : false } ,
205
+ { key : 'focusLayer' , context : false , pick : false } ,
206
+ { key : 'pickLayer' , context : false , pick : true }
207
+ ] , function ( d ) { return d . key ; } ) ;
226
208
227
209
fullLayout . _glcanvas . enter ( ) . append ( 'canvas' )
228
210
. attr ( 'class' , function ( d ) {
@@ -278,37 +260,31 @@ function plot(gd, data, layout, config) {
278
260
return Plots . previousPromises ( gd ) ;
279
261
}
280
262
281
- // draw anything that can affect margins.
282
- function marginPushers ( ) {
283
- // First reset the list of things that are allowed to change the margins
284
- // So any deleted traces or components will be wiped out of the
285
- // automargin calculation.
286
- // This means *every* margin pusher must be listed here, even if it
287
- // doesn't actually try to push the margins until later.
288
- Plots . clearAutoMarginIds ( gd ) ;
263
+ var oldMargins = Lib . extendFlat ( { } , fullLayout . _size ) ;
289
264
290
- subroutines . drawMarginPushers ( gd ) ;
291
- Axes . allowAutoMargin ( gd ) ;
265
+ function pushMargin ( ) {
266
+ Registry . getComponentMethod ( 'rangeselector' , 'pushMargin' ) ( gd ) ;
267
+ Registry . getComponentMethod ( 'sliders' , 'pushMargin' ) ( gd ) ;
268
+ Registry . getComponentMethod ( 'updatemenus' , 'pushMargin' ) ( gd ) ;
269
+ Registry . getComponentMethod ( 'legend' , 'pushMargin' ) ( gd ) ;
270
+ Registry . getComponentMethod ( 'colorbar' , 'pushMargin' ) ( gd ) ;
271
+ if ( hasCartesian ) Axes . pushMargin ( gd ) ;
292
272
293
- Plots . doAutoMargin ( gd ) ;
294
- return Plots . previousPromises ( gd ) ;
273
+ return Lib . syncOrAsync ( [ Plots . previousPromises , Plots . doAutoMargin ] , gd ) ;
295
274
}
296
275
297
276
// in case the margins changed, draw margin pushers again
298
- function marginPushersAgain ( ) {
299
- if ( ! Plots . didMarginChange ( oldMargins , fullLayout . _size ) ) return ;
277
+ function pushMarginAgain ( ) {
300
278
301
- return Lib . syncOrAsync ( [
302
- marginPushers ,
303
- subroutines . layoutStyles
304
- ] , gd ) ;
279
+ if ( Plots . didMarginChange ( oldMargins , fullLayout . _size ) ) {
280
+ oldMargins = Lib . extendFlat ( { } , fullLayout . _size ) ;
281
+ return pushMargin ( ) ;
282
+ }
305
283
}
306
284
307
285
function positionAndAutorange ( ) {
308
- if ( ! recalc ) {
309
- doAutoRangeAndConstraints ( ) ;
310
- return ;
311
- }
286
+ if ( ! hasCartesian ) return ;
287
+ if ( ! recalc ) return doAutoRangeAndConstraints ( ) ;
312
288
313
289
// TODO: autosize extra for text markers and images
314
290
// see https://github.com/plotly/plotly.js/issues/1111
@@ -324,48 +300,49 @@ function plot(gd, data, layout, config) {
324
300
325
301
subroutines . doAutoRangeAndConstraints ( gd ) ;
326
302
327
- // store initial ranges *after* enforcing constraints, otherwise
328
- // we will never look like we're at the initial ranges
329
- if ( graphWasEmpty ) Axes . saveRangeInitial ( gd ) ;
330
-
331
303
// this one is different from shapes/annotations calcAutorange
332
304
// the others incorporate those components into ax._extremes,
333
305
// this one actually sets the ranges in rangesliders.
334
306
Registry . getComponentMethod ( 'rangeslider' , 'calcAutorange' ) ( gd ) ;
335
307
}
336
308
337
- // draw ticks, titles, and calculate axis scaling (._b, ._m)
309
+ function saveInitial ( ) {
310
+ if ( graphWasEmpty && hasCartesian ) {
311
+ // store initial ranges *after* enforcing constraints, otherwise
312
+ // we will never look like we're at the initial ranges
313
+ Axes . saveRangeInitial ( gd ) ;
314
+ // save initial show spikes once per graph
315
+ Axes . saveShowSpikeInitial ( gd ) ;
316
+ }
317
+ }
318
+
338
319
function drawAxes ( ) {
339
- return Axes . draw ( gd , graphWasEmpty ? '' : 'redraw' ) ;
320
+ if ( hasCartesian ) {
321
+ return Axes . draw ( gd , graphWasEmpty ? '' : 'redraw' ) ;
322
+ }
340
323
}
341
324
342
325
var seq = [
343
326
Plots . previousPromises ,
344
327
addFrames ,
345
328
drawFramework ,
346
- marginPushers ,
347
- marginPushersAgain
348
- ] ;
349
-
350
- if ( hasCartesian ) seq . push ( positionAndAutorange ) ;
351
-
352
- seq . push ( subroutines . layoutStyles ) ;
353
- if ( hasCartesian ) seq . push ( drawAxes ) ;
354
-
355
- seq . push (
329
+ positionAndAutorange ,
330
+ pushMargin ,
331
+ pushMarginAgain ,
332
+ pushMarginAgain ,
333
+ positionAndAutorange ,
334
+ saveInitial ,
335
+ subroutines . layoutStyles ,
356
336
subroutines . drawData ,
337
+ subroutines . drawMarginPushers ,
338
+ drawAxes ,
357
339
subroutines . finalDraw ,
358
340
initInteractions ,
359
341
Plots . addLinks ,
360
342
Plots . rehover ,
361
343
Plots . redrag ,
362
- // TODO: doAutoMargin is only needed here for axis automargin, which
363
- // happens outside of marginPushers where all the other automargins are
364
- // calculated. Would be much better to separate margin calculations from
365
- // component drawing - see https://github.com/plotly/plotly.js/issues/2704
366
- Plots . doAutoMargin ,
367
344
Plots . previousPromises
368
- ) ;
345
+ ] ;
369
346
370
347
// even if everything we did was synchronous, return a promise
371
348
// so that the caller doesn't care which route we took
@@ -379,13 +356,7 @@ function plot(gd, data, layout, config) {
379
356
}
380
357
381
358
function emitAfterPlot ( gd ) {
382
- var fullLayout = gd . _fullLayout ;
383
-
384
- if ( fullLayout . _redrawFromAutoMarginCount ) {
385
- fullLayout . _redrawFromAutoMarginCount -- ;
386
- } else {
387
- gd . emit ( 'plotly_afterplot' ) ;
388
- }
359
+ gd . emit ( 'plotly_afterplot' ) ;
389
360
}
390
361
391
362
function setPlotConfig ( obj ) {
0 commit comments