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

Time Scale autoskip issue #3686

Closed
sassomedia opened this issue Dec 6, 2016 · 1 comment
Closed

Time Scale autoskip issue #3686

sassomedia opened this issue Dec 6, 2016 · 1 comment

Comments

@sassomedia
Copy link
Contributor

Expected Behavior

Ideally what I'd like to achieve is something like this D3.js chart, where the time scale, if it spans multiple months and autoskips dates, adds the months or even years underneath the dates at the corresponding location. This looks a lot less cluttered than repeating the month and/or year with every date.

d3-chart

Current Behavior

A multiline date is not supported in Chart.js

Possible Solution

I tried to replicate this behavior instead on the same line via the afterTickToLabelConversion function. There I would only return the actual day for a tick, unless it's a new month, where the month gets prepended:

demo

One challenge there is that with a longer date range and autoskipping active, the first of the month is not necessarily going to be plotted. It might be that the 3rd or 5th of the month is the actual date that shows up. In order to know when the first drawn date of a month is, I need to know the skipRatio. Unfortunately, the scaleInstance that gets passed into it, does not contain that. So I calculated it based on the original formula.

However, I noticed that the more the date range was increased, the calculated skipRatio did not actually match the dots drawn. It seems to be related to the Math.floor part, where the actual skipRatio could result in something like 6.9 which Math.floor rounds down to 6 while the dots where spaced 7 apart. Changing this to Math.round instead in both the source and in my afterTickToLabelConversion function seemed to solve the issue. So my codepen contains the modified Chart.js on top, example code at the bottom.

Context

Now, I thought I solved this issue by changing Math.floor to Math.round, but once I navigate back almost a year to January, the proper labeling stops working and I'm not exactly sure why that is. Any suggestions if this could be solved differently would be appreciated. Thanks!

Steps to Reproduce (for bugs)

  1. Go to http://codepen.io/anon/pen/vyRjPj?editors=0010#0
  2. Change Start Date back month by month and see the time scale properly update
  3. Once you hit January, time scale is skipping months

(Side note: while stepping through the months, you will notice that December sometimes goes missing and that seems to be related to this already existing bug.)

Environment

@kurkle
Copy link
Member

kurkle commented Jan 2, 2020

You can use 2 scales:
https://codepen.io/kurkle/pen/ExabxWr?editors=1010

@kurkle kurkle closed this as completed Jan 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants