Git Product home page Git Product logo

Comments (7)

leeoniya avatar leeoniya commented on June 15, 2024

if you're talking about timeseries / line data, you'll probably want cursor.dataIdx, which allows you to supply your own callback that determines which datapoints are hovered for each series based on cursor position and the nearest index in the dataset:

uPlot/dist/uPlot.d.ts

Lines 555 to 556 in ff021df

/** returns data idx used for hover points & legend display (defaults to closestIdx) */
dataIdx?: Cursor.DataIdxRefiner;

demo: https://leeoniya.github.io/uPlot/demos/nearest-non-null.html

if you're talking about cursor.focus which determines which series to highlight (when cursor.focus.prox > 0), there's a similar setting cursor.focus.dist:

uPlot/dist/uPlot.d.ts

Lines 525 to 526 in ff021df

/** measures cursor y distance to a series in CSS pixels (for triggering setSeries hook with closest) */
dist?: (self: uPlot, seriesIdx: number, dataIdx: number, valPos: number, curPos: number) => number;

from uplot.

AndrewPhilbin avatar AndrewPhilbin commented on June 15, 2024

Thank you for the reply. I'm wondering if my particular use case is actually a little strange or a bit of an edge case:

example

In the screenshot, what I'm aiming for is for the red series to be easier to focus/select. When other points are close by, it's finicky to get these particular series to focus and requires zooming in a lot.

After looking into the properties you mentioned it seems like I what I need is to use cursor.dataIdx to hover the nearest non-null point on the red series, but only within a certain distance, and at that point trigger a series focus. I'm just having a little trouble conceptualizing how to achieve this with hooks/cursor settings/etc.

from uplot.

leeoniya avatar leeoniya commented on June 15, 2024

i think you'll need to make a runnable jsfiddle that reproduces the issue, with actual data. e.g.: https://jsfiddle.net/q73vxrpe/

the cursor in your screenshot is close enough that it should be focusing without anything extra. my guess is that your data for the red series is not in ascending-x order (as it should be for all series).

from uplot.

AndrewPhilbin avatar AndrewPhilbin commented on June 15, 2024

I didn't consider the potential data issue and will certainly start there! If that seems alright I will post a fiddle that recreates this behavior. Thank you for your help!

from uplot.

AndrewPhilbin avatar AndrewPhilbin commented on June 15, 2024

I'm still not sure if I'm just making a simple mistake, but in this fiddle https://jsfiddle.net/Yumcaxion/hnw9mdcq/58/, in the chart using time: true for the x-scale, the points on the red two-point line are impossible to hover until you've zoomed in quite a bit and even then they are difficult to hover. I've confirmed that the timestamps are all unique and in ascending order.

In the time: false x-scale chart, the distance for the point hover/series focus seems like it works as expected. These lines are a little weird because they will always only be two points surrounded by null values, but it seems that as long as the datasets are the same length as the primary y set, this shouldn't be an issue, correct?

Apologies for the hastily assembled fiddle.

from uplot.

leeoniya avatar leeoniya commented on June 15, 2024

well, the shape of the data ends up being different. the actual timestamp data has two nearly-coincident points surrounding the red timestamp.

the hover works by converting your mouse cursor position, which only has pixel-level resolution to an index. and if you have a ton of indices in a single pixel, the binary search will always land on the same index for the same pixel. the reason it works in the indexed case is cause the spacing is wider/more uniform.

i think the way to go here is the cursor.dataIdx route.

in uPlot v2, there will be no alignment requirement, so this case should "just work", but v2 is a ways off still :)

image

from uplot.

AndrewPhilbin avatar AndrewPhilbin commented on June 15, 2024

That makes perfect sense! I'm not sure why I didn't make that connection from the different series timestamps being so close together. This gives me some ideas on how to solve this. I appreciate the help!

from uplot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.