From f0950d3241b00ef338edb346a7c623572560fcf8 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Sat, 7 Jun 2025 22:43:30 +0200 Subject: [PATCH] Lib: Add chart options generator function --- src/lib/chart.ts | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/lib/chart.ts diff --git a/src/lib/chart.ts b/src/lib/chart.ts new file mode 100644 index 0000000..2127c20 --- /dev/null +++ b/src/lib/chart.ts @@ -0,0 +1,60 @@ +import { type LineChartOptions, ScaleTypes } from "@carbon/charts-svelte"; + +export const make_chart_options = ( + title: string, + bottom: string, + left: string, + group: string = "group", + width: string = "100%", + height: string = "400px", +): LineChartOptions => { + return { + title: title, + axes: { + bottom: { + mapsTo: bottom, + scaleType: ScaleTypes.LABELS, + }, + left: { + mapsTo: left, + scaleType: ScaleTypes.LINEAR, + }, + }, + data: { + groupMapsTo: group, + }, + curve: "curveMonotoneX", + // toolbar: { + // enabled: false, + // }, + animations: true, + // canvasZoom: { + // enabled: false, + // }, + grid: { + x: { + enabled: true, + alignWithAxisTicks: true, + }, + y: { + enabled: true, + alignWithAxisTicks: true, + }, + }, + legend: { + enabled: true, + clickable: true, + position: "top", + }, + points: { + enabled: true, + radius: 5, + }, + tooltip: { + showTotal: false, + }, + resizable: true, + width: width, + height: height, + }; +};