Skip to content

Pointer should ignore clicks on other marks #2298

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

Open
mootari opened this issue Mar 14, 2025 · 3 comments
Open

Pointer should ignore clicks on other marks #2298

mootari opened this issue Mar 14, 2025 · 3 comments
Labels
bug Something isn’t working

Comments

@mootari
Copy link
Member

mootari commented Mar 14, 2025

Consider the following example where a bar mark is used to highlight and pick selections, with a dot mark on top that has external links.

Clicking on any of the dots (either left click to open the link directly, or right click to open the context menu) will also pin the pointer selection.

Plot.plot({
  marks: [
    Plot.barY("abcd", Plot.pointerX({x: d => d, fill: "#eee", maxRadius: Infinity})),
    Plot.dotX("abcd", {r: 30, fill: d => d, href: d => `https://google.com/?q=${d}`})
  ],
})
Image

As an aside, the pointerdown handler should perhaps only respond to "pure" left clicks (button=0 and no modifier keys pressed).

@mootari mootari added the bug Something isn’t working label Mar 14, 2025
@Fil
Copy link
Contributor

Fil commented Mar 14, 2025

related: #1832

@mootari
Copy link
Member Author

mootari commented Mar 14, 2025

... I guess this request is largely incompatible with how Pointer is currently implemented, given that it is point/proximity based and has no notion of event targets?

Workaround to exclude a single mark:

Plot.plot({
  marks: [
    Plot.barY("abcd", Plot.pointerX({x: d => d, fill: "#eee", maxRadius: Infinity})),
    Plot.dotX("abcd", {r: 30, fill: d => d, href: d => `https://google.com/?q=${d}`, render(...args) {
      const ret = args.pop().apply(this, args);
      ret.addEventListener("pointerdown", e => e.stopPropagation());
      return ret;
    }})
  ],
})

@mootari
Copy link
Member Author

mootari commented Mar 14, 2025

Alternative workaround that's a bit more flexible: https://observablehq.com/@mootari/plot-group

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn’t working
Projects
None yet
Development

No branches or pull requests

2 participants