Annotations workflow, UI/UX polish

This commit is contained in:
Francis Cao committed 2026-09-03 12:59:56 -07:00
1 parent 26e236c95c
commit 336fbcb3c5
18 files changed
+463 -87

No files matched your search

+5
View File
@@ -1,5 +1,10 @@
import { endOfDay, endOfHour, startOfDay, startOfHour } from 'date-fns';
export interface AnnotationRange {
startAt: number;
endAt: number;
}
/**
* Returns the `date` URL parameter value that filters the website view
* to the day (all-day annotation) or hour (timed annotation) of an annotation.
+9 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, test } from 'vitest';
import { renderNumberLabels } from './charts';
import { getChartBucketIndex, renderNumberLabels } from './charts';
// test for renderNumberLabels
@@ -38,3 +38,11 @@ describe('renderNumberLabels', () => {
expect(renderNumberLabels(input)).toBe(expected);
});
});
describe('getChartBucketIndex', () => {
test('places an annotation in its monthly data bucket', () => {
const data = [{ x: '2026-08' }, { x: '2026-09' }];
expect(getChartBucketIndex(data, new Date('2026-08-27T07:00:00.000Z'))).toBe(0);
});
});
+15
View File
@@ -24,3 +24,18 @@ export function renderDateLabels(unit: string, locale: string) {
}
};
}
export function getChartBucketIndex(data: any[], date: Date) {
let index = -1;
for (let i = 0; i < data.length; i++) {
const timestamp = new Date(data[i]?.x ?? data[i]).getTime();
if (!Number.isFinite(timestamp)) continue;
if (timestamp > date.getTime()) break;
index = i;
}
return index;
}