Skip to content

Commit 2c2393e

Browse files
committed
Make hovered serie bold in Tooltip
With many versions, particularly in React Native, it may be hard to track which serie correspond to which entry on the tooltip. In this PR, I track hovered serie and make hovered serie bold to make comparing numbers easier.
1 parent 09fc137 commit 2c2393e

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/components/VersionDownloadChart.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ const VersionDownloadChart: React.FC<VersionDownloadChartProps> = ({
110110

111111
const [legendElement, setLegendElement] = useState<HTMLDivElement>();
112112
const [hiddenSeries, setHiddenSeries] = useState<string[]>([]);
113+
const [hoveredVersion, setHoveredVersion] = useState<string | null>(null);
113114

114115
const filteredHistory = React.useMemo(
115116
() =>
@@ -240,6 +241,7 @@ const VersionDownloadChart: React.FC<VersionDownloadChartProps> = ({
240241
versionHues,
241242
unit,
242243
theme: tooltipTheme,
244+
hoveredVersion,
243245
})}
244246
/>
245247
)}
@@ -277,6 +279,9 @@ const VersionDownloadChart: React.FC<VersionDownloadChartProps> = ({
277279
stackId="1"
278280
fill={fill}
279281
fillOpacity={1}
282+
onMouseEnter={() => {
283+
setHoveredVersion(name);
284+
}}
280285
/>
281286
))}
282287

src/components/VersionTooltip.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ export type VersionProps = {
5959
versionHues: Record<string, number>;
6060
unit?: Unit;
6161
theme?: ITheme;
62+
hoveredVersion?: string | null;
6263
};
6364

6465
export const VersionTooltipContent: React.FC<
6566
VersionProps & DateTooltipProps
66-
> = ({ label, payload, unit, versionHues, theme }) => {
67+
> = ({ label, payload, unit, versionHues, theme, hoveredVersion }) => {
6768
const reversedItems = [...(payload ?? [])];
6869
reversedItems.reverse();
6970

@@ -91,11 +92,22 @@ export const VersionTooltipContent: React.FC<
9192
<Text
9293
variant="small"
9394
className={styles.versionLabel}
94-
style={{ color: colorChipColor }}
95+
style={{
96+
color: colorChipColor,
97+
fontWeight:
98+
hoveredVersion === entry.name ? "bold" : "normal",
99+
}}
95100
>
96101
{entry.name}
97102
</Text>
98-
<Text variant="small" className={styles.versionCount}>
103+
<Text
104+
variant="small"
105+
className={styles.versionCount}
106+
style={{
107+
fontWeight:
108+
hoveredVersion === entry.name ? "bold" : "normal",
109+
}}
110+
>
99111
{formattedValue}
100112
</Text>
101113
</li>

0 commit comments

Comments
 (0)