Skip to content

Commit

Permalink
[FIX] chart: fix trend line axis alignment
Browse files Browse the repository at this point in the history
Task Description

Following #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 #5442

Task: 0
X-original-commit: 80c7840
Signed-off-by: Rémi Rahir (rar) <[email protected]>
  • Loading branch information
anhe-odoo authored and rrahir committed Jan 8, 2025
1 parent ea553ef commit b63c922
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/helpers/figures/charts/runtime/chartjs_scales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit b63c922

Please sign in to comment.