diff --git a/web/components/charts/generic-charts.tsx b/web/components/charts/generic-charts.tsx index df57e0ab..bbcb0685 100644 --- a/web/components/charts/generic-charts.tsx +++ b/web/components/charts/generic-charts.tsx @@ -87,6 +87,27 @@ export const SingleValueDistributionChart = (props: { const xAxis = axisBottom(xScale).tickFormat(formatX) const yAxis = axisLeft(yScale).tickFormat(formatY) + const xBisector = bisector((p: DistributionPoint) => p[0]) + const onMouseOver = useEvent((event: React.PointerEvent) => { + const tt = tooltipRef.current + if (tt != null) { + const [mouseX, mouseY] = pointer(event) + const queryX = xScale.invert(mouseX) + const [_x, y] = data[xBisector.center(data, queryX)] + tt.innerHTML = `${formatY(y)} ${formatX(queryX)}` + tt.style.display = 'block' + tt.style.top = mouseY - 10 + 'px' + tt.style.left = mouseX + 20 + 'px' + } + }) + + const onMouseLeave = useEvent(() => { + const tt = tooltipRef.current + if (tt != null) { + tt.style.display = 'none' + } + }) + return (
- + p[0]) + const xBisector = bisector((p: HistoryPoint) => p[0]) const onMouseOver = useEvent((event: React.PointerEvent) => { const tt = tooltipRef.current if (tt != null) { const [mouseX, mouseY] = pointer(event) - const date = xScale.invert(mouseX) - const [_, prob] = data[dateBisector.center(data, date)] - tt.innerHTML = `${formatY(prob)} ${formatX(date)}` + const queryX = xScale.invert(mouseX) + const [_x, y] = data[xBisector.center(data, queryX)] + tt.innerHTML = `${formatY(y)} ${formatX(queryX)}` tt.style.display = 'block' tt.style.top = mouseY - 10 + 'px' tt.style.left = mouseX + 20 + 'px'