@@ -979,10 +979,12 @@ describe('sankey tests', function () {
979979 } )
980980 . then ( done , done . fail ) ;
981981 } ) ;
982-
982+
983983 it ( '@noCI should position hover labels correctly - horizontal, reversed' , function ( done ) {
984984 var gd = createGraphDiv ( ) ;
985985 var forwardOffsetX ;
986+ var forwardPosY ;
987+ var forwardLinkLeft ;
986988
987989 function plotWith ( direction ) {
988990 var fig = Lib . extendDeep ( { } , mock ) ;
@@ -1001,6 +1003,8 @@ describe('sankey tests', function () {
10011003 var linkRect = rectForLink ( 'Thermal generation' , 'Losses' ) ;
10021004 var pos = d3Select ( '.hovertext' ) . node ( ) . getBoundingClientRect ( ) ;
10031005 forwardOffsetX = pos . x - ( linkRect . left + linkRect . width / 2 ) ;
1006+ forwardPosY = pos . y ;
1007+ forwardLinkLeft = linkRect . left ;
10041008
10051009 return plotWith ( 'reversed' ) ;
10061010 } )
@@ -1029,13 +1033,29 @@ describe('sankey tests', function () {
10291033 - 1.5 ,
10301034 'label offset from its link is direction-independent'
10311035 ) ;
1036+
1037+ // matrix(-1 0 0 1 0 0) mirrors along x only.
1038+ expect ( pos . y ) . toBeCloseTo (
1039+ forwardPosY ,
1040+ - 1.5 ,
1041+ 'y position is unaffected by direction'
1042+ ) ;
1043+
1044+ // Guard against a vacuously passing test: the offset above is
1045+ // only meaningful if the link actually moved.
1046+ expect ( Math . abs ( linkRect . left - forwardLinkLeft ) ) . toBeGreaterThan (
1047+ 50 ,
1048+ 'link is actually mirrored along x'
1049+ ) ;
10321050 } )
10331051 . then ( done , done . fail ) ;
10341052 } ) ;
10351053
10361054 it ( '@noCI should position hover labels correctly - vertical, reversed' , function ( done ) {
10371055 var gd = createGraphDiv ( ) ;
10381056 var forwardOffsetY ;
1057+ var forwardPosX ;
1058+ var forwardLinkTop ;
10391059
10401060 function plotWith ( direction ) {
10411061 var fig = Lib . extendDeep ( { } , mock ) ;
@@ -1050,6 +1070,8 @@ describe('sankey tests', function () {
10501070 var linkRect = rectForLink ( 'Thermal generation' , 'Losses' ) ;
10511071 var pos = d3Select ( '.hovertext' ) . node ( ) . getBoundingClientRect ( ) ;
10521072 forwardOffsetY = pos . y - ( linkRect . top + linkRect . height / 2 ) ;
1073+ forwardPosX = pos . x ;
1074+ forwardLinkTop = linkRect . top ;
10531075
10541076 return plotWith ( 'reversed' ) ;
10551077 } )
@@ -1070,6 +1092,19 @@ describe('sankey tests', function () {
10701092 - 1.5 ,
10711093 'label offset from its link is direction-independent'
10721094 ) ;
1095+
1096+ // matrix(0 -1 1 0 0 0) maps data y to screen x (unmirrored)
1097+ // and mirrors along screen y only.
1098+ expect ( pos . x ) . toBeCloseTo (
1099+ forwardPosX ,
1100+ - 1.5 ,
1101+ 'x position is unaffected by direction'
1102+ ) ;
1103+
1104+ expect ( Math . abs ( linkRect . top - forwardLinkTop ) ) . toBeGreaterThan (
1105+ 50 ,
1106+ 'link is actually mirrored along y'
1107+ ) ;
10731108 } )
10741109 . then ( done , done . fail ) ;
10751110 } ) ;
0 commit comments