@@ -3,9 +3,10 @@ import {getSource} from "../channel.js";
3
3
import { create } from "../context.js" ;
4
4
import { defined } from "../defined.js" ;
5
5
import { formatDefault } from "../format.js" ;
6
+ import { pointerPosition } from "../interactions/pointer.js" ;
6
7
import { Mark } from "../mark.js" ;
7
8
import { maybeAnchor , maybeFrameAnchor , maybeTuple , number , string } from "../options.js" ;
8
- import { applyDirectStyles , applyFrameAnchor , applyIndirectStyles , applyTransform , impliedString } from "../style.js" ;
9
+ import { applyDirectStyles , applyIndirectStyles , applyTransform , impliedString } from "../style.js" ;
9
10
import { inferTickFormat } from "./axis.js" ;
10
11
import { applyIndirectTextStyles , defaultWidth , ellipsis , monospaceWidth } from "./text.js" ;
11
12
import { cut , clipper , splitter , maybeTextOverflow } from "./text.js" ;
@@ -92,12 +93,10 @@ export class Tip extends Mark {
92
93
// unspecified, we fallback to the frame anchor. We also need to know the
93
94
// facet offsets to detect when the tip would draw outside the plot, and
94
95
// thus we need to change the orientation.
95
- const { x : X , y : Y , x1 : X1 , y1 : Y1 , x2 : X2 , y2 : Y2 } = channels ;
96
- const [ cx , cy ] = applyFrameAnchor ( this , dimensions ) ;
96
+ const { x1 : X1 , y1 : Y1 , x2 : X2 , y2 : Y2 , x : X = X1 ?? X2 , y : Y = Y1 ?? Y2 } = channels ;
97
97
const ox = fx ? fx ( index . fx ) - marginLeft : 0 ;
98
98
const oy = fy ? fy ( index . fy ) - marginTop : 0 ;
99
- const px = X2 ? ( i ) => ( X1 [ i ] + X2 [ i ] ) / 2 : X ? ( i ) => X [ i ] : ( ) => cx ;
100
- const py = Y2 ? ( i ) => ( Y1 [ i ] + Y2 [ i ] ) / 2 : Y ? ( i ) => Y [ i ] : ( ) => cy ;
99
+ const [ px , py ] = pointerPosition ( mark , channels , dimensions ) ;
101
100
102
101
// Resolve the text metric implementation. We may need an ellipsis for text
103
102
// truncation, so we optimistically compute the ellipsis width.
@@ -142,7 +141,7 @@ export class Tip extends Mark {
142
141
const g = create ( "svg:g" , context )
143
142
. call ( applyIndirectStyles , this , dimensions , context )
144
143
. call ( applyIndirectTextStyles , this )
145
- . call ( applyTransform , this , { x : ( X || X2 ) && x , y : ( Y || Y2 ) && y } )
144
+ . call ( applyTransform , this , { x : X && x , y : Y && y } )
146
145
. call ( ( g ) =>
147
146
g
148
147
. selectAll ( )
0 commit comments