@@ -40,7 +40,7 @@ var cartesianConstants = require('../plots/cartesian/constants');
4040var axisConstraints = require ( '../plots/cartesian/constraints' ) ;
4141var enforceAxisConstraints = axisConstraints . enforce ;
4242var cleanAxisConstraints = axisConstraints . clean ;
43- var axisIds = require ( '../plots/cartesian/axis_ids' ) ;
43+ var doAutoRange = require ( '../plots/cartesian/autorange' ) . doAutoRange ;
4444
4545var numericNameWarningCount = 0 ;
4646var numericNameWarningCountLimit = 5 ;
@@ -283,7 +283,7 @@ exports.plot = function(gd, data, layout, config) {
283283
284284 function positionAndAutorange ( ) {
285285 if ( ! recalc ) {
286- enforceAxisConstraints ( gd ) ;
286+ doAutoRangeAndConstraints ( ) ;
287287 return ;
288288 }
289289
@@ -332,7 +332,7 @@ exports.plot = function(gd, data, layout, config) {
332332 var ax = axList [ i ] ;
333333 cleanAxisConstraints ( gd , ax ) ;
334334
335- Axes . doAutoRange ( ax ) ;
335+ doAutoRange ( ax ) ;
336336 }
337337
338338 enforceAxisConstraints ( gd ) ;
@@ -1846,7 +1846,7 @@ function _relayout(gd, aobj) {
18461846 var axId ;
18471847
18481848 function recordAlteredAxis ( pleafPlus ) {
1849- var axId = axisIds . name2id ( pleafPlus . split ( '.' ) [ 0 ] ) ;
1849+ var axId = Axes . name2id ( pleafPlus . split ( '.' ) [ 0 ] ) ;
18501850 rangesAltered [ axId ] = 1 ;
18511851 return axId ;
18521852 }
@@ -1857,20 +1857,21 @@ function _relayout(gd, aobj) {
18571857 throw new Error ( 'cannot set ' + ai + 'and a parent attribute simultaneously' ) ;
18581858 }
18591859
1860- var p = Lib . nestedProperty ( layout , ai ) ,
1861- vi = aobj [ ai ] ,
1862- plen = p . parts . length ,
1863- // p.parts may end with an index integer if the property is an array
1864- pend = typeof p . parts [ plen - 1 ] === 'string' ? ( plen - 1 ) : ( plen - 2 ) ,
1865- // last property in chain (leaf node)
1866- pleaf = p . parts [ pend ] ,
1867- // leaf plus immediate parent
1868- pleafPlus = p . parts [ pend - 1 ] + '.' + pleaf ,
1869- // trunk nodes (everything except the leaf)
1870- ptrunk = p . parts . slice ( 0 , pend ) . join ( '.' ) ,
1871- parentIn = Lib . nestedProperty ( gd . layout , ptrunk ) . get ( ) ,
1872- parentFull = Lib . nestedProperty ( fullLayout , ptrunk ) . get ( ) ,
1873- vOld = p . get ( ) ;
1860+ var p = Lib . nestedProperty ( layout , ai ) ;
1861+ var vi = aobj [ ai ] ;
1862+ var plen = p . parts . length ;
1863+ // p.parts may end with an index integer if the property is an array
1864+ var pend = plen - 1 ;
1865+ while ( pend > 0 && typeof p . parts [ plen - 1 ] !== 'string' ) { pend -- ; }
1866+ // last property in chain (leaf node)
1867+ var pleaf = p . parts [ pend ] ;
1868+ // leaf plus immediate parent
1869+ var pleafPlus = p . parts [ pend - 1 ] + '.' + pleaf ;
1870+ // trunk nodes (everything except the leaf)
1871+ var ptrunk = p . parts . slice ( 0 , pend ) . join ( '.' ) ;
1872+ var parentIn = Lib . nestedProperty ( gd . layout , ptrunk ) . get ( ) ;
1873+ var parentFull = Lib . nestedProperty ( fullLayout , ptrunk ) . get ( ) ;
1874+ var vOld = p . get ( ) ;
18741875
18751876 if ( vi === undefined ) continue ;
18761877
@@ -2093,25 +2094,18 @@ function _relayout(gd, aobj) {
20932094 flags . calc = true ;
20942095 for ( var groupAxId in group ) {
20952096 if ( ! rangesAltered [ groupAxId ] ) {
2096- axisIds . getFromId ( gd , groupAxId ) . _constraintShrinkable = true ;
2097+ Axes . getFromId ( gd , groupAxId ) . _constraintShrinkable = true ;
20972098 }
20982099 }
20992100 }
21002101 }
21012102 }
21022103
2103- var oldWidth = fullLayout . width ,
2104- oldHeight = fullLayout . height ;
2105-
2106- // calculate autosizing
2107- if ( gd . layout . autosize ) Plots . plotAutoSize ( gd , gd . layout , fullLayout ) ;
2108-
2109- // avoid unnecessary redraws
2110- var hasSizechanged = aobj . height || aobj . width ||
2111- ( fullLayout . width !== oldWidth ) ||
2112- ( fullLayout . height !== oldHeight ) ;
2113-
2114- if ( hasSizechanged ) flags . calc = true ;
2104+ // If the autosize changed or height or width was explicitly specified,
2105+ // this triggers a redraw
2106+ // TODO: do we really need special aobj.height/width handling here?
2107+ // couldn't editType do this?
2108+ if ( updateAutosize ( gd ) || aobj . height || aobj . width ) flags . plot = true ;
21152109
21162110 if ( flags . plot || flags . calc ) {
21172111 flags . layoutReplot = true ;
@@ -2128,6 +2122,22 @@ function _relayout(gd, aobj) {
21282122 } ;
21292123}
21302124
2125+ /*
2126+ * updateAutosize: we made a change, does it change the autosize result?
2127+ * puts the new size into fullLayout
2128+ * returns true if either height or width changed
2129+ */
2130+ function updateAutosize ( gd ) {
2131+ var fullLayout = gd . _fullLayout ;
2132+ var oldWidth = fullLayout . width ;
2133+ var oldHeight = fullLayout . height ;
2134+
2135+ // calculate autosizing
2136+ if ( gd . layout . autosize ) Plots . plotAutoSize ( gd , gd . layout , fullLayout ) ;
2137+
2138+ return ( fullLayout . width !== oldWidth ) || ( fullLayout . height !== oldHeight ) ;
2139+ }
2140+
21312141// for editing annotations or shapes - is it on autoscaled axes?
21322142function refAutorange ( gd , obj , axLetter ) {
21332143 if ( ! Lib . isPlainObject ( obj ) ) return false ;
@@ -2313,6 +2323,17 @@ exports.react = function(gd, data, layout, config) {
23132323 var restyleFlags = diffData ( gd , oldFullData , newFullData , immutable ) ;
23142324 var relayoutFlags = diffLayout ( gd , oldFullLayout , newFullLayout , immutable ) ;
23152325
2326+ // TODO: how to translate this part of relayout to Plotly.react?
2327+ // // Setting width or height to null must reset the graph's width / height
2328+ // // back to its initial value as computed during the first pass in Plots.plotAutoSize.
2329+ // //
2330+ // // To do so, we must manually set them back here using the _initialAutoSize cache.
2331+ // if(['width', 'height'].indexOf(ai) !== -1 && vi === null) {
2332+ // fullLayout[ai] = gd._initialAutoSize[ai];
2333+ // }
2334+
2335+ if ( updateAutosize ( gd ) ) relayoutFlags . layoutReplot = true ;
2336+
23162337 // clear calcdata if required
23172338 if ( restyleFlags . calc || relayoutFlags . calc ) gd . calcdata = undefined ;
23182339 if ( relayoutFlags . margins ) helpers . clearAxisAutomargins ( gd ) ;
0 commit comments