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 #5268

Task: 4279972
Signed-off-by: Rémi Rahir (rar) <[email protected]>
  • Loading branch information
hokolomopo committed Dec 23, 2024
1 parent a594943 commit 66f0c66
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/helpers/figures/charts/chart_common_line_scatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,10 @@ export function createLineOrScatterChartRuntime(
formatValue(value, { format: labelFormat, locale });
config.options.plugins!.tooltip!.callbacks!.label = (tooltipItem) => {
const dataSetPoint = dataSetsValues[tooltipItem.datasetIndex!].data![tooltipItem.dataIndex!];
let label: string | number = tooltipItem.label || labelValues.values[tooltipItem.dataIndex!];
let label: string | number =
tooltipItem.dataset.xAxisID === TREND_LINE_XAXIS_ID
? ""
: tooltipItem.label || labelValues.values[tooltipItem.dataIndex!];
if (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 @@ -2128,6 +2128,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",
(chartType) => {
Expand Down

0 comments on commit 66f0c66

Please sign in to comment.