@@ -1223,7 +1223,7 @@ plots.sanitizeMargins = function(fullLayout) {
12231223 }
12241224} ;
12251225
1226- // called by legend and colorbar routines to see if we need to
1226+ // called by components to see if we need to
12271227// expand the margins to show them
12281228// o is {x,l,r,y,t,b} where x and y are plot fractions,
12291229// the rest are pixels in each direction
@@ -1263,7 +1263,7 @@ plots.doAutoMargin = function(gd) {
12631263 var gs = fullLayout . _size ,
12641264 oldmargins = JSON . stringify ( gs ) ;
12651265
1266- // adjust margins for outside legends and colorbars
1266+ // adjust margins for outside components
12671267 // fullLayout.margin is the requested margin,
12681268 // fullLayout._size has margins and plotsize after adjustment
12691269 var ml = Math . max ( fullLayout . margin . l || 0 , 0 ) ,
@@ -1273,26 +1273,37 @@ plots.doAutoMargin = function(gd) {
12731273 pm = fullLayout . _pushmargin ;
12741274
12751275 if ( fullLayout . margin . autoexpand !== false ) {
1276+
12761277 // fill in the requested margins
12771278 pm . base = {
12781279 l : { val : 0 , size : ml } ,
12791280 r : { val : 1 , size : mr } ,
12801281 t : { val : 1 , size : mt } ,
12811282 b : { val : 0 , size : mb }
12821283 } ;
1284+
12831285 // now cycle through all the combinations of l and r
12841286 // (and t and b) to find the required margins
1285- Object . keys ( pm ) . forEach ( function ( k1 ) {
1287+
1288+ var pmKeys = Object . keys ( pm ) ;
1289+
1290+ for ( var i = 0 ; i < pmKeys . length ; i ++ ) {
1291+ var k1 = pmKeys [ i ] ;
1292+
12861293 var pushleft = pm [ k1 ] . l || { } ,
12871294 pushbottom = pm [ k1 ] . b || { } ,
12881295 fl = pushleft . val ,
12891296 pl = pushleft . size ,
12901297 fb = pushbottom . val ,
12911298 pb = pushbottom . size ;
1292- Object . keys ( pm ) . forEach ( function ( k2 ) {
1299+
1300+ for ( var j = 0 ; j < pmKeys . length ; j ++ ) {
1301+ var k2 = pmKeys [ j ] ;
1302+
12931303 if ( isNumeric ( pl ) && pm [ k2 ] . r ) {
12941304 var fr = pm [ k2 ] . r . val ,
12951305 pr = pm [ k2 ] . r . size ;
1306+
12961307 if ( fr > fl ) {
12971308 var newl = ( pl * fr +
12981309 ( pr - fullLayout . width ) * fl ) / ( fr - fl ) ,
@@ -1304,9 +1315,11 @@ plots.doAutoMargin = function(gd) {
13041315 }
13051316 }
13061317 }
1318+
13071319 if ( isNumeric ( pb ) && pm [ k2 ] . t ) {
13081320 var ft = pm [ k2 ] . t . val ,
13091321 pt = pm [ k2 ] . t . size ;
1322+
13101323 if ( ft > fb ) {
13111324 var newb = ( pb * ft +
13121325 ( pt - fullLayout . height ) * fb ) / ( ft - fb ) ,
@@ -1318,8 +1331,8 @@ plots.doAutoMargin = function(gd) {
13181331 }
13191332 }
13201333 }
1321- } ) ;
1322- } ) ;
1334+ }
1335+ }
13231336 }
13241337
13251338 gs . l = Math . round ( ml ) ;
0 commit comments