@@ -314,6 +314,11 @@ describe('axis zoom/pan and main plot zoom', function() {
314314 } ;
315315 }
316316
317+ function makeDragFns ( subplot , directions , dx , dy , x0 , y0 ) {
318+ var dragger = getDragger ( subplot , directions ) ;
319+ return drag . makeFns ( dragger , dx , dy , { x0 : x0 , y0 : y0 } ) ;
320+ }
321+
317322 describe ( 'subplots with shared axes' , function ( ) {
318323 var initialRange = [ 0 , 2 ] ;
319324 var autoRange = [ - 0.1594 , 2.1594 ] ;
@@ -577,67 +582,46 @@ describe('axis zoom/pan and main plot zoom', function() {
577582 } ) ;
578583
579584 it ( 'should draw correct zoomboxes corners' , function ( done ) {
580- var dragCoverNode ;
581- var p1 ;
582-
583- function _dragStart ( p0 , dp ) {
584- var node = getDragger ( 'xy' , 'nsew' ) ;
585- mouseEvent ( 'mousemove' , p0 [ 0 ] , p0 [ 1 ] , { element : node } ) ;
586- mouseEvent ( 'mousedown' , p0 [ 0 ] , p0 [ 1 ] , { element : node } ) ;
587-
588- var promise = drag . waitForDragCover ( ) . then ( function ( dcn ) {
589- dragCoverNode = dcn ;
590- p1 = [ p0 [ 0 ] + dp [ 0 ] , p0 [ 1 ] + dp [ 1 ] ] ;
591- mouseEvent ( 'mousemove' , p1 [ 0 ] , p1 [ 1 ] , { element : dragCoverNode } ) ;
592- } ) ;
593- return promise ;
594- }
595-
596- function _assertAndDragEnd ( msg , exp ) {
597- var zl = d3 . select ( gd ) . select ( 'g.zoomlayer' ) ;
598- var d = zl . select ( '.zoombox-corners' ) . attr ( 'd' ) ;
599-
600- if ( exp . cornerCnt ) {
601- var actual = ( d . match ( / Z / g) || [ ] ) . length ;
602- expect ( actual ) . toBe ( exp . cornerCnt , 'zoombox corner cnt: ' + msg ) ;
603- } else {
604- expect ( d ) . toBe ( 'M0,0Z' , 'no zoombox corners: ' + msg ) ;
605- }
606-
607- mouseEvent ( 'mouseup' , p1 [ 0 ] , p1 [ 1 ] , { element : dragCoverNode } ) ;
608- return drag . waitForDragCoverRemoval ( ) ;
585+ function _run ( msg , dp , exp ) {
586+ var drag = makeDragFns ( 'xy' , 'nsew' , dp [ 0 ] , dp [ 1 ] , 170 , 170 ) ;
587+
588+ return drag . start ( ) . then ( function ( ) {
589+ var zl = d3 . select ( gd ) . select ( 'g.zoomlayer' ) ;
590+ var d = zl . select ( '.zoombox-corners' ) . attr ( 'd' ) ;
591+
592+ if ( exp . cornerCnt ) {
593+ var actual = ( d . match ( / Z / g) || [ ] ) . length ;
594+ expect ( actual ) . toBe ( exp . cornerCnt , 'zoombox corner cnt: ' + msg ) ;
595+ } else {
596+ expect ( d ) . toBe ( 'M0,0Z' , 'no zoombox corners: ' + msg ) ;
597+ }
598+ } )
599+ . then ( drag . end ) ;
609600 }
610601
611602 Plotly . plot ( gd , [ { y : [ 1 , 2 , 1 ] } ] )
612- . then ( function ( ) { return _dragStart ( [ 170 , 170 ] , [ 30 , 30 ] ) ; } )
613603 . then ( function ( ) {
614- return _assertAndDragEnd ( 'full-x full-y' , { cornerCnt : 4 } ) ;
604+ return _run ( 'full-x full-y' , [ 30 , 30 ] , { cornerCnt : 4 } ) ;
615605 } )
616- . then ( function ( ) { return _dragStart ( [ 170 , 170 ] , [ 5 , 30 ] ) ; } )
617606 . then ( function ( ) {
618- return _assertAndDragEnd ( 'full-y' , { cornerCnt : 2 } ) ;
607+ return _run ( 'full-y' , [ 5 , 30 ] , { cornerCnt : 2 } ) ;
619608 } )
620- . then ( function ( ) { return _dragStart ( [ 170 , 170 ] , [ 30 , 2 ] ) ; } )
621609 . then ( function ( ) {
622- return _assertAndDragEnd ( 'full-x' , { cornerCnt : 2 } ) ;
610+ return _run ( 'full-x' , [ 30 , 2 ] , { cornerCnt : 2 } ) ;
623611 } )
624612 . then ( function ( ) { return Plotly . relayout ( gd , 'xaxis.fixedrange' , true ) ; } )
625- . then ( function ( ) { return _dragStart ( [ 170 , 170 ] , [ 30 , 30 ] ) ; } )
626613 . then ( function ( ) {
627- return _assertAndDragEnd ( 'full-x full-y w/ fixed xaxis' , { cornerCnt : 2 } ) ;
614+ return _run ( 'full-x full-y w/ fixed xaxis' , [ 30 , 30 ] , { cornerCnt : 2 } ) ;
628615 } )
629- . then ( function ( ) { return _dragStart ( [ 170 , 170 ] , [ 30 , 5 ] ) ; } )
630616 . then ( function ( ) {
631- return _assertAndDragEnd ( 'full-x w/ fixed xaxis' , { cornerCnt : 0 } ) ;
617+ return _run ( 'full-x w/ fixed xaxis' , [ 30 , 5 ] , { cornerCnt : 0 } ) ;
632618 } )
633619 . then ( function ( ) { return Plotly . relayout ( gd , { 'xaxis.fixedrange' : false , 'yaxis.fixedrange' : true } ) ; } )
634- . then ( function ( ) { return _dragStart ( [ 170 , 170 ] , [ 30 , 30 ] ) ; } )
635620 . then ( function ( ) {
636- return _assertAndDragEnd ( 'full-x full-y w/ fixed yaxis' , { cornerCnt : 2 } ) ;
621+ return _run ( 'full-x full-y w/ fixed yaxis' , [ 30 , 30 ] , { cornerCnt : 2 } ) ;
637622 } )
638- . then ( function ( ) { return _dragStart ( [ 170 , 170 ] , [ 5 , 30 ] ) ; } )
639623 . then ( function ( ) {
640- return _assertAndDragEnd ( 'full-y w/ fixed yaxis' , { cornerCnt : 0 } ) ;
624+ return _run ( 'full-y w/ fixed yaxis' , [ 5 , 30 ] , { cornerCnt : 0 } ) ;
641625 } )
642626 . catch ( failTest )
643627 . then ( done ) ;
@@ -665,28 +649,6 @@ describe('axis zoom/pan and main plot zoom', function() {
665649 it ( 'should compute correct multicategory tick label span during drag' , function ( done ) {
666650 var fig = Lib . extendDeep ( { } , require ( '@mocks/multicategory.json' ) ) ;
667651
668- var dragCoverNode ;
669- var p1 ;
670-
671- function _dragStart ( draggerClassName , p0 , dp ) {
672- var node = getDragger ( 'xy' , draggerClassName ) ;
673- mouseEvent ( 'mousemove' , p0 [ 0 ] , p0 [ 1 ] , { element : node } ) ;
674- mouseEvent ( 'mousedown' , p0 [ 0 ] , p0 [ 1 ] , { element : node } ) ;
675-
676- var promise = drag . waitForDragCover ( ) . then ( function ( dcn ) {
677- dragCoverNode = dcn ;
678- p1 = [ p0 [ 0 ] + dp [ 0 ] , p0 [ 1 ] + dp [ 1 ] ] ;
679- mouseEvent ( 'mousemove' , p1 [ 0 ] , p1 [ 1 ] , { element : dragCoverNode } ) ;
680- } ) ;
681- return promise ;
682- }
683-
684- function _assertAndDragEnd ( msg , exp ) {
685- _assertLabels ( msg , exp ) ;
686- mouseEvent ( 'mouseup' , p1 [ 0 ] , p1 [ 1 ] , { element : dragCoverNode } ) ;
687- return drag . waitForDragCoverRemoval ( ) ;
688- }
689-
690652 function _assertLabels ( msg , exp ) {
691653 var tickLabels = d3 . select ( gd ) . selectAll ( '.xtick > text' ) ;
692654 expect ( tickLabels . size ( ) ) . toBe ( exp . angle . length , msg + ' - # of tick labels' ) ;
@@ -708,23 +670,28 @@ describe('axis zoom/pan and main plot zoom', function() {
708670 } ) ;
709671 }
710672
673+ function _run ( msg , dp , exp ) {
674+ var drag = makeDragFns ( 'xy' , 'e' , dp [ 0 ] , dp [ 1 ] , 585 , 390 ) ;
675+ return drag . start ( )
676+ . then ( function ( ) { _assertLabels ( msg , exp ) ; } )
677+ . then ( drag . end ) ;
678+ }
679+
711680 Plotly . plot ( gd , fig )
712681 . then ( function ( ) {
713682 _assertLabels ( 'base' , {
714683 angle : [ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
715684 y : [ 406 , 406 ]
716685 } ) ;
717686 } )
718- . then ( function ( ) { return _dragStart ( 'edrag' , [ 585 , 390 ] , [ - 340 , 0 ] ) ; } )
719687 . then ( function ( ) {
720- return _assertAndDragEnd ( 'drag to wide-range -> rotates labels' , {
688+ return _run ( 'drag to wide-range -> rotates labels' , [ - 340 , 0 ] , {
721689 angle : [ 90 , 90 , 90 , 90 , 90 , 90 , 90 ] ,
722690 y : [ 430 , 430 ]
723691 } ) ;
724692 } )
725- . then ( function ( ) { return _dragStart ( 'edrag' , [ 585 , 390 ] , [ 100 , 0 ] ) ; } )
726693 . then ( function ( ) {
727- return _assertAndDragEnd ( 'drag to narrow-range -> un-rotates labels' , {
694+ return _run ( 'drag to narrow-range -> un-rotates labels' , [ 100 , 0 ] , {
728695 angle : [ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
729696 y : [ 406 , 406 ]
730697 } ) ;
0 commit comments