From b63c922e1b0797202b7c4294256806e6bea21f64 Mon Sep 17 00:00:00 2001 From: Anthony Hendrickx Date: Wed, 8 Jan 2025 13:01:59 +0000 Subject: [PATCH] [FIX] chart: fix trend line axis alignment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task Description Following https://github.com/odoo/o-spreadsheet/pull/5282, we now have the trend line data as an array of Point, and try to align the trend line axis to the real x-axis. This can't be done for categorical axis and time axis without treating the trend axis as a category axis, for both. This PR aims to fix the axis for the datetime data, where the axis was considered as a datetime axis but can't be anymore. As this is caused by the way chartJs decides to align the axis, we don't have any other solution, neither have we a possibility to test the fix. closes odoo/o-spreadsheet#5442 Task: 0 X-original-commit: 80c784083e68cd70e328630d193bcc214525b861 Signed-off-by: RĂ©mi Rahir (rar) --- src/helpers/figures/charts/runtime/chartjs_scales.ts | 3 ++- 1 file 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 4d721bf01..77b5f7cd6 100644 --- a/src/helpers/figures/charts/runtime/chartjs_scales.ts +++ b/src/helpers/figures/charts/runtime/chartjs_scales.ts @@ -111,11 +111,12 @@ export function getLineChartScales( ...(scales.x as any), display: false, }; - if (axisType === "category") { + if (axisType === "category" || axisType === "time") { /* We add a second x axis here to draw the trend lines, with the labels length being * set so that the second axis points match the classical x axis */ const maxLength = Math.max(...trendDatasets.map((trendDataset) => trendDataset?.length || 0)); + scales[TREND_LINE_XAXIS_ID]!["type"] = "category"; scales[TREND_LINE_XAXIS_ID]!["labels"] = range(0, maxLength).map((x) => x.toString()); scales[TREND_LINE_XAXIS_ID]!["offset"] = false; }