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

cursor hidx to neareset left #313

Closed
vinnitu opened this issue Sep 25, 2020 · 4 comments
Closed

cursor hidx to neareset left #313

vinnitu opened this issue Sep 25, 2020 · 4 comments
Labels
question Further information is requested

Comments

@vinnitu
Copy link

vinnitu commented Sep 25, 2020

Hi!

In a stepped chart I want to show the same nearest left point as selected in both cases.

image

How to handle it with dataIdx?

@leeoniya
Copy link
Owner

take a look at https://github.com/leeoniya/uPlot/blob/master/demos/nearest-non-null.html

you'd just exclude the right value search loop.

@leeoniya leeoniya added the question Further information is requested label Sep 25, 2020
@vinnitu
Copy link
Author

vinnitu commented Sep 25, 2020

here is all values is defined (not one null)

@leeoniya
Copy link
Owner

leeoniya commented Sep 25, 2020

you said in another issue that you also had null and undefined values.

anyways, in dataIdx(), you'll want to grab self.cursor.left and pass it to self.posToVal() this will give you an exact value along x at the cursor position. then you can test the distance to the current and adjacent indices' values to make the decision which index to return.

@leeoniya
Copy link
Owner

i've added a raw xValue parameter to dataIdx() that simplifies this implementation. i've added this behavior to the stepped-line demo:

https://leeoniya.github.io/uPlot/demos/line-stepped.html

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

No branches or pull requests

2 participants