Skip to content

Commit 13cf688

Browse files
committed
[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] chartjs/Chart.js#12128 closes #7267 Task: 4908471 X-original-commit: 935b5ec Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
1 parent b4764cb commit 13cf688

File tree

3 files changed

+2
-1
lines changed

3 files changed

+2
-1
lines changed

src/helpers/figures/charts/runtime/chartjs_scales.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export function getLineChartScales(
105105
};
106106
Object.assign(scales!.x!, axis);
107107
scales!.x!.ticks!.maxTicksLimit = 15;
108+
delete scales?.x?.ticks?.callback;
108109
} else if (axisType === "linear") {
109110
scales!.x!.type = "linear";
110111
scales!.x!.ticks!.callback = (value) => formatValue(value, { format: labelFormat, locale });

tests/figures/chart/__snapshots__/chart_plugin.test.ts.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ exports[`Linear/Time charts snapshot test of chartJS configuration for date char
264264
},
265265
"stacked": undefined,
266266
"ticks": {
267-
"callback": [Function],
268267
"color": "#000000",
269268
"maxTicksLimit": 15,
270269
"padding": 5,

tests/figures/chart/chart_plugin.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,6 +2662,7 @@ describe("Linear/Time charts", () => {
26622662
);
26632663
let config = getChartConfiguration(model, chartId);
26642664
expect(config.options?.scales?.x?.type).toEqual("time");
2665+
expect(config.options?.scales?.x?.ticks?.callback).toBeUndefined();
26652666
});
26662667

26672668
test("time axis for line/bar chart with formulas w/ date format as labels", () => {

0 commit comments

Comments
 (0)