@@ -778,6 +778,47 @@ describe('sankey tests', function() {
778778 . then ( done ) ;
779779 } ) ;
780780
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+
781822 it ( 'should not show any labels if hovermode is false' , function ( done ) {
782823 var gd = createGraphDiv ( ) ;
783824 var mockCopy = Lib . extendDeep ( { } , mock ) ;
@@ -1265,7 +1306,18 @@ describe('sankey tests', function() {
12651306} ) ;
12661307
12671308function assertLabel ( content , style ) {
1309+ assertMultipleLabels ( [ content ] , [ style ] ) ;
1310+ }
1311+
1312+ function assertMultipleLabels ( contentArray , styleArray ) {
12681313 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 ) {
12691321 var lines = g . selectAll ( '.nums .line' ) ;
12701322 var name = g . selectAll ( '.name' ) ;
12711323 var tooltipBoundingBox = g . node ( ) . getBoundingClientRect ( ) ;
0 commit comments