Skip to content

Commit a5024fc

Browse files
authored
Return the usual euclidian distance to determine the winner across facets, not the squashed distance. (#1777)
fixes #1776
1 parent 99397d9 commit a5024fc

File tree

5 files changed

+645
-2
lines changed

5 files changed

+645
-2
lines changed

src/interactions/pointer.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,29 @@ function pointerK(kx, ky, {x, y, px, py, maxRadius = 40, channels, render, ...op
130130
return r;
131131
}
132132

133+
// Select the closest point to the mouse in the current facet; for
134+
// pointerX or pointerY, the orthogonal component of the distance is
135+
// squashed, selecting primarily on the dominant dimension. Across facets,
136+
// use unsquashed distance to determine the winner.
133137
function pointermove(event) {
134138
if (state.sticky || (event.pointerType === "mouse" && event.buttons === 1)) return; // dragging
135139
let [xp, yp] = pointof(event);
136140
(xp -= tx), (yp -= ty); // correct for facets and band scales
141+
const kpx = xp < dimensions.marginLeft || xp > dimensions.width - dimensions.marginRight ? 1 : kx;
142+
const kpy = yp < dimensions.marginTop || yp > dimensions.height - dimensions.marginBottom ? 1 : ky;
137143
let ii = null;
138144
let ri = maxRadius * maxRadius;
139145
for (const j of index) {
140-
const dx = kx * (px(j) - xp);
141-
const dy = ky * (py(j) - yp);
146+
const dx = kpx * (px(j) - xp);
147+
const dy = kpy * (py(j) - yp);
142148
const rj = dx * dx + dy * dy;
143149
if (rj <= ri) (ii = j), (ri = rj);
144150
}
151+
if (ii != null && (kx !== 1 || ky !== 1)) {
152+
const dx = px(ii) - xp;
153+
const dy = py(ii) - yp;
154+
ri = dx * dx + dy * dy;
155+
}
145156
update(ii, ri);
146157
}
147158

0 commit comments

Comments
 (0)