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

Fix #38: Trend diagram: Correct x-axis decade labels for decades 1900 and before #176

Merged
merged 1 commit into from
Jun 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions app/scripts/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -2156,13 +2156,21 @@ view.GraphResults = class GraphResults extends BaseResults {
const toDate = (sec) => moment(sec * 1000).toDate()

const time = new Rickshaw.Fixtures.Time()
// Fix time.ceil for decades: Rickshaw.Fixtures.Time.ceil
// returns one decade too small values for 1900 and before.
// (The root cause may be Rickshaw's approximate handling of
// leap years: 1900 was not a leap year.)
const old_ceil = time.ceil
time.ceil = (time, unit) => {
if (unit.name === "decade") {
const out = Math.ceil(time / unit.seconds) * unit.seconds
const mom = moment(out * 1000)
if (mom.date() === 31) {
mom.add("day", 1)
const monthDay = mom.date()
// If the day of the month is not 1, it is within the
// previous month (December), so add enough days to
// move the date to the expected month (January).
if (monthDay !== 1) {
mom.add(32 - monthDay, "day")
}
return mom.unix()
} else {
Expand All @@ -2172,9 +2180,10 @@ view.GraphResults = class GraphResults extends BaseResults {

const xAxis = new Rickshaw.Graph.Axis.Time({
graph,
// Use the fixed .ceil for decades
timeFixture: time,
// timeUnit: time.unit("month") # TODO: bring back decade
})
// timeUnit: time.unit("month") # TODO: bring back decade
// timeFixture: new Rickshaw.Fixtures.Time()

this.preview = new Rickshaw.Graph.RangeSlider.Preview({
graph,
Expand Down