gancio-upstream/assets/helper.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-04-26 23:13:59 +02:00
import dayjs from 'dayjs'
2021-03-10 16:09:35 +01:00
export function attributesFromEvents (_events) {
// const colors = ['teal', 'green', 'yellow', 'teal', 'indigo', 'green', 'red', 'purple', 'pink', 'gray']
// merge events with same date
2021-03-10 16:09:35 +01:00
let attributes = []
2021-04-26 23:13:59 +02:00
const now = dayjs().unix()
for(let e of _events) {
const key = dayjs.unix(e.start_datetime).format('YYYYMMDD')
const c = e.start_datetime < now ? 'vc-past' : ''
2021-03-10 16:09:35 +01:00
const i = attributes.find(a => a.day === key)
if (!i) {
attributes.push({ day: key, key: e.id, n: 1, dates: new Date(e.start_datetime * 1000),
dot: { color: 'teal', class: c } })
continue
}
2021-03-10 16:09:35 +01:00
i.n++
if (i.n >= 20 ) {
i.dot = { color: 'purple', class: c }
} else if ( i.n >= 10 ) {
i.dot = { color: 'red', class: c}
} else if ( i.n >= 5 ) {
i.dot = { color: 'orange', class: c}
} else if ( i.n >= 3 ) {
i.dot = { color: 'yellow', class: c}
} else {
i.dot = { color: 'teal', class: c }
}
}
2021-03-10 16:09:35 +01:00
// add a bar to highlight today
attributes.push({ key: 'today', dates: new Date(), highlight: { color: 'green', fillMode: 'outline' } })
2021-03-10 16:09:35 +01:00
return attributes
}