@@ -188,6 +188,43 @@ 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 = Lib . extendDeep ( { } , require ( '@mocks/10.json' ) ) ;
193+ mock . layout . dragmode = 'pan' ;
194+
195+ function _drag ( x0 , y0 , x1 , y1 , n ) {
196+ mouseEvent ( 'mousedown' , x0 , y0 ) ;
197+ var dx = ( x1 - x0 ) / n ;
198+ var dy = ( y1 - y0 ) / n ;
199+ for ( var i = 0 ; i <= n ; i ++ ) {
200+ mouseEvent ( 'mousemove' , x0 + dx * i , y0 + dy * i ) ;
201+ }
202+ mouseEvent ( 'mouseup' , x1 , y1 ) ;
203+ }
204+
205+ var nsteps = 10 ; var events = [ ] ; var relayoutCallback ;
206+ Plotly . plot ( gd , mock . data , mock . layout )
207+ . then ( function ( ) {
208+ relayoutCallback = jasmine . createSpy ( 'relayoutCallback' ) ;
209+ gd . on ( 'plotly_relayout' , relayoutCallback ) ;
210+ gd . on ( 'plotly_relayouting' , function ( e ) {
211+ events . push ( e ) ;
212+ } ) ;
213+ _drag ( 100 , 150 , 220 , 250 , nsteps ) ;
214+ } )
215+ . then ( function ( ) {
216+ expect ( events . length ) . toEqual ( nsteps ) ;
217+ var first = events . splice ( 0 , 1 ) [ 0 ] ;
218+ var last = events . splice ( - 1 , 1 ) [ 0 ] ;
219+ expect ( first [ 'xaxis.range[1]' ] - first [ 'xaxis.range[0]' ] ) . toBeCloseTo ( 6 , 0 ) ;
220+ expect ( last [ 'xaxis.range[1]' ] - last [ 'xaxis.range[0]' ] ) . toBeCloseTo ( 6 , 0 ) ;
221+
222+ expect ( first [ 'xaxis.range[1]' ] - last [ 'xaxis.range[1]' ] ) . toBeCloseTo ( 1 , 0 ) ;
223+ } )
224+ . catch ( failTest )
225+ . then ( done ) ;
226+ } ) ;
227+
191228 it ( 'should show/hide `cliponaxis: false` pts according to range' , function ( done ) {
192229 function _assert ( markerDisplay , textDisplay , barTextDisplay ) {
193230 var gd3 = d3 . select ( gd ) ;
@@ -289,10 +326,10 @@ describe('axis zoom/pan and main plot zoom', function() {
289326 return document . querySelector ( '.' + directions + 'drag[data-subplot="' + subplot + '"]' ) ;
290327 }
291328
292- function doDrag ( subplot , directions , dx , dy ) {
329+ function doDrag ( subplot , directions , dx , dy , nsteps ) {
293330 return function ( ) {
294331 var dragger = getDragger ( subplot , directions ) ;
295- return drag ( dragger , dx , dy ) ;
332+ return drag ( dragger , dx , dy , undefined , undefined , undefined , nsteps ) ;
296333 } ;
297334 }
298335
@@ -311,7 +348,11 @@ describe('axis zoom/pan and main plot zoom', function() {
311348 var dy = opts . dy || 0 ;
312349 var dragger = getDragger ( subplot , directions ) ;
313350 var coords = getNodeCoords ( dragger , edge ) ;
314- mouseEvent ( 'scroll' , coords . x + dx , coords . y + dy , { deltaY : deltaY , element : dragger } ) ;
351+ var nsteps = opts . nsteps || 1 ;
352+
353+ for ( var i = 1 ; i <= nsteps ; i ++ ) {
354+ mouseEvent ( 'scroll' , coords . x + dx , coords . y + dy , { deltaY : deltaY / nsteps * i , element : dragger } ) ;
355+ }
315356 return delay ( constants . REDRAWDELAY + 10 ) ( ) ;
316357 } ;
317358 }
@@ -629,6 +670,44 @@ describe('axis zoom/pan and main plot zoom', function() {
629670 . then ( done ) ;
630671 } ) ;
631672
673+ it ( 'should emit plotly_relayouting events when drawing zoom selection' , function ( done ) {
674+ var nsteps = 10 ; var events = [ ] ; var relayoutCallback ;
675+ Plotly . plot ( gd , [ { y : [ 1 , 2 , 1 ] } ] )
676+ . then ( function ( ) {
677+ relayoutCallback = jasmine . createSpy ( 'relayoutCallback' ) ;
678+ gd . on ( 'plotly_relayout' , relayoutCallback ) ;
679+ gd . on ( 'plotly_relayouting' , function ( e ) {
680+ events . push ( e ) ;
681+ } ) ;
682+ } )
683+ . then ( doDrag ( 'xy' , 'nsew' , 100 , 100 , nsteps ) )
684+ . then ( function ( ) {
685+ expect ( events . length ) . toEqual ( nsteps ) ;
686+ expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
687+ } )
688+ . catch ( failTest )
689+ . then ( done ) ;
690+ } ) ;
691+
692+ it ( 'should emit plotly_relayouting events when zooming via mouse wheel' , function ( done ) {
693+ var nsteps = 10 ; var events = [ ] ; var relayoutCallback ;
694+ Plotly . plot ( gd , [ { y : [ 1 , 2 , 1 ] } ] , { } , { scrollZoom : true } )
695+ . then ( function ( ) {
696+ relayoutCallback = jasmine . createSpy ( 'relayoutCallback' ) ;
697+ gd . on ( 'plotly_relayout' , relayoutCallback ) ;
698+ gd . on ( 'plotly_relayouting' , function ( e ) {
699+ events . push ( e ) ;
700+ } ) ;
701+ } )
702+ . then ( doScroll ( 'xy' , 'nsew' , 100 , { edge : 'se' , nsteps : nsteps } ) )
703+ . then ( function ( ) {
704+ expect ( events . length ) . toEqual ( nsteps ) ;
705+ expect ( relayoutCallback ) . toHaveBeenCalledTimes ( 1 ) ;
706+ } )
707+ . catch ( failTest )
708+ . then ( done ) ;
709+ } ) ;
710+
632711 it ( 'handles xy, x-only and y-only zoombox updates' , function ( done ) {
633712 function _assert ( msg , xrng , yrng ) {
634713 expect ( gd . layout . xaxis . range ) . toBeCloseToArray ( xrng , 2 , 'xrng - ' + msg ) ;
@@ -1466,15 +1545,15 @@ describe('axis zoom/pan and main plot zoom', function() {
14661545 return drag . start ( )
14671546 . then ( _assert ( 'just after start of zoombox' , {
14681547 nodeCnt : 4 ,
1469- xrng : [ - 0.1927 , 3.1927 ] ,
1548+ xrng : [ 1.5 , 1.6880 ] ,
14701549 hasDragData : true ,
14711550 zoombox : 'M269.5,114.5h-3v41h3ZM300.5,114.5h3v41h-3Z' ,
14721551 clipTranslate : [ 0 , 0 ]
14731552 } ) )
14741553 . then ( delay ( step ) )
14751554 . then ( _assert ( 'during zoombox drag' , {
14761555 nodeCnt : 5 ,
1477- xrng : [ - 0.257 , 4.257 ] ,
1556+ xrng : [ 2 , 2.2507 ] ,
14781557 hasDragData : true ,
14791558 zoombox : 'M269.5,114.5h-3v41h3ZM300.5,114.5h3v41h-3Z' ,
14801559 clipTranslate : [ 0 , 0 ]
0 commit comments