@@ -414,8 +414,13 @@ describe('Test select box and lasso per trace:', function() {
414
414
pts . forEach ( function ( p , i ) {
415
415
var e = expected [ i ] || [ ] ;
416
416
keys . forEach ( function ( k , j ) {
417
- expect ( p [ k ] )
418
- . toBe ( e [ j ] , msg + 'selected pt ' + i + ' - ' + k + ' val' ) ;
417
+ var msgFull = msg + 'selected pt ' + i + ' - ' + k + ' val' ;
418
+
419
+ if ( typeof e [ j ] === 'number' ) {
420
+ expect ( p [ k ] ) . toBeCloseTo ( e [ j ] , 1 , msgFull ) ;
421
+ } else {
422
+ expect ( p [ k ] ) . toBe ( e [ j ] , msgFull ) ;
423
+ }
419
424
} ) ;
420
425
} ) ;
421
426
@@ -428,11 +433,18 @@ describe('Test select box and lasso per trace:', function() {
428
433
var callNumber = 0 ;
429
434
430
435
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 ) ;
436
+ var msg = '(call #' + callNumber + ') select box range ' ;
437
+ var ranges = selectedData . range || { } ;
438
+
439
+ if ( subplot ) {
440
+ expect ( ranges [ subplot ] || [ ] )
441
+ . toBeCloseTo2DArray ( expected , tol , msg + 'for ' + subplot ) ;
442
+ } else {
443
+ expect ( ranges . x || [ ] )
444
+ . toBeCloseToArray ( expected [ 0 ] , tol , msg + 'x coords' ) ;
445
+ expect ( ranges . y || [ ] )
446
+ . toBeCloseToArray ( expected [ 1 ] , tol , msg + 'y coords' ) ;
447
+ }
436
448
437
449
callNumber ++ ;
438
450
} ;
@@ -443,11 +455,18 @@ describe('Test select box and lasso per trace:', function() {
443
455
var callNumber = 0 ;
444
456
445
457
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 ) ;
458
+ var msg = '(call #' + callNumber + ') lasso points ' ;
459
+ var lassoPoints = selectedData . lassoPoints || { } ;
460
+
461
+ if ( subplot ) {
462
+ expect ( lassoPoints [ subplot ] || [ ] )
463
+ . toBeCloseTo2DArray ( expected , tol , msg + 'for ' + subplot ) ;
464
+ } else {
465
+ expect ( lassoPoints . x || [ ] )
466
+ . toBeCloseToArray ( expected [ 0 ] , tol , msg + 'x coords' ) ;
467
+ expect ( lassoPoints . y || [ ] )
468
+ . toBeCloseToArray ( expected [ 1 ] , tol , msg + 'y coords' ) ;
469
+ }
451
470
452
471
callNumber ++ ;
453
472
} ;
@@ -708,4 +727,100 @@ describe('Test select box and lasso per trace:', function() {
708
727
. catch ( fail )
709
728
. then ( done ) ;
710
729
} , LONG_TIMEOUT_INTERVAL ) ;
730
+
731
+ it ( 'should work for bar traces' , function ( done ) {
732
+ var assertPoints = makeAssertPoints ( [ 'curveNumber' , 'x' , 'y' ] ) ;
733
+ var assertRanges = makeAssertRanges ( ) ;
734
+ var assertLassoPoints = makeAssertLassoPoints ( ) ;
735
+
736
+ var fig = Lib . extendDeep ( { } , require ( '@mocks/0' ) ) ;
737
+ fig . layout . dragmode = 'lasso' ;
738
+
739
+ Plotly . plot ( gd , fig )
740
+ . then ( function ( ) {
741
+ return _run (
742
+ [ [ 350 , 200 ] , [ 400 , 200 ] , [ 400 , 250 ] , [ 350 , 250 ] , [ 350 , 200 ] ] ,
743
+ function ( ) {
744
+ assertPoints ( [
745
+ [ 0 , 4.9 , 0.371 ] , [ 0 , 5 , 0.368 ] , [ 0 , 5.1 , 0.356 ] , [ 0 , 5.2 , 0.336 ] ,
746
+ [ 0 , 5.3 , 0.309 ] , [ 0 , 5.4 , 0.275 ] , [ 0 , 5.5 , 0.235 ] , [ 0 , 5.6 , 0.192 ] ,
747
+ [ 0 , 5.7 , 0.145 ] ,
748
+ [ 1 , 5.1 , 0.485 ] , [ 1 , 5.2 , 0.409 ] , [ 1 , 5.3 , 0.327 ] ,
749
+ [ 1 , 5.4 , 0.24 ] , [ 1 , 5.5 , 0.149 ] , [ 1 , 5.6 , 0.059 ] ,
750
+ [ 2 , 4.9 , 0.473 ] , [ 2 , 5 , 0.368 ] , [ 2 , 5.1 , 0.258 ] ,
751
+ [ 2 , 5.2 , 0.146 ] , [ 2 , 5.3 , 0.036 ]
752
+ ] ) ;
753
+ assertLassoPoints ( [
754
+ [ 4.87 , 5.74 , 5.74 , 4.87 , 4.87 ] ,
755
+ [ 0.53 , 0.53 , - 0.02 , - 0.02 , 0.53 ]
756
+ ] ) ;
757
+ } ,
758
+ null , LASSOEVENTS , 'bar lasso'
759
+ ) ;
760
+ } )
761
+ . then ( function ( ) {
762
+ return Plotly . relayout ( gd , 'dragmode' , 'select' ) ;
763
+ } )
764
+ . then ( function ( ) {
765
+ return _run (
766
+ [ [ 350 , 200 ] , [ 370 , 220 ] ] ,
767
+ function ( ) {
768
+ assertPoints ( [
769
+ [ 0 , 4.9 , 0.371 ] , [ 0 , 5 , 0.368 ] , [ 0 , 5.1 , 0.356 ] , [ 0 , 5.2 , 0.336 ] ,
770
+ [ 1 , 5.1 , 0.485 ] , [ 1 , 5.2 , 0.41 ] ,
771
+ [ 2 , 4.9 , 0.473 ] , [ 2 , 5 , 0.37 ]
772
+ ] ) ;
773
+ assertRanges ( [ [ 4.87 , 5.22 ] , [ 0.31 , 0.53 ] ] ) ;
774
+ } ,
775
+ null , BOXEVENTS , 'bar select'
776
+ ) ;
777
+ } )
778
+ . catch ( fail )
779
+ . then ( done ) ;
780
+ } ) ;
781
+
782
+ it ( 'should work for histogram traces' , function ( done ) {
783
+ var assertPoints = makeAssertPoints ( [ 'curveNumber' , 'x' , 'y' ] ) ;
784
+ var assertRanges = makeAssertRanges ( ) ;
785
+ var assertLassoPoints = makeAssertLassoPoints ( ) ;
786
+
787
+ var fig = Lib . extendDeep ( { } , require ( '@mocks/hist_grouped' ) ) ;
788
+ fig . layout . dragmode = 'lasso' ;
789
+ fig . layout . width = 600 ;
790
+ fig . layout . height = 500 ;
791
+
792
+ Plotly . plot ( gd , fig )
793
+ . then ( function ( ) {
794
+ return _run (
795
+ [ [ 200 , 200 ] , [ 400 , 200 ] , [ 400 , 350 ] , [ 200 , 350 ] , [ 200 , 200 ] ] ,
796
+ function ( ) {
797
+ assertPoints ( [
798
+ [ 0 , 1.8 , 2 ] , [ 1 , 2.2 , 1 ] , [ 1 , 3.2 , 1 ]
799
+ ] ) ;
800
+ assertLassoPoints ( [
801
+ [ 1.66 , 3.59 , 3.59 , 1.66 , 1.66 ] ,
802
+ [ 2.17 , 2.17 , 0.69 , 0.69 , 2.17 ]
803
+ ] ) ;
804
+ } ,
805
+ null , LASSOEVENTS , 'histogram lasso'
806
+ ) ;
807
+ } )
808
+ . then ( function ( ) {
809
+ return Plotly . relayout ( gd , 'dragmode' , 'select' ) ;
810
+ } )
811
+ . then ( function ( ) {
812
+ return _run (
813
+ [ [ 200 , 200 ] , [ 400 , 350 ] ] ,
814
+ function ( ) {
815
+ assertPoints ( [
816
+ [ 0 , 1.8 , 2 ] , [ 1 , 2.2 , 1 ] , [ 1 , 3.2 , 1 ]
817
+ ] ) ;
818
+ assertRanges ( [ [ 1.66 , 3.59 ] , [ 0.69 , 2.17 ] ] ) ;
819
+ } ,
820
+ null , BOXEVENTS , 'bar select'
821
+ ) ;
822
+ } )
823
+ . catch ( fail )
824
+ . then ( done ) ;
825
+ } ) ;
711
826
} ) ;
0 commit comments