Add weekday to the visitor graph (#386)

* Add weekdays to the visitor graph

Abbreviate both weekday and month in order to keep horizontal spacing
roughly the same as it's been.

Closes #175.

* Add note to CHANGELOG
This commit is contained in:
Chad Whitacre 2020-10-29 09:43:58 -04:00 committed by GitHub
parent ff515c641d
commit 73375b8289
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
### Added
- Ability to add event metadata plausible/analytics#381
- Display weekday on the visitor graph plausible/analytics#175
### Changed
- Use alpine as base image to decrease Docker image size plausible/analytics#353

View File

@ -53,6 +53,14 @@ const MONTHS = [
"November", "December"
]
const MONTHS_ABBREV = [
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
]
const DAYS_ABBREV = [
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
]
function dateFormatter(interval, longForm) {
return function(isoDate) {
let date = new Date(isoDate)
@ -60,7 +68,10 @@ function dateFormatter(interval, longForm) {
if (interval === 'month') {
return MONTHS[date.getUTCMonth()];
} else if (interval === 'date') {
return date.getUTCDate() + ' ' + MONTHS[date.getUTCMonth()];
var day = DAYS_ABBREV[date.getUTCDay()];
var date_ = date.getUTCDate();
var month = MONTHS_ABBREV[date.getUTCMonth()];
return day + ', ' + date_ + ' ' + month;
} else if (interval === 'hour') {
const parts = isoDate.split(/[^0-9]/);
date = new Date(parts[0],parts[1]-1,parts[2],parts[3],parts[4],parts[5])