Debian Codegraph @

frontend/src/charts/scatterplot.ts

raw
1 import type { Result } from "../lib/result";
2 import type { ValidationError } from "../lib/validation";
3 import { array, date, object, string } from "../lib/validation";
4
5 /** Data point for the scatterplot (events). */
6 export interface ScatterPlotDatum {
7 readonly date: Date;
8 readonly type: string;
9 readonly description: string;
10 }
11
12 export class ScatterPlot {
13 readonly type = "scatterplot";
14
15 constructor(
16 readonly name: string | null,
17 readonly data: readonly ScatterPlotDatum[],
18 ) {}
19 }
20
21 const scatterplot_validator = array<ScatterPlotDatum>(
22 object({ type: string, date, description: string }),
23 );
24
25 export function scatterplot(
26 label: string | null,
27 json: unknown,
28 ): Result<ScatterPlot, ValidationError> {
29 return scatterplot_validator(json).map(
30 (value) => new ScatterPlot(label, value),
31 );
32 }