Skip to content

Commit d2c1c02

Browse files
committed
p[xy] precedence
1 parent 4fbcc67 commit d2c1c02

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/interactions/pointer.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ function pointerK(kx, ky, {x, y, px, py, maxRadius = 40, channels, ...options} =
2525
const facetState = faceted ? (state.facetState ??= new Map()) : null;
2626
const tx = scales.fx ? scales.fx(index.fx) - dimensions.marginLeft : 0;
2727
const ty = scales.fy ? scales.fy(index.fy) - dimensions.marginTop : 0;
28-
const {x: X0, y: Y0, x1: X1, y1: Y1, x2: X2, y2: Y2, px: X = X0, py: Y = Y0} = values;
28+
const {x: X, y: Y, x1: X1, y1: Y1, x2: X2, y2: Y2, px: PX, py: PY} = values;
2929
const [cx, cy] = applyFrameAnchor(this, dimensions);
30+
const px = PX ? (i) => PX[i] : X2 ? (i) => (X1[i] + X2[i]) / 2 : X ? (i) => X[i] : () => cx;
31+
const py = PY ? (i) => PY[i] : Y2 ? (i) => (Y1[i] + Y2[i]) / 2 : Y ? (i) => Y[i] : () => cy;
3032
let i; // currently focused index
3133
let g; // currently rendered mark
3234

@@ -80,10 +82,8 @@ function pointerK(kx, ky, {x, y, px, py, maxRadius = 40, channels, ...options} =
8082
let ii = null;
8183
let ri = maxRadius * maxRadius;
8284
for (const j of index) {
83-
const xj = X2 ? (X1[j] + X2[j]) / 2 : X ? X[j] : cx;
84-
const yj = Y2 ? (Y1[j] + Y2[j]) / 2 : Y ? Y[j] : cy;
85-
const dx = kx * (xj - xp);
86-
const dy = ky * (yj - yp);
85+
const dx = kx * (px(j) - xp);
86+
const dy = ky * (py(j) - yp);
8787
const rj = dx * dx + dy * dy;
8888
if (rj <= ri) (ii = j), (ri = rj);
8989
}

0 commit comments

Comments
 (0)