leeoniya / leeoniya/uPlot

cursor hover with shared X: per-series nearest Y using cursor.dataIdx

Open
#1,113 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
10.5k
Forks
463
PR merge metrics
No merged PRs in 30d

Description

Hi, and thanks for uPlot. I’m using it a lot and really appreciate its speed and small footprint.

I’m using uPlot in a case where multiple series share the same X values. With the current cursor behavior, when several points share the same X, the cursor snaps to the nearest X index as expected, but for each series the highlighted point at that X seems fixed: moving the mouse up and down over vertically stacked points does not change which point is highlighted.

For my use case it would be useful to have an optional behavior where:

  • uPlot still finds the nearest X index as it does now, and
  • for each visible series, among all points that share that X value, the point whose rendered Y (valToPos(y, scale)) is closest to the cursor’s Y position is selected.

In short: “closest X, then per-series closest Y” when multiple points share the same X value.

I put together a small repro and an experimental cursor.dataIdx override here (two charts: default behavior vs. overridden behavior):

Questions:

  • Is the current behavior for shared X values (sticking to a single index per series at that X, regardless of cursor Y) intentional?
  • I’m wondering whether a “closest X, then per-series closest Y” hover mode might be something you’d consider supporting as an optional behavior in uPlot, or at least mentioning as a recommended pattern for shared-X use cases like this.

I’m mainly sharing this use case and the workaround in case it’s useful to you or other users. If this feels out of scope for core, I’m also totally fine keeping it as a user-level pattern like in the JSFiddle.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the shared-X cursor behavior described in the issue and compare the default chart with the experimental cursor.dataIdx override in the linked JSFiddle. Determine whether an optional “closest X, then per-series closest Y” mode fits uPlot’s cursor behavior, or whether the workaround should remain a recommended user-level pattern.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
data-visualization
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.