aboutsummaryrefslogtreecommitdiff
path: root/src/lib.ts
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2022-12-29 16:17:39 +1100
committerTerry Truong <terry06890@gmail.com>2022-12-29 16:20:26 +1100
commit20d69469a4c80a196de23625d0420487b0ed04a6 (patch)
treee3a7aad153e72322c0810c66bda3b70daa8d815a /src/lib.ts
parent4ad7206443660587a15a7b47384b927188155da8 (diff)
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
Diffstat (limited to 'src/lib.ts')
-rw-r--r--src/lib.ts21
1 files changed, 21 insertions, 0 deletions
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 {