Skip to content
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