@@ -188,6 +188,48 @@ describe('main plot pan', function() {
188188 . then ( done ) ;
189189 } ) ;
190190
191+ it ( 'should emit plotly_relayouting events during pan interactions' , function ( done ) {
192+ var mock = require ( '@mocks/10.json' ) ;
193+
194+ function _drag ( x0 , y0 , x1 , y1 , n ) {
195+ mouseEvent ( 'mousedown' , x0 , y0 ) ;
196+ var dx = ( x1 - x0 ) / n ;
197+ var dy = ( y1 - y0 ) / n ;
198+ for ( var i = 0 ; i <= n ; i ++ ) {
199+ mouseEvent ( 'mousemove' , x0 + dx * i , y0 + dy * i ) ;
200+ }
201+ mouseEvent ( 'mouseup' , x1 , y1 ) ;
202+ }
203+
204+ var nsteps = 10 ; var events = [ ] ; var relayoutCallback ;
205+ Plotly . plot ( gd , mock . data , mock . layout ) . then ( function ( ) {
206+ // Switch to pan mode
207+ modeBar = gd . _fullLayout . _modeBar ;
208+ var buttonPan = selectButton ( modeBar , 'pan2d' ) ;
209+ buttonPan . click ( ) ;
210+ expect ( buttonPan . isActive ( ) ) . toBe ( true ) ; // switched on dragmode
211+ } )
212+ . then ( function ( ) {
213+ relayoutCallback = jasmine . createSpy ( 'relayoutCallback' ) ;
214+ gd . on ( 'plotly_relayout' , relayoutCallback ) ;
215+ gd . on ( 'plotly_relayouting' , function ( e ) {
216+ events . push ( e ) ;
217+ } ) ;
218+ _drag ( 100 , 150 , 220 , 250 , nsteps ) ;
219+ } )
220+ . then ( function ( ) {
221+ expect ( events . length ) . toEqual ( nsteps ) ;
222+ var first = events . splice ( 0 , 1 ) [ 0 ] ;
223+ var last = events . splice ( - 1 , 1 ) [ 0 ] ;
224+ expect ( first [ 'xaxis.range[1]' ] - first [ 'xaxis.range[0]' ] ) . toBeCloseTo ( 6 , 0 ) ;
225+ expect ( last [ 'xaxis.range[1]' ] - last [ 'xaxis.range[0]' ] ) . toBeCloseTo ( 6 , 0 ) ;
226+
227+ expect ( first [ 'xaxis.range[1]' ] - last [ 'xaxis.range[1]' ] ) . toBeCloseTo ( 1 , 0 ) ;
228+ } )
229+ . catch ( failTest )
230+ . then ( done ) ;
231+ } ) ;
232+
191233 it ( 'should show/hide `cliponaxis: false` pts according to range' , function ( done ) {
192234 function _assert ( markerDisplay , textDisplay , barTextDisplay ) {
193235 var gd3 = d3 . select ( gd ) ;
@@ -289,10 +331,10 @@ describe('axis zoom/pan and main plot zoom', function() {
289331 return document . querySelector ( '.' + directions + 'drag[data-subplot="' + subplot + '"]' ) ;
290332 }
291333
292- function doDrag ( subplot , directions , dx , dy ) {
334+ function doDrag ( subplot , directions , dx , dy , nsteps ) {
293335 return function ( ) {
294336 var dragger = getDragger ( subplot , directions ) ;
295- return drag ( dragger , dx , dy ) ;
337+ return drag ( dragger , dx , dy , undefined , undefined , undefined , nsteps ) ;
296338 } ;
297339 }
298340
@@ -311,7 +353,11 @@ describe('axis zoom/pan and main plot zoom', function() {
311353 var dy = opts . dy || 0 ;
312354 var dragger = getDragger ( subplot , directions ) ;
313355 var coords = getNodeCoords ( dragger , edge ) ;
314- mouseEvent ( 'scroll' , coords . x + dx , coords . y + dy , { deltaY : deltaY , element : dragger } ) ;
356+ var nsteps = opts . nsteps || 1 ;
357+
358+ for ( var i = 1 ; i <= nsteps ; i ++ ) {
359+ mouseEvent ( 'scroll' , coords . x + dx , coords . y + dy , { deltaY : deltaY / nsteps * i , element : dragger } ) ;
360+ }
315361 return delay ( constants . REDRAWDELAY + 10 ) ( ) ;
316362 } ;
317363 }
@@ -629,6 +675,44 @@ describe('axis zoom/pan and main plot zoom', function() {
629675 . then ( done ) ;
630676 } ) ;
631677
678+ it ( 'should emit plotly_relayouting events when drawing zoom selection' , function ( done ) {
679+ var nsteps = 10 ; var events = [ ] ; var relayoutCallback ;
680+ Plotly . plot ( gd , [ { y : [ 1 , 2 , 1 ] } ] )
681+ . then ( function ( ) {
682+ relayoutCallback = jasmine . createSpy ( 'relayoutCallback' ) ;
683+ gd . on ( 'plotly_relayout' , relayoutCallback ) ;
684+ gd . on ( 'plotly_relayouting' , function ( e ) {
685+ events . push ( e ) ;
686+ } ) ;
687+ } )
688+ . then ( doDrag ( 'xy' , 'nsew' , 100 , 100 , nsteps ) )
689+ . then ( function ( ) {
690+ expect ( events . length ) . toEqual ( nsteps ) ;
691+ expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
692+ } )
693+ . catch ( failTest )
694+ . then ( done ) ;
695+ } ) ;
696+
697+ it ( 'should emit plotly_relayouting events when zooming via mouse wheel' , function ( done ) {
698+ var nsteps = 10 ; var events = [ ] ; var relayoutCallback ;
699+ Plotly . plot ( gd , [ { y : [ 1 , 2 , 1 ] } ] , { } , { scrollZoom : true } )
700+ . then ( function ( ) {
701+ relayoutCallback = jasmine . createSpy ( 'relayoutCallback' ) ;
702+ gd . on ( 'plotly_relayout' , relayoutCallback ) ;
703+ gd . on ( 'plotly_relayouting' , function ( e ) {
704+ events . push ( e ) ;
705+ } ) ;
706+ } )
707+ . then ( doScroll ( 'xy' , 'nsew' , 100 , { edge : 'se' , nsteps : nsteps } ) )
708+ . then ( function ( ) {
709+ expect ( events . length ) . toEqual ( nsteps ) ;
710+ expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
711+ } )
712+ . catch ( failTest )
713+ . then ( done ) ;
714+ } ) ;
715+
632716 it ( 'handles xy, x-only and y-only zoombox updates' , function ( done ) {
633717 function _assert ( msg , xrng , yrng ) {
634718 expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( xrng , 2 , 'xrng - ' + msg ) ;
0 commit comments