@@ -409,10 +409,6 @@ function plotPolar(gd, data, layout) {
409409 if ( layout ) gd . layout = layout ;
410410 Plotly . micropolar . manager . fillLayout ( gd ) ;
411411
412- if ( gd . _fullLayout . autosize === 'initial' && gd . _context . autosizable ) {
413- plotAutoSize ( gd , { } ) ;
414- gd . _fullLayout . autosize = layout . autosize = true ;
415- }
416412 // resize canvas
417413 paperDiv . style ( {
418414 width : gd . _fullLayout . width + 'px' ,
@@ -2148,8 +2144,6 @@ Plotly.relayout = function relayout(gd, astr, val) {
21482144 return ( fullLayout [ axName ] || { } ) . autorange ;
21492145 }
21502146
2151- var hw = [ 'height' , 'width' ] ;
2152-
21532147 // alter gd.layout
21542148 for ( var ai in aobj ) {
21552149 var p = Lib . nestedProperty ( layout , ai ) ,
@@ -2172,14 +2166,8 @@ Plotly.relayout = function relayout(gd, astr, val) {
21722166 // op and has no flag.
21732167 undoit [ ai ] = ( pleaf === 'reverse' ) ? vi : p . get ( ) ;
21742168
2175- // check autosize or autorange vs size and range
2176- if ( hw . indexOf ( ai ) !== - 1 ) {
2177- doextra ( 'autosize' , false ) ;
2178- }
2179- else if ( ai === 'autosize' ) {
2180- doextra ( hw , undefined ) ;
2181- }
2182- else if ( pleafPlus . match ( / ^ [ x y z ] a x i s [ 0 - 9 ] * \. r a n g e ( \[ [ 0 | 1 ] \] ) ? $ / ) ) {
2169+ // check autorange vs range
2170+ if ( pleafPlus . match ( / ^ [ x y z ] a x i s [ 0 - 9 ] * \. r a n g e ( \[ [ 0 | 1 ] \] ) ? $ / ) ) {
21832171 doextra ( ptrunk + '.autorange' , false ) ;
21842172 }
21852173 else if ( pleafPlus . match ( / ^ [ x y z ] a x i s [ 0 - 9 ] * \. a u t o r a n g e $ / ) ) {
@@ -2357,11 +2345,20 @@ Plotly.relayout = function relayout(gd, astr, val) {
23572345 Queue . add ( gd , relayout , [ gd , undoit ] , relayout , [ gd , redoit ] ) ;
23582346 }
23592347
2360- // calculate autosizing - if size hasn't changed,
2361- // will remove h&w so we don't need to redraw
2362- if ( aobj . autosize ) aobj = plotAutoSize ( gd , aobj ) ;
2348+ var oldWidth = gd . _fullLayout . width ,
2349+ oldHeight = gd . _fullLayout . height ;
23632350
2364- if ( aobj . height || aobj . width || aobj . autosize ) docalc = true ;
2351+ // coerce the updated layout
2352+ Plots . supplyDefaults ( gd ) ;
2353+
2354+ // calculate autosizing
2355+ if ( gd . layout . autosize ) Plots . plotAutoSize ( gd , gd . layout , gd . _fullLayout ) ;
2356+
2357+ // avoid unnecessary redraws
2358+ var changed = aobj . height || aobj . width ||
2359+ ( gd . _fullLayout . width !== oldWidth ) ||
2360+ ( gd . _fullLayout . height !== oldHeight ) ;
2361+ if ( changed ) docalc = true ;
23652362
23662363 // redraw
23672364 // first check if there's still anything to do
@@ -2382,7 +2379,6 @@ Plotly.relayout = function relayout(gd, astr, val) {
23822379 }
23832380 else if ( ak . length ) {
23842381 // if we didn't need to redraw entirely, just do the needed parts
2385- Plots . supplyDefaults ( gd ) ;
23862382 fullLayout = gd . _fullLayout ;
23872383
23882384 if ( dolegend ) {
@@ -2491,86 +2487,6 @@ Plotly.purge = function purge(gd) {
24912487 return gd ;
24922488} ;
24932489
2494- /**
2495- * Reduce all reserved margin objects to a single required margin reservation.
2496- *
2497- * @param {Object } margins
2498- * @returns {{left: number, right: number, bottom: number, top: number} }
2499- */
2500- function calculateReservedMargins ( margins ) {
2501- var resultingMargin = { left : 0 , right : 0 , bottom : 0 , top : 0 } ,
2502- marginName ;
2503-
2504- if ( margins ) {
2505- for ( marginName in margins ) {
2506- if ( margins . hasOwnProperty ( marginName ) ) {
2507- resultingMargin . left += margins [ marginName ] . left || 0 ;
2508- resultingMargin . right += margins [ marginName ] . right || 0 ;
2509- resultingMargin . bottom += margins [ marginName ] . bottom || 0 ;
2510- resultingMargin . top += margins [ marginName ] . top || 0 ;
2511- }
2512- }
2513- }
2514- return resultingMargin ;
2515- }
2516-
2517- function plotAutoSize ( gd , aobj ) {
2518- var fullLayout = gd . _fullLayout ,
2519- context = gd . _context ,
2520- computedStyle ;
2521-
2522- var newHeight , newWidth ;
2523-
2524- gd . emit ( 'plotly_autosize' ) ;
2525-
2526- // embedded in an iframe - just take the full iframe size
2527- // if we get to this point, with no aspect ratio restrictions
2528- if ( gd . _context . fillFrame ) {
2529- newWidth = window . innerWidth ;
2530- newHeight = window . innerHeight ;
2531-
2532- // somehow we get a few extra px height sometimes...
2533- // just hide it
2534- document . body . style . overflow = 'hidden' ;
2535- }
2536- else if ( isNumeric ( context . frameMargins ) && context . frameMargins > 0 ) {
2537- var reservedMargins = calculateReservedMargins ( gd . _boundingBoxMargins ) ,
2538- reservedWidth = reservedMargins . left + reservedMargins . right ,
2539- reservedHeight = reservedMargins . bottom + reservedMargins . top ,
2540- gdBB = fullLayout . _container . node ( ) . getBoundingClientRect ( ) ,
2541- factor = 1 - 2 * context . frameMargins ;
2542-
2543- newWidth = Math . round ( factor * ( gdBB . width - reservedWidth ) ) ;
2544- newHeight = Math . round ( factor * ( gdBB . height - reservedHeight ) ) ;
2545- }
2546- else {
2547- // plotly.js - let the developers do what they want, either
2548- // provide height and width for the container div,
2549- // specify size in layout, or take the defaults,
2550- // but don't enforce any ratio restrictions
2551- computedStyle = window . getComputedStyle ( gd ) ;
2552- newHeight = parseFloat ( computedStyle . height ) || fullLayout . height ;
2553- newWidth = parseFloat ( computedStyle . width ) || fullLayout . width ;
2554- }
2555-
2556- if ( Math . abs ( fullLayout . width - newWidth ) > 1 ||
2557- Math . abs ( fullLayout . height - newHeight ) > 1 ) {
2558- fullLayout . height = gd . layout . height = newHeight ;
2559- fullLayout . width = gd . layout . width = newWidth ;
2560- }
2561- // if there's no size change, update layout but
2562- // delete the autosize attr so we don't redraw
2563- // but can't call layoutStyles for initial autosize
2564- else if ( fullLayout . autosize !== 'initial' ) {
2565- delete ( aobj . autosize ) ;
2566- fullLayout . autosize = gd . layout . autosize = true ;
2567- }
2568-
2569- Plots . sanitizeMargins ( fullLayout ) ;
2570-
2571- return aobj ;
2572- }
2573-
25742490// -------------------------------------------------------
25752491// makePlotFramework: Create the plot container and axes
25762492// -------------------------------------------------------
@@ -2590,13 +2506,6 @@ function makePlotFramework(gd) {
25902506 . classed ( 'svg-container' , true )
25912507 . style ( 'position' , 'relative' ) ;
25922508
2593- // Initial autosize
2594- if ( fullLayout . autosize === 'initial' ) {
2595- plotAutoSize ( gd , { } ) ;
2596- fullLayout . autosize = true ;
2597- gd . layout . autosize = true ;
2598- }
2599-
26002509 // Make the graph containers
26012510 // start fresh each time we get here, so we know the order comes out
26022511 // right, rather than enter/exit which can muck up the order
0 commit comments