Skip to content

: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.

fix(insights): show goal line value on hover in quill charts (#73941)

HaynesPostHog5179d35da101
diff --git a/packages/quill/packages/charts/AGENTS.md b/packages/quill/packages/charts/AGENTS.md
index 7378e67265d3..36cee3a0bde2 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).
+- `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.
- `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.tsx
index 817c3256ecab..1b44d05964f2 100644
--- a/packages/quill/packages/charts/src/overlays/ReferenceLine.test.tsx
+++ b/packages/quill/packages/charts/src/overlays/ReferenceLine.test.tsx
@@ -1,4 +1,4 @@
-import { cleanup, type RenderResult } from '@testing-library/react'
+import { cleanup, fireEvent, type RenderResult } from '@testing-library/react'
import React from 'react'
import type { BaseChartContext } from '../core/chart-context'
@@ -66,6 +66,16 @@ describe('ReferenceLine', () => {
expect(getByText('Target')).toBeTruthy()
})
+ it('appends the value to the label on hover and restores it on leave', () => {
+ // value must sit inside the test scale's 0-100 range or the line renders null.
+ const { getByText } = renderInChart(<ReferenceLine value={50} label="Target" />)
+ const label = getByText('Target') as HTMLDivElement
+ fireEvent.mouseEnter(label)
+ expect(getByText('Target: 50')).toBeTruthy()
+ fireEvent.mouseLeave(label)
+ expect(getByText('Target')).toBeTruthy()
+ })
+
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
diff --git a/packages/quill/packages/charts/src/overlays/ReferenceLine.tsx b/packages/quill/packages/charts/src/overlays/ReferenceLine.tsx
index ff6bb69dc8bf..047d6b1122cc 100644
--- a/packages/quill/packages/charts/src/overlays/ReferenceLine.tsx
+++ b/packages/quill/packages/charts/src/overlays/ReferenceLine.tsx
@@ -1,5 +1,5 @@
/* eslint-disable react/forbid-dom-props -- dynamic pixel positions from d3 scales */
-import React, { useMemo } from 'react'
+import React, { useMemo, useState } from 'react'
import { useChartLayout } from '../core/chart-context'
import { TOOLTIP_FALLBACK_BG, TOOLTIP_FALLBACK_COLOR } from './TooltipSurface'
@@ -106,6 +106,8 @@ export function ReferenceLine(props: ReferenceLineProps): React.ReactElement | n
fillOpacity: style?.fillOpacity ?? 0.1,
label: props.label,
labelPosition: props.labelPosition ?? 'end',
+ // Numeric lines (goal thresholds) reveal their value on hover; vertical marker lines don't.
+ valueText: typeof props.value === 'number' ? props.value.toLocaleString() : undefined,
}
if (orientation === 'horizontal') {
@@ -127,6 +129,8 @@ interface ResolvedProps {
fillOpacity: number
label: string | undefined
labelPosition: ReferenceLineLabelPosition
+ /** Formatted value shown appended to the label on hover. Undefined for non-numeric lines. */
+ valueText: string | undefined
}
function HorizontalReferenceLine({
@@ -138,6 +142,7 @@ function HorizontalReferenceLine({
fillOpacity,
label,
labelPosition,
+ valueText,
}: ResolvedProps & { y: number; yAxisId?: string }): React.ReactElement | null {
const { scales, dimensions } = useChartLayout()
const { plotLeft, plotTop, plotWidth, plotHeight, width: containerWidth } = dimensions
@@ -185,6 +190,7 @@ function HorizontalReferenceLine({
fillOpacity={fillOpacity}
lineStyle={lineStyle}
label={label}
+ valueText={valueText}
labelStyle={labelStyle}
/>
)
@@ -206,6 +212,7 @@ function VerticalStripe({
fillOpacity,
label,
labelPosition,
+ valueText,
}: Omit<ResolvedProps, 'fillSide'> & {
x: number
fillBefore: boolean
@@ -250,6 +257,7 @@ function VerticalStripe({
fillOpacity={fillOpacity}
lineStyle={lineStyle}
label={label}
+ valueText={valueText}
labelStyle={labelStyle}
/>
)
@@ -295,6 +303,7 @@ function ReferenceLineView({
fillOpacity,
lineStyle,
label,
+ valueText,
labelStyle,
}: {
fillRect: React.CSSProperties | null
@@ -302,14 +311,18 @@ function ReferenceLineView({
fillOpacity: number
lineStyle: React.CSSProperties
label: string | undefined
+ valueText: string | undefined
labelStyle: React.CSSProperties
}): React.ReactElement {
const { theme } = useChartLayout()
+ const [hovered, setHovered] = useState(false)
const resolvedLabelStyle: React.CSSProperties = {
...labelStyle,
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).
+ const content = hovered && valueText ? (label ? `${label}: ${valueText}` : valueText) : label
return (
<>
{fillRect && (
@@ -319,13 +332,15 @@ function ReferenceLineView({
/>
)}
<div data-attr="hog-chart-reference-line" className="absolute pointer-events-none" style={lineStyle} />
- {label && (
+ {content && (
<div
data-attr="hog-chart-reference-line-label"
- className="absolute pointer-events-none whitespace-nowrap font-medium text-[11px] rounded px-1 py-0.5"
+ className="absolute whitespace-nowrap font-medium text-[11px] rounded px-1 py-0.5 cursor-default"
style={resolvedLabelStyle}
+ onMouseEnter={() => setHovered(true)}
+ onMouseLeave={() => setHovered(false)}
>
- {label}
+ {content}
</div>
)}
</>