-
Notifications
You must be signed in to change notification settings - Fork 185
A pointer interaction that handles click differently? #1832
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
Comments
Maybe we can call it the “clicker” interaction in homage to TLOU. 😂 |
Another example https://observablehq.com/d/7e5f1eec1354f1a2 |
We are using Plot as our visualization library to embed within an in house "production" app and being able to disable "click-to-stick" would be great for things like: Initial click on figure expands to full screen view -> optionally click to stick to highlight data point -> download SVG. |
+1 For click only pointer. We are using Plot for interactive viz app, and selected value will trigger the "list detail data" function, we do hope to set "click" as a stable interaction. We need to request data base on the selected value, and it should not be be triggered too often. The hover to point is nice for realtime data exhibition, but not very ideal for this scenario. |
If it's helpful to anyone, current @nozzleio, we are listening to pointer events and grabbing the useStrictEffect(() => {
if (plotEl) {
plotEl.innerHTML = ''
plotEl.append(plot)
}
let registeredOnLeave = false
const onTipHoverCb = () => {
if (!registeredOnLeave) {
registeredOnLeave = true
const onLeave = e => {
if (!plotEl.contains(e.target)) {
getOnTipHover()?.(undefined!)
registeredOnLeave = false
document.removeEventListener('mousemove', onLeave)
}
}
document.addEventListener('mousemove', onLeave)
}
getOnTipHover()?.(plot.value as T)
}
const onTipClickCb = (e: any) => {
if (plot.value) getOnTipClick()?.(plot.value as T, e)
}
plot.addEventListener('mousemove', onTipHoverCb)
plot.addEventListener('click', onTipClickCb)
return () => {
plot.removeEventListener('mousemove', onTipHoverCb)
plot.removeEventListener('click', onTipClickCb)
}
}, [getOnTipClick, getOnTipHover, width, height, plot, plotEl]) |
The first option or any form of value exposing really leaves us the opportunity to do whatever we want. The current default of |
Hello! I would love to be able to disable the default I see a PR to this effect https://github.com/observablehq/plot/pull/1979/files. Is this still a viable solution? Anything I can do to help? |
A quick workaround for this is that you can use event.stopPropagation on pointerdown events to prevent the pointer interaction from becoming sticky. Another approach is to emit a pointerleave event that causes the pointer event to hide and clear the sticky bit. const pointerdowned = (event) => {
const pointerleave = new PointerEvent("pointerleave", {bubbles: true, pointerType: "mouse"});
event.target.dispatchEvent(pointerleave);
}; |
@mbostock I have tried using event.stopPropagation on my chart pointerdown events but it seems to only trigger when I click in the whitespace of the chart, when I click on a chart element (such as a dot, bar, or line) the pointerdown event is not fired. Do you have any other insight into this issue or workarounds? |
@jessiesanford I know this is a little stale, but if you're trying to make this tooltip leave when you click on the chart, I was able to get this to work (took a bit of fiddling): const plot = Plot.plot(...)
plot.addEventListener(
"pointerdown",
(event) => {
event.stopPropagation();
// Do whatever you want with event and plot.value.....
// Force a pointerleave to hide the tooltip
const pointerleave = new PointerEvent("pointerleave", {
bubbles: true,
pointerType: "mouse",
});
event.target?.dispatchEvent(pointerleave);
},
{ capture: true } // this needs to be on to capture the pointerdown
); |
Same issue in this discussion #2292 |
When building an interactive app, we might want:
The text was updated successfully, but these errors were encountered: