Skip to content

Set bin size to 1 for binX #2233

Answered by Fil
mkfreeman asked this question in Q&A
Nov 14, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

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

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mkfreeman
Comment options

Answer selected by mkfreeman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants