0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-12-01 12:21:02 +01:00

Fix lingering tooltips in Line Graphs (#5663)

* fix lingering tooltips

* handle component unmount scenario
This commit is contained in:
Alex Gyujin Kim 2021-08-19 14:26:14 -07:00 committed by GitHub
parent ba332ce713
commit ce077bd51b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -61,6 +61,7 @@ export function LineGraph({
const [boundaryInterval, setBoundaryInterval] = useState(0)
const [topExtent, setTopExtent] = useState(0)
const [annotationInRange, setInRange] = useState(false)
const [tooltipVisible, setTooltipVisible] = useState(false)
const size = useWindowSize()
const annotationsCondition =
@ -78,6 +79,20 @@ export function LineGraph({
buildChart()
}, [datasets, color, visibilityMap])
// Hacky! - Chartjs doesn't internally call tooltip callback on mouseout from right border.
// Let's manually remove tooltips when the chart is being hovered over. #5061
useEffect(() => {
const removeTooltip = () => {
const tooltipEl = document.getElementById('ph-graph-tooltip')
if (tooltipEl && !tooltipVisible) {
tooltipEl.style.opacity = 0
}
}
removeTooltip()
return removeTooltip // remove tooltip on component unmount
}, [tooltipVisible])
// annotation related effects
// update boundaries and axis padding when user hovers with mouse or annotations load
@ -378,6 +393,11 @@ export function LineGraph({
evt.target.style.cursor = 'default'
}
}
if (evt.type === 'mouseout') {
setTooltipVisible(false)
} else {
setTooltipVisible(true)
}
},
},
onClick: (_, [point]) => {