From 20d69469a4c80a196de23625d0420487b0ed04a6 Mon Sep 17 00:00:00 2001 From: Terry Truong Date: Thu, 29 Dec 2022 16:17:39 +1100 Subject: Show event-count data on timeline Backend: Send event-count data to client in EventResponse instance Fix certain usages of gregorian calendar instead of julian Move HistDate, SCALES, etc, into cal.py Frontend: Make App update a unitCountMaps object using event-count data from server Make TimeLine show visual indication of unit counts Add showEventCounts option to store Update unit tests --- src/lib.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/lib.ts') diff --git a/src/lib.ts b/src/lib.ts index 353fa57..7797469 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -305,6 +305,10 @@ export type HistEventJson = { imgId: number, pop: number, } +export type EventResponseJson = { + events: HistEventJson[], + unitCounts: {[x: number]: number}, +} export function jsonToHistDate(json: HistDateJson){ if (json.gcal == null){ return new YearDate(json.year); @@ -493,6 +497,23 @@ export function getEventPrecision(event: HistEvent): number { } return Number.POSITIVE_INFINITY; } +export function dateToUnit(date: HistDate, scale: number): number { + if (scale >= 1){ + return Math.floor(date.year / scale); + } else if (scale == MONTH_SCALE){ + if (!date.gcal){ + return julianToJdn(date.year, date.month, 1); + } else { + return gregorianToJdn(date.year, date.month, 1); + } + } else { // scale == DAY_SCALE + if (!date.gcal){ + return julianToJdn(date.year, date.month, date.day); + } else { + return gregorianToJdn(date.year, date.month, date.day); + } + } +} // For sending timeline-bound data to BaseLine export class TimelineState { -- cgit v1.2.3