-
Is it possible to specify to
It seems that a See a few approaches in this notebook: https://observablehq.com/d/4a1a0770b9e533b1 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Fun. There is no solution if two data points have the same exact date. So you have to make the assumption that they are all different. Then I suppose that the desired interval can be defined as a heuristic, such as the minimum of the differences between consecutive dates, maybe rounded to account for durations that overlap the DST: interval = {
const m = d3.min(
d3.pairs(d3.sort(Plot.valueof(fakeData, "date")),
([a, b]) => Math.round((b - a) / 60000) // minutes
);
return m < 2
? d3.utcMinute
: m < 10
? d3.utcMinute.every(m)
: m < 60
? d3.utcMinute.every(m)
: m < 23 * 60
? d3.utcHour.every(Math.round(m / 60))
: m < 23 * 60 * 7
? d3.utcDay
: m < 24 * 60 * 27
? d3.utcWeek
: m < 24 * 60 * 364
? d3.utcMonth
: d3.utcYear;
} I haven't really tested and it's incomplete (milliseconds, quarters, centuries etc) |
Beta Was this translation helpful? Give feedback.
Fun. There is no solution if two data points have the same exact date. So you have to make the assumption that they are all different.
Then I suppose that the desired interval can be defined as a heuristic, such as the minimum of the differences between consecutive dates, maybe rounded to account for durations that overlap the DST: