@@ -388,16 +388,16 @@ describe('sankey tests', function() {
388
388
describe ( 'Test hover/click interactions:' , function ( ) {
389
389
afterEach ( destroyGraphDiv ) ;
390
390
391
+ function _hover ( px , py ) {
392
+ mouseEvent ( 'mousemove' , px , py ) ;
393
+ mouseEvent ( 'mouseover' , px , py ) ;
394
+ Lib . clearThrottle ( ) ;
395
+ }
396
+
391
397
it ( 'should show the correct hover labels' , function ( done ) {
392
398
var gd = createGraphDiv ( ) ;
393
399
var mockCopy = Lib . extendDeep ( { } , mock ) ;
394
400
395
- function _hover ( px , py ) {
396
- mouseEvent ( 'mousemove' , px , py ) ;
397
- mouseEvent ( 'mouseover' , px , py ) ;
398
- Lib . clearThrottle ( ) ;
399
- }
400
-
401
401
Plotly . plot ( gd , mockCopy ) . then ( function ( ) {
402
402
_hover ( 404 , 302 ) ;
403
403
@@ -464,12 +464,6 @@ describe('sankey tests', function() {
464
464
var mockCopy = Lib . extendDeep ( { } , mock ) ;
465
465
delete mockCopy . data [ 0 ] . link . label ;
466
466
467
- function _hover ( px , py ) {
468
- mouseEvent ( 'mousemove' , px , py ) ;
469
- mouseEvent ( 'mouseover' , px , py ) ;
470
- Lib . clearThrottle ( ) ;
471
- }
472
-
473
467
Plotly . plot ( gd , mockCopy )
474
468
. then ( function ( ) {
475
469
_hover ( 450 , 300 ) ;
@@ -482,6 +476,22 @@ describe('sankey tests', function() {
482
476
. catch ( failTest )
483
477
. then ( done ) ;
484
478
} ) ;
479
+
480
+ it ( 'should not show labels if hovermode is false' , function ( done ) {
481
+ var gd = createGraphDiv ( ) ;
482
+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
483
+
484
+ Plotly . plot ( gd , mockCopy ) . then ( function ( ) {
485
+ return Plotly . relayout ( gd , 'hovermode' , false ) ;
486
+ } )
487
+ . then ( function ( ) {
488
+ _hover ( 404 , 302 ) ;
489
+
490
+ assertNoLabel ( ) ;
491
+ } )
492
+ . catch ( failTest )
493
+ . then ( done ) ;
494
+ } ) ;
485
495
} ) ;
486
496
487
497
describe ( 'Test hover/click event data:' , function ( ) {
@@ -527,44 +537,52 @@ describe('sankey tests', function() {
527
537
mouseEvent ( 'mouseout' , pos [ 0 ] , pos [ 1 ] ) ;
528
538
} ) ;
529
539
530
- it ( 'should output correct hover/click/unhover event data' , function ( done ) {
531
- var fig = Lib . extendDeep ( { } , mock ) ;
540
+ function _assert ( d , expectedPtData ) {
541
+ expect ( d . event ) . toBeDefined ( 'original event reference' ) ;
532
542
533
- function _assert ( d , expectedPtData ) {
534
- expect ( d . event ) . toBeDefined ( 'original event reference' ) ;
543
+ var ptData = d . points [ 0 ] ;
544
+ Object . keys ( expectedPtData ) . forEach ( function ( k ) {
545
+ expect ( ptData [ k ] ) . toBe ( expectedPtData [ k ] , 'point data for ' + k ) ;
546
+ } ) ;
547
+ }
535
548
536
- var ptData = d . points [ 0 ] ;
537
- Object . keys ( expectedPtData ) . forEach ( function ( k ) {
538
- expect ( ptData [ k ] ) . toBe ( expectedPtData [ k ] , 'point data for ' + k ) ;
539
- } ) ;
540
- }
549
+ it ( 'should output correct click event data' , function ( done ) {
550
+ var fig = Lib . extendDeep ( { } , mock ) ;
541
551
542
552
Plotly . plot ( gd , fig )
543
- . then ( function ( ) { return _hover ( 'node' ) ; } )
553
+ . then ( function ( ) { return _click ( 'node' ) ; } )
544
554
. then ( function ( d ) {
545
555
_assert ( d , {
546
556
curveNumber : 0 ,
547
557
pointNumber : 4 ,
548
558
label : 'Solid'
549
559
} ) ;
550
560
} )
551
- . then ( function ( ) { return _hover ( 'link' ) ; } )
561
+ . then ( function ( ) { return _click ( 'link' ) ; } )
552
562
. then ( function ( d ) {
553
563
_assert ( d , {
554
564
curveNumber : 0 ,
555
565
pointNumber : 61 ,
556
566
value : 46.477
557
567
} ) ;
558
568
} )
559
- . then ( function ( ) { return _click ( 'node' ) ; } )
569
+ . catch ( failTest )
570
+ . then ( done ) ;
571
+ } ) ;
572
+
573
+ it ( 'should output correct hover/unhover event data' , function ( done ) {
574
+ var fig = Lib . extendDeep ( { } , mock ) ;
575
+
576
+ Plotly . plot ( gd , fig )
577
+ . then ( function ( ) { return _hover ( 'node' ) ; } )
560
578
. then ( function ( d ) {
561
579
_assert ( d , {
562
580
curveNumber : 0 ,
563
581
pointNumber : 4 ,
564
582
label : 'Solid'
565
583
} ) ;
566
584
} )
567
- . then ( function ( ) { return _click ( 'link' ) ; } )
585
+ . then ( function ( ) { return _hover ( 'link' ) ; } )
568
586
. then ( function ( d ) {
569
587
_assert ( d , {
570
588
curveNumber : 0 ,
@@ -591,6 +609,30 @@ describe('sankey tests', function() {
591
609
. catch ( failTest )
592
610
. then ( done ) ;
593
611
} ) ;
612
+
613
+ it ( 'should not output hover/unhover event data when hovermoder is false' , function ( done ) {
614
+ var fig = Lib . extendDeep ( { } , mock ) ;
615
+
616
+ Plotly . plot ( gd , fig )
617
+ . then ( function ( ) { return Plotly . relayout ( gd , 'hovermode' , false ) ; } )
618
+ . then ( function ( ) { return _hover ( 'node' ) ; } )
619
+ . then ( failTest ) . catch ( function ( err ) {
620
+ expect ( err ) . toBe ( 'plotly_hover did not get called!' ) ;
621
+ } )
622
+ . then ( function ( ) { return _unhover ( 'node' ) ; } )
623
+ . then ( failTest ) . catch ( function ( err ) {
624
+ expect ( err ) . toBe ( 'plotly_unhover did not get called!' ) ;
625
+ } )
626
+ . then ( function ( ) { return _hover ( 'link' ) ; } )
627
+ . then ( failTest ) . catch ( function ( err ) {
628
+ expect ( err ) . toBe ( 'plotly_hover did not get called!' ) ;
629
+ } )
630
+ . then ( function ( ) { return _unhover ( 'link' ) ; } )
631
+ . then ( failTest ) . catch ( function ( err ) {
632
+ expect ( err ) . toBe ( 'plotly_unhover did not get called!' ) ;
633
+ } )
634
+ . then ( done ) ;
635
+ } ) ;
594
636
} ) ;
595
637
} ) ;
596
638
@@ -620,3 +662,8 @@ function assertLabel(content, style) {
620
662
fontColor : style [ 4 ]
621
663
} ) ;
622
664
}
665
+
666
+ function assertNoLabel ( ) {
667
+ var g = d3 . selectAll ( '.hovertext' ) ;
668
+ expect ( g . size ( ) ) . toBe ( 0 ) ;
669
+ }
0 commit comments