@@ -40,7 +40,7 @@ var cartesianConstants = require('../plots/cartesian/constants');
40
40
var axisConstraints = require ( '../plots/cartesian/constraints' ) ;
41
41
var enforceAxisConstraints = axisConstraints . enforce ;
42
42
var cleanAxisConstraints = axisConstraints . clean ;
43
- var axisIds = require ( '../plots/cartesian/axis_ids' ) ;
43
+ var doAutoRange = require ( '../plots/cartesian/autorange' ) . doAutoRange ;
44
44
45
45
var numericNameWarningCount = 0 ;
46
46
var numericNameWarningCountLimit = 5 ;
@@ -283,7 +283,7 @@ exports.plot = function(gd, data, layout, config) {
283
283
284
284
function positionAndAutorange ( ) {
285
285
if ( ! recalc ) {
286
- enforceAxisConstraints ( gd ) ;
286
+ doAutoRangeAndConstraints ( ) ;
287
287
return ;
288
288
}
289
289
@@ -332,7 +332,7 @@ exports.plot = function(gd, data, layout, config) {
332
332
var ax = axList [ i ] ;
333
333
cleanAxisConstraints ( gd , ax ) ;
334
334
335
- Axes . doAutoRange ( ax ) ;
335
+ doAutoRange ( ax ) ;
336
336
}
337
337
338
338
enforceAxisConstraints ( gd ) ;
@@ -1846,7 +1846,7 @@ function _relayout(gd, aobj) {
1846
1846
var axId ;
1847
1847
1848
1848
function recordAlteredAxis ( pleafPlus ) {
1849
- var axId = axisIds . name2id ( pleafPlus . split ( '.' ) [ 0 ] ) ;
1849
+ var axId = Axes . name2id ( pleafPlus . split ( '.' ) [ 0 ] ) ;
1850
1850
rangesAltered [ axId ] = 1 ;
1851
1851
return axId ;
1852
1852
}
@@ -2093,25 +2093,18 @@ function _relayout(gd, aobj) {
2093
2093
flags . calc = true ;
2094
2094
for ( var groupAxId in group ) {
2095
2095
if ( ! rangesAltered [ groupAxId ] ) {
2096
- axisIds . getFromId ( gd , groupAxId ) . _constraintShrinkable = true ;
2096
+ Axes . getFromId ( gd , groupAxId ) . _constraintShrinkable = true ;
2097
2097
}
2098
2098
}
2099
2099
}
2100
2100
}
2101
2101
}
2102
2102
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 ;
2115
2108
2116
2109
if ( flags . plot || flags . calc ) {
2117
2110
flags . layoutReplot = true ;
@@ -2128,6 +2121,22 @@ function _relayout(gd, aobj) {
2128
2121
} ;
2129
2122
}
2130
2123
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
+
2131
2140
// for editing annotations or shapes - is it on autoscaled axes?
2132
2141
function refAutorange ( gd , obj , axLetter ) {
2133
2142
if ( ! Lib . isPlainObject ( obj ) ) return false ;
@@ -2313,6 +2322,17 @@ exports.react = function(gd, data, layout, config) {
2313
2322
var restyleFlags = diffData ( gd , oldFullData , newFullData , immutable ) ;
2314
2323
var relayoutFlags = diffLayout ( gd , oldFullLayout , newFullLayout , immutable ) ;
2315
2324
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
+
2316
2336
// clear calcdata if required
2317
2337
if ( restyleFlags . calc || relayoutFlags . calc ) gd . calcdata = undefined ;
2318
2338
if ( relayoutFlags . margins ) helpers . clearAxisAutomargins ( gd ) ;
0 commit comments