@@ -42,11 +42,13 @@ function drag(path, options) {
42
42
mouseEvent ( 'mouseup' , path [ len - 1 ] [ 0 ] , path [ len - 1 ] [ 1 ] , options ) ;
43
43
}
44
44
45
- function assertSelectionNodes ( cornerCnt , outlineCnt ) {
45
+ function assertSelectionNodes ( cornerCnt , outlineCnt , _msg ) {
46
+ var msg = _msg ? ' - ' + _msg : '' ;
47
+
46
48
expect ( d3 . selectAll ( '.zoomlayer > .zoombox-corners' ) . size ( ) )
47
- . toBe ( cornerCnt , 'selection corner count' ) ;
49
+ . toBe ( cornerCnt , 'selection corner count' + msg ) ;
48
50
expect ( d3 . selectAll ( '.zoomlayer > .select-outline' ) . size ( ) )
49
- . toBe ( outlineCnt , 'selection outline count' ) ;
51
+ . toBe ( outlineCnt , 'selection outline count' + msg ) ;
50
52
}
51
53
52
54
var selectingCnt , selectingData , selectedCnt , selectedData , deselectCnt , doubleClickData ;
@@ -537,16 +539,27 @@ describe('@flaky Test select box and lasso in general:', function() {
537
539
mockCopy . layout . dragmode = 'select' ;
538
540
mockCopy . config = { scrollZoom : true } ;
539
541
540
- Plotly . plot ( gd , mockCopy ) . then ( function ( ) {
542
+ function _drag ( ) {
541
543
resetEvents ( gd ) ;
542
544
drag ( selectPath ) ;
543
545
return selectedPromise ;
544
- } )
545
- . then ( function ( ) {
546
+ }
547
+
548
+ function _scroll ( ) {
546
549
mouseEvent ( 'mousemove' , selectPath [ 0 ] [ 0 ] , selectPath [ 0 ] [ 1 ] ) ;
547
550
mouseEvent ( 'scroll' , selectPath [ 0 ] [ 0 ] , selectPath [ 0 ] [ 1 ] , { deltaX : 0 , deltaY : - 20 } ) ;
551
+ }
552
+
553
+ Plotly . plot ( gd , mockCopy )
554
+ . then ( _drag )
555
+ . then ( _scroll )
556
+ . then ( function ( ) {
557
+ assertSelectionNodes ( 0 , 0 ) ;
548
558
} )
559
+ . then ( _drag )
560
+ . then ( _scroll )
549
561
. then ( function ( ) {
562
+ // make sure it works the 2nd time aroung
550
563
assertSelectionNodes ( 0 , 0 ) ;
551
564
} )
552
565
. catch ( failTest )
@@ -721,6 +734,142 @@ describe('@flaky Test select box and lasso in general:', function() {
721
734
. catch ( failTest )
722
735
. then ( done ) ;
723
736
} ) ;
737
+
738
+ it ( 'should remember selection polygons from previous select/lasso mode' , function ( done ) {
739
+ var gd = createGraphDiv ( ) ;
740
+ var path1 = [ [ 150 , 150 ] , [ 170 , 170 ] ] ;
741
+ var path2 = [ [ 193 , 193 ] , [ 213 , 193 ] ] ;
742
+
743
+ var fig = Lib . extendDeep ( { } , mock ) ;
744
+ fig . layout . margin = { l : 0 , t : 0 , r : 0 , b : 0 } ;
745
+ fig . layout . width = 500 ;
746
+ fig . layout . height = 500 ;
747
+ fig . layout . dragmode = 'select' ;
748
+ fig . config = { scrollZoom : true } ;
749
+
750
+ // d attr to array of segment [x,y]
751
+ function outline2coords ( outline ) {
752
+ if ( ! outline . size ( ) ) return [ [ ] ] ;
753
+
754
+ return outline . attr ( 'd' )
755
+ . replace ( / Z / g, '' )
756
+ . split ( 'M' )
757
+ . filter ( Boolean )
758
+ . map ( function ( s ) {
759
+ return s . split ( 'L' )
760
+ . map ( function ( s ) { return s . split ( ',' ) . map ( Number ) ; } ) ;
761
+ } )
762
+ . reduce ( function ( a , b ) { return a . concat ( b ) ; } ) ;
763
+ }
764
+
765
+ function _assert ( msg , exp ) {
766
+ var outline = d3 . select ( gd ) . select ( '.zoomlayer' ) . select ( '.select-outline-1' ) ;
767
+
768
+ if ( exp . outline ) {
769
+ expect ( outline2coords ( outline ) ) . toBeCloseTo2DArray ( exp . outline , 2 , msg ) ;
770
+ } else {
771
+ assertSelectionNodes ( 0 , 0 , msg ) ;
772
+ }
773
+ }
774
+
775
+ function _drag ( path , opts ) {
776
+ return function ( ) {
777
+ resetEvents ( gd ) ;
778
+ drag ( path , opts ) ;
779
+ return selectedPromise ;
780
+ } ;
781
+ }
782
+
783
+ Plotly . plot ( gd , fig )
784
+ . then ( function ( ) { _assert ( 'base' , { outline : false } ) ; } )
785
+ . then ( _drag ( path1 ) )
786
+ . then ( function ( ) {
787
+ _assert ( 'select path1' , {
788
+ outline : [ [ 150 , 150 ] , [ 150 , 170 ] , [ 170 , 170 ] , [ 170 , 150 ] , [ 150 , 150 ] ]
789
+ } ) ;
790
+ } )
791
+ . then ( _drag ( path2 ) )
792
+ . then ( function ( ) {
793
+ _assert ( 'select path2' , {
794
+ outline : [ [ 193 , 0 ] , [ 193 , 500 ] , [ 213 , 500 ] , [ 213 , 0 ] , [ 193 , 0 ] ]
795
+ } ) ;
796
+ } )
797
+ . then ( _drag ( path1 ) )
798
+ . then ( _drag ( path2 , { shiftKey : true } ) )
799
+ . then ( function ( ) {
800
+ _assert ( 'select path1+path2' , {
801
+ outline : [
802
+ [ 170 , 170 ] , [ 170 , 150 ] , [ 150 , 150 ] , [ 150 , 170 ] , [ 170 , 170 ] ,
803
+ [ 213 , 500 ] , [ 213 , 0 ] , [ 193 , 0 ] , [ 193 , 500 ] , [ 213 , 500 ]
804
+ ]
805
+ } ) ;
806
+ } )
807
+ . then ( function ( ) {
808
+ return Plotly . relayout ( gd , 'dragmode' , 'lasso' ) ;
809
+ } )
810
+ . then ( function ( ) {
811
+ // N.B. all relayout calls clear the selection outline at the moment,
812
+ // perhaps we could make an exception for select <-> lasso ?
813
+ _assert ( 'after relayout -> lasso' , { outline : false } ) ;
814
+ } )
815
+ . then ( _drag ( lassoPath , { shiftKey : true } ) )
816
+ . then ( function ( ) {
817
+ // merged with previous 'select' polygon
818
+ _assert ( 'after shift lasso' , {
819
+ outline : [
820
+ [ 170 , 170 ] , [ 170 , 150 ] , [ 150 , 150 ] , [ 150 , 170 ] , [ 170 , 170 ] ,
821
+ [ 213 , 500 ] , [ 213 , 0 ] , [ 193 , 0 ] , [ 193 , 500 ] , [ 213 , 500 ] ,
822
+ [ 335 , 243 ] , [ 328 , 169 ] , [ 316 , 171 ] , [ 318 , 239 ] , [ 335 , 243 ]
823
+ ]
824
+ } ) ;
825
+ } )
826
+ . then ( _drag ( lassoPath ) )
827
+ . then ( function ( ) {
828
+ _assert ( 'after lasso (no-shift)' , {
829
+ outline : [ [ 316 , 171 ] , [ 318 , 239 ] , [ 335 , 243 ] , [ 328 , 169 ] , [ 316 , 171 ] ]
830
+ } ) ;
831
+ } )
832
+ . then ( function ( ) {
833
+ return Plotly . relayout ( gd , 'dragmode' , 'pan' ) ;
834
+ } )
835
+ . then ( function ( ) {
836
+ _assert ( 'after relayout -> pan' , { outline : false } ) ;
837
+ drag ( path2 ) ;
838
+ _assert ( 'after pan' , { outline : false } ) ;
839
+ return Plotly . relayout ( gd , 'dragmode' , 'select' ) ;
840
+ } )
841
+ . then ( function ( ) {
842
+ _assert ( 'after relayout back to select' , { outline : false } ) ;
843
+ } )
844
+ . then ( _drag ( path1 , { shiftKey : true } ) )
845
+ . then ( function ( ) {
846
+ // this used to merged 'lasso' polygons before (see #2669)
847
+ _assert ( 'shift select path1 after pan' , {
848
+ outline : [ [ 150 , 150 ] , [ 150 , 170 ] , [ 170 , 170 ] , [ 170 , 150 ] , [ 150 , 150 ] ]
849
+ } ) ;
850
+ } )
851
+ . then ( _drag ( path2 , { shiftKey : true } ) )
852
+ . then ( function ( ) {
853
+ _assert ( 'shift select path1+path2 after pan' , {
854
+ outline : [
855
+ [ 170 , 170 ] , [ 170 , 150 ] , [ 150 , 150 ] , [ 150 , 170 ] , [ 170 , 170 ] ,
856
+ [ 213 , 500 ] , [ 213 , 0 ] , [ 193 , 0 ] , [ 193 , 500 ] , [ 213 , 500 ]
857
+ ]
858
+ } ) ;
859
+ } )
860
+ . then ( function ( ) {
861
+ mouseEvent ( 'mousemove' , 200 , 200 ) ;
862
+ mouseEvent ( 'scroll' , 200 , 200 , { deltaX : 0 , deltaY : - 20 } ) ;
863
+ } )
864
+ . then ( _drag ( path1 , { shiftKey : true } ) )
865
+ . then ( function ( ) {
866
+ _assert ( 'shift select path1 after scroll' , {
867
+ outline : [ [ 150 , 150 ] , [ 150 , 170 ] , [ 170 , 170 ] , [ 170 , 150 ] , [ 150 , 150 ] ]
868
+ } ) ;
869
+ } )
870
+ . catch ( failTest )
871
+ . then ( done ) ;
872
+ } ) ;
724
873
} ) ;
725
874
726
875
describe ( '@flaky Test select box and lasso per trace:' , function ( ) {
0 commit comments