@@ -13,6 +13,7 @@ var getFromId = axIds.getFromId;
1313var isLinked = axIds . isLinked ;
1414
1515module . exports = {
16+ applyAutorangeOptions : applyAutorangeOptions ,
1617 getAutoRange : getAutoRange ,
1718 makePadFn : makePadFn ,
1819 doAutoRange : doAutoRange ,
@@ -75,16 +76,20 @@ function getAutoRange(gd, ax) {
7576 maxmax = Math . max ( maxmax , maxArray [ i ] . val ) ;
7677 }
7778
78- var axReverse = false ;
79+ var autorange = ax . autorange ;
80+ var axReverse =
81+ autorange === 'reversed' ||
82+ autorange === 'min reversed' ||
83+ autorange === 'max reversed' ;
7984
80- if ( ax . range ) {
85+ if ( ! axReverse && ax . range ) {
8186 var rng = Lib . simpleMap ( ax . range , ax . r2l ) ;
8287 axReverse = rng [ 1 ] < rng [ 0 ] ;
8388 }
89+
8490 // one-time setting to easily reverse the axis
8591 // when plotting from code
8692 if ( ax . autorange === 'reversed' ) {
87- axReverse = true ;
8893 ax . autorange = true ;
8994 }
9095
@@ -176,6 +181,10 @@ function getAutoRange(gd, ax) {
176181 ] ;
177182 }
178183
184+ newRange = applyAutorangeOptions ( newRange , ax ) ;
185+
186+ if ( ax . limitRange ) ax . limitRange ( ) ;
187+
179188 // maintain reversal
180189 if ( axReverse ) newRange . reverse ( ) ;
181190
@@ -209,7 +218,7 @@ function makePadFn(fullLayout, ax, max) {
209218 ( ax . ticklabelposition || '' ) . indexOf ( 'inside' ) !== - 1 ||
210219 ( anchorAxis . ticklabelposition || '' ) . indexOf ( 'inside' ) !== - 1
211220 ) {
212- var axReverse = ax . autorange === 'reversed' ;
221+ var axReverse = ax . isReversed ( ) ;
213222 if ( ! axReverse ) {
214223 var rng = Lib . simpleMap ( ax . range , ax . r2l ) ;
215224 axReverse = rng [ 1 ] < rng [ 0 ] ;
@@ -623,3 +632,91 @@ function goodNumber(v) {
623632
624633function lessOrEqual ( v0 , v1 ) { return v0 <= v1 ; }
625634function greaterOrEqual ( v0 , v1 ) { return v0 >= v1 ; }
635+
636+ function applyAutorangeMinOptions ( v , ax ) {
637+ var autorangeoptions = ax . autorangeoptions ;
638+ if (
639+ autorangeoptions &&
640+ autorangeoptions . minallowed !== undefined &&
641+ hasValidMinAndMax ( ax , autorangeoptions . minallowed , autorangeoptions . maxallowed )
642+ ) {
643+ return autorangeoptions . minallowed ;
644+ }
645+
646+ if (
647+ autorangeoptions &&
648+ autorangeoptions . clipmin !== undefined &&
649+ hasValidMinAndMax ( ax , autorangeoptions . clipmin , autorangeoptions . clipmax )
650+ ) {
651+ return Math . max ( v , ax . d2l ( autorangeoptions . clipmin ) ) ;
652+ }
653+ return v ;
654+ }
655+
656+ function applyAutorangeMaxOptions ( v , ax ) {
657+ var autorangeoptions = ax . autorangeoptions ;
658+
659+ if (
660+ autorangeoptions &&
661+ autorangeoptions . maxallowed !== undefined &&
662+ hasValidMinAndMax ( ax , autorangeoptions . minallowed , autorangeoptions . maxallowed )
663+ ) {
664+ return autorangeoptions . maxallowed ;
665+ }
666+
667+ if (
668+ autorangeoptions &&
669+ autorangeoptions . clipmax !== undefined &&
670+ hasValidMinAndMax ( ax , autorangeoptions . clipmin , autorangeoptions . clipmax )
671+ ) {
672+ return Math . min ( v , ax . d2l ( autorangeoptions . clipmax ) ) ;
673+ }
674+
675+ return v ;
676+ }
677+
678+ function hasValidMinAndMax ( ax , min , max ) {
679+ // in case both min and max are defined, ensure min < max
680+ if (
681+ min !== undefined &&
682+ max !== undefined
683+ ) {
684+ min = ax . d2l ( min ) ;
685+ max = ax . d2l ( max ) ;
686+ return min < max ;
687+ }
688+ return true ;
689+ }
690+
691+ // this function should be (and is) called before reversing the range
692+ // so range[0] is the minimum and range[1] is the maximum
693+ function applyAutorangeOptions ( range , ax ) {
694+ if ( ! ax || ! ax . autorangeoptions ) return range ;
695+
696+ var min = range [ 0 ] ;
697+ var max = range [ 1 ] ;
698+
699+ var include = ax . autorangeoptions . include ;
700+ if ( include !== undefined ) {
701+ var lMin = ax . d2l ( min ) ;
702+ var lMax = ax . d2l ( max ) ;
703+
704+ if ( ! Lib . isArrayOrTypedArray ( include ) ) include = [ include ] ;
705+ for ( var i = 0 ; i < include . length ; i ++ ) {
706+ var v = ax . d2l ( include [ i ] ) ;
707+ if ( lMin >= v ) {
708+ lMin = v ;
709+ min = v ;
710+ }
711+ if ( lMax <= v ) {
712+ lMax = v ;
713+ max = v ;
714+ }
715+ }
716+ }
717+
718+ min = applyAutorangeMinOptions ( min , ax ) ;
719+ max = applyAutorangeMaxOptions ( max , ax ) ;
720+
721+ return [ min , max ] ;
722+ }
0 commit comments