Skip to content

Commit 3bfd3d1

Browse files
hokolomoporrahir
authored andcommitted
[FIX] chart: trend line tooltip for scatter/line charts
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]>
1 parent 37f2328 commit 3bfd3d1

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ export function getLineChartTooltip(
5858
if (axisType === "linear") {
5959
tooltip.callbacks!.label = (tooltipItem) => {
6060
const dataSetPoint = tooltipItem.parsed.y as CellValue;
61-
let label = tooltipItem.parsed.x as CellValue;
61+
let label =
62+
tooltipItem.dataset.xAxisID === TREND_LINE_XAXIS_ID
63+
? ""
64+
: (tooltipItem.parsed.x as CellValue);
65+
6266
if (typeof label === "string" && isNumber(label, locale)) {
6367
label = toNumber(label, locale);
6468
}

tests/figures/chart/chart_plugin.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,6 +2163,25 @@ describe("Chart design configuration", () => {
21632163
expect(label).toBe("Dataset 1: (500%, $6,000.00)");
21642164
});
21652165

2166+
test("scatter chart trend line tooltip label", () => {
2167+
setGrid(model, { A1: "1", A2: "2", B1: "12", B2: "15" });
2168+
2169+
createChart(
2170+
model,
2171+
{
2172+
labelRange: "A1:A2",
2173+
dataSets: [{ dataRange: "B1:B2", trend: { type: "polynomial", order: 1, display: true } }],
2174+
type: "scatter",
2175+
dataSetsHaveTitle: false,
2176+
},
2177+
"1"
2178+
);
2179+
const chart = model.getters.getChartRuntime("1") as ScatterChartRuntime;
2180+
const label = getTooltipLabel(chart, 1, 0);
2181+
2182+
expect(label).toBe("Trend line for Series 1: 12");
2183+
});
2184+
21662185
test.each(["line", "scatter", "bar", "combo"] as const)(
21672186
"%s chart correctly use right axis if set up in definition, and the grid lines are only displayed once",
21682187
(chartType) => {

0 commit comments

Comments
 (0)