Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix pointerX & faceting #1777

Merged
merged 6 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/interactions/pointer.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,29 @@ function pointerK(kx, ky, {x, y, px, py, maxRadius = 40, channels, render, ...op
return r;
}

// Select the closest point to the mouse in the current facet; for
// pointerX or pointerY, the orthogonal component of the distance is
// squashed, selecting primarily on the dominant dimension. Across facets,
// use unsquashed distance to determine the winner.
function pointermove(event) {
if (state.sticky || (event.pointerType === "mouse" && event.buttons === 1)) return; // dragging
let [xp, yp] = pointof(event);
(xp -= tx), (yp -= ty); // correct for facets and band scales
const kpx = xp < dimensions.marginLeft || xp > dimensions.width - dimensions.marginRight ? 1 : kx;
const kpy = yp < dimensions.marginTop || yp > dimensions.height - dimensions.marginBottom ? 1 : ky;
let ii = null;
let ri = maxRadius * maxRadius;
for (const j of index) {
const dx = kx * (px(j) - xp);
const dy = ky * (py(j) - yp);
const dx = kpx * (px(j) - xp);
const dy = kpy * (py(j) - yp);
const rj = dx * dx + dy * dy;
if (rj <= ri) (ii = j), (ri = rj);
}
if (ii != null && (kx !== 1 || ky !== 1)) {
const dx = px(ii) - xp;
const dy = py(ii) - yp;
ri = dx * dx + dy * dy;
}
update(ii, ri);
}

Expand Down
Loading