Skip to content

Commit

Permalink
Merge branch 'fix-38-trend-diagram-decade-labels' into dev-v9
Browse files Browse the repository at this point in the history
* fix-38-trend-diagram-decade-labels:
  Fix spraakbanken#38: Correct trend diagram labels for decades <1900
  styles cleanup
  • Loading branch information
janiemi committed May 26, 2021
2 parents 78d15aa + b20a23b commit 2a4414a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
18 changes: 14 additions & 4 deletions app/scripts/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -2156,13 +2156,22 @@ 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 before 1900. (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).
// (Should we check the month, too?)
if (monthDay !== 1) {
mom.add(32 - monthDay, "day")
}
return mom.unix()
} else {
Expand All @@ -2172,9 +2181,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
13 changes: 0 additions & 13 deletions app/styles/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1351,11 +1351,6 @@ label[for=lemgram_select]:before {
transition: left 400ms ease;
}

#showLineDiagram {
position: relative;
top: 3px;
}

.right_col {
padding-right: 2px;
}
Expand Down Expand Up @@ -1520,14 +1515,6 @@ label[for=lemgram_select]:before {
opacity: 0.7;
}

#showLineDiagram {
display: none;
}

.lab #showLineDiagram {
display: inline;
}

#labs_logo {
display: none;
svg {
Expand Down

0 comments on commit 2a4414a

Please sign in to comment.