@@ -444,3 +444,149 @@ describe('Test hover and click interactions', function() {
444
444
. then ( done ) ;
445
445
} ) ;
446
446
} ) ;
447
+
448
+ describe ( 'Test gl2d lasso/select:' , function ( ) {
449
+ var mockFancy = require ( '@mocks/gl2d_14.json' ) ;
450
+ var mockFast = Lib . extendDeep ( { } , mockFancy , {
451
+ data : [ { mode : 'markers' } ] ,
452
+ layout : {
453
+ xaxis : { type : 'linear' } ,
454
+ yaxis : { type : 'linear' }
455
+ }
456
+ } ) ;
457
+
458
+ var gd ;
459
+ var selectPath = [ [ 93 , 193 ] , [ 143 , 193 ] ] ;
460
+ var lassoPath = [ [ 316 , 171 ] , [ 318 , 239 ] , [ 335 , 243 ] , [ 328 , 169 ] ] ;
461
+ var lassoPath2 = [ [ 93 , 193 ] , [ 143 , 193 ] , [ 143 , 500 ] , [ 93 , 500 ] , [ 93 , 193 ] ] ;
462
+
463
+ afterEach ( function ( ) {
464
+ Plotly . purge ( gd ) ;
465
+ destroyGraphDiv ( ) ;
466
+ } ) ;
467
+
468
+ function drag ( path ) {
469
+ var len = path . length ;
470
+
471
+ mouseEvent ( 'mousemove' , path [ 0 ] [ 0 ] , path [ 0 ] [ 1 ] ) ;
472
+ mouseEvent ( 'mousedown' , path [ 0 ] [ 0 ] , path [ 0 ] [ 1 ] ) ;
473
+
474
+ path . slice ( 1 , len ) . forEach ( function ( pt ) {
475
+ mouseEvent ( 'mousemove' , pt [ 0 ] , pt [ 1 ] ) ;
476
+ } ) ;
477
+
478
+ mouseEvent ( 'mouseup' , path [ len - 1 ] [ 0 ] , path [ len - 1 ] [ 1 ] ) ;
479
+ }
480
+
481
+ function select ( path ) {
482
+ return new Promise ( function ( resolve , reject ) {
483
+ gd . once ( 'plotly_selected' , resolve ) ;
484
+ setTimeout ( function ( ) { reject ( 'did not trigger *plotly_selected*' ) ; } , 100 ) ;
485
+ drag ( path ) ;
486
+ } ) ;
487
+ }
488
+
489
+ function assertEventData ( actual , expected ) {
490
+ expect ( actual . points . length ) . toBe ( expected . points . length ) ;
491
+
492
+ expected . points . forEach ( function ( e , i ) {
493
+ var a = actual . points [ i ] ;
494
+ if ( a ) {
495
+ expect ( a . x ) . toBe ( e . x , 'x' ) ;
496
+ expect ( a . y ) . toBe ( e . y , 'y' ) ;
497
+ }
498
+ } ) ;
499
+ }
500
+
501
+ function countGlObjects ( ) {
502
+ return gd . _fullLayout . _plots . xy . _scene2d . glplot . objects . length ;
503
+ }
504
+
505
+ it ( 'should work under fast mode with *select* dragmode' , function ( done ) {
506
+ var _mock = Lib . extendDeep ( { } , mockFast ) ;
507
+ _mock . layout . dragmode = 'select' ;
508
+ gd = createGraphDiv ( ) ;
509
+
510
+ Plotly . plot ( gd , _mock ) . then ( function ( ) {
511
+ expect ( countGlObjects ( ) ) . toBe ( 1 , 'has on gl-scatter2d object' ) ;
512
+
513
+ return select ( selectPath ) ;
514
+ } )
515
+ . then ( function ( eventData ) {
516
+ assertEventData ( eventData , {
517
+ points : [
518
+ { x : 3.911 , y : 0.401 } ,
519
+ { x : 5.34 , y : 0.403 } ,
520
+ { x : 6.915 , y : 0.411 }
521
+ ]
522
+ } ) ;
523
+ expect ( countGlObjects ( ) ) . toBe ( 2 , 'adds a dimmed gl-scatter2d objects' ) ;
524
+ } )
525
+ . catch ( fail )
526
+ . then ( done ) ;
527
+ } ) ;
528
+
529
+ it ( 'should work under fast mode with *lasso* dragmode' , function ( done ) {
530
+ var _mock = Lib . extendDeep ( { } , mockFast ) ;
531
+ _mock . layout . dragmode = 'lasso' ;
532
+ gd = createGraphDiv ( ) ;
533
+
534
+ Plotly . plot ( gd , _mock ) . then ( function ( ) {
535
+ expect ( countGlObjects ( ) ) . toBe ( 1 ) ;
536
+
537
+ return select ( lassoPath2 ) ;
538
+ } )
539
+ . then ( function ( eventData ) {
540
+ assertEventData ( eventData , {
541
+ points : [
542
+ { x : 3.911 , y : 0.401 } ,
543
+ { x : 5.34 , y : 0.403 } ,
544
+ { x : 6.915 , y : 0.411 }
545
+ ]
546
+ } ) ;
547
+ expect ( countGlObjects ( ) ) . toBe ( 2 ) ;
548
+ } )
549
+ . catch ( fail )
550
+ . then ( done ) ;
551
+ } ) ;
552
+
553
+ it ( 'should work under fancy mode with *select* dragmode' , function ( done ) {
554
+ var _mock = Lib . extendDeep ( { } , mockFancy ) ;
555
+ _mock . layout . dragmode = 'select' ;
556
+ gd = createGraphDiv ( ) ;
557
+
558
+ Plotly . plot ( gd , _mock ) . then ( function ( ) {
559
+ expect ( countGlObjects ( ) ) . toBe ( 2 , 'has a gl-line2d and a gl-scatter2d-sdf' ) ;
560
+
561
+ return select ( selectPath ) ;
562
+ } )
563
+ . then ( function ( eventData ) {
564
+ assertEventData ( eventData , {
565
+ points : [ { x : 0.004 , y : 12.5 } ]
566
+ } ) ;
567
+ expect ( countGlObjects ( ) ) . toBe ( 2 , 'only changes colors of gl-scatter2d-sdf object' ) ;
568
+ } )
569
+ . catch ( fail )
570
+ . then ( done ) ;
571
+ } ) ;
572
+
573
+ it ( 'should work under fancy mode with *lasso* dragmode' , function ( done ) {
574
+ var _mock = Lib . extendDeep ( { } , mockFancy ) ;
575
+ _mock . layout . dragmode = 'lasso' ;
576
+ gd = createGraphDiv ( ) ;
577
+
578
+ Plotly . plot ( gd , _mock ) . then ( function ( ) {
579
+ expect ( countGlObjects ( ) ) . toBe ( 2 , 'has a gl-line2d and a gl-scatter2d-sdf' ) ;
580
+
581
+ return select ( lassoPath ) ;
582
+ } )
583
+ . then ( function ( eventData ) {
584
+ assertEventData ( eventData , {
585
+ points : [ { x : 0.099 , y : 2.75 } ]
586
+ } ) ;
587
+ expect ( countGlObjects ( ) ) . toBe ( 2 , 'only changes colors of gl-scatter2d-sdf object' ) ;
588
+ } )
589
+ . catch ( fail )
590
+ . then ( done ) ;
591
+ } ) ;
592
+ } ) ;
0 commit comments