Commit e7331139 authored by lynn's avatar lynn Committed by GitHub

fix: modify chart axis to to match crosshairs in year view (#4547)

* fix

* simplify

* refactor

* move logic to monthTickFormatter

* time to date string
parent 272b030b
...@@ -18,7 +18,7 @@ import { ...@@ -18,7 +18,7 @@ import {
dayHourFormatter, dayHourFormatter,
hourFormatter, hourFormatter,
monthDayFormatter, monthDayFormatter,
monthFormatter, monthTickFormatter,
monthYearDayFormatter, monthYearDayFormatter,
monthYearFormatter, monthYearFormatter,
weekFormatter, weekFormatter,
...@@ -140,7 +140,7 @@ function tickFormat( ...@@ -140,7 +140,7 @@ function tickFormat(
case TimePeriod.MONTH: case TimePeriod.MONTH:
return [monthDayFormatter(locale), dayHourFormatter(locale), getTicks(startTimestamp, endTimestamp)] return [monthDayFormatter(locale), dayHourFormatter(locale), getTicks(startTimestamp, endTimestamp)]
case TimePeriod.YEAR: case TimePeriod.YEAR:
return [monthFormatter(locale), monthYearDayFormatter(locale), getTicks(startTimestamp, endTimestamp)] return [monthTickFormatter(locale), monthYearDayFormatter(locale), getTicks(startTimestamp, endTimestamp)]
case TimePeriod.ALL: case TimePeriod.ALL:
return [monthYearFormatter(locale), monthYearDayFormatter(locale), getTicks(startTimestamp, endTimestamp)] return [monthYearFormatter(locale), monthYearDayFormatter(locale), getTicks(startTimestamp, endTimestamp)]
} }
......
...@@ -41,8 +41,19 @@ export const monthYearDayFormatter = (locale: string) => (timestamp: NumberValue ...@@ -41,8 +41,19 @@ export const monthYearDayFormatter = (locale: string) => (timestamp: NumberValue
day: 'numeric', day: 'numeric',
}) })
export const monthFormatter = (locale: string) => (timestamp: NumberValue) => export const monthTickFormatter = (locale: string) => (timestamp: NumberValue) => {
createDateFormatter(timestamp, locale, { month: 'long' }) let date = new Date(timestamp.valueOf() * 1000)
// when a tick maps to a date not on the first of the month, modify the tick to the closest
// first of month date. For example, Dec 31 becomes Jan 1, and Dec 5 becomes Dec 1.
if (date.getDate() !== 1) {
date =
date.getDate() >= 15
? new Date(date.getFullYear(), date.getMonth() + 1, 1)
: new Date(date.getFullYear(), date.getMonth(), 1)
}
return date.toLocaleDateString(locale, { month: 'long' })
}
export const weekFormatter = (locale: string) => (timestamp: NumberValue) => export const weekFormatter = (locale: string) => (timestamp: NumberValue) =>
createDateFormatter(timestamp, locale, { weekday: 'long' }) createDateFormatter(timestamp, locale, { weekday: 'long' })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment