The Wayback Machine - https://web.archive.org/web/20201203021725/https://github.com/leeoniya/uPlot/pull/126
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

Added highlight weekends demo #126

Closed
wants to merge 1 commit into from

Conversation

@ldstein
Copy link
Contributor

@ldstein ldstein commented Feb 13, 2020

This PR demonstrates a very basic highlight weekends plugin.

It (or something similar) could be used in #119 .

image

@leeoniya
Copy link
Owner

@leeoniya leeoniya commented Feb 13, 2020

thanks @ldstein

as you can see from your image, new Date fails to align to actual day boundaries. this simplr version will only work when both your machine and the desired timezone in which you want to view the data are the same. a proper solution would have to use uPlot.tzDate and replicate some of the same logic used internally to place axis ticks. this makes writing plugins along the time scale particularly nuanced/challenging.

i feel like it's worth exposing some sort of ticks() method which can reusue the logic and return temporal breakpoints at a higher resolution than the ticks generated for the grid. this can then be used to help with situations like this. one limitation is that the times cannot be arbitrary, but have to align to logical markers.

@ldstein
Copy link
Contributor Author

@ldstein ldstein commented Feb 13, 2020

Thanks @leeoniya . Clearly a more complicated issue than I anticipated.

I've closed the PR. Will reopen once I'm able to revisit.

@ldstein ldstein closed this Feb 13, 2020
@CrashLaker
Copy link

@CrashLaker CrashLaker commented Mar 3, 2020

Hi.

As I understood from this we need to use the tzDate passed in opts otherwise the new Date() approach would work just fine right?

Atm can we access the opts inside the plugin's scope?

edit...
or maybe have access to the same function used to draw the x axis.

@leeoniya
Copy link
Owner

@leeoniya leeoniya commented Mar 3, 2020

yes, you have to use uPlot.tzDate. the real trick is not to iterate every datapoint in the scale range in search of weekends, because that would mean creating 60,000 Date instances when you have 30,000 datapoints. you have to find these weekends efficiently, like the axis ticks find breaks in months, days, hours without walking the data.

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

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.