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

Aligning timescale bars to the start of period? #310

Closed
adam-antonik opened this issue Sep 23, 2020 · 6 comments
Closed

Aligning timescale bars to the start of period? #310

adam-antonik opened this issue Sep 23, 2020 · 6 comments
Labels
bug Something isn't working

Comments

@adam-antonik
Copy link

I very much like this library, but can't see how to solve one thing that annoys me.

If I plot say a timeseries of 12000 daily values, on the x-axis I have a number of years labeled, with grey grid lines, but these labels and grid lines do not correspond to the start of the year, e.g. the grid line labelled 1978 is at the value for 1978-11-08, similarly if I zoom in, then I get labelled month grid lines, these sit somewhere in the middle of the month.

This makes reading the chart much trickier than it should be. Is there some option I haven't noticed to align these how I want?

@leeoniya
Copy link
Owner

odd. i have not seen this type of misalignment. all temporal demos which i have seem to work properly. e.g. https://leeoniya.github.io/uPlot/demos/months.html

please create a jsfiddle or provide your data and chart opts which reproduce this issue.

@leeoniya
Copy link
Owner

that link does not work :(

@adam-antonik
Copy link
Author

Sorry about that, let me try again https://jsfiddle.net/buyzhq76/

@leeoniya leeoniya added bug Something isn't working and removed needs-repro labels Sep 24, 2020
@leeoniya
Copy link
Owner

might have something to do with leap year accounting. seems to start out fine and then goes off the rails.

@leeoniya
Copy link
Owner

leeoniya commented Sep 28, 2020

ok, so there were a couple things going on here.

with distr: 2 enabled, there is no knowledge of time (discussed at length in #311 (comment)). all the values are simply treated as labels and uPlot selects some chunking divisor of that array to display, starting from index 0. the reason it was showing the ticks in the middle of the year is simply because the time formatters at multi-year resolutions do not include the more granular parts of the date, since they expect to land on exact Jan 1 boundaries, but distr: 2 does not guarantee this. anyways, the solution should have been simply to remove distr: 2, but that did not work either.

the second issue was a bug in the way year incrementing was done and how the first tick was getting set. it was both a starting point problem, and also a leap year problem. this has been fixed by the linked commit (though i'm not sure if it's fully bulletproof).

your fiddle now works correctly when you drop distr: 2.

@adam-antonik
Copy link
Author

Thanks, that's very helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants