: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): restore goal line value-on-hover on charts (#76345)
timgl5de3f6e15b31
diff --git a/packages/quill/packages/charts/AGENTS.md b/packages/quill/packages/charts/AGENTS.mdindex 865bf084f3b2..aff848e45eca 100644--- a/packages/quill/packages/charts/AGENTS.md+++ b/packages/quill/packages/charts/AGENTS.md@@ -81,7 +81,7 @@ Safari is the exception: it never fires `contextrestored`, so a context lost the- `DefaultTooltip` (the built-in tooltip, also usable from a custom `tooltip` render prop) takes optional `valueFormatter`, `labelFormatter`, `labelRenderer`, `showHeader`, `showTotal`, `totalLabel`, `totalFormatter`, `sortedByValue`, `hideZeroRows`, `onRowClick`, and `footer`. `valueFormatter` gets `(value, entry)` — the row's `seriesData` entry as a second arg — so each row can format with its own `series.meta` (e.g. per-column currency/duration); it may return a node, not just a string (e.g. a property-formatted value). `labelFormatter` transforms the raw x-axis label shown in the tooltip header (e.g. convert an ISO datetime string to "Jun 24, 10:00"); on time-series charts with `xAxis.timezone` + `interval` set it defaults to an interval-aware date formatter that includes the weekday for single-day buckets ("Sat, Jun 6, 2026", "Sat, Jun 6, 14:00"; week/month buckets span days, so "Jun 1, 2026", "Jun 2026"), so the header matches the auto-formatted axis ticks — an explicit `labelFormatter` still wins. `labelRenderer` overrides how each row's label renders (defaults to the series label) — use for richer labels than a plain string, e.g. breakdown-value pills. `showHeader` (default true) toggles the header label row — pass false for charts without a meaningful header (pie slices, aggregated single-column bars). `showTotal` appends a footer row summing the visible series; it excludes `overlay` series (goal lines) and series with `visibility.total: false` (values that don't sum meaningfully with the rest, e.g. a percentage column alongside counts — the row itself still renders) from the sum, and is suppressed when fewer than two summable series remain. `totalFormatter` formats the total (defaults to `valueFormatter` applied with the first summable row's entry); `totalLabel` defaults to `'Total'`. `sortedByValue` sorts rows by value descending so the highest value appears first. `hideZeroRows` drops rows whose value is exactly `0` (e.g. lifecycle statuses absent for a period), so the tooltip lists only series with data at the hovered point. `onRowClick` makes each series row clickable (firing with the row's `seriesData` entry) — the tooltip must be pinned for clicks to land, since an unpinned tooltip is `pointer-events: none`; use it to open a per-series drill-down (e.g. the persons modal). `footer` renders arbitrary content below all rows (with a divider) — useful for "click to inspect" hints. A formatter taking only `value` stays compatible — the extra arg is ignored. Pinned tooltips are copy-friendly: outside-dismissal keys off where the press _started_ (pointer-down outside the tooltip/chart, or Escape), so a text-selection drag that releases outside the tooltip doesn't dismiss it, and a click that completes a text selection inside a row doesn't fire `onRowClick`.- BarChart sets `TooltipContext.hoveredSeriesKey` — the key of the bar/segment under the cursor (stacked: the visible segment; grouped: the band-slot hit). Stacked `seriesData` keeps every segment in declaration order, so a custom tooltip that describes a single segment (e.g. a funnel breakdown) must select by `hoveredSeriesKey`, not `seriesData[0]`. It may reference a series hidden from `seriesData` via `visibility.tooltip: false` (e.g. a drop-off filler), and is `undefined` on other chart types and pinned rebuilds without a cursor.- To tune the built-in tooltip **without writing a render prop**, put those same fields on `config.tooltip` (`{ enabled, pinnable, resolveClickToNearestSeries, placement, valueFormatter, labelFormatter, showTotal, totalLabel, totalFormatter, sortedByValue }`). When no `tooltip` render prop is supplied, the chart renders `DefaultTooltip` with them applied; a render prop, if given, owns content entirely and these are ignored. Prefer config for "format each row / add a total" cases (e.g. SQL insights pass per-column formatters this way) and reach for the render prop only for genuinely custom tooltip markup (e.g. adding a `footer` hint). `resolveClickToNearestSeries` (default false) changes what a click on a `pinnable` multi-series chart does: instead of always pinning first (letting the user then click a specific row), it resolves the series nearest the cursor and fires `onPointClick` for it directly — skip pinning only where a click's target series is visually unambiguous by position (e.g. funnel breakdown areas, one per breakdown value); leave it off where series overlap closely and a wrong guess is costly (e.g. trend lines).-- `ReferenceLine` variants: `goal` (dashed grey), `alert` (dashed red), `marker` (solid thin). A numeric line's label reveals its value on hover (appended as `label: value`), matching the legacy chart.js goal-line behavior.+- `ReferenceLine` variants: `goal` (dashed grey), `alert` (dashed red), `marker` (solid thin). A numeric line reveals its value on hover of the line itself (via a wider invisible hit area) or its label — appended as `label: value` when it has a label, shown alone when it doesn't — matching the legacy chart.js goal-line behavior.- `TrendLineOverlay` renders linear/exponential regression lines as SVG polylines on vertical bar and combo charts. Use via `trendLines?: TrendLineConfig[]` in `TimeSeriesBarChartConfig` or `TimeSeriesComboChartConfig` — the chart computes the derived series via `buildTrendLineSeries` and passes them to the overlay as a child. Only works for `axisOrientation: 'vertical'`; returns null on horizontal charts. Legend-toggled-off series are filtered automatically.- `ValueLabels` formatter gets `(value, seriesIndex, dataIndex, context)`; in percent layouts `value` is a 0–1 fraction — use `context.rawValue` for the original. `context.bandValues` is the stack's values at this index and `context.previousBandValues` the same for the preceding index (empty at the first), so a formatter can compute a segment's share of the current or the previous band (e.g. period-over-period). Collision avoidance is a single greedy pass over the full 2D label box (`minGap` on every side): a label is dropped only when it actually overlaps a higher-priority one, so on bar charts neighbours at different heights both keep their labels instead of the axis dropping every other bar. Ties resolve toward earlier series and left-to-right / top-to-bottom.- Every multi-series chart (`LineChart`, `BarChart`, `TimeSeriesLineChart`, `TimeSeriesBarChart`, `SlopeChart`, `PieChart`) takes a `config.legend: ChartLegendConfig` (`{ show, position, align, gap, interactive, hiddenKeys, onToggleSeries, renderItem }`). With `show: true` the chart renders a built-in legend that, by default (`interactive`), is click-to-toggle: clicking a row hides that series (no draw, no scale contribution, no tooltip — the axes rescale into the freed space) while the row stays listed but dimmed so it can be restored. The chart owns the toggled-off state (uncontrolled); set `interactive: false` for a static legend, or pass `hiddenKeys` + `onToggleSeries` to control it yourself. Hidden by default. `config.legend.renderItem(defaultNode, item)` wraps each rendered row, so consumers can augment it (e.g. attach a right-click context menu) while keeping the default swatch/label/toggle rendering — return `defaultNode` to leave a row untouched. Toggling on time-series charts lists the user's series only (not derived trend lines / CI bands) — and hiding a series also hides everything derived from it (its CI band, moving average, and trend line), so no orphaned overlay floats over the gap.diff --git a/packages/quill/packages/charts/src/overlays/ReferenceLine.test.tsx b/packages/quill/packages/charts/src/overlays/ReferenceLine.test.tsxindex 1b44d05964f2..cfd98a632904 100644--- a/packages/quill/packages/charts/src/overlays/ReferenceLine.test.tsx+++ b/packages/quill/packages/charts/src/overlays/ReferenceLine.test.tsx@@ -76,6 +76,17 @@ describe('ReferenceLine', () => {expect(getByText('Target')).toBeTruthy()})+ it('reveals the value on line hover even when the line has no text label', () => {+ const { container, getByText, queryByText } = renderInChart(<ReferenceLine value={50} />)+ expect(queryByText('50')).toBeNull() // nothing shown at rest+ const hitArea = container.querySelector('[data-attr="hog-chart-reference-line-hit-area"]')!+ expect(hitArea).not.toBeNull()+ fireEvent.mouseEnter(hitArea)+ expect(getByText('50')).toBeTruthy()+ fireEvent.mouseLeave(hitArea)+ expect(queryByText('50')).toBeNull()+ })+it('anchors the label at the start when labelPosition="start"', () => {const { getByText } = renderInChart(<ReferenceLine value={50} label="T" labelPosition="start" />)const label = getByText('T') as HTMLDivElement@@ -114,9 +125,7 @@ describe('ReferenceLine', () => {it('renders a fill rect above the line when fillSide="above"', () => {const { container } = renderInChart(<ReferenceLine value={50} fillSide="above" />)- const divs = container.querySelectorAll<HTMLDivElement>('div')- expect(divs).toHaveLength(2)- const fill = divs[0]+ const fill = container.querySelector<HTMLDivElement>('div[style*="background-color"]')!// above fill runs from plotTop down to the line yexpect(fill.style.top).toBe('16px')expect(parseFloat(fill.style.height)).toBeGreaterThan(0)@@ -124,9 +133,7 @@ describe('ReferenceLine', () => {it('renders a fill rect below the line when fillSide="below"', () => {const { container } = renderInChart(<ReferenceLine value={50} fillSide="below" />)- const divs = container.querySelectorAll<HTMLDivElement>('div')- expect(divs).toHaveLength(2)- const fill = divs[0]+ const fill = container.querySelector<HTMLDivElement>('div[style*="background-color"]')!expect(parseFloat(fill.style.top)).toBeGreaterThan(DIMENSIONS.plotTop)})diff --git a/packages/quill/packages/charts/src/overlays/ReferenceLine.tsx b/packages/quill/packages/charts/src/overlays/ReferenceLine.tsxindex 047d6b1122cc..d0e0088e32b8 100644--- a/packages/quill/packages/charts/src/overlays/ReferenceLine.tsx+++ b/packages/quill/packages/charts/src/overlays/ReferenceLine.tsx@@ -66,6 +66,11 @@ const VARIANT_DEFAULTS: Record<ReferenceLineVariant, ResolvedStyle> = {const LABEL_HEIGHT = 20/** Padding between the label and the plot edge. */const LABEL_PADDING = 4+/** Thickness of the invisible hover target centered on the line (height for horizontal lines, width+ * for vertical). The stroked line itself is only a couple of pixels, so hovering it to reveal the+ * value would be near-impossible without a wider hit area — this restores the legacy behavior where+ * hovering anywhere on a goal line surfaces its number, even when the line has no visible label. */+const HOVER_HIT_THICKNESS = 12function resolveStyle(variant: ReferenceLineVariant, style: ReferenceLineStyle | undefined): ResolvedStyle {const defaults = VARIANT_DEFAULTS[variant]@@ -183,12 +188,19 @@ function HorizontalReferenceLine({fillRect = { left: plotLeft, top: y, width: plotWidth, height: plotBottom - y }}+ // Numeric lines reveal their value on hover, so give the line a full-width hover target.+ const hitAreaStyle: React.CSSProperties | null =+ valueText != null+ ? { left: plotLeft, top: y - HOVER_HIT_THICKNESS / 2, width: plotWidth, height: HOVER_HIT_THICKNESS }+ : null+return (<ReferenceLineViewfillRect={fillRect}fillColor={fillColor}fillOpacity={fillOpacity}lineStyle={lineStyle}+ hitAreaStyle={hitAreaStyle}label={label}valueText={valueText}labelStyle={labelStyle}@@ -250,12 +262,19 @@ function VerticalStripe({fillRect = { left: x, top: plotTop, width: plotRight - x, height: plotHeight }}+ // Numeric lines reveal their value on hover, so give the line a full-height hover target.+ const hitAreaStyle: React.CSSProperties | null =+ valueText != null+ ? { left: x - HOVER_HIT_THICKNESS / 2, top: plotTop, width: HOVER_HIT_THICKNESS, height: plotHeight }+ : null+return (<ReferenceLineViewfillRect={fillRect}fillColor={fillColor}fillOpacity={fillOpacity}lineStyle={lineStyle}+ hitAreaStyle={hitAreaStyle}label={label}valueText={valueText}labelStyle={labelStyle}@@ -302,6 +321,7 @@ function ReferenceLineView({fillColor,fillOpacity,lineStyle,+ hitAreaStyle,label,valueText,labelStyle,@@ -310,6 +330,7 @@ function ReferenceLineView({fillColor: stringfillOpacity: numberlineStyle: React.CSSProperties+ hitAreaStyle: React.CSSProperties | nulllabel: string | undefinedvalueText: string | undefinedlabelStyle: React.CSSProperties@@ -321,8 +342,11 @@ function ReferenceLineView({backgroundColor: theme.tooltipBackground ?? TOOLTIP_FALLBACK_BG,color: theme.tooltipColor ?? TOOLTIP_FALLBACK_COLOR,}- // Hovering the label reveals the line's value, appended to its text label (or shown alone).+ // Hovering the line (or its label) reveals the value, appended to its text label (or shown alone).const content = hovered && valueText ? (label ? `${label}: ${valueText}` : valueText) : label+ // The overlay layer is pointer-events-none, so anything that needs to catch hover must opt back in.+ const setHoveredOn = (): void => setHovered(true)+ const setHoveredOff = (): void => setHovered(false)return (<>{fillRect && (@@ -335,14 +359,25 @@ function ReferenceLineView({{content && (<divdata-attr="hog-chart-reference-line-label"- className="absolute whitespace-nowrap font-medium text-[11px] rounded px-1 py-0.5 cursor-default"+ className="absolute pointer-events-auto whitespace-nowrap font-medium text-[11px] rounded px-1 py-0.5 cursor-default"style={resolvedLabelStyle}- onMouseEnter={() => setHovered(true)}- onMouseLeave={() => setHovered(false)}+ onMouseEnter={setHoveredOn}+ onMouseLeave={setHoveredOff}>{content}</div>)}+ {/* Rendered last so the transparent hover target sits above the line and label, catching+ hover anywhere along the line — the label reads through it since it has no background. */}+ {hitAreaStyle && (+ <div+ data-attr="hog-chart-reference-line-hit-area"+ className="absolute pointer-events-auto"+ style={hitAreaStyle}+ onMouseEnter={setHoveredOn}+ onMouseLeave={setHoveredOff}+ />+ )}</>)}