@@ -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
}
@@ -1857,20 +1857,21 @@ function _relayout(gd, aobj) {
1857
1857
throw new Error ( 'cannot set ' + ai + 'and a parent attribute simultaneously' ) ;
1858
1858
}
1859
1859
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 ( ) ;
1874
1875
1875
1876
if ( vi === undefined ) continue ;
1876
1877
@@ -2093,25 +2094,18 @@ function _relayout(gd, aobj) {
2093
2094
flags . calc = true ;
2094
2095
for ( var groupAxId in group ) {
2095
2096
if ( ! rangesAltered [ groupAxId ] ) {
2096
- axisIds . getFromId ( gd , groupAxId ) . _constraintShrinkable = true ;
2097
+ Axes . getFromId ( gd , groupAxId ) . _constraintShrinkable = true ;
2097
2098
}
2098
2099
}
2099
2100
}
2100
2101
}
2101
2102
}
2102
2103
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 ;
2115
2109
2116
2110
if ( flags . plot || flags . calc ) {
2117
2111
flags . layoutReplot = true ;
@@ -2128,6 +2122,22 @@ function _relayout(gd, aobj) {
2128
2122
} ;
2129
2123
}
2130
2124
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
+
2131
2141
// for editing annotations or shapes - is it on autoscaled axes?
2132
2142
function refAutorange ( gd , obj , axLetter ) {
2133
2143
if ( ! Lib . isPlainObject ( obj ) ) return false ;
@@ -2313,6 +2323,17 @@ exports.react = function(gd, data, layout, config) {
2313
2323
var restyleFlags = diffData ( gd , oldFullData , newFullData , immutable ) ;
2314
2324
var relayoutFlags = diffLayout ( gd , oldFullLayout , newFullLayout , immutable ) ;
2315
2325
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
+
2316
2337
// clear calcdata if required
2317
2338
if ( restyleFlags . calc || relayoutFlags . calc ) gd . calcdata = undefined ;
2318
2339
if ( relayoutFlags . margins ) helpers . clearAxisAutomargins ( gd ) ;
0 commit comments