From 15035fe65e7dd54db83337da3d2b055d8bb668e9 Mon Sep 17 00:00:00 2001 From: Terry Truong Date: Tue, 18 Oct 2022 00:42:33 +1100 Subject: Use RBTree to store events, and lookup by date range Currently produces TypeErrors from rbtree.ts's single_rotate() saying 'save is null'. This also happens when using minimally-adapted rbtree.js. Not sure how to resolve this. --- src/lib.ts | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) (limited to 'src/lib.ts') diff --git a/src/lib.ts b/src/lib.ts index 0751fa5..b635d28 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -299,17 +299,39 @@ export class TimelineState { } } -export type HistEvent = { - id: number, - title: string, - start: HistDate, - startUpper: HistDate | null, - end: HistDate | null, - endUpper: HistDate | null, - ctg: string, - imgId: number, - pop: number, -}; +export class HistEvent { + id: number; + title: string; + start: HistDate; + startUpper: HistDate | null; + end: HistDate | null; + endUpper: HistDate | null; + ctg: string; + imgId: number; + pop: number; + constructor( + id: number, title: string, start: HistDate, startUpper: HistDate | null = null, + end: HistDate | null = null, endUpper: HistDate | null = null, ctg='', imgId=0, pop=0){ + this.id = id; + this.title = title; + this.start = start; + this.startUpper = startUpper; + this.end = end; + this.endUpper = endUpper; + this.ctg = ctg; + this.imgId = imgId; + this.pop = pop; + } +} +export function cmpHistEvent(event: HistEvent, event2: HistEvent){ + if (event.start.isEarlier(event2.start)){ + return -1; + } else if (!event.start.equals(event2.start)){ + return 1; + } else { + return event.id - event2.id; + } +} // For server requests const SERVER_DATA_URL = (new URL(window.location.href)).origin + '/data/' -- cgit v1.2.3