Skip to content

Commit 748bc6a

Browse files
committed
Fix for line/area chart hovering
1 parent 0ea3c5c commit 748bc6a

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

apps/webapp/app/components/primitives/charts/ChartLine.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ export function ChartLineRenderer({
127127
...yAxisPropsProp,
128128
};
129129

130+
// Handle mouse leave to also reset highlight
131+
const handleMouseLeave = () => {
132+
highlight.setTooltipActive(false);
133+
highlight.reset();
134+
};
135+
130136
// Render stacked area chart if stacked prop is true
131137
if (stacked && dataKeys.length > 1) {
132138
return (
@@ -139,8 +145,16 @@ export function ChartLineRenderer({
139145
left: 12,
140146
right: 12,
141147
}}
142-
onMouseEnter={() => highlight.setTooltipActive(true)}
143-
onMouseLeave={() => highlight.setTooltipActive(false)}
148+
onMouseMove={(e: any) => {
149+
// Update active payload for legend
150+
if (e?.activePayload?.length) {
151+
highlight.setActivePayload(e.activePayload);
152+
highlight.setTooltipActive(true);
153+
} else {
154+
highlight.setTooltipActive(false);
155+
}
156+
}}
157+
onMouseLeave={handleMouseLeave}
144158
>
145159
<CartesianGrid vertical={false} stroke="#272A2E" strokeDasharray="3 3" />
146160
<XAxis {...xAxisConfig} />
@@ -178,8 +192,16 @@ export function ChartLineRenderer({
178192
left: 12,
179193
right: 12,
180194
}}
181-
onMouseEnter={() => highlight.setTooltipActive(true)}
182-
onMouseLeave={() => highlight.setTooltipActive(false)}
195+
onMouseMove={(e: any) => {
196+
// Update active payload for legend
197+
if (e?.activePayload?.length) {
198+
highlight.setActivePayload(e.activePayload);
199+
highlight.setTooltipActive(true);
200+
} else {
201+
highlight.setTooltipActive(false);
202+
}
203+
}}
204+
onMouseLeave={handleMouseLeave}
183205
>
184206
<CartesianGrid vertical={false} stroke="#272A2E" strokeDasharray="3 3" />
185207
<XAxis {...xAxisConfig} />

0 commit comments

Comments
 (0)