@@ -479,15 +479,8 @@ plots.supplyDefaults = function(gd, opts) {
479
479
// relink functions and _ attributes to promote consistency between plots
480
480
relinkPrivateKeys ( newFullLayout , oldFullLayout ) ;
481
481
482
- // TODO may return a promise
483
- plots . doAutoMargin ( gd ) ;
484
-
485
- // set scale after auto margin routine
486
- var axList = axisIDs . list ( gd ) ;
487
- for ( i = 0 ; i < axList . length ; i ++ ) {
488
- var ax = axList [ i ] ;
489
- ax . setScale ( ) ;
490
- }
482
+ // set up containers for margin calculations
483
+ initMargins ( newFullLayout ) ;
491
484
492
485
// update object references in calcdata
493
486
if ( ! skipUpdateCalc && oldCalcdata . length === newFullData . length ) {
@@ -1651,7 +1644,20 @@ plots.allowAutoMargin = function(gd, id) {
1651
1644
gd . _fullLayout . _pushmarginIds [ id ] = 1 ;
1652
1645
} ;
1653
1646
1654
- function setupAutoMargin ( fullLayout ) {
1647
+ function initMargins ( fullLayout ) {
1648
+ var margin = fullLayout . margin ;
1649
+
1650
+ if ( ! fullLayout . _size ) {
1651
+ var gs = fullLayout . _size = {
1652
+ l : Math . round ( margin . l ) ,
1653
+ r : Math . round ( margin . r ) ,
1654
+ t : Math . round ( margin . t ) ,
1655
+ b : Math . round ( margin . b ) ,
1656
+ p : Math . round ( margin . pad )
1657
+ } ;
1658
+ gs . w = Math . round ( fullLayout . width ) - gs . l - gs . r ;
1659
+ gs . h = Math . round ( fullLayout . height ) - gs . t - gs . b ;
1660
+ }
1655
1661
if ( ! fullLayout . _pushmargin ) fullLayout . _pushmargin = { } ;
1656
1662
if ( ! fullLayout . _pushmarginIds ) fullLayout . _pushmarginIds = { } ;
1657
1663
}
@@ -1674,8 +1680,6 @@ function setupAutoMargin(fullLayout) {
1674
1680
plots . autoMargin = function ( gd , id , o ) {
1675
1681
var fullLayout = gd . _fullLayout ;
1676
1682
1677
- setupAutoMargin ( fullLayout ) ;
1678
-
1679
1683
var pushMargin = fullLayout . _pushmargin ;
1680
1684
var pushMarginIds = fullLayout . _pushmarginIds ;
1681
1685
@@ -1719,18 +1723,19 @@ plots.autoMargin = function(gd, id, o) {
1719
1723
plots . doAutoMargin = function ( gd ) {
1720
1724
var fullLayout = gd . _fullLayout ;
1721
1725
if ( ! fullLayout . _size ) fullLayout . _size = { } ;
1722
- setupAutoMargin ( fullLayout ) ;
1726
+ initMargins ( fullLayout ) ;
1723
1727
1724
- var gs = fullLayout . _size ,
1725
- oldmargins = JSON . stringify ( gs ) ;
1728
+ var gs = fullLayout . _size ;
1729
+ var oldmargins = JSON . stringify ( gs ) ;
1730
+ var margin = fullLayout . margin ;
1726
1731
1727
1732
// adjust margins for outside components
1728
1733
// fullLayout.margin is the requested margin,
1729
1734
// fullLayout._size has margins and plotsize after adjustment
1730
- var ml = Math . max ( fullLayout . margin . l || 0 , 0 ) ;
1731
- var mr = Math . max ( fullLayout . margin . r || 0 , 0 ) ;
1732
- var mt = Math . max ( fullLayout . margin . t || 0 , 0 ) ;
1733
- var mb = Math . max ( fullLayout . margin . b || 0 , 0 ) ;
1735
+ var ml = margin . l ;
1736
+ var mr = margin . r ;
1737
+ var mt = margin . t ;
1738
+ var mb = margin . b ;
1734
1739
var pushMargin = fullLayout . _pushmargin ;
1735
1740
var pushMarginIds = fullLayout . _pushmarginIds ;
1736
1741
@@ -1800,7 +1805,7 @@ plots.doAutoMargin = function(gd) {
1800
1805
gs . r = Math . round ( mr ) ;
1801
1806
gs . t = Math . round ( mt ) ;
1802
1807
gs . b = Math . round ( mb ) ;
1803
- gs . p = Math . round ( fullLayout . margin . pad ) ;
1808
+ gs . p = Math . round ( margin . pad ) ;
1804
1809
gs . w = Math . round ( fullLayout . width ) - gs . l - gs . r ;
1805
1810
gs . h = Math . round ( fullLayout . height ) - gs . t - gs . b ;
1806
1811
0 commit comments