@@ -651,3 +651,80 @@ describe('Activate and edit selections', function() {
651
651
. then ( done , done . fail ) ;
652
652
} ) ;
653
653
} ) ;
654
+
655
+
656
+ describe ( 'emit plotly_selected event on editing selections in various dragmodes' , function ( ) {
657
+ var gd ;
658
+
659
+ beforeEach ( function ( ) {
660
+ gd = createGraphDiv ( ) ;
661
+ } ) ;
662
+
663
+ afterEach ( destroyGraphDiv ) ;
664
+
665
+ [ 'zoom' , 'pan' , 'drawrect' , 'drawclosedpath' , 'drawcircle' ] . forEach ( function ( dragmode ) {
666
+ it ( 'get eventData for editing selections using ' + dragmode + ' dragmode' , function ( done ) {
667
+ var fig = {
668
+ data : [
669
+ {
670
+ x : [ 0 , 1 , 2 ] ,
671
+ y : [ 1 , 2 , 3 ]
672
+ }
673
+ ] ,
674
+ layout : {
675
+ width : 800 ,
676
+ height : 600 ,
677
+ margin : {
678
+ t : 100 ,
679
+ b : 50 ,
680
+ l : 100 ,
681
+ r : 50
682
+ } ,
683
+ selections : [ { x0 : 0.5 , x1 : 1.5 , y0 : 1.5 , y1 : 2.5 } ] ,
684
+ dragmode : dragmode
685
+ }
686
+ } ;
687
+
688
+ var range ;
689
+ var points ;
690
+ var lassoPoints ;
691
+ var selections ;
692
+
693
+ Plotly . newPlot ( gd , fig )
694
+
695
+ . then ( function ( ) {
696
+ gd . on ( 'plotly_selected' , function ( d ) {
697
+ lassoPoints = d . lassoPoints ;
698
+ range = d . range ;
699
+ points = d . points ;
700
+ selections = d . selections ;
701
+ } ) ;
702
+ } )
703
+
704
+ . then ( function ( ) { click ( 400 , 300 ) ; } ) // activate selection
705
+ . then ( function ( ) { drag ( [ [ 400 , 300 ] , [ 600 , 100 ] ] ) ; } ) // move selection
706
+ . then ( function ( ) {
707
+ expect ( range ) . not . toBeUndefined ( ) ;
708
+ expect ( range . x ) . toBeCloseToArray ( [ 1.1926580086580088 , 2.1926580086580088 ] , 3 ) ;
709
+ expect ( range . y ) . toBeCloseToArray ( [ 2.5062641509433967 , 3.5062641509433967 ] , 3 ) ;
710
+
711
+ expect ( lassoPoints ) . toBeUndefined ( ) ;
712
+
713
+ expect ( points ) . not . toBeUndefined ( ) ;
714
+ expect ( points . length ) . toEqual ( 1 ) ;
715
+ expect ( points [ 0 ] . fullData ) . not . toBeUndefined ( ) ;
716
+ expect ( points [ 0 ] . data ) . not . toBeUndefined ( ) ;
717
+ expect ( points [ 0 ] . data . selectedpoints ) . toEqual ( [ 2 ] ) ;
718
+
719
+ expect ( selections ) . not . toBeUndefined ( ) ;
720
+ expect ( selections . length ) . toEqual ( 1 ) ;
721
+ expect ( selections [ 0 ] ) . not . toBeUndefined ( ) ;
722
+ expect ( selections [ 0 ] . x0 ) . toBeCloseTo ( 1.1926580086580088 , 3 ) ;
723
+ expect ( selections [ 0 ] . x1 ) . toBeCloseTo ( 2.1926580086580088 , 3 ) ;
724
+ expect ( selections [ 0 ] . y0 ) . toBeCloseTo ( 2.5062641509433967 , 3 ) ;
725
+ expect ( selections [ 0 ] . y1 ) . toBeCloseTo ( 3.5062641509433967 , 3 ) ;
726
+ } )
727
+ . then ( done , done . fail ) ;
728
+ } ) ;
729
+ } ) ;
730
+ } ) ;
0 commit comments