@@ -497,15 +497,8 @@ plots.supplyDefaults = function(gd, opts) {
497497 if ( uids [ uid ] === 'old' ) delete tracePreGUI [ uid ] ;
498498 }
499499
500- // TODO may return a promise
501- plots . doAutoMargin ( gd ) ;
502-
503- // set scale after auto margin routine
504- var axList = axisIDs . list ( gd ) ;
505- for ( i = 0 ; i < axList . length ; i ++ ) {
506- var ax = axList [ i ] ;
507- ax . setScale ( ) ;
508- }
500+ // set up containers for margin calculations
501+ initMargins ( newFullLayout ) ;
509502
510503 // update object references in calcdata
511504 if ( ! skipUpdateCalc && oldCalcdata . length === newFullData . length ) {
@@ -1686,7 +1679,20 @@ plots.allowAutoMargin = function(gd, id) {
16861679 gd . _fullLayout . _pushmarginIds [ id ] = 1 ;
16871680} ;
16881681
1689- function setupAutoMargin ( fullLayout ) {
1682+ function initMargins ( fullLayout ) {
1683+ var margin = fullLayout . margin ;
1684+
1685+ if ( ! fullLayout . _size ) {
1686+ var gs = fullLayout . _size = {
1687+ l : Math . round ( margin . l ) ,
1688+ r : Math . round ( margin . r ) ,
1689+ t : Math . round ( margin . t ) ,
1690+ b : Math . round ( margin . b ) ,
1691+ p : Math . round ( margin . pad )
1692+ } ;
1693+ gs . w = Math . round ( fullLayout . width ) - gs . l - gs . r ;
1694+ gs . h = Math . round ( fullLayout . height ) - gs . t - gs . b ;
1695+ }
16901696 if ( ! fullLayout . _pushmargin ) fullLayout . _pushmargin = { } ;
16911697 if ( ! fullLayout . _pushmarginIds ) fullLayout . _pushmarginIds = { } ;
16921698}
@@ -1709,8 +1715,6 @@ function setupAutoMargin(fullLayout) {
17091715plots . autoMargin = function ( gd , id , o ) {
17101716 var fullLayout = gd . _fullLayout ;
17111717
1712- setupAutoMargin ( fullLayout ) ;
1713-
17141718 var pushMargin = fullLayout . _pushmargin ;
17151719 var pushMarginIds = fullLayout . _pushmarginIds ;
17161720
@@ -1754,18 +1758,19 @@ plots.autoMargin = function(gd, id, o) {
17541758plots . doAutoMargin = function ( gd ) {
17551759 var fullLayout = gd . _fullLayout ;
17561760 if ( ! fullLayout . _size ) fullLayout . _size = { } ;
1757- setupAutoMargin ( fullLayout ) ;
1761+ initMargins ( fullLayout ) ;
17581762
1759- var gs = fullLayout . _size ,
1760- oldmargins = JSON . stringify ( gs ) ;
1763+ var gs = fullLayout . _size ;
1764+ var oldmargins = JSON . stringify ( gs ) ;
1765+ var margin = fullLayout . margin ;
17611766
17621767 // adjust margins for outside components
17631768 // fullLayout.margin is the requested margin,
17641769 // fullLayout._size has margins and plotsize after adjustment
1765- var ml = Math . max ( fullLayout . margin . l || 0 , 0 ) ;
1766- var mr = Math . max ( fullLayout . margin . r || 0 , 0 ) ;
1767- var mt = Math . max ( fullLayout . margin . t || 0 , 0 ) ;
1768- var mb = Math . max ( fullLayout . margin . b || 0 , 0 ) ;
1770+ var ml = margin . l ;
1771+ var mr = margin . r ;
1772+ var mt = margin . t ;
1773+ var mb = margin . b ;
17691774 var pushMargin = fullLayout . _pushmargin ;
17701775 var pushMarginIds = fullLayout . _pushmarginIds ;
17711776
@@ -1835,7 +1840,7 @@ plots.doAutoMargin = function(gd) {
18351840 gs . r = Math . round ( mr ) ;
18361841 gs . t = Math . round ( mt ) ;
18371842 gs . b = Math . round ( mb ) ;
1838- gs . p = Math . round ( fullLayout . margin . pad ) ;
1843+ gs . p = Math . round ( margin . pad ) ;
18391844 gs . w = Math . round ( fullLayout . width ) - gs . l - gs . r ;
18401845 gs . h = Math . round ( fullLayout . height ) - gs . t - gs . b ;
18411846
0 commit comments