@@ -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 }
@@ -2093,25 +2093,18 @@ function _relayout(gd, aobj) {
20932093 flags . calc = true ;
20942094 for ( var groupAxId in group ) {
20952095 if ( ! rangesAltered [ groupAxId ] ) {
2096- axisIds . getFromId ( gd , groupAxId ) . _constraintShrinkable = true ;
2096+ Axes . getFromId ( gd , groupAxId ) . _constraintShrinkable = true ;
20972097 }
20982098 }
20992099 }
21002100 }
21012101 }
21022102
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 ;
2103+ // If the autosize changed or height or width was explicitly specified,
2104+ // this triggers a redraw
2105+ // TODO: do we really need special aobj.height/width handling here?
2106+ // couldn't editType do this?
2107+ if ( updateAutosize ( gd ) || aobj . height || aobj . width ) flags . plot = true ;
21152108
21162109 if ( flags . plot || flags . calc ) {
21172110 flags . layoutReplot = true ;
@@ -2128,6 +2121,22 @@ function _relayout(gd, aobj) {
21282121 } ;
21292122}
21302123
2124+ /*
2125+ * updateAutosize: we made a change, does it change the autosize result?
2126+ * puts the new size into fullLayout
2127+ * returns true if either height or width changed
2128+ */
2129+ function updateAutosize ( gd ) {
2130+ var fullLayout = gd . _fullLayout ;
2131+ var oldWidth = fullLayout . width ;
2132+ var oldHeight = fullLayout . height ;
2133+
2134+ // calculate autosizing
2135+ if ( gd . layout . autosize ) Plots . plotAutoSize ( gd , gd . layout , fullLayout ) ;
2136+
2137+ return ( fullLayout . width !== oldWidth ) || ( fullLayout . height !== oldHeight ) ;
2138+ }
2139+
21312140// for editing annotations or shapes - is it on autoscaled axes?
21322141function refAutorange ( gd , obj , axLetter ) {
21332142 if ( ! Lib . isPlainObject ( obj ) ) return false ;
@@ -2313,6 +2322,17 @@ exports.react = function(gd, data, layout, config) {
23132322 var restyleFlags = diffData ( gd , oldFullData , newFullData , immutable ) ;
23142323 var relayoutFlags = diffLayout ( gd , oldFullLayout , newFullLayout , immutable ) ;
23152324
2325+ // TODO: how to translate this part of relayout to Plotly.react?
2326+ // // Setting width or height to null must reset the graph's width / height
2327+ // // back to its initial value as computed during the first pass in Plots.plotAutoSize.
2328+ // //
2329+ // // To do so, we must manually set them back here using the _initialAutoSize cache.
2330+ // if(['width', 'height'].indexOf(ai) !== -1 && vi === null) {
2331+ // fullLayout[ai] = gd._initialAutoSize[ai];
2332+ // }
2333+
2334+ if ( updateAutosize ( gd ) ) relayoutFlags . layoutReplot = true ;
2335+
23162336 // clear calcdata if required
23172337 if ( restyleFlags . calc || relayoutFlags . calc ) gd . calcdata = undefined ;
23182338 if ( relayoutFlags . margins ) helpers . clearAxisAutomargins ( gd ) ;
0 commit comments