@@ -33,6 +33,7 @@ var helpers = require('./helpers');
33
33
var subroutines = require ( './subroutines' ) ;
34
34
var cartesianConstants = require ( '../plots/cartesian/constants' ) ;
35
35
var enforceAxisConstraints = require ( '../plots/cartesian/constraints' ) ;
36
+ var axisIds = require ( '../plots/cartesian/axis_ids' ) ;
36
37
37
38
38
39
/**
@@ -1860,6 +1861,16 @@ function _relayout(gd, aobj) {
1860
1861
return ( ax || { } ) . autorange ;
1861
1862
}
1862
1863
1864
+ // for constraint enforcement: keep track of all axes (as {id: name})
1865
+ // we're editing the (auto)range of, so we can tell the others constrained
1866
+ // to scale with them that it's OK for them to shrink
1867
+ var rangesAltered = { } ;
1868
+
1869
+ function recordAlteredAxis ( pleafPlus ) {
1870
+ var axId = axisIds . name2id ( pleafPlus . split ( '.' ) [ 0 ] ) ;
1871
+ rangesAltered [ axId ] = 1 ;
1872
+ }
1873
+
1863
1874
// alter gd.layout
1864
1875
for ( var ai in aobj ) {
1865
1876
if ( helpers . hasParent ( aobj , ai ) ) {
@@ -1894,15 +1905,17 @@ function _relayout(gd, aobj) {
1894
1905
//
1895
1906
// To do so, we must manually set them back here using the _initialAutoSize cache.
1896
1907
if ( [ 'width' , 'height' ] . indexOf ( ai ) !== - 1 && vi === null ) {
1897
- gd . _fullLayout [ ai ] = gd . _initialAutoSize [ ai ] ;
1908
+ fullLayout [ ai ] = gd . _initialAutoSize [ ai ] ;
1898
1909
}
1899
1910
// check autorange vs range
1900
1911
else if ( pleafPlus . match ( / ^ [ x y z ] a x i s [ 0 - 9 ] * \. r a n g e ( \[ [ 0 | 1 ] \] ) ? $ / ) ) {
1901
1912
doextra ( ptrunk + '.autorange' , false ) ;
1913
+ recordAlteredAxis ( pleafPlus ) ;
1902
1914
}
1903
1915
else if ( pleafPlus . match ( / ^ [ x y z ] a x i s [ 0 - 9 ] * \. a u t o r a n g e $ / ) ) {
1904
1916
doextra ( [ ptrunk + '.range[0]' , ptrunk + '.range[1]' ] ,
1905
1917
undefined ) ;
1918
+ recordAlteredAxis ( pleafPlus ) ;
1906
1919
}
1907
1920
else if ( pleafPlus . match ( / ^ a s p e c t r a t i o \. [ x y z ] $ / ) ) {
1908
1921
doextra ( proot + '.aspectmode' , 'manual' ) ;
@@ -2121,16 +2134,37 @@ function _relayout(gd, aobj) {
2121
2134
if ( ! finished ) flags . doplot = true ;
2122
2135
}
2123
2136
2124
- var oldWidth = gd . _fullLayout . width ,
2125
- oldHeight = gd . _fullLayout . height ;
2137
+ // figure out if we need to recalculate axis constraints
2138
+ var constraints = fullLayout . _axisConstraintGroups ;
2139
+ for ( var axId in rangesAltered ) {
2140
+ for ( i = 0 ; i < constraints . length ; i ++ ) {
2141
+ var group = constraints [ i ] ;
2142
+ if ( group [ axId ] ) {
2143
+ // Always recalc if we're changing constrained ranges.
2144
+ // Otherwise it's possible to violate the constraints by
2145
+ // specifying arbitrary ranges for all axes in the group.
2146
+ // this way some ranges may expand beyond what's specified,
2147
+ // as they do at first draw, to satisfy the constraints.
2148
+ flags . docalc = true ;
2149
+ for ( var groupAxId in group ) {
2150
+ if ( ! rangesAltered [ groupAxId ] ) {
2151
+ axisIds . getFromId ( gd , groupAxId ) . _constraintShrinkable = true ;
2152
+ }
2153
+ }
2154
+ }
2155
+ }
2156
+ }
2157
+
2158
+ var oldWidth = fullLayout . width ,
2159
+ oldHeight = fullLayout . height ;
2126
2160
2127
2161
// calculate autosizing
2128
- if ( gd . layout . autosize ) Plots . plotAutoSize ( gd , gd . layout , gd . _fullLayout ) ;
2162
+ if ( gd . layout . autosize ) Plots . plotAutoSize ( gd , gd . layout , fullLayout ) ;
2129
2163
2130
2164
// avoid unnecessary redraws
2131
2165
var hasSizechanged = aobj . height || aobj . width ||
2132
- ( gd . _fullLayout . width !== oldWidth ) ||
2133
- ( gd . _fullLayout . height !== oldHeight ) ;
2166
+ ( fullLayout . width !== oldWidth ) ||
2167
+ ( fullLayout . height !== oldHeight ) ;
2134
2168
2135
2169
if ( hasSizechanged ) flags . docalc = true ;
2136
2170
0 commit comments