Skip to content

Commit

Permalink
[FIX] chart: trend line tooltip for scatter/line charts
Browse files Browse the repository at this point in the history
For scatter/line chart whose labels were numbers, the trend line
tooltip was showing something like `(15, 9)`. 9 was the
correct Y value, but the 15 was referring to the fact that it was the
15th point in the generated trend line. Which made no sense to the user.

This commit changes the tooltip to show only the Y value.

closes #5379

Task: 4279972
X-original-commit: 66f0c66
Signed-off-by: Rémi Rahir (rar) <[email protected]>
  • Loading branch information
hokolomopo authored and rrahir committed Jan 2, 2025
1 parent 37f2328 commit 3bfd3d1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/helpers/figures/charts/runtime/chartjs_tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ export function getLineChartTooltip(
if (axisType === "linear") {
tooltip.callbacks!.label = (tooltipItem) => {
const dataSetPoint = tooltipItem.parsed.y as CellValue;
let label = tooltipItem.parsed.x as CellValue;
let label =
tooltipItem.dataset.xAxisID === TREND_LINE_XAXIS_ID
? ""
: (tooltipItem.parsed.x as CellValue);

if (typeof label === "string" && isNumber(label, locale)) {
label = toNumber(label, locale);
}
Expand Down
19 changes: 19 additions & 0 deletions tests/figures/chart/chart_plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2163,6 +2163,25 @@ describe("Chart design configuration", () => {
expect(label).toBe("Dataset 1: (500%, $6,000.00)");
});

test("scatter chart trend line tooltip label", () => {
setGrid(model, { A1: "1", A2: "2", B1: "12", B2: "15" });

createChart(
model,
{
labelRange: "A1:A2",
dataSets: [{ dataRange: "B1:B2", trend: { type: "polynomial", order: 1, display: true } }],
type: "scatter",
dataSetsHaveTitle: false,
},
"1"
);
const chart = model.getters.getChartRuntime("1") as ScatterChartRuntime;
const label = getTooltipLabel(chart, 1, 0);

expect(label).toBe("Trend line for Series 1: 12");
});

test.each(["line", "scatter", "bar", "combo"] as const)(
"%s chart correctly use right axis if set up in definition, and the grid lines are only displayed once",
(chartType) => {
Expand Down

0 comments on commit 3bfd3d1

Please sign in to comment.