Skip to content

Commit c783c6f

Browse files
committed
feat: use colored product icons in chart tooltips for SKU groups
Replace the colored ● dot with the actual product Octicon (filled with the series color) in tooltip rows across all three chart types: TimeSeriesChart, CostBreakdownChart, and ModelBreakdownChart.
1 parent 1923595 commit c783c6f

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

src/components/charts/CostBreakdownChart.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,28 @@ export function CostBreakdownChart({ stackField = 'model', metricOptions }: Cost
5252
});
5353

5454
const seriesColor = colorMap.get(groupInfo.group) ?? '#808fa3';
55+
const displayName = formatDisplayValue(groupInfo.group, stackField) || ' ';
56+
const isSku = stackField === 'sku';
57+
const iconHtml = isSku ? getSkuIconSvg(groupInfo.group, seriesColor) : '';
5558
return {
5659
type: 'column' as const,
57-
name: stackField === 'sku'
58-
? `<span style="display:flex;align-items:center;gap:4px">${getSkuIconSvg(groupInfo.group, seriesColor)}${formatDisplayValue(groupInfo.group, stackField) || ' '}</span>`
59-
: formatDisplayValue(groupInfo.group, stackField) || ' ',
60+
name: iconHtml
61+
? `<span style="display:flex;align-items:center;gap:4px">${iconHtml}${displayName}</span>`
62+
: displayName,
6063
data,
6164
color: seriesColor,
65+
...(isSku && {
66+
tooltip: {
67+
pointFormatter: function (this: Highcharts.Point) {
68+
const val = this.y ?? 0;
69+
const icon = getSkuIconSvg(groupInfo.group, String(this.color));
70+
const formatted = activeMetric.isCurrency
71+
? `$${val.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`
72+
: formatCompact(val);
73+
return `<tr><td>${icon} ${displayName}:&nbsp;</td><td style="text-align:right;"><b>${formatted}</b></td></tr>`;
74+
},
75+
},
76+
}),
6277
};
6378
});
6479

src/components/charts/ModelBreakdownChart.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,29 @@ export function GroupBreakdownChart({ stackField = 'model', metricOptions }: Gro
9292
});
9393

9494
const seriesColor = colorMap.get(stackInfo.stack) ?? '#808fa3';
95+
const displayName = formatDisplayValue(stackInfo.stack, stackField) || ' ';
96+
const isSku = stackField === 'sku';
97+
const iconHtml = isSku ? getSkuIconSvg(stackInfo.stack, seriesColor) : '';
9598
return {
9699
type: 'bar' as const,
97-
name: stackField === 'sku'
98-
? `<span style="display:flex;align-items:center;gap:4px">${getSkuIconSvg(stackInfo.stack, seriesColor)}${formatDisplayValue(stackInfo.stack, stackField) || ' '}</span>`
99-
: formatDisplayValue(stackInfo.stack, stackField) || ' ',
100+
name: iconHtml
101+
? `<span style="display:flex;align-items:center;gap:4px">${iconHtml}${displayName}</span>`
102+
: displayName,
100103
data,
101104
color: seriesColor,
102105
visible: !isHidden,
106+
...(isSku && {
107+
tooltip: {
108+
pointFormatter: function (this: Highcharts.Point) {
109+
const val = this.y ?? 0;
110+
const icon = getSkuIconSvg(stackInfo.stack, String(this.color));
111+
const formatted = activeMetric.isCurrency
112+
? `$${val.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`
113+
: formatCompact(val);
114+
return `<tr><td>${icon} ${displayName}:&nbsp;</td><td style="text-align:right;"><b>${formatted}</b></td></tr>`;
115+
},
116+
},
117+
}),
103118
events: {
104119
legendItemClick: function () {
105120
toggleGroup(stackInfo.stack);

src/components/charts/TimeSeriesChart.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ export function TimeSeriesChart({ metricOptions }: { metricOptions?: MetricOptio
154154
const formatted = activeMetric.isCurrency
155155
? `$${val.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`
156156
: formatCompact(val);
157-
return `<span style="color:${this.color}">●</span> ${displayName}: <b>${formatted}</b><br/>`;
157+
return isSku
158+
? `${getSkuIconSvg(group.key, String(this.color))} ${displayName}: <b>${formatted}</b><br/>`
159+
: `<span style="color:${this.color}">●</span> ${displayName}: <b>${formatted}</b><br/>`;
158160
},
159161
},
160162
});

0 commit comments

Comments
 (0)