@@ -63,8 +63,8 @@ describe('zoom box element', function() {
63
63
64
64
describe ( 'main plot pan' , function ( ) {
65
65
66
- var mock = require ( '@mocks/10.json' ) ,
67
- gd , modeBar , relayoutCallback ;
66
+ var mock = require ( '@mocks/10.json' ) ;
67
+ var gd , modeBar , relayoutCallback ;
68
68
69
69
beforeEach ( function ( done ) {
70
70
gd = createGraphDiv ( ) ;
@@ -106,70 +106,86 @@ describe('main plot pan', function() {
106
106
expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
107
107
expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
108
108
109
- delay ( MODEBAR_DELAY ) ( )
110
- . then ( function ( ) {
109
+ function _drag ( x0 , y0 , x1 , y1 ) {
110
+ mouseEvent ( 'mousedown' , x0 , y0 ) ;
111
+ mouseEvent ( 'mousemove' , x1 , y1 ) ;
112
+ mouseEvent ( 'mouseup' , x1 , y1 ) ;
113
+ }
111
114
112
- expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
113
- relayoutCallback . calls . reset ( ) ;
115
+ function _checkAxes ( xRange , yRange ) {
116
+ expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( xRange , precision ) ;
117
+ expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( yRange , precision ) ;
118
+ }
114
119
120
+ function _runDrag ( xr0 , xr1 , yr0 , yr1 ) {
115
121
// Drag scene along the X axis
116
-
117
- mouseEvent ( 'mousedown' , 110 , 150 ) ;
118
- mouseEvent ( 'mousemove' , 220 , 150 ) ;
119
- mouseEvent ( 'mouseup' , 220 , 150 ) ;
120
-
121
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( newX , precision ) ;
122
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
122
+ _drag ( 110 , 150 , 220 , 150 ) ;
123
+ _checkAxes ( xr1 , yr0 ) ;
123
124
124
125
// Drag scene back along the X axis (not from the same starting point but same X delta)
125
-
126
- mouseEvent ( 'mousedown' , 280 , 150 ) ;
127
- mouseEvent ( 'mousemove' , 170 , 150 ) ;
128
- mouseEvent ( 'mouseup' , 170 , 150 ) ;
129
-
130
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
131
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
126
+ _drag ( 280 , 150 , 170 , 150 ) ;
127
+ _checkAxes ( xr0 , yr0 ) ;
132
128
133
129
// Drag scene along the Y axis
134
-
135
- mouseEvent ( 'mousedown' , 110 , 150 ) ;
136
- mouseEvent ( 'mousemove' , 110 , 190 ) ;
137
- mouseEvent ( 'mouseup' , 110 , 190 ) ;
138
-
139
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
140
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( newY , precision ) ;
130
+ _drag ( 110 , 150 , 110 , 190 ) ;
131
+ _checkAxes ( xr0 , yr1 ) ;
141
132
142
133
// Drag scene back along the Y axis (not from the same starting point but same Y delta)
143
-
144
- mouseEvent ( 'mousedown' , 280 , 130 ) ;
145
- mouseEvent ( 'mousemove' , 280 , 90 ) ;
146
- mouseEvent ( 'mouseup' , 280 , 90 ) ;
147
-
148
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
149
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
134
+ _drag ( 280 , 130 , 280 , 90 ) ;
135
+ _checkAxes ( xr0 , yr0 ) ;
150
136
151
137
// Drag scene along both the X and Y axis
152
-
153
- mouseEvent ( 'mousedown' , 110 , 150 ) ;
154
- mouseEvent ( 'mousemove' , 220 , 190 ) ;
155
- mouseEvent ( 'mouseup' , 220 , 190 ) ;
156
-
157
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( newX , precision ) ;
158
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( newY , precision ) ;
138
+ _drag ( 110 , 150 , 220 , 190 ) ;
139
+ _checkAxes ( xr1 , yr1 ) ;
159
140
160
141
// Drag scene back along the X and Y axis (not from the same starting point but same delta vector)
142
+ _drag ( 280 , 130 , 170 , 90 ) ;
143
+ _checkAxes ( xr0 , yr0 ) ;
144
+ }
161
145
162
- mouseEvent ( 'mousedown' , 280 , 130 ) ;
163
- mouseEvent ( 'mousemove' , 170 , 90 ) ;
164
- mouseEvent ( 'mouseup' , 170 , 90 ) ;
146
+ delay ( MODEBAR_DELAY ) ( )
147
+ . then ( function ( ) {
165
148
166
- expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
167
- expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
149
+ expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
150
+ relayoutCallback . calls . reset ( ) ;
151
+ _runDrag ( originalX , newX , originalY , newY ) ;
168
152
} )
169
153
. then ( delay ( MODEBAR_DELAY ) )
170
154
. then ( function ( ) {
171
155
// X and back; Y and back; XY and back
172
156
expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 6 ) ;
157
+ return Plotly . relayout ( gd , { 'xaxis.fixedrange' : true } ) ;
158
+ } )
159
+ . then ( function ( ) {
160
+ relayoutCallback . calls . reset ( ) ;
161
+ _runDrag ( originalX , originalX , originalY , newY ) ;
162
+ } )
163
+ . then ( delay ( MODEBAR_DELAY ) )
164
+ . then ( function ( ) {
165
+ // Y and back; XY and back
166
+ // should perhaps be 4, but the noop drags still generate a relayout call.
167
+ // TODO: should we try and remove this call?
168
+ expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 6 ) ;
169
+ return Plotly . relayout ( gd , { 'yaxis.fixedrange' : true } ) ;
170
+ } )
171
+ . then ( function ( ) {
172
+ relayoutCallback . calls . reset ( ) ;
173
+ _runDrag ( originalX , originalX , originalY , originalY ) ;
174
+ } )
175
+ . then ( delay ( MODEBAR_DELAY ) )
176
+ . then ( function ( ) {
177
+ // both axes are fixed - no changes
178
+ expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 0 ) ;
179
+ return Plotly . relayout ( gd , { 'xaxis.fixedrange' : false , dragmode : 'pan' } ) ;
180
+ } )
181
+ . then ( function ( ) {
182
+ relayoutCallback . calls . reset ( ) ;
183
+ _runDrag ( originalX , newX , originalY , originalY ) ;
184
+ } )
185
+ . then ( delay ( MODEBAR_DELAY ) )
186
+ . then ( function ( ) {
187
+ // X and back; XY and back
188
+ expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 6 ) ;
173
189
} )
174
190
. catch ( failTest )
175
191
. then ( done ) ;
0 commit comments