@@ -7401,11 +7401,17 @@ describe('hovermode: (x|y)unified', function () {
74017401 getHoverLabel ( )
74027402 . selectAll ( 'g.traces text.legendtext' )
74037403 . each ( function ( ) {
7404- const bBox = this . getBoundingClientRect ( ) ;
7405- items . push ( { anchor : this . getAttribute ( 'text-anchor' ) , left : bBox . left , right : bBox . right } ) ;
7404+ const { left, right } = this . getBoundingClientRect ( ) ;
7405+ items . push ( {
7406+ anchor : this . getAttribute ( 'text-anchor' ) ,
7407+ left,
7408+ right,
7409+ x : this . getAttribute ( 'x' )
7410+ } ) ;
74067411 } ) ;
74077412 return items ;
74087413 } ;
7414+ let rightAlignedShort ;
74097415
74107416 Plotly . newPlot ( gd , [ { y : [ 1 , 2 , 3 ] } , { y : [ 1000000 , 2000000 , 3000000 ] } ] , {
74117417 hovermode : 'x unified' ,
@@ -7418,8 +7424,10 @@ describe('hovermode: (x|y)unified', function () {
74187424 _hover ( gd , { xval : 1 } ) ;
74197425 const [ short , long ] = getItems ( ) ;
74207426 expect ( [ short . anchor , long . anchor ] ) . toEqual ( [ 'end' , 'end' ] ) ;
7421- expect ( short . right ) . toBeCloseTo ( long . right , 0 ) ;
7427+ // Compare anchor positions because the text rect can extend past the anchor by a font-dependent amount
7428+ expect ( short . x ) . toBe ( long . x ) ;
74227429 expect ( short . left ) . toBeGreaterThan ( long . left ) ;
7430+ rightAlignedShort = short ;
74237431
74247432 return Plotly . relayout ( gd , 'hoverlabel.align' , 'left' ) ;
74257433 } )
@@ -7435,7 +7443,9 @@ describe('hovermode: (x|y)unified', function () {
74357443 _hover ( gd , { xval : 1 } ) ;
74367444 const [ short , long ] = getItems ( ) ;
74377445 expect ( [ short . anchor , long . anchor ] ) . toEqual ( [ 'end' , 'start' ] ) ;
7438- expect ( short . right ) . toBeWithin ( long . right , 1 ) ;
7446+ // Same text and box as the first step, so the right-aligned item must not move
7447+ expect ( short . x ) . toBe ( rightAlignedShort . x ) ;
7448+ expect ( short . right ) . toBeCloseTo ( rightAlignedShort . right , 0 ) ;
74397449 } )
74407450 . then ( done , done . fail ) ;
74417451 } ) ;
0 commit comments