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(charts): open persons modal on funnel steps breakdown click instead of pinning tooltip (#67715)

Sam Pennington836726a6b805
diff --git a/packages/quill/packages/charts/AGENTS.md b/packages/quill/packages/charts/AGENTS.md
index f9a382fce787..9ff11c2f9971 100644
--- a/packages/quill/packages/charts/AGENTS.md
+++ b/packages/quill/packages/charts/AGENTS.md
@@ -68,7 +68,7 @@ Charts fill their container and need a parent with real dimensions — a `0`-hei
- Overlays (`ReferenceLine`/`ReferenceLines`, `ValueLabels`, `AxisTitles`, `TrendLineOverlay`) compose as children.
- `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"). `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) 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.
-- To tune the built-in tooltip **without writing a render prop**, put those same fields on `config.tooltip` (`{ enabled, pinnable, 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).
+- 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).
- `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).
diff --git a/packages/quill/packages/charts/src/core/Chart.tsx b/packages/quill/packages/charts/src/core/Chart.tsx
index a076c9ffe424..87a24e41e385 100644
--- a/packages/quill/packages/charts/src/core/Chart.tsx
+++ b/packages/quill/packages/charts/src/core/Chart.tsx
@@ -142,6 +142,7 @@ export function Chart<Meta = unknown>({
const {
enabled: showTooltip = true,
pinnable: pinnableTooltip = false,
+ resolveClickToNearestSeries = false,
placement: tooltipPlacement = 'follow-data',
valueFormatter: tooltipValueFormatter,
labelFormatter: tooltipLabelFormatter,
@@ -216,6 +217,7 @@ export function Chart<Meta = unknown>({
wrapperRef,
showTooltip,
pinnable: pinnableTooltip,
+ resolveClickToNearestSeries,
onPointClick,
onDateRangeZoom,
resolveValue,
diff --git a/packages/quill/packages/charts/src/core/hooks/useChartInteraction.test.ts b/packages/quill/packages/charts/src/core/hooks/useChartInteraction.test.ts
index bffd475148c2..5977d931305d 100644
--- a/packages/quill/packages/charts/src/core/hooks/useChartInteraction.test.ts
+++ b/packages/quill/packages/charts/src/core/hooks/useChartInteraction.test.ts
@@ -87,7 +87,8 @@ describe('useChartInteraction — tooltip pinning', () => {
function renderInteraction(
pinnable = true,
- onPointClick?: (data: unknown) => void
+ onPointClick?: (data: unknown) => void,
+ resolveClickToNearestSeries = false
): RenderHookResult<ReturnType<typeof useChartInteraction>, unknown> {
return renderHook(() =>
useChartInteraction({
@@ -99,6 +100,7 @@ describe('useChartInteraction — tooltip pinning', () => {
wrapperRef: refs.wrapperRef,
showTooltip: true,
pinnable,
+ resolveClickToNearestSeries,
onPointClick: onPointClick as never,
resolveValue: (s, i) => s.data[i],
})
@@ -279,6 +281,29 @@ describe('useChartInteraction — tooltip pinning', () => {
expect(result.current.tooltipCtx?.isPinned).toBe(true)
})
+ // Series values at Tue (x=200): a=20 -> yPixel 180, b=15 -> yPixel 185.
+ it.each<[number, string]>([
+ [180, 'a'],
+ [185, 'b'],
+ ])(
+ 'resolveClickToNearestSeries fires onPointClick for the series nearest cursorY=%i (%s) instead of pinning',
+ (cursorY, expectedKey) => {
+ const onPointClick = jest.fn()
+ const { result } = renderInteraction(true, onPointClick, true)
+
+ act(() => {
+ simulateMouseMove(result.current.handlers, refs, 200, cursorY)
+ })
+ act(() => {
+ result.current.handlers.onClick()
+ })
+
+ expect(onPointClick).toHaveBeenCalledTimes(1)
+ expect(onPointClick.mock.calls[0][0].series.key).toBe(expectedKey)
+ expect(result.current.tooltipCtx?.isPinned).toBe(false)
+ }
+ )
+
it('rebuilds the pinned tooltip when series data changes underneath the pin', () => {
const { rerender, result } = renderHook(
({ s }: { s: typeof series }) =>
diff --git a/packages/quill/packages/charts/src/core/hooks/useChartInteraction.ts b/packages/quill/packages/charts/src/core/hooks/useChartInteraction.ts
index eb82c2d8a38b..3d07c9ff5e0f 100644
--- a/packages/quill/packages/charts/src/core/hooks/useChartInteraction.ts
+++ b/packages/quill/packages/charts/src/core/hooks/useChartInteraction.ts
@@ -1,5 +1,6 @@
import React, { useCallback, useMemo } from 'react'
+import { findClosestSeriesKey } from '../../overlays/tooltipUtils'
import {
buildLabelPositions,
buildPointClickData,
@@ -31,6 +32,8 @@ interface UseChartInteractionOptions<Meta> {
wrapperRef: React.RefObject<HTMLDivElement>
showTooltip: boolean
pinnable: boolean
+ /** See `TooltipConfig.resolveClickToNearestSeries`. */
+ resolveClickToNearestSeries?: boolean
onPointClick?: (data: PointClickData<Meta>) => void
onDateRangeZoom?: (data: DateRangeZoomData) => void
resolveValue?: ResolveValueFn
@@ -49,6 +52,36 @@ interface UseChartInteractionOptions<Meta> {
wrapClickData?: (data: PointClickData<Meta>, scales: ChartScales) => PointClickData<Meta>
}
+/** Resolves a click on a pinnable multi-series chart to whichever series is nearest the cursor,
+ * reusing the already-computed tooltip row values/positions rather than re-deriving them —
+ * `tooltipCtx.seriesData` reflects each series' own tooltip-visibility and value formatting,
+ * which a fresh lookup via `buildPointClickData` would not. Returns `null` when no series is
+ * closest (e.g. an empty tooltip). */
+function resolveNearestSeriesClickData<Meta>(
+ dataIndex: number,
+ series: ResolvedSeries<Meta>[],
+ labels: string[],
+ tooltipCtx: TooltipContext<Meta>,
+ interactionAxis: 'x' | 'y',
+ cursor: { x: number; y: number }
+): PointClickData<Meta> | null {
+ const cursorValueCoord = interactionAxis === 'y' ? cursor.x : cursor.y
+ const closestKey = findClosestSeriesKey(tooltipCtx.seriesData, cursorValueCoord)
+ const closest = closestKey ? tooltipCtx.seriesData.find((d) => d.series.key === closestKey) : undefined
+ if (!closest) {
+ return null
+ }
+ return {
+ seriesIndex: series.findIndex((s) => s.key === closest.series.key),
+ dataIndex,
+ series: closest.series,
+ value: closest.value,
+ label: labels[dataIndex],
+ crossSeriesData: tooltipCtx.seriesData.map((d) => ({ series: d.series, value: d.value })),
+ cursor,
+ }
+}
+
interface UseChartInteractionResult<Meta> {
hoverIndex: number
hoverPosition: { x: number; y: number } | null
@@ -71,6 +104,7 @@ export function useChartInteraction<Meta = unknown>({
wrapperRef,
showTooltip,
pinnable,
+ resolveClickToNearestSeries = false,
onPointClick,
onDateRangeZoom,
resolveValue = defaultResolveValue,
@@ -265,6 +299,22 @@ export function useChartInteraction<Meta = unknown>({
// consumer's own row handler. With a single series there's nothing to pin, so
// onPointClick fires immediately instead.
if (pinnable && tooltipCtx && tooltipCtx.seriesData.length > 1) {
+ // Opt-in: a click nearer one series than the others is unambiguous, so resolve it
+ // and fire onPointClick directly instead of making the user pin then pick a row.
+ if (resolveClickToNearestSeries && onPointClick && hoverPositionRef.current) {
+ const clickData = resolveNearestSeriesClickData(
+ currentIndex,
+ series,
+ labels,
+ tooltipCtx,
+ interactionAxis,
+ hoverPositionRef.current
+ )
+ if (clickData) {
+ onPointClick(wrapClickData && scales ? wrapClickData(clickData, scales) : clickData)
+ return
+ }
+ }
pin()
return
}
@@ -281,6 +331,8 @@ export function useChartInteraction<Meta = unknown>({
labels,
resolveValue,
pinnable,
+ resolveClickToNearestSeries,
+ interactionAxis,
tooltipCtx,
isPinned,
clearTooltip,
diff --git a/packages/quill/packages/charts/src/core/types.ts b/packages/quill/packages/charts/src/core/types.ts
index 02d157b835fe..3a2a438f8571 100644
--- a/packages/quill/packages/charts/src/core/types.ts
+++ b/packages/quill/packages/charts/src/core/types.ts
@@ -299,6 +299,11 @@ export interface TooltipConfig {
enabled?: boolean
/** When true, clicking a data point with multiple series pins the tooltip in place. */
pinnable?: boolean
+ /** When a pinnable tooltip covers multiple series, resolve the series nearest the cursor and
+ * fire `onPointClick` for it directly instead of pinning — skips the pin-then-click-a-row
+ * step. Opt-in per chart; default false keeps the pin-first flow for ambiguous multi-series
+ * charts (e.g. overlapping trend lines) where a wrong guess is costly. */
+ resolveClickToNearestSeries?: boolean
/** Where the tooltip anchors. `follow-data` (default) tracks the highest data point at the
* hovered x; `top` fixes the tooltip to the top of the chart so it doesn't jump vertically
* as the cursor moves between data points; `cursor` tracks the mouse, so the tooltip sits
diff --git a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx
index fe5615914f3f..666b80073f2b 100644
--- a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx
+++ b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx
@@ -23,8 +23,9 @@ import { buildFunnelStepsBarConfig, FUNNEL_STEPS_BAND_PADDING } from '../shared/
import { FunnelStepsBarTooltip } from './FunnelStepsBarTooltip'
import {
buildFunnelStepsBarData,
- type FunnelStepsBarSeriesMeta,
resolveFunnelStepClick,
+ withFunnelStepsBarInteraction,
+ type FunnelStepsBarSeriesMeta,
} from './funnelStepsBarTransforms'
const BASE_STEP_WIDTH_PX = 240
@@ -86,13 +87,10 @@ export function FunnelStepsBarChart({
const isBreakdownCompare = steps[0]?.nested_breakdown?.some(
(variant) => variant.compare_label != null && hasBreakdown(variant.breakdown_value)
)
- const config = useMemo(() => {
- const base = isBreakdownCompare ? { ...chartConfig, legend: { show: true, interactive: false } } : chartConfig
- if (quillTooltipEnabled) {
- return { ...base, tooltip: { pinnable: true, placement: 'cursor' as const } }
- }
- return base
- }, [isBreakdownCompare, quillTooltipEnabled])
+ const config = useMemo(
+ () => withFunnelStepsBarInteraction(chartConfig, { isBreakdownCompare, quillTooltipEnabled }),
+ [isBreakdownCompare, quillTooltipEnabled]
+ )
const groupTypeLabel = aggregationLabel(querySource?.aggregation_group_type_index).plural
const showTime = steps.some((step) => step.average_conversion_time != null)
diff --git a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.test.ts b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.test.ts
index 354228725fd6..5c0a0dffaaf9 100644
--- a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.test.ts
+++ b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.test.ts
@@ -1,12 +1,13 @@
-import type { PointClickData, Series } from '@posthog/quill-charts'
+import type { BarChartConfig, PointClickData, Series } from '@posthog/quill-charts'
import { EntityTypes, type FunnelStepWithConversionMetrics } from '~/types'
import {
buildFunnelStepsBarData,
FUNNEL_STEPS_SERIES_KEY_PREFIX,
- type FunnelStepsBarSeriesMeta,
resolveFunnelStepClick,
+ withFunnelStepsBarInteraction,
+ type FunnelStepsBarSeriesMeta,
} from './funnelStepsBarTransforms'
type StepOverrides = Partial<FunnelStepWithConversionMetrics> & { fromBasisStep: number }
@@ -164,3 +165,31 @@ describe('resolveFunnelStepClick', () => {
expect(resolveFunnelStepClick(noBreakdownSteps, makeClick({ dataIndex: 99 }))).toBeNull()
})
})
+
+describe('withFunnelStepsBarInteraction', () => {
+ const baseConfig: BarChartConfig = { barLayout: 'grouped', tooltip: { placement: 'top' } }
+
+ it('returns the base config unchanged when the new tooltip is off', () => {
+ const config = withFunnelStepsBarInteraction(baseConfig, { quillTooltipEnabled: false })
+
+ expect(config).toBe(baseConfig)
+ })
+
+ it('enables a pinnable tooltip that resolves clicks to the nearest series when the new tooltip is on', () => {
+ // A breakdown puts one series per breakdown value at each step, so a pinnable tooltip
+ // here always covers multiple series — resolveClickToNearestSeries must stay set or a
+ // click pins the tooltip instead of opening the persons modal (the bug this guards).
+ const config = withFunnelStepsBarInteraction(baseConfig, { quillTooltipEnabled: true })
+
+ expect(config.tooltip).toEqual({ pinnable: true, resolveClickToNearestSeries: true, placement: 'cursor' })
+ })
+
+ it('adds a static legend for breakdown + compare, independent of the tooltip flag', () => {
+ const config = withFunnelStepsBarInteraction(baseConfig, {
+ isBreakdownCompare: true,
+ quillTooltipEnabled: false,
+ })
+
+ expect(config.legend).toEqual({ show: true, interactive: false })
+ })
+})
diff --git a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.ts b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.ts
index 58dd42b1a2e9..c01dc1f61255 100644
--- a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.ts
+++ b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/funnelStepsBarTransforms.ts
@@ -1,7 +1,8 @@
-import type { PointClickData } from '@posthog/quill-charts'
+import type { BarChartConfig, PointClickData } from '@posthog/quill-charts'
import type { FunnelStepWithConversionMetrics } from '~/types'
+import { INSIGHT_TOOLTIP_CONFIG } from '../../shared/tooltipConfig'
import { RATE_TO_PERCENT } from '../shared/funnelBarHorizontalShared'
import {
buildFunnelStepsBars,
@@ -72,6 +73,25 @@ export function buildFunnelStepsBarData(
return buildFunnelStepsBars(steps, seriesVariants)
}
+/** Derives the chart config from the base config plus the two things that vary per render:
+ * whether the legend is needed (breakdown + compare) and whether the new pinnable tooltip is
+ * enabled. A breakdown always puts one series per breakdown value at each step, so a pinnable
+ * tooltip here always covers multiple series — `resolveClickToNearestSeries` resolves the
+ * click to the nearest one and opens its persons modal directly instead of pinning first. */
+export function withFunnelStepsBarInteraction(
+ baseConfig: BarChartConfig,
+ options: { isBreakdownCompare?: boolean; quillTooltipEnabled: boolean }
+): BarChartConfig {
+ const base = options.isBreakdownCompare ? { ...baseConfig, legend: { show: true, interactive: false } } : baseConfig
+ if (options.quillTooltipEnabled) {
+ return {
+ ...base,
+ tooltip: { ...INSIGHT_TOOLTIP_CONFIG, resolveClickToNearestSeries: true },
+ }
+ }
+ return base
+}
+
export interface FunnelStepClickTarget {
step: FunnelStepWithConversionMetrics
series: FunnelStepWithConversionMetrics