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.

Task: 4251681
X-original-commit: ec02c46
  • Loading branch information
rrahir authored and pro-odoo committed Oct 24, 2024
1 parent f519934 commit 19feb72
Show file tree
Hide file tree
Showing 2 changed files with 14 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 @@ -157,7 +157,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;
}
const toolTipFormat = !format && Math.abs(yLabel) >= 1000 ? "#,##" : format;
Expand Down
13 changes: 13 additions & 0 deletions tests/figures/chart/chart_plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,7 @@ describe("Chart design configuration", () => {
expect(label).toEqual("6,000");
});

<<<<<<< 18.0
test.each(["line", "scatter", "combo", "bar"] as const)(
"%s chart with no title and no legend have the correct padding",
(chartType) => {
Expand Down Expand Up @@ -2050,6 +2051,18 @@ describe("Chart design configuration", () => {
left: 20,
right: 20,
});
||||||| 890f74235c9acf20fad16c1bfe054bf329a06ada
=======
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");
>>>>>>> 5d9984709ef8d5f57803fbf1a49c56233990ee1c
}
);
});
Expand Down

0 comments on commit 19feb72

Please sign in to comment.