@@ -557,69 +557,61 @@ describe('@flaky Test select box and lasso in general:', function() {
557
557
558
558
var gd = createGraphDiv ( ) ;
559
559
560
- var selectPath = [ [ 170 - 68 , 100 - 96 ] , [ 255 - 68 , 160 - 96 ] ] ;
560
+ // drag around just the center point, but if we have a selectdirection we may
561
+ // get either the ones to the left and right or above and below
562
+ var selectPath = [ [ 175 , 175 ] , [ 225 , 225 ] ] ;
561
563
562
- Plotly . newPlot ( gd , [
563
- { x : [ 1 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 3 , 3 ] , type : 'histogram' } ,
564
- { x : [ 1 , 2 , 3 ] , y : [ - 1 , - 2 , - 3 ] , type : 'bar' }
565
- ] , {
564
+ function selectDrag ( ) {
565
+ resetEvents ( gd ) ;
566
+ drag ( selectPath ) ;
567
+ return selectedPromise ;
568
+ }
569
+
570
+ function assertSelectedPointNumbers ( pointNumbers ) {
571
+ var pts = selectedData . points ;
572
+ expect ( pts . length ) . toBe ( pointNumbers . length ) ;
573
+ pointNumbers . forEach ( function ( pointNumber , i ) {
574
+ expect ( pts [ i ] . pointNumber ) . toBe ( pointNumber ) ;
575
+ } ) ;
576
+ }
577
+
578
+ Plotly . newPlot ( gd , [ {
579
+ x : [ 1 , 1 , 1 , 2 , 2 , 2 , 3 , 3 , 3 ] ,
580
+ y : [ 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 ] ,
581
+ mode : 'markers'
582
+ } ] , {
566
583
width : 400 ,
567
- height : 300 ,
568
- showlegend : false ,
569
- dragmode : 'select'
584
+ height : 400 ,
585
+ dragmode : 'select' ,
586
+ margin : { l : 100 , r : 100 , t : 100 , b : 100 } ,
587
+ xaxis : { range : [ 0 , 4 ] } ,
588
+ yaxis : { range : [ 0 , 4 ] }
570
589
} )
571
- . then ( function ( ) {
572
- // expect(gd.fullLayout.selectdirection).toBe('any');
573
- resetEvents ( gd ) ;
574
- drag ( selectPath ) ;
575
-
576
- selectedPromise . then ( function ( ) {
577
- expect ( selectedData . points . length ) . toBe ( 1 ) ;
578
- expect ( selectedData . points [ 0 ] . x ) . toBe ( 1.8 ) ;
579
- expect ( selectedData . points [ 0 ] . y ) . toBe ( 3 ) ;
580
- } ) ;
590
+ . then ( selectDrag )
591
+ . then ( function ( ) {
592
+ expect ( gd . _fullLayout . selectdirection ) . toBe ( 'any' ) ;
593
+ assertSelectedPointNumbers ( [ 4 ] ) ;
581
594
582
- return Plotly . relayout ( gd , { selectdirection : 'h' } ) ;
583
- } )
584
- . then ( function ( ) {
585
- resetEvents ( gd ) ;
586
- drag ( selectPath ) ;
587
-
588
- selectedPromise . then ( function ( )
589
- {
590
- expect ( selectedData . points . length ) . toBe ( 2 ) ;
591
- expect ( selectedData . points [ 0 ] . x ) . toBe ( 1.8 ) ;
592
- expect ( selectedData . points [ 1 ] . x ) . toBe ( 2.2 ) ;
593
- } ) ;
595
+ return Plotly . relayout ( gd , { selectdirection : 'h' } ) ;
596
+ } )
597
+ . then ( selectDrag )
598
+ . then ( function ( ) {
599
+ assertSelectedPointNumbers ( [ 3 , 4 , 5 ] ) ;
594
600
595
- return Plotly . relayout ( gd , { selectdirection : 'v' } ) ;
596
- } )
597
- . then ( function ( ) {
598
- resetEvents ( gd ) ;
599
- drag ( selectPath ) ;
600
-
601
- selectedPromise . then ( function ( )
602
- {
603
- expect ( selectedData . points . length ) . toBe ( 2 ) ;
604
- expect ( selectedData . points [ 0 ] . x ) . toBe ( 1.8 ) ;
605
- expect ( selectedData . points [ 1 ] . x ) . toBe ( 2.8000000000000003 ) ;
606
- } ) ;
601
+ return Plotly . relayout ( gd , { selectdirection : 'v' } ) ;
602
+ } )
603
+ . then ( selectDrag )
604
+ . then ( function ( ) {
605
+ assertSelectedPointNumbers ( [ 1 , 4 , 7 ] ) ;
607
606
608
- return Plotly . relayout ( gd , { selectdirection : 'd' } ) ;
609
- } )
610
- . then ( function ( ) {
611
- resetEvents ( gd ) ;
612
- drag ( selectPath ) ;
613
-
614
- selectedPromise . then ( function ( )
615
- {
616
- expect ( selectedData . points . length ) . toBe ( 2 ) ;
617
- expect ( selectedData . points [ 0 ] . x ) . toBe ( 1.8 ) ;
618
- expect ( selectedData . points [ 1 ] . x ) . toBe ( 2.2 ) ;
619
- } ) ;
620
- } )
621
- . catch ( fail ) // hmm, we should change the name of this import to failTest, since fail is already a jasmine global, for sync failure, we're overriding it here with our async version (we've already done this in other places)
622
- . then ( done ) ;
607
+ return Plotly . relayout ( gd , { selectdirection : 'd' } ) ;
608
+ } )
609
+ . then ( selectDrag )
610
+ . then ( function ( ) {
611
+ assertSelectedPointNumbers ( [ 4 ] ) ;
612
+ } )
613
+ . catch ( failTest )
614
+ . then ( done ) ;
623
615
624
616
} ) ;
625
617
0 commit comments