Skip to content

Commit

Permalink
[FIX] Charts: Fix tooltip value when data is zero
Browse files Browse the repository at this point in the history
Following a refactoring of the charts, the tooltip would not display the
data value when the data equalled zero.

How to reproduce:
- generate a line graph such that one of the dataset points is 0
- Hover the said data point

-> the tooltip will read something along "Series 1:" and no value
afterwards.

closes #5128

Task: 4251681
X-original-commit: 9f337f3
Signed-off-by: Pierre Rousseau (pro) <[email protected]>
  • Loading branch information
rrahir authored and pro-odoo committed Oct 24, 2024
1 parent 426c232 commit 6becc7d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/helpers/figures/charts/chart_ui_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export function getDefaultChartJsRuntime(
const xLabel = tooltipItem.dataset?.label || tooltipItem.label;
// tooltipItem.parsed can be an object or a number for pie charts
let yLabel = horizontalChart ? tooltipItem.parsed.x : tooltipItem.parsed.y;
if (!yLabel) {
if (yLabel === undefined || yLabel === null) {
yLabel = tooltipItem.parsed;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/figures/chart/chart_plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2034,6 +2034,18 @@ describe("Chart design configuration", () => {
}
);

test.each(["bar", "line"])(
"Basic chart tooltip label, zero-values are properly displayed",
(chartType) => {
setCellContent(model, "A2", "0");
createChart(model, { ...defaultChart, type: chartType as "bar" | "line" }, "42");
const runtime = model.getters.getChartRuntime("42") as BarChartRuntime;
const label = getTooltipLabel(runtime, 0, 0);

expect(label).toEqual("0");
}
);

test.each(["line", "scatter", "combo", "bar"] as const)(
"%s chart with no title but a legend have the correct padding",
(chartType) => {
Expand Down

0 comments on commit 6becc7d

Please sign in to comment.