@@ -63,8 +63,8 @@ describe('zoom box element', function() {
6363
6464describe ( 'main plot pan' , function ( ) {
6565
66- var mock = require ( '@mocks/10.json' ) ,
67- gd , modeBar , relayoutCallback ;
66+ var mock = require ( '@mocks/10.json' ) ;
67+ var gd , modeBar , relayoutCallback ;
6868
6969 beforeEach ( function ( done ) {
7070 gd = createGraphDiv ( ) ;
@@ -106,70 +106,86 @@ describe('main plot pan', function() {
106106 expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( originalX , precision ) ;
107107 expect ( gd . layout . yaxis . range ) . toBeCloseToArray ( originalY , precision ) ;
108108
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+ }
111114
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+ }
114119
120+ function _runDrag ( xr0 , xr1 , yr0 , yr1 ) {
115121 // 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 ) ;
123124
124125 // 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 ) ;
132128
133129 // 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 ) ;
141132
142133 // 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 ) ;
150136
151137 // 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 ) ;
159140
160141 // 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+ }
161145
162- mouseEvent ( 'mousedown' , 280 , 130 ) ;
163- mouseEvent ( 'mousemove' , 170 , 90 ) ;
164- mouseEvent ( 'mouseup' , 170 , 90 ) ;
146+ delay ( MODEBAR_DELAY ) ( )
147+ . then ( function ( ) {
165148
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 ) ;
168152 } )
169153 . then ( delay ( MODEBAR_DELAY ) )
170154 . then ( function ( ) {
171155 // X and back; Y and back; XY and back
172156 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 ) ;
173189 } )
174190 . catch ( failTest )
175191 . then ( done ) ;
0 commit comments