@@ -778,6 +778,47 @@ describe('sankey tests', function() {
778
778
. then ( done ) ;
779
779
} ) ;
780
780
781
+ it ( 'should show the multiple hover labels in a flow in hovermode `x`' , function ( done ) {
782
+ var gd = createGraphDiv ( ) ;
783
+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
784
+ Plotly . plot ( gd , mockCopy ) . then ( function ( ) {
785
+ _hover ( 351 , 202 ) ;
786
+
787
+ assertLabel (
788
+ [ 'source: Nuclear' , 'target: Thermal generation' , '100TWh' ] ,
789
+ [ 'rgb(144, 238, 144)' , 'rgb(68, 68, 68)' , 13 , 'Arial' , 'rgb(68, 68, 68)' ]
790
+ ) ;
791
+
792
+ var g = d3 . selectAll ( '.hovertext' ) ;
793
+ expect ( g . size ( ) ) . toBe ( 1 ) ;
794
+ return Plotly . relayout ( gd , 'hovermode' , 'x' ) ;
795
+ } )
796
+ . then ( function ( ) {
797
+ _hover ( 351 , 202 ) ;
798
+
799
+ assertMultipleLabels (
800
+ [
801
+ [ 'Old generation plant (made-up)' , 'source: Nuclear' , 'target: Thermal generation' , '500TWh' ] ,
802
+ [ 'New generation plant (made-up)' , 'source: Nuclear' , 'target: Thermal generation' , '140TWh' ] ,
803
+ [ 'source: Nuclear' , 'target: Thermal generation' , '100TWh' ] ,
804
+ [ 'source: Nuclear' , 'target: Thermal generation' , '100TWh' ]
805
+ ] ,
806
+ [
807
+ [ 'rgb(33, 102, 172)' , 'rgb(255, 255, 255)' , 13 , 'Arial' , 'rgb(255, 255, 255)' ] ,
808
+ [ 'rgb(178, 24, 43)' , 'rgb(255, 255, 255)' , 13 , 'Arial' , 'rgb(255, 255, 255)' ] ,
809
+ [ 'rgb(144, 238, 144)' , 'rgb(68, 68, 68)' , 13 , 'Arial' , 'rgb(68, 68, 68)' ] ,
810
+ [ 'rgb(218, 165, 32)' , 'rgb(68, 68, 68)' , 13 , 'Arial' , 'rgb(68, 68, 68)' ]
811
+ ]
812
+ ) ;
813
+
814
+ var g = d3 . select ( '.hovertext:nth-child(3)' ) ;
815
+ var domRect = g . node ( ) . getBoundingClientRect ( ) ;
816
+ expect ( ( domRect . bottom + domRect . top ) / 2 ) . toBeCloseTo ( 203 , 0 , 'it should center the hoverlabel associated with hovered link' ) ;
817
+ } )
818
+ . catch ( failTest )
819
+ . then ( done ) ;
820
+ } ) ;
821
+
781
822
it ( 'should not show any labels if hovermode is false' , function ( done ) {
782
823
var gd = createGraphDiv ( ) ;
783
824
var mockCopy = Lib . extendDeep ( { } , mock ) ;
@@ -1265,7 +1306,18 @@ describe('sankey tests', function() {
1265
1306
} ) ;
1266
1307
1267
1308
function assertLabel ( content , style ) {
1309
+ assertMultipleLabels ( [ content ] , [ style ] ) ;
1310
+ }
1311
+
1312
+ function assertMultipleLabels ( contentArray , styleArray ) {
1268
1313
var g = d3 . selectAll ( '.hovertext' ) ;
1314
+ expect ( g . size ( ) ) . toEqual ( contentArray . length , 'wrong number of hoverlabels, expected to find ' + contentArray . length ) ;
1315
+ g . each ( function ( el , i ) {
1316
+ _assertLabelGroup ( d3 . select ( this ) , contentArray [ i ] , styleArray [ i ] ) ;
1317
+ } ) ;
1318
+ }
1319
+
1320
+ function _assertLabelGroup ( g , content , style ) {
1269
1321
var lines = g . selectAll ( '.nums .line' ) ;
1270
1322
var name = g . selectAll ( '.name' ) ;
1271
1323
var tooltipBoundingBox = g . node ( ) . getBoundingClientRect ( ) ;
0 commit comments