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

Pointing at coincident points #1621

Open
mbostock opened this issue May 23, 2023 · 9 comments
Open

Pointing at coincident points #1621

mbostock opened this issue May 23, 2023 · 9 comments
Labels
enhancement New feature or request question Further information is needed

Comments

@mbostock
Copy link
Member

Since the pointer transform only focuses one point at a time, if points are coincident (or nearly so), some points may not be focusable. Should the pointer transform allow focusing multiple points simultaneously, and then the tip mark could handle cycling between points, or showing multiple tips with collision detection? Or should the pointer transform support an interactive method of cycling through nearby points, say by clicking?

@mbostock mbostock added enhancement New feature or request question Further information is needed labels May 23, 2023
@Fil
Copy link
Contributor

Fil commented May 24, 2023

A slightly different way to approach this would be to allow a pointer to catch all the points within a given radius, maybe ordered by distance with the closest one on top. The mark could then decide what to do when it needs to represent several points. For example the tip mark could try to show "as many tips as possible" and rotate through them on click, but the dot mark would not have to do anything fancier than simply draw all the selected dots. With a null radius, we would have the current behavior: a single point (the last one wins). With a number, we would guarantee an array of points (0, 1, or more), within that radius. With radius==0 only coincident points would return an array of more than one value.

@mbostock
Copy link
Member Author

Yep, that’s what I meant by “allow focusing multiple points simultaneously”. 👍

@net
Copy link

net commented May 25, 2023

I think the mark should detect collisions and try to gracefully render colliding tips without further interaction, that way the solution is also applicable to non-interactive plots with static tips (such as the US states example in the docs).

@mbostock
Copy link
Member Author

Yes, @net, perhaps we should have another feature request for that. Though even so that will only scale to at best ~4 tips, so we’ll still need some way to disambiguate pointing at coincident/dense points.

@net
Copy link

net commented May 25, 2023

@mbostock if resolving the collisions through positioning fails, the mark could fall back on merging the tips into one, positioning the point of the tip at the average of the collided tips, and rendering the merged tip contents in one tip. Of course, that only scales so far too, but it would fix the US states example 🙂

+-------------+
| weight 54   |
| height 1.63 |
+-------------+
| weight 55   |
| height 1.63 |
+-   ---------+
  |/

@Fil Fil mentioned this issue Jun 6, 2023
2 tasks
@korvin89
Copy link

Hi @mbostock! First of all, thank you for your great work! :)
We are looking forward to this feature. We want to replace the current library for drawing graphs with Observable Plot, but we lack the functionality that is discussed in this issue.

What do you think about adding access to all points data with the same values of the corresponding axis via pointer? It will help to render one tip for all data(points) represented by the same value.

Here is our user case

image

@Fil
Copy link
Contributor

Fil commented Jul 21, 2023

See #1671

@korvin89
Copy link

See #1671

Great! Is it possible to stack tips into one?
Fork of your example

image

@Fil
Copy link
Contributor

Fil commented Jul 21, 2023

For that use case you'll probably want to group (or bin) the values by date, then compose a grouped tooltip. Here's a quick example, which is definitely not completely functional, given that there are too many lines, but hopefully enough to convey the idea:

    Plot.tip(
      bls,
      Plot.pointerX(
        Plot.groupX(
          {
            y: "median",
            title: data => data.map(d => d.unemployment).join("\n")
          },
          {
            x: "date",
            y: "unemployment",
            z: "date"
          }
        )
      )
    )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is needed
Projects
None yet
Development

No branches or pull requests

4 participants