@@ -314,6 +314,11 @@ describe('axis zoom/pan and main plot zoom', function() {
314
314
} ;
315
315
}
316
316
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
+
317
322
describe ( 'subplots with shared axes' , function ( ) {
318
323
var initialRange = [ 0 , 2 ] ;
319
324
var autoRange = [ - 0.1594 , 2.1594 ] ;
@@ -577,67 +582,46 @@ describe('axis zoom/pan and main plot zoom', function() {
577
582
} ) ;
578
583
579
584
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 ) ;
609
600
}
610
601
611
602
Plotly . plot ( gd , [ { y : [ 1 , 2 , 1 ] } ] )
612
- . then ( function ( ) { return _dragStart ( [ 170 , 170 ] , [ 30 , 30 ] ) ; } )
613
603
. then ( function ( ) {
614
- return _assertAndDragEnd ( 'full-x full-y' , { cornerCnt : 4 } ) ;
604
+ return _run ( 'full-x full-y' , [ 30 , 30 ] , { cornerCnt : 4 } ) ;
615
605
} )
616
- . then ( function ( ) { return _dragStart ( [ 170 , 170 ] , [ 5 , 30 ] ) ; } )
617
606
. then ( function ( ) {
618
- return _assertAndDragEnd ( 'full-y' , { cornerCnt : 2 } ) ;
607
+ return _run ( 'full-y' , [ 5 , 30 ] , { cornerCnt : 2 } ) ;
619
608
} )
620
- . then ( function ( ) { return _dragStart ( [ 170 , 170 ] , [ 30 , 2 ] ) ; } )
621
609
. then ( function ( ) {
622
- return _assertAndDragEnd ( 'full-x' , { cornerCnt : 2 } ) ;
610
+ return _run ( 'full-x' , [ 30 , 2 ] , { cornerCnt : 2 } ) ;
623
611
} )
624
612
. then ( function ( ) { return Plotly . relayout ( gd , 'xaxis.fixedrange' , true ) ; } )
625
- . then ( function ( ) { return _dragStart ( [ 170 , 170 ] , [ 30 , 30 ] ) ; } )
626
613
. 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 } ) ;
628
615
} )
629
- . then ( function ( ) { return _dragStart ( [ 170 , 170 ] , [ 30 , 5 ] ) ; } )
630
616
. then ( function ( ) {
631
- return _assertAndDragEnd ( 'full-x w/ fixed xaxis' , { cornerCnt : 0 } ) ;
617
+ return _run ( 'full-x w/ fixed xaxis' , [ 30 , 5 ] , { cornerCnt : 0 } ) ;
632
618
} )
633
619
. then ( function ( ) { return Plotly . relayout ( gd , { 'xaxis.fixedrange' : false , 'yaxis.fixedrange' : true } ) ; } )
634
- . then ( function ( ) { return _dragStart ( [ 170 , 170 ] , [ 30 , 30 ] ) ; } )
635
620
. 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 } ) ;
637
622
} )
638
- . then ( function ( ) { return _dragStart ( [ 170 , 170 ] , [ 5 , 30 ] ) ; } )
639
623
. then ( function ( ) {
640
- return _assertAndDragEnd ( 'full-y w/ fixed yaxis' , { cornerCnt : 0 } ) ;
624
+ return _run ( 'full-y w/ fixed yaxis' , [ 5 , 30 ] , { cornerCnt : 0 } ) ;
641
625
} )
642
626
. catch ( failTest )
643
627
. then ( done ) ;
@@ -665,28 +649,6 @@ describe('axis zoom/pan and main plot zoom', function() {
665
649
it ( 'should compute correct multicategory tick label span during drag' , function ( done ) {
666
650
var fig = Lib . extendDeep ( { } , require ( '@mocks/multicategory.json' ) ) ;
667
651
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
-
690
652
function _assertLabels ( msg , exp ) {
691
653
var tickLabels = d3 . select ( gd ) . selectAll ( '.xtick > text' ) ;
692
654
expect ( tickLabels . size ( ) ) . toBe ( exp . angle . length , msg + ' - # of tick labels' ) ;
@@ -708,23 +670,28 @@ describe('axis zoom/pan and main plot zoom', function() {
708
670
} ) ;
709
671
}
710
672
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
+
711
680
Plotly . plot ( gd , fig )
712
681
. then ( function ( ) {
713
682
_assertLabels ( 'base' , {
714
683
angle : [ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
715
684
y : [ 406 , 406 ]
716
685
} ) ;
717
686
} )
718
- . then ( function ( ) { return _dragStart ( 'edrag' , [ 585 , 390 ] , [ - 340 , 0 ] ) ; } )
719
687
. then ( function ( ) {
720
- return _assertAndDragEnd ( 'drag to wide-range -> rotates labels' , {
688
+ return _run ( 'drag to wide-range -> rotates labels' , [ - 340 , 0 ] , {
721
689
angle : [ 90 , 90 , 90 , 90 , 90 , 90 , 90 ] ,
722
690
y : [ 430 , 430 ]
723
691
} ) ;
724
692
} )
725
- . then ( function ( ) { return _dragStart ( 'edrag' , [ 585 , 390 ] , [ 100 , 0 ] ) ; } )
726
693
. then ( function ( ) {
727
- return _assertAndDragEnd ( 'drag to narrow-range -> un-rotates labels' , {
694
+ return _run ( 'drag to narrow-range -> un-rotates labels' , [ 100 , 0 ] , {
728
695
angle : [ 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
729
696
y : [ 406 , 406 ]
730
697
} ) ;
0 commit comments