SPB Git

Repository Public

Chart.tsx 1.2 KB 24 lines tsx

1import { ChartSvg } from "@/renderer/chart/ChartSvg";2import type { ChartSpec } from "@/renderer/chart/types";3import type { Locale, Tone } from "@/schema";45type Point = ChartSpec["series"][number]["points"][number];67/** Builds a numeric ChartSpec for the shared chart component. Empty series are dropped (a chart series needs a point). */8export function chartSpec(o: {9  kind: ChartSpec["kind"]; title: string; xLabel: string; yLabel: string; dataKind: ChartSpec["dataKind"];10  series: { name: string; tone: Tone; points: Point[] }[]; annotations?: { x?: number; y?: number; label: string }[];11}): ChartSpec {12  return {13    kind: o.kind, dataKind: o.dataKind, title: o.title,14    x: { label: o.xLabel, scale: "linear", type: "number" }, y: { label: o.yLabel, scale: "linear" },15    series: o.series.filter((s) => s.points.length > 0),16    ...(o.annotations && o.annotations.length ? { annotations: o.annotations } : {}),17  };18}1920export function Chart({ chart, locale, idPrefix, height = 320 }: { chart: ChartSpec; locale: Locale; idPrefix: string; height?: number }) {21  if (!chart.series.length) return null;22  return <div className="sim-chart"><ChartSvg chart={chart} locale={locale} width={560} height={height} idPrefix={idPrefix} /></div>;23}24
Files main
Menu

Theme