Skip to content

Commit 1ce0be9

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 fccde5a commit 1ce0be9

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
() =>
@@ -218,6 +219,7 @@ const VersionDownloadChart: React.FC<VersionDownloadChartProps> = ({
218219
versionHues,
219220
unit,
220221
theme: tooltipTheme,
222+
hoveredVersion,
221223
})}
222224
/>
223225
)}
@@ -255,6 +257,9 @@ const VersionDownloadChart: React.FC<VersionDownloadChartProps> = ({
255257
stackId="1"
256258
fill={fill}
257259
fillOpacity={1}
260+
onMouseEnter={() => {
261+
setHoveredVersion(name);
262+
}}
258263
/>
259264
))}
260265

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;
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)