@@ -32,7 +32,9 @@ var manageArrays = require('./manage_arrays');
3232var helpers = require ( './helpers' ) ;
3333var subroutines = require ( './subroutines' ) ;
3434var cartesianConstants = require ( '../plots/cartesian/constants' ) ;
35- var enforceAxisConstraints = require ( '../plots/cartesian/constraints' ) ;
35+ var axisConstraints = require ( '../plots/cartesian/constraints' ) ;
36+ var enforceAxisConstraints = axisConstraints . enforce ;
37+ var cleanAxisConstraints = axisConstraints . clean ;
3638var axisIds = require ( '../plots/cartesian/axis_ids' ) ;
3739
3840
@@ -190,8 +192,7 @@ Plotly.plot = function(gd, data, layout, config) {
190192
191193 return Lib . syncOrAsync ( [
192194 subroutines . layoutStyles ,
193- drawAxes ,
194- initInteractions
195+ drawAxes
195196 ] , gd ) ;
196197 }
197198
@@ -220,19 +221,19 @@ Plotly.plot = function(gd, data, layout, config) {
220221
221222 // in case the margins changed, draw margin pushers again
222223 function marginPushersAgain ( ) {
223- var seq = JSON . stringify ( fullLayout . _size ) === oldmargins ?
224- [ ] :
225- [ marginPushers , subroutines . layoutStyles ] ;
224+ if ( JSON . stringify ( fullLayout . _size ) === oldmargins ) return ;
226225
227- // re-initialize cartesian interaction,
228- // which are sometimes cleared during marginPushers
229- seq = seq . concat ( initInteractions ) ;
230-
231- return Lib . syncOrAsync ( seq , gd ) ;
226+ return Lib . syncOrAsync ( [
227+ marginPushers ,
228+ subroutines . layoutStyles
229+ ] , gd ) ;
232230 }
233231
234232 function positionAndAutorange ( ) {
235- if ( ! recalc ) return ;
233+ if ( ! recalc ) {
234+ enforceAxisConstraints ( gd ) ;
235+ return ;
236+ }
236237
237238 var subplots = Plots . getSubplotIds ( fullLayout , 'cartesian' ) ,
238239 modules = fullLayout . _modules ;
@@ -270,7 +271,10 @@ Plotly.plot = function(gd, data, layout, config) {
270271
271272 var axList = Plotly . Axes . list ( gd , '' , true ) ;
272273 for ( var i = 0 ; i < axList . length ; i ++ ) {
273- Plotly . Axes . doAutoRange ( axList [ i ] ) ;
274+ var ax = axList [ i ] ;
275+ cleanAxisConstraints ( gd , ax ) ;
276+
277+ Plotly . Axes . doAutoRange ( ax ) ;
274278 }
275279
276280 enforceAxisConstraints ( gd ) ;
@@ -365,11 +369,13 @@ Plotly.plot = function(gd, data, layout, config) {
365369 drawFramework ,
366370 marginPushers ,
367371 marginPushersAgain ,
372+ initInteractions ,
368373 positionAndAutorange ,
369374 subroutines . layoutStyles ,
370375 drawAxes ,
371376 drawData ,
372377 finalDraw ,
378+ initInteractions ,
373379 Plots . rehover
374380 ] ;
375381
@@ -1917,10 +1923,12 @@ function _relayout(gd, aobj) {
19171923 // we're editing the (auto)range of, so we can tell the others constrained
19181924 // to scale with them that it's OK for them to shrink
19191925 var rangesAltered = { } ;
1926+ var axId ;
19201927
19211928 function recordAlteredAxis ( pleafPlus ) {
19221929 var axId = axisIds . name2id ( pleafPlus . split ( '.' ) [ 0 ] ) ;
19231930 rangesAltered [ axId ] = 1 ;
1931+ return axId ;
19241932 }
19251933
19261934 // alter gd.layout
@@ -1963,11 +1971,25 @@ function _relayout(gd, aobj) {
19631971 else if ( pleafPlus . match ( / ^ [ x y z ] a x i s [ 0 - 9 ] * \. r a n g e ( \[ [ 0 | 1 ] \] ) ? $ / ) ) {
19641972 doextra ( ptrunk + '.autorange' , false ) ;
19651973 recordAlteredAxis ( pleafPlus ) ;
1974+ Lib . nestedProperty ( fullLayout , ptrunk + '._inputRange' ) . set ( null ) ;
19661975 }
19671976 else if ( pleafPlus . match ( / ^ [ x y z ] a x i s [ 0 - 9 ] * \. a u t o r a n g e $ / ) ) {
19681977 doextra ( [ ptrunk + '.range[0]' , ptrunk + '.range[1]' ] ,
19691978 undefined ) ;
19701979 recordAlteredAxis ( pleafPlus ) ;
1980+ Lib . nestedProperty ( fullLayout , ptrunk + '._inputRange' ) . set ( null ) ;
1981+ var axFull = Lib . nestedProperty ( fullLayout , ptrunk ) . get ( ) ;
1982+ if ( axFull . _inputDomain ) {
1983+ // if we're autoranging and this axis has a constrained domain,
1984+ // reset it so we don't get locked into a shrunken size
1985+ axFull . _input . domain = axFull . _inputDomain . slice ( ) ;
1986+ }
1987+ }
1988+ else if ( pleafPlus . match ( / ^ [ x y z ] a x i s [ 0 - 9 ] * \. d o m a i n ( \[ [ 0 | 1 ] \] ) ? $ / ) ) {
1989+ Lib . nestedProperty ( fullLayout , ptrunk + '._inputDomain' ) . set ( null ) ;
1990+ }
1991+ else if ( pleafPlus . match ( / ^ [ x y z ] a x i s [ 0 - 9 ] * \. c o n s t r a i n .* $ / ) ) {
1992+ flags . docalc = true ;
19711993 }
19721994 else if ( pleafPlus . match ( / ^ a s p e c t r a t i o \. [ x y z ] $ / ) ) {
19731995 doextra ( proot + '.aspectmode' , 'manual' ) ;
@@ -2047,6 +2069,7 @@ function _relayout(gd, aobj) {
20472069 // will not make sense, so autorange it.
20482070 doextra ( ptrunk + '.autorange' , true ) ;
20492071 }
2072+ Lib . nestedProperty ( fullLayout , ptrunk + '._inputRange' ) . set ( null ) ;
20502073 }
20512074 else if ( pleaf . match ( cartesianConstants . AX_NAME_PATTERN ) ) {
20522075 var fullProp = Lib . nestedProperty ( fullLayout , ai ) . get ( ) ,
@@ -2193,7 +2216,7 @@ function _relayout(gd, aobj) {
21932216
21942217 // figure out if we need to recalculate axis constraints
21952218 var constraints = fullLayout . _axisConstraintGroups ;
2196- for ( var axId in rangesAltered ) {
2219+ for ( axId in rangesAltered ) {
21972220 for ( i = 0 ; i < constraints . length ; i ++ ) {
21982221 var group = constraints [ i ] ;
21992222 if ( group [ axId ] ) {
0 commit comments