Skip to content

click-click #1540

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

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 7 additions & 2 deletions src/interactions/pointer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function pointerK(kx, ky, {x, y, px, py, maxRadius = 40, channels, ...options} =
// Isolate state per-pointer, per-plot; if the pointer is reused by
// multiple marks, they will share the same state (e.g., sticky modality).
let state = states.get(svg);
if (!state) states.set(svg, (state = {sticky: false, roots: [], renders: []}));
if (!state) states.set(svg, (state = {sticky: false, roots: [], renders: [], moves: []}));

// This serves as a unique identifier of the rendered mark per-plot; it is
// used to record the currently-rendered elements (state.roots) so that we
Expand Down Expand Up @@ -116,12 +116,16 @@ function pointerK(kx, ky, {x, y, px, py, maxRadius = 40, channels, ...options} =
g.replaceWith(r);
}
state.roots[renderIndex] = r;
state.moves[renderIndex] = move;
return (g = r);
}

function pointermove(event) {
if (state.sticky || (event.pointerType === "mouse" && event.buttons === 1)) return; // dragging
let [xp, yp] = pointof(event);
move(pointof(event));
}

function move([xp, yp]) {
(xp -= tx), (yp -= ty); // correct for facets and band scales
let ii = null;
let ri = maxRadius * maxRadius;
Expand All @@ -136,6 +140,7 @@ function pointerK(kx, ky, {x, y, px, py, maxRadius = 40, channels, ...options} =

function pointerdown(event) {
if (event.pointerType !== "mouse") return;
if (i == null) ((p) => state.moves.forEach((m) => m(p)))(pointof(event));
if (i == null) return; // not pointing
if (state.sticky && state.roots.some((r) => r?.contains(event.target))) return; // stay sticky
if (state.sticky) (state.sticky = false), state.renders.forEach((r) => r(null)); // clear all pointers
Expand Down