Skip to content

Commit cab1405

Browse files
committed
[FIX] charts: truncate radar chart labels correctly
Before this commit: - Radar chart point labels were truncated incorrectly because Chart.js passes extra arguments (label, index, labels) to the callback. - As a result, truncateLabel received the index as maxLen and applied unnecessary truncation. After this commit: - The callback now wraps truncateLabel to pass only the label string. - This ensures long labels are truncated with ellipsis and short labels remain unchanged. closes #7178 Task: 5078858 X-original-commit: b2aec82 Signed-off-by: Adrien Minne (adrm) <adrm@odoo.com> Signed-off-by: Ronakkumar Mukeshbhai Bharadiya (rmbh) <rmbh@odoo.com>
1 parent 17f44f0 commit cab1405

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export function getRadarChartScales(
226226
},
227227
pointLabels: {
228228
color: chartFontColor(definition.background),
229-
callback: truncateLabel,
229+
callback: (label: string) => truncateLabel(label),
230230
},
231231
suggestedMin: minValue < 0 ? minValue - 1 : 0,
232232
},

tests/figures/chart/radar_chart_plugin.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ describe("radar chart", () => {
148148
const runtime = model.getters.getChartRuntime("chartId") as RadarChartRuntime;
149149
expect(runtime.chartJsConfig.options?.scales?.r?.suggestedMin).toBe(-8);
150150
});
151+
152+
test("Radar chart point labels are truncated properly", () => {
153+
const model = new Model();
154+
createRadarChart(model, { dataSets: [{ dataRange: "A1:A2" }] }, "chartId");
155+
const runtime = model.getters.getChartRuntime("chartId") as RadarChartRuntime;
156+
const callback = (runtime.chartJsConfig.options?.scales?.r as any)?.pointLabels
157+
?.callback as Function;
158+
159+
expect(callback("short", 0)).toBe("short");
160+
expect(callback("very very long label of radar", 1)).toBe("very very long label…");
161+
});
151162
});
152163

153164
test("Humanization is taken into account for the axis ticks of a radar chart", async () => {

0 commit comments

Comments
 (0)