Repository navigation
anchor non-divisor fixed-duration intervals to the Unix epoch - #2484
Open
developjik wants to merge 1 commit into
Open
developjik wants to merge 1 commit into
developjik wants to merge 1 commit into
Conversation
d3’s interval.every keeps only the boundaries whose clock field (say, getHours) is a multiple of the period, so “11 hours” restarted at (UTC) midnight each day and “65 minutes” produced floor and ceil 60 minutes apart. Anchor fixed-duration units (seconds, minutes, hours) to the Unix epoch instead, the way d3 implements millisecond.every. Fixes observablehq#2452
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2452.
What
Multiples of a fixed-duration unit whose period doesn't divide the parent unit — say
"11 hours"within a 24-hour day, or"65 minutes"within an hour — are now anchored to the Unix epoch and recur exactly every n units, the same way d3 implementsmillisecond.every:So binning hourly events with
{interval: "11 hours"}now produces equal-width bins (the expectation in #2452) instead of a day split into 11h + 11h + 2h.Why
asIntervalimplemented periods through d3'sinterval.every(period), which returns a filtered interval that keeps only the boundaries whose clock field (e.g.getHours()) is a multiple of the period:That is a useful calendar alignment for calendar units (
month.every(3)= quarters), but for a fixed duration the period restarting at (UTC) midnight each day makes some bins smaller than others and floor/ceil disagree with the interval's own duration. Anchoring to the epoch matches whatmillisecond.everyalready does in d3, and what Plot'snumberIntervaldoes for numeric intervals (Math.floor(d / n) * n).Scope of the behavior change
second,minute,hourwhose period doesn't divide the parent unit (e.g."11 hours","65 minutes","45 seconds","90 seconds"), in both thetimeandutcflavors (a fixed duration has the same boundaries in either)."3 hours","5 minutes") in whole-hour time zones, since the epoch grid and the clock-field grid coincide; and calendar units (day,week,monday,month,year), which keep usinginterval.every— a fixed epoch grid would be wrong across DST and calendar boundaries for those.Tests
test/marks/time-test.js: the previous"45 seconds"assertions pinned the old minute-restart behavior (d3.timeSecond.every(45)); they now expect epoch-anchored boundaries via adurationRangehelper, and new cases cover"11 hours"(time and utc),"65 minutes"floor/ceil, and that divisor periods ("5 seconds","15 seconds") still match d3.