Skip to content

Commit 8410c6f

Browse files
committed
fix: aggregate value tooltip
1 parent 1687334 commit 8410c6f

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

packages/shared/charts/src/utils/__tests__/aggregations.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("aggregateDataPoints", () => {
3434

3535
expect(result.x).toEqual(["A", "B", "C"]);
3636
expect(result.y).toEqual([25, 45, 30]);
37-
expect(result.hovertext).toEqual(["SUM: 25 (2 values)", "SUM: 45 (2 values)", "hover4"]);
37+
expect(result.hovertext).toEqual(["25", "45", "hover4"]);
3838
});
3939

4040
it("should preserve original hover text for single values", () => {
@@ -100,7 +100,7 @@ describe("aggregateDataPoints", () => {
100100
expect(result.y).toEqual([25, 20]);
101101
// For A (grouped): "SUM: 25 (2 values)"
102102
// For B (single, no original hovertext): undefined
103-
expect(result.hovertext).toEqual(["SUM: 25 (2 values)", undefined]);
103+
expect(result.hovertext).toEqual(["25", undefined]);
104104
expect(result.hoverinfo).toBe("text"); // Because "SUM: 25 (2 values)" is present
105105
});
106106

@@ -133,7 +133,7 @@ describe("aggregateDataPoints", () => {
133133
] as Array<[AggregationType, number]>)("should correctly compute aggregation", (aggregationType, expected) => {
134134
const result = aggregateDataPoints(aggregationType, points);
135135
expect(result.y).toEqual([expected]);
136-
expect(result.hovertext).toEqual([`${aggregationType.toUpperCase()}: ${expected} (4 values)`]);
136+
expect(result.hovertext).toEqual([expected.toLocaleString()]);
137137
});
138138

139139
describe("median aggregation", () => {
@@ -197,7 +197,7 @@ describe("aggregateDataPoints", () => {
197197
points.hovertext = ["hover1", undefined as any, "hover3", "hover4"];
198198
const result = aggregateDataPoints("sum", points);
199199

200-
expect(result.hovertext).toEqual(["SUM: 25 (2 values)", "SUM: 45 (2 values)"]);
200+
expect(result.hovertext).toEqual(["25", "45"]);
201201
});
202202

203203
it("should preserve other properties and original data for non-aggregated points", () => {
@@ -223,21 +223,21 @@ describe("aggregateDataPoints", () => {
223223
const points = createMockDataPoints(["A", "A"], [10, 15], ["hover1", "hover2"]);
224224
const result = aggregateDataPoints("avg", points);
225225

226-
expect(result.hovertext).toEqual(["AVG: 12.5 (2 values)"]);
226+
expect(result.hovertext).toEqual(["12.5"]);
227227
});
228228

229229
it("should handle decimal values in hover text", () => {
230230
const points = createMockDataPoints(["A", "A"], [1, 2], ["hover1", "hover2"]);
231231
const result = aggregateDataPoints("avg", points);
232232

233-
expect(result.hovertext).toEqual(["AVG: 1.5 (2 values)"]);
233+
expect(result.hovertext).toEqual(["1.5"]);
234234
});
235235

236236
it("should show count in hover text", () => {
237237
const points = createMockDataPoints(["A", "A", "A"], [1, 2, 3], ["h1", "h2", "h3"]);
238238
const result = aggregateDataPoints("sum", points);
239239

240-
expect(result.hovertext).toEqual(["SUM: 6 (3 values)"]);
240+
expect(result.hovertext).toEqual(["6"]);
241241
});
242242
});
243243
});

packages/shared/charts/src/utils/aggregations.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ export function aggregateDataPoints(
5555
const aggregatedValue = computeAggregate(yVals, aggregationType);
5656
aggregatedY.push(aggregatedValue);
5757

58-
const aggregatedHoverText =
59-
yVals.length > 1
60-
? `${aggregationType.toUpperCase()}: ${aggregatedValue} (${yVals.length} values)`
61-
: hoverTexts[0];
58+
const aggregatedHoverText = yVals.length > 1 ? aggregatedValue.toLocaleString() : hoverTexts[0];
6259

6360
aggregatedHover.push(aggregatedHoverText);
6461
}

0 commit comments

Comments
 (0)