@@ -428,11 +428,18 @@ describe('Test select box and lasso per trace:', function() {
428
428
var callNumber = 0 ;
429
429
430
430
return function ( expected ) {
431
- var msg = '(call #' + callNumber + ') ' ;
432
- var ranges = ( selectedData . range || { } ) [ subplot ] || [ ] ;
433
-
434
- expect ( ranges )
435
- . toBeCloseTo2DArray ( expected , tol , msg + 'select box range for ' + subplot ) ;
431
+ var msg = '(call #' + callNumber + ') select box range ' ;
432
+ var ranges = selectedData . range || { } ;
433
+
434
+ if ( subplot ) {
435
+ expect ( ranges [ subplot ] || [ ] )
436
+ . toBeCloseTo2DArray ( expected , tol , msg + 'for ' + subplot ) ;
437
+ } else {
438
+ expect ( ranges . x || [ ] )
439
+ . toBeCloseToArray ( expected [ 0 ] , tol , msg + 'x coords' ) ;
440
+ expect ( ranges . y || [ ] )
441
+ . toBeCloseToArray ( expected [ 1 ] , tol , msg + 'y coords' ) ;
442
+ }
436
443
437
444
callNumber ++ ;
438
445
} ;
@@ -443,11 +450,18 @@ describe('Test select box and lasso per trace:', function() {
443
450
var callNumber = 0 ;
444
451
445
452
return function ( expected ) {
446
- var msg = '(call #' + callNumber + ') ' ;
447
- var lassoPoints = ( selectedData . lassoPoints || { } ) [ subplot ] || [ ] ;
448
-
449
- expect ( lassoPoints )
450
- . toBeCloseTo2DArray ( expected , tol , msg + 'lasso points for ' + subplot ) ;
453
+ var msg = '(call #' + callNumber + ') lasso points ' ;
454
+ var lassoPoints = selectedData . lassoPoints || { } ;
455
+
456
+ if ( subplot ) {
457
+ expect ( lassoPoints [ subplot ] || [ ] )
458
+ . toBeCloseTo2DArray ( expected , tol , msg + 'for ' + subplot ) ;
459
+ } else {
460
+ expect ( lassoPoints . x || [ ] )
461
+ . toBeCloseToArray ( expected [ 0 ] , tol , msg + 'x coords' ) ;
462
+ expect ( lassoPoints . y || [ ] )
463
+ . toBeCloseToArray ( expected [ 1 ] , tol , msg + 'y coords' ) ;
464
+ }
451
465
452
466
callNumber ++ ;
453
467
} ;
@@ -708,4 +722,55 @@ describe('Test select box and lasso per trace:', function() {
708
722
. catch ( fail )
709
723
. then ( done ) ;
710
724
} , LONG_TIMEOUT_INTERVAL ) ;
725
+
726
+ it ( 'should work for bar traces' , function ( done ) {
727
+ var assertPoints = makeAssertPoints ( [ 'curveNumber' , 'x' , 'y' ] ) ;
728
+ var assertRanges = makeAssertRanges ( ) ;
729
+ var assertLassoPoints = makeAssertLassoPoints ( ) ;
730
+
731
+ var fig = Lib . extendDeep ( { } , require ( '@mocks/0' ) ) ;
732
+ fig . layout . dragmode = 'lasso' ;
733
+
734
+ Plotly . plot ( gd , fig )
735
+ . then ( function ( ) {
736
+ return _run (
737
+ [ [ 350 , 200 ] , [ 400 , 200 ] , [ 400 , 250 ] , [ 350 , 250 ] , [ 350 , 200 ] ] ,
738
+ function ( ) {
739
+ assertPoints ( [
740
+ [ 0 , 4.9 , 0.371 ] , [ 0 , 5 , 0.368 ] , [ 0 , 5.1 , 0.356 ] , [ 0 , 5.2 , 0.336 ] ,
741
+ [ 0 , 5.3 , 0.309 ] , [ 0 , 5.4 , 0.275 ] , [ 0 , 5.5 , 0.235 ] , [ 0 , 5.6 , 0.192 ] ,
742
+ [ 0 , 5.7 , 0.145 ] ,
743
+ [ 1 , 5.1 , 0.485 ] , [ 1 , 5.2 , 0.40900000000000003 ] , [ 1 , 5.3 , 0.327 ] ,
744
+ [ 1 , 5.4 , 0.24000000000000002 ] , [ 1 , 5.5 , 0.149 ] , [ 1 , 5.6 , 0.059 ] ,
745
+ [ 2 , 4.9 , 0.473 ] , [ 2 , 5 , 0.36800000000000005 ] , [ 2 , 5.1 , 0.258 ] ,
746
+ [ 2 , 5.2 , 0.14600000000000002 ] , [ 2 , 5.3 , 0.03600000000000003 ]
747
+ ] ) ;
748
+ assertLassoPoints ( [
749
+ [ 4.87 , 5.74 , 5.74 , 4.87 , 4.87 ] ,
750
+ [ 0.53 , 0.53 , - 0.02 , - 0.02 , 0.53 ]
751
+ ] ) ;
752
+ } ,
753
+ null , LASSOEVENTS , 'bar lasso'
754
+ ) ;
755
+ } )
756
+ . then ( function ( ) {
757
+ return Plotly . relayout ( gd , 'dragmode' , 'select' ) ;
758
+ } )
759
+ . then ( function ( ) {
760
+ return _run (
761
+ [ [ 350 , 200 ] , [ 370 , 220 ] ] ,
762
+ function ( ) {
763
+ assertPoints ( [
764
+ [ 0 , 4.9 , 0.371 ] , [ 0 , 5 , 0.368 ] , [ 0 , 5.1 , 0.356 ] , [ 0 , 5.2 , 0.336 ] ,
765
+ [ 1 , 5.1 , 0.485 ] , [ 1 , 5.2 , 0.40900000000000003 ] ,
766
+ [ 2 , 4.9 , 0.473 ] , [ 2 , 5 , 0.36800000000000005 ]
767
+ ] ) ;
768
+ assertRanges ( [ [ 4.87 , 5.22 ] , [ 0.31 , 0.53 ] ] ) ;
769
+ } ,
770
+ null , BOXEVENTS , 'bar select'
771
+ ) ;
772
+ } )
773
+ . catch ( fail )
774
+ . then ( done ) ;
775
+ } ) ;
711
776
} ) ;
0 commit comments