From cc55592298142cdfc1ee6631244229272b57c746 Mon Sep 17 00:00:00 2001 From: "Adrien Minne (adrm)" Date: Tue, 30 Sep 2025 10:36:42 +0000 Subject: [PATCH] [FIX] chart: wrong label format for date chart Date charts would always have a datetime format for the labels, no matter the format of the data. They would also be truncated, which we probably don't want for dates. The issue is that the date charts had a callback for the ticks using `truncateLabel`, and `getLabelForValue` which seems bugged in date charts[1]. This commit removes the tick callback for date charts, letting the luxon time adapter format the dates. [1] https://github.com/chartjs/Chart.js/issues/12128 Task: 4908471 X-original-commit: 935b5ec2ffe5355a994f285e4bb1eec6d8d402b1 --- src/helpers/figures/charts/runtime/chartjs_scales.ts | 1 + tests/figures/chart/__snapshots__/chart_plugin.test.ts.snap | 1 - tests/figures/chart/chart_plugin.test.ts | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/helpers/figures/charts/runtime/chartjs_scales.ts b/src/helpers/figures/charts/runtime/chartjs_scales.ts index 573ec501c8..dc4e4ec186 100644 --- a/src/helpers/figures/charts/runtime/chartjs_scales.ts +++ b/src/helpers/figures/charts/runtime/chartjs_scales.ts @@ -105,6 +105,7 @@ export function getLineChartScales( }; Object.assign(scales!.x!, axis); scales!.x!.ticks!.maxTicksLimit = 15; + delete scales?.x?.ticks?.callback; } else if (axisType === "linear") { scales!.x!.type = "linear"; scales!.x!.ticks!.callback = (value) => formatValue(value, { format: labelFormat, locale }); diff --git a/tests/figures/chart/__snapshots__/chart_plugin.test.ts.snap b/tests/figures/chart/__snapshots__/chart_plugin.test.ts.snap index f93cb96c04..0c60ec71b2 100644 --- a/tests/figures/chart/__snapshots__/chart_plugin.test.ts.snap +++ b/tests/figures/chart/__snapshots__/chart_plugin.test.ts.snap @@ -264,7 +264,6 @@ exports[`Linear/Time charts snapshot test of chartJS configuration for date char }, "stacked": undefined, "ticks": { - "callback": [Function], "color": "#000000", "maxTicksLimit": 15, "padding": 5, diff --git a/tests/figures/chart/chart_plugin.test.ts b/tests/figures/chart/chart_plugin.test.ts index 5d6725ae6e..5a937e7700 100644 --- a/tests/figures/chart/chart_plugin.test.ts +++ b/tests/figures/chart/chart_plugin.test.ts @@ -2662,6 +2662,7 @@ describe("Linear/Time charts", () => { ); let config = getChartConfiguration(model, chartId); expect(config.options?.scales?.x?.type).toEqual("time"); + expect(config.options?.scales?.x?.ticks?.callback).toBeUndefined(); }); test("time axis for line/bar chart with formulas w/ date format as labels", () => {