From 2ebb6b55f421bafe035077accfeb4bebf8d3d190 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Thu, 1 Feb 2024 20:43:08 +0200 Subject: [PATCH] Fix build analyzer stat graphs X axis label Closes #1644 --- app/components/Chart.tsx | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/components/Chart.tsx b/app/components/Chart.tsx index 1450ea5a0..d2772efa8 100644 --- a/app/components/Chart.tsx +++ b/app/components/Chart.tsx @@ -11,6 +11,7 @@ export default function Chart({ containerClassName, headerSuffix, valueSuffix, + xAxis, }: { options: [ { label: string; data: Array<{ primary: Date; secondary: number }> }, @@ -18,6 +19,7 @@ export default function Chart({ containerClassName?: string; headerSuffix?: string; valueSuffix?: string; + xAxis: "linear" | "localTime"; }) { const { i18n } = useTranslation(); const theme = useTheme(); @@ -26,20 +28,25 @@ export default function Chart({ const primaryAxis = React.useMemo< AxisOptions<(typeof options)[number]["data"][number]> >( + // @ts-expect-error TODO: type this () => ({ getValue: (datum) => datum.primary, - scaleType: "localTime", + scaleType: xAxis, shouldNice: false, formatters: { - scale: (val) => { - return val.toLocaleDateString(i18n.language, { - day: "numeric", - month: "numeric", - }); + scale: (val: any) => { + if (val instanceof Date) { + return val.toLocaleDateString(i18n.language, { + day: "numeric", + month: "numeric", + }); + } + + return val; }, }, }), - [i18n.language], + [i18n.language, xAxis], ); const secondaryAxes = React.useMemo<