:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(insights): hog-charts hover regressions from #60187 (#60255)
Sam Pennington4eac96f80c29
diff --git a/frontend/src/lib/hog-charts/charts/BarChart/BarChart.tsx b/frontend/src/lib/hog-charts/charts/BarChart/BarChart.tsxindex 4b89ee38b2a8..d0d6f501adb5 100644--- a/frontend/src/lib/hog-charts/charts/BarChart/BarChart.tsx+++ b/frontend/src/lib/hog-charts/charts/BarChart/BarChart.tsx@@ -214,13 +214,27 @@ function BarChartInner<Meta = unknown>({},y: (value: number) => d3Scales.value(value),yTicks: () => d3Scales.value.ticks?.(yTickCount) ?? [],- // Width of the bar (narrower than the band in grouped mode after sub-band- // padding) so band-edge-anchored overlays land beside the bar, not the gap.- extent: () =>- isHorizontal- ? undefined- : ((barLayout === 'grouped' ? d3Scales.group?.bandwidth() : undefined) ??- d3Scales.band.bandwidth()),+ // Width of the rendered bar content within the band. In grouped mode the+ // bars sit inside group outer padding, so `band.bandwidth()` overshoots+ // the rightmost bar's right edge and anchors the tooltip in empty space.+ extent: () => {+ if (isHorizontal) {+ return undefined+ }+ const groupScale = d3Scales.group+ if (barLayout === 'grouped' && groupScale) {+ const domain = groupScale.domain()+ if (domain.length > 0) {+ const firstOffset = groupScale(domain[0]) ?? 0+ const lastOffset = groupScale(domain[domain.length - 1]) ?? 0+ const contentExtent = lastOffset + groupScale.bandwidth() - firstOffset+ if (contentExtent > 0) {+ return contentExtent+ }+ }+ }+ return d3Scales.band.bandwidth()+ },_private: barChartPrivate,}},diff --git a/frontend/src/lib/hog-charts/core/hooks/useChartDraw.ts b/frontend/src/lib/hog-charts/core/hooks/useChartDraw.tsindex 314805b6c09d..655f40903229 100644--- a/frontend/src/lib/hog-charts/core/hooks/useChartDraw.ts+++ b/frontend/src/lib/hog-charts/core/hooks/useChartDraw.ts@@ -153,7 +153,12 @@ export function useChartDraw({hoverRafRef.current = null}}- // series/labels/theme/hoverPosition/drawHover are read via refs — see top of hook.+ // hoverPosition is in the dep array (not the ref) so the overlay redraws when the+ // cursor moves *within* the same band — bar charts decide on a hit per-frame in+ // `drawHover`, and entering a bar from canvas-empty-space doesn't change hoverIndex.+ // The fade timer only resets on hoverIndex change (see check above), so re-running+ // the effect per mousemove doesn't restart the animation.+ // series/labels/theme/drawHover are read via refs — see top of hook.// eslint-disable-next-line react-hooks/exhaustive-deps- }, [overlayCtx, dimensions, scales, hoverIndex, hoverAnimationMs])+ }, [overlayCtx, dimensions, scales, hoverIndex, hoverPosition, hoverAnimationMs])}diff --git a/frontend/src/lib/hog-charts/overlays/ValueLabels.tsx b/frontend/src/lib/hog-charts/overlays/ValueLabels.tsxindex b525325994d6..10a305a699a1 100644--- a/frontend/src/lib/hog-charts/overlays/ValueLabels.tsx+++ b/frontend/src/lib/hog-charts/overlays/ValueLabels.tsx@@ -1,6 +1,6 @@import React, { useMemo } from 'react'-import { useChart } from '../core/chart-context'+import { useChartHover, useChartLayout } from '../core/chart-context'import { resolveYScaleForSeries } from '../core/scales'import type { ChartScales, ResolvedSeries, ResolveValueFn } from '../core/types'import { getTextMeasureCtx } from '../utils/text-measure'@@ -354,7 +354,8 @@ export function ValueLabels({minGap = 4,mode = 'per-segment',}: ValueLabelsProps): React.ReactElement | null {- const { series, scales, labels, theme, resolvePositionValue, axis, hoverIndex } = useChart()+ const { series, scales, labels, theme, resolvePositionValue, axis } = useChartLayout()+ const { hoverIndex } = useChartHover()const isHorizontal = axis.orientation === 'horizontal'const isPercent = axis.isPercent@@ -379,6 +380,26 @@ export function ValueLabels({[series, labels, scales, resolvePositionValue, formatter, minGap, isHorizontal, mode, isPercent])+ // Skip the lift when a dataIndex has labels at multiple distinct x positions+ // (grouped bars) — hoverIndex can't disambiguate which bar the cursor is on, so+ // lifting all of them is worse than lifting none. Labels sharing the same x+ // (stacked / multi-series at band center) are one visual column and lift together.+ const liftableIndices = useMemo(() => {+ const xsByIndex = new Map<number, Set<number>>()+ for (const c of visible) {+ const xs = xsByIndex.get(c.dataIndex) ?? new Set<number>()+ xs.add(Math.round(c.x))+ xsByIndex.set(c.dataIndex, xs)+ }+ const set = new Set<number>()+ for (const [dIdx, xs] of xsByIndex) {+ if (xs.size === 1) {+ set.add(dIdx)+ }+ }+ return set+ }, [visible])+if (visible.length === 0) {return null}@@ -388,7 +409,7 @@ export function ValueLabels({return (<>{visible.map((c) => {- const isHovered = c.dataIndex === hoverIndex+ const isHovered = c.dataIndex === hoverIndex && liftableIndices.has(c.dataIndex)return (<divkey={c.key}