Skip to content

Add inspect_curve operation #5240

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
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Add inspect_curve operation #5240

wants to merge 2 commits into from

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Mar 21, 2022

Selects one of multiple datashaded curves by drawing a vertical line at the x-position and identifying all points of intersection of that line on the rasterized plot. The intersection closest to the specified y-coordinate is picked and the data of all rasterized curves is searched for proximity to that coordinate.

Here's a demo with 10 curves with 100k points each:

xs = pd.date_range('2010-01-01', '2022-01-01', freq='1h')
ts = hv.NdOverlay({i: hv.Curve((xs, np.random.randn(len(xs)).cumsum())) for i in range(10)})
raster = rasterize(ts)

overlay = inspect_curve(raster).opts(tools=['hover'])
overlay.streams[0].source = raster
(raster * overlay).opts(width=800)

inspect_curve

Copy link
Member

@jbednar jbednar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool, thanks! It's important to document precisely what the implications, limitations, and costs of this approach are, especially compared to other possible implementations. My guesses:

  • It appears to assume that the curve is (nearly) a function, i.e. that there is at most one y value for a given x value (or that if there are multiple, they are connected vertically, not fully disjoint?). If so, that's fine and a useful assumption, but should be clearly documented, and other inspect functions could relax that assumption if needed.
  • From what I can see, if a particular curve crosses close to the clicked location but does not happen to have a vertex near the location, then my understanding is that it won't be selected, either because it doesn't fit the tolerance or because another curve not as close to the click but with a vertex that's within tolerance gets selected. That's a limitation that should be documented, but may be ok; we can tell people to click near a vertex in such a situation.
  • I wonder if there is a practical alternative that interpolates each curve at the available x values, computing the y value explicitly, and then can do a cheap lookup of the y value when it gets a click. That would optimize clicking or hovering performance, but may incur a cost in memory and CPU whenever the viewport changes.

Not sure what other alternatives there are.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants