aboutsummaryrefslogtreecommitdiff
path: root/src/lib.ts
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2022-10-18 00:42:33 +1100
committerTerry Truong <terry06890@gmail.com>2022-10-18 00:42:33 +1100
commit15035fe65e7dd54db83337da3d2b055d8bb668e9 (patch)
tree71f6bee28d0709faaca0a6ea9ba45e68f88b92a0 /src/lib.ts
parent78ab026ffacbfd14992c2bfda1b9e290ace25cbf (diff)
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.
Diffstat (limited to 'src/lib.ts')
-rw-r--r--src/lib.ts44
1 files changed, 33 insertions, 11 deletions
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/'