@@ -27,6 +27,12 @@ module.exports = function enforceAxisConstraints(gd) {
27
27
28
28
var minScale = Infinity ;
29
29
var maxScale = 0 ;
30
+ // mostly matchScale will be the same as minScale
31
+ // ie we expand axis ranges to encompass *everything*
32
+ // that's currently in any of their ranges, but during
33
+ // autorange of a subset of axes we will ignore other
34
+ // axes for this purpose.
35
+ var matchScale = Infinity ;
30
36
var normScales = { } ;
31
37
var axes = { } ;
32
38
@@ -42,6 +48,13 @@ module.exports = function enforceAxisConstraints(gd) {
42
48
// abs: inverted scales still satisfy the constraint
43
49
normScales [ axisID ] = normScale = Math . abs ( ax . _m ) / group [ axisID ] ;
44
50
minScale = Math . min ( minScale , normScale ) ;
51
+ if ( ax . _constraintShrinkable ) {
52
+ // this has served its purpose, so remove it
53
+ delete ax . _constraintShrinkable ;
54
+ }
55
+ else {
56
+ matchScale = Math . min ( matchScale , normScale ) ;
57
+ }
45
58
maxScale = Math . max ( maxScale , normScale ) ;
46
59
}
47
60
@@ -53,7 +66,19 @@ module.exports = function enforceAxisConstraints(gd) {
53
66
axisID = axisIDs [ j ] ;
54
67
normScale = normScales [ axisID ] ;
55
68
56
- if ( normScale > minScale ) scaleZoom ( axes [ axisID ] , normScale / minScale ) ;
69
+ if ( normScale !== matchScale ) {
70
+ ax = axes [ axisID ] ;
71
+ // if range matches _rangeInitial before the constraint is applied,
72
+ // change _rangeInitial to the new range - otherwise a doubleclick
73
+ // will never autorange because we're not starting at the reset point.
74
+ var wasAtInitial = ( ax . _rangeInitial &&
75
+ ax . range [ 0 ] === ax . _rangeInitial [ 0 ] &&
76
+ ax . range [ 1 ] === ax . _rangeInitial [ 1 ] ) ;
77
+
78
+ scaleZoom ( ax , normScale / matchScale ) ;
79
+
80
+ if ( wasAtInitial ) ax . _rangeInitial = ax . range . slice ( ) ;
81
+ }
57
82
}
58
83
}
59
84
} ;
0 commit comments