@@ -252,10 +252,15 @@ exports.plot = function(gd, data, layout, config) {
252
252
var calcdata = gd . calcdata ;
253
253
var i , cd , trace ;
254
254
255
- Registry . getComponentMethod ( 'legend' , 'draw' ) ( gd ) ;
256
- Registry . getComponentMethod ( 'rangeselector' , 'draw' ) ( gd ) ;
257
- Registry . getComponentMethod ( 'sliders' , 'draw' ) ( gd ) ;
258
- Registry . getComponentMethod ( 'updatemenus' , 'draw' ) ( gd ) ;
255
+ // First reset the list of things that are allowed to change the margins
256
+ // So any deleted traces or components will be wiped out of the
257
+ // automargin calculation.
258
+ // This means *every* margin pusher must be listed here, even if it
259
+ // doesn't actually try to push the margins until later.
260
+ Plots . clearAutoMarginIds ( gd ) ;
261
+
262
+ subroutines . drawMarginPushers ( gd ) ;
263
+ Axes . allowAutoMargin ( gd ) ;
259
264
260
265
for ( i = 0 ; i < calcdata . length ; i ++ ) {
261
266
cd = calcdata [ i ] ;
@@ -354,6 +359,10 @@ exports.plot = function(gd, data, layout, config) {
354
359
initInteractions ,
355
360
Plots . addLinks ,
356
361
Plots . rehover ,
362
+ // TODO: shouldn't really need doAutoMargin here, but without it some
363
+ // edits don't manage to tweak the margins the way they should
364
+ // in the tests, the only one that presently breaks is axis.position
365
+ Plots . doAutoMargin ,
357
366
Plots . previousPromises
358
367
) ;
359
368
@@ -1666,7 +1675,6 @@ exports.relayout = function relayout(gd, astr, val) {
1666
1675
1667
1676
// clear calcdata if required
1668
1677
if ( flags . calc ) gd . calcdata = undefined ;
1669
- if ( flags . margins ) helpers . clearAxisAutomargins ( gd ) ;
1670
1678
1671
1679
// fill in redraw sequence
1672
1680
@@ -1685,16 +1693,7 @@ exports.relayout = function relayout(gd, astr, val) {
1685
1693
if ( flags . layoutstyle ) seq . push ( subroutines . layoutStyles ) ;
1686
1694
1687
1695
if ( flags . axrange ) {
1688
- // N.B. leave as sequence of subroutines (for now) instead of
1689
- // subroutine of its own so that finalDraw always gets
1690
- // executed after drawData
1691
- seq . push (
1692
- function ( gd ) {
1693
- return subroutines . doTicksRelayout ( gd , specs . rangesAltered ) ;
1694
- } ,
1695
- subroutines . drawData ,
1696
- subroutines . finalDraw
1697
- ) ;
1696
+ addAxRangeSequence ( seq , specs . rangesAltered ) ;
1698
1697
}
1699
1698
1700
1699
if ( flags . ticks ) seq . push ( subroutines . doTicksRelayout ) ;
@@ -1718,6 +1717,22 @@ exports.relayout = function relayout(gd, astr, val) {
1718
1717
} ) ;
1719
1718
} ;
1720
1719
1720
+ function addAxRangeSequence ( seq , rangesAltered ) {
1721
+ // N.B. leave as sequence of subroutines (for now) instead of
1722
+ // subroutine of its own so that finalDraw always gets
1723
+ // executed after drawData
1724
+ var doTicks = rangesAltered ?
1725
+ function ( gd ) { return subroutines . doTicksRelayout ( gd , rangesAltered ) ; } :
1726
+ subroutines . doTicksRelayout ;
1727
+
1728
+ seq . push (
1729
+ doTicks ,
1730
+ subroutines . drawData ,
1731
+ subroutines . finalDraw ,
1732
+ subroutines . drawMarginPushers
1733
+ ) ;
1734
+ }
1735
+
1721
1736
var AX_RANGE_RE = / ^ [ x y z ] a x i s [ 0 - 9 ] * \. r a n g e ( \[ [ 0 | 1 ] \] ) ? $ / ;
1722
1737
var AX_AUTORANGE_RE = / ^ [ x y z ] a x i s [ 0 - 9 ] * \. a u t o r a n g e $ / ;
1723
1738
var AX_DOMAIN_RE = / ^ [ x y z ] a x i s [ 0 - 9 ] * \. d o m a i n ( \[ [ 0 | 1 ] \] ) ? $ / ;
@@ -2137,7 +2152,6 @@ exports.update = function update(gd, traceUpdate, layoutUpdate, _traces) {
2137
2152
// clear calcdata and/or axis types if required
2138
2153
if ( restyleFlags . clearCalc || relayoutFlags . calc ) gd . calcdata = undefined ;
2139
2154
if ( restyleFlags . clearAxisTypes ) helpers . clearAxisTypes ( gd , traces , layoutUpdate ) ;
2140
- if ( relayoutFlags . margins ) helpers . clearAxisAutomargins ( gd ) ;
2141
2155
2142
2156
// fill in redraw sequence
2143
2157
var seq = [ ] ;
@@ -2168,13 +2182,7 @@ exports.update = function update(gd, traceUpdate, layoutUpdate, _traces) {
2168
2182
if ( relayoutFlags . legend ) seq . push ( subroutines . doLegend ) ;
2169
2183
if ( relayoutFlags . layoutstyle ) seq . push ( subroutines . layoutStyles ) ;
2170
2184
if ( relayoutFlags . axrange ) {
2171
- seq . push (
2172
- function ( gd ) {
2173
- return subroutines . doTicksRelayout ( gd , relayoutSpecs . rangesAltered ) ;
2174
- } ,
2175
- subroutines . drawData ,
2176
- subroutines . finalDraw
2177
- ) ;
2185
+ addAxRangeSequence ( seq , relayoutSpecs . rangesAltered ) ;
2178
2186
}
2179
2187
if ( relayoutFlags . ticks ) seq . push ( subroutines . doTicksRelayout ) ;
2180
2188
if ( relayoutFlags . modebar ) seq . push ( subroutines . doModeBar ) ;
@@ -2291,8 +2299,6 @@ exports.react = function(gd, data, layout, config) {
2291
2299
// otherwise do the calcdata updates and calcTransform array remaps that we skipped earlier
2292
2300
else Plots . supplyDefaultsUpdateCalc ( gd . calcdata , newFullData ) ;
2293
2301
2294
- if ( relayoutFlags . margins ) helpers . clearAxisAutomargins ( gd ) ;
2295
-
2296
2302
// Note: what restyle/relayout use impliedEdits and clearAxisTypes for
2297
2303
// must be handled by the user when using Plotly.react.
2298
2304
@@ -2334,13 +2340,7 @@ exports.react = function(gd, data, layout, config) {
2334
2340
if ( restyleFlags . colorbars ) seq . push ( subroutines . doColorBars ) ;
2335
2341
if ( relayoutFlags . legend ) seq . push ( subroutines . doLegend ) ;
2336
2342
if ( relayoutFlags . layoutstyle ) seq . push ( subroutines . layoutStyles ) ;
2337
- if ( relayoutFlags . axrange ) {
2338
- seq . push (
2339
- subroutines . doTicksRelayout ,
2340
- subroutines . drawData ,
2341
- subroutines . finalDraw
2342
- ) ;
2343
- }
2343
+ if ( relayoutFlags . axrange ) addAxRangeSequence ( seq ) ;
2344
2344
if ( relayoutFlags . ticks ) seq . push ( subroutines . doTicksRelayout ) ;
2345
2345
if ( relayoutFlags . modebar ) seq . push ( subroutines . doModeBar ) ;
2346
2346
if ( relayoutFlags . camera ) seq . push ( subroutines . doCamera ) ;
0 commit comments