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 hovered breakdown in horizontal funnel tooltip (#67748)

Xanderc840fa040144
diff --git a/frontend/src/scenes/funnels/FunnelTooltip.tsx b/frontend/src/scenes/funnels/FunnelTooltip.tsx
index 9df753e9c0d8..0f8f085166ba 100644
--- a/frontend/src/scenes/funnels/FunnelTooltip.tsx
+++ b/frontend/src/scenes/funnels/FunnelTooltip.tsx
@@ -42,6 +42,8 @@ export interface FunnelTooltipProps {
comparePeriodDateRange?: string | null
/** Baseline conversion rate across all breakdown values; shown only for breakdown variants past the first step. */
aggregateConversionRate?: number | null
+ /** True when the cursor is over the unfilled track area (drop-off region) rather than the bar. */
+ isDropOffHover?: boolean
}
export function FunnelTooltip({
@@ -53,9 +55,26 @@ export function FunnelTooltip({
embedded = false,
comparePeriodDateRange,
aggregateConversionRate,
+ isDropOffHover = false,
}: FunnelTooltipProps): JSX.Element {
const { allCohorts } = useValues(cohortsModel)
const { formatPropertyValueForDisplay } = useValues(propertyDefinitionsModel)
+ const headerLabel = funnelTooltipHeaderLabel({
+ // Pure compare bars (no real breakdown) show only the period; breakdown and
+ // breakdown + compare bars show the breakdown value (plus the period if any).
+ breakdownLabel:
+ !series.compare_label || hasBreakdown(series.breakdown_value)
+ ? formatBreakdownLabel(
+ series.breakdown_value,
+ breakdownFilter,
+ allCohorts.results,
+ formatPropertyValueForDisplay
+ )
+ : null,
+ compareLabel: series.compare_label,
+ comparePeriodDateRange,
+ })
+ const showDropOff = isDropOffHover && stepIndex > 0
return (
<div
data-attr="funnel-tooltip"
@@ -68,64 +87,73 @@ export function FunnelTooltip({
<LemonRow icon={<Lettermark name={stepIndex + 1} color={LettermarkColor.Gray} />} fullWidth>
<strong>
<EntityFilterInfo filter={getActionFilterFromFunnelStep(series)} allowWrap />
- <span className="mx-1">•</span>
- {funnelTooltipHeaderLabel({
- // Pure compare bars (no real breakdown) show only the period; breakdown and
- // breakdown + compare bars show the breakdown value (plus the period if any).
- breakdownLabel:
- !series.compare_label || hasBreakdown(series.breakdown_value)
- ? formatBreakdownLabel(
- series.breakdown_value,
- breakdownFilter,
- allCohorts.results,
- formatPropertyValueForDisplay
- )
- : null,
- compareLabel: series.compare_label,
- comparePeriodDateRange,
- })}
+ {headerLabel && (
+ <>
+ <span className="mx-1">•</span>
+ {headerLabel}
+ </>
+ )}
</strong>
</LemonRow>
<LemonDivider className="my-2" />
<table>
<tbody>
- <tr>
- <td>{stepIndex === 0 ? 'Entered' : 'Converted'}</td>
- <td>{humanFriendlyNumber(series.count)}</td>
- </tr>
- {stepIndex > 0 && (
- <tr>
- <td>Dropped off</td>
- <td>{humanFriendlyNumber(series.droppedOffFromPrevious)}</td>
- </tr>
- )}
- <tr>
- <td>Conversion so far</td>
- <td>{percentage(series.conversionRates.total, 2, true)}</td>
- </tr>
- {stepIndex > 0 && aggregateConversionRate != null && (
- <tr>
- <td>Baseline conversion rate</td>
- <td>{percentage(aggregateConversionRate, 2, true)}</td>
- </tr>
- )}
- {stepIndex > 0 && (
- <tr>
- <td>Conversion from previous</td>
- <td>{percentage(series.conversionRates.fromPrevious, 2, true)}</td>
- </tr>
- )}
- {stepIndex > 0 && series.median_conversion_time != null && (
- <tr>
- <td>Median time from previous</td>
- <td>{humanFriendlyDuration(series.median_conversion_time, { maxUnits: 3 })}</td>
- </tr>
- )}
- {stepIndex > 0 && series.average_conversion_time != null && (
- <tr>
- <td>Average time from previous</td>
- <td>{humanFriendlyDuration(series.average_conversion_time, { maxUnits: 3 })}</td>
- </tr>
+ {showDropOff ? (
+ <>
+ <tr>
+ <td>Dropped off</td>
+ <td>{humanFriendlyNumber(series.droppedOffFromPrevious)}</td>
+ </tr>
+ <tr>
+ <td>Drop-off from previous</td>
+ <td>{percentage(1 - series.conversionRates.fromPrevious, 2, true)}</td>
+ </tr>
+ <tr>
+ <td>Drop-off from start</td>
+ <td>{percentage(1 - series.conversionRates.total, 2, true)}</td>
+ </tr>
+ </>
+ ) : (
+ <>
+ <tr>
+ <td>{stepIndex === 0 ? 'Entered' : 'Converted'}</td>
+ <td>{humanFriendlyNumber(series.count)}</td>
+ </tr>
+ {stepIndex > 0 && (
+ <tr>
+ <td>Dropped off</td>
+ <td>{humanFriendlyNumber(series.droppedOffFromPrevious)}</td>
+ </tr>
+ )}
+ <tr>
+ <td>Conversion so far</td>
+ <td>{percentage(series.conversionRates.total, 2, true)}</td>
+ </tr>
+ {stepIndex > 0 && aggregateConversionRate != null && (
+ <tr>
+ <td>Baseline conversion rate</td>
+ <td>{percentage(aggregateConversionRate, 2, true)}</td>
+ </tr>
+ )}
+ {stepIndex > 0 && (
+ <tr>
+ <td>Conversion from previous</td>
+ <td>{percentage(series.conversionRates.fromPrevious, 2, true)}</td>
+ </tr>
+ )}
+ {stepIndex > 0 && series.median_conversion_time != null && (
+ <tr>
+ <td>Median time from previous</td>
+ <td>{humanFriendlyDuration(series.median_conversion_time, { maxUnits: 3 })}</td>
+ </tr>
+ )}
+ {stepIndex > 0 && series.average_conversion_time != null && (
+ <tr>
+ <td>Average time from previous</td>
+ <td>{humanFriendlyDuration(series.average_conversion_time, { maxUnits: 3 })}</td>
+ </tr>
+ )}
+ </>
)}
</tbody>
</table>
diff --git a/packages/quill/packages/charts/AGENTS.md b/packages/quill/packages/charts/AGENTS.md
index 9ff11c2f9971..6233bc117bfd 100644
--- a/packages/quill/packages/charts/AGENTS.md
+++ b/packages/quill/packages/charts/AGENTS.md
@@ -68,6 +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.
+- 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).
- `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.
diff --git a/packages/quill/packages/charts/src/charts/BarChart/BarChart.test.tsx b/packages/quill/packages/charts/src/charts/BarChart/BarChart.test.tsx
index a78f49b04b09..96db857ca3e9 100644
--- a/packages/quill/packages/charts/src/charts/BarChart/BarChart.test.tsx
+++ b/packages/quill/packages/charts/src/charts/BarChart/BarChart.test.tsx
@@ -269,6 +269,38 @@ describe('BarChart', () => {
expect(tipLow.seriesData.map((s) => s.series.key)).toEqual(['a', 'b'])
})
+ // Mirrors the horizontal funnel bar: breakdown segments plus a tooltip-hidden filler
+ // padding the stack to 100. seriesData keeps declaration order, so consumers need
+ // hoveredSeriesKey to know which segment the cursor is in — including the filler,
+ // which has no seriesData row of its own.
+ it.each<[string, number, string]>([
+ ['first segment', 20, 'a'],
+ ['middle segment', 55, 'b'],
+ ['tooltip-hidden filler segment', 85, 'filler'],
+ ])('stacked exposes hoveredSeriesKey for cursor in the %s', async (_name, valueAtCursor, expectedKey) => {
+ const series: Series[] = [
+ { key: 'a', label: 'A', data: [40] },
+ { key: 'b', label: 'B', data: [30] },
+ { key: 'filler', label: 'Filler', data: [30], visibility: { tooltip: false } },
+ ]
+ const { chart } = renderHogChart(
+ <BarChart
+ series={series}
+ labels={['step']}
+ theme={THEME}
+ config={{ barLayout: 'stacked', axisOrientation: 'horizontal' }}
+ />
+ )
+ // Stack totals 100, so the nice value scale spans [0, 100] across the plot width.
+ fireEvent.mouseMove(chart.element, {
+ clientX: dimensions.plotLeft + (valueAtCursor / 100) * dimensions.plotWidth,
+ clientY: dimensions.plotTop + dimensions.plotHeight / 2,
+ })
+ const tooltip = await chart.waitForTooltip()
+ expect(tooltip.hoveredSeriesKey).toBe(expectedKey)
+ expect(tooltip.seriesData.map((s) => s.series.key)).toEqual(['a', 'b'])
+ })
+
it('stacked onPointClick routes to the segment whose rect contains the cursor', async () => {
const onPointClick = jest.fn()
const { chart } = renderHogChart(
@@ -480,6 +512,7 @@ describe('BarChart', () => {
})
const tooltip = await chart.waitForTooltip()
expect(tooltip.seriesData.map((s) => s.series.key)).toEqual(['b'])
+ expect(tooltip.hoveredSeriesKey).toBe('b')
})
// Regression: grouped clicks always resolved to the first series, so a breakdown
diff --git a/packages/quill/packages/charts/src/charts/BarChart/BarTooltip.tsx b/packages/quill/packages/charts/src/charts/BarChart/BarTooltip.tsx
index c45a9df139ea..16e7027a84dd 100644
--- a/packages/quill/packages/charts/src/charts/BarChart/BarTooltip.tsx
+++ b/packages/quill/packages/charts/src/charts/BarChart/BarTooltip.tsx
@@ -109,6 +109,9 @@ function narrowSeriesByCursor<Meta>(
visibleKey = visible.series.key
visibleDataIndex = visible.dataIndex
}
+ // Surface the hovered identity so consumer tooltips can single out the segment/bar the
+ // cursor is actually over — stacked keeps every segment in seriesData, so index 0 is not it.
+ const hoveredSeriesKey = visibleKey ?? (hits.size === 1 ? hits.values().next().value : undefined)
const filtered = ctx.seriesData.filter((entry) => hits.has(entry.series.key))
// For sparse-stacked overlap ctx.dataIndex is a zero cell for the visible series. Rewrite
// the entry's value (and ctx.dataIndex) to the segment's own index so row clicks route
@@ -123,7 +126,7 @@ function narrowSeriesByCursor<Meta>(
const value = typeof raw === 'number' && Number.isFinite(raw) ? raw : entry.value
return { ...entry, value }
})
- return { ...ctx, seriesData: revalued, dataIndex: di }
+ return { ...ctx, seriesData: revalued, dataIndex: di, hoveredSeriesKey }
}
- return { ...ctx, seriesData: filtered }
+ return { ...ctx, seriesData: filtered, hoveredSeriesKey }
}
diff --git a/packages/quill/packages/charts/src/core/types.ts b/packages/quill/packages/charts/src/core/types.ts
index 3a2a438f8571..ca87c35f7de9 100644
--- a/packages/quill/packages/charts/src/core/types.ts
+++ b/packages/quill/packages/charts/src/core/types.ts
@@ -156,6 +156,13 @@ export interface TooltipContext<Meta = unknown> {
* distance-to-midpoint, giving correct results regardless of segment size differences. */
yPixelBottom?: number
}[]
+ /** Key of the series whose bar/segment is under the cursor. Set only by BarChart's
+ * cursor narrowing (stacked: the visible segment containing the cursor; grouped: the
+ * band-slot hit) — `undefined` for other chart types and for pinned rebuilds with no
+ * cursor. May reference a series hidden from `seriesData` via `visibility.tooltip:
+ * false` (e.g. a drop-off filler segment), so callers must not assume a matching
+ * `seriesData` entry exists. */
+ hoveredSeriesKey?: string
/** Pixel position (relative to the chart container) for anchoring the tooltip.
* `width` (optional) is the horizontal data-extent centered on `x` — bar charts
* populate it with the band width so {@link Tooltip} can anchor at the band edge
diff --git a/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/FunnelBarHorizontalTooltip.tsx b/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/FunnelBarHorizontalTooltip.tsx
index c260476594be..1f50f52962ed 100644
--- a/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/FunnelBarHorizontalTooltip.tsx
+++ b/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/FunnelBarHorizontalTooltip.tsx
@@ -11,7 +11,7 @@ import type { BreakdownFilter } from '~/queries/schema/schema-general'
import type { FunnelStepWithConversionMetrics } from '~/types'
import { FunnelStepTooltip } from '../shared/FunnelStepTooltip'
-import type { FunnelBarHorizontalSegmentMeta } from './funnelBarHorizontalTransforms'
+import { type FunnelBarHorizontalSegmentMeta, resolveFunnelBarHorizontalHover } from './funnelBarHorizontalTransforms'
interface FunnelBarHorizontalTooltipProps {
context: TooltipContext<FunnelBarHorizontalSegmentMeta>
@@ -37,23 +37,17 @@ export function FunnelBarHorizontalTooltip({
const { featureFlags } = useValues(featureFlagLogic)
const quillTooltipEnabled = !!featureFlags[FEATURE_FLAGS.PRODUCT_ANALYTICS_INSIGHTS_TOOLTIPS]
- const entry = context.seriesData[0]
- if (!entry) {
+ const target = resolveFunnelBarHorizontalHover(context, step, stepIndex)
+ if (!target) {
return null
}
- const breakdownIndex = entry.series.meta?.breakdownIndex
- const series =
- breakdownIndex != null && step.nested_breakdown?.[breakdownIndex] ? step.nested_breakdown[breakdownIndex] : step
+ const { series, isDropOffHover, color } = target
const aggregateConversionRate = getFunnelAggregateConversionRate(series, step)
const comparePeriodDateRange = series.compare_label
? funnelComparePeriodDateRange(series.compare_label, resolvedDateRange, compareTo)
: null
- // Horizontal bar chart: cursor right of the bar's end pixel is in the track (drop-off) region.
- const isDropOffHover =
- stepIndex > 0 && context.hoverPosition != null && entry.yPixel != null && context.hoverPosition.x > entry.yPixel
-
const sharedProps = {
showPersonsModal,
stepIndex,
@@ -65,8 +59,8 @@ export function FunnelBarHorizontalTooltip({
}
return quillTooltipEnabled ? (
- <FunnelStepTooltip {...sharedProps} isDropOffHover={isDropOffHover} color={entry.color} />
+ <FunnelStepTooltip {...sharedProps} isDropOffHover={isDropOffHover} color={color} />
) : (
- <FunnelTooltip {...sharedProps} />
+ <FunnelTooltip {...sharedProps} isDropOffHover={isDropOffHover} />
)
}
diff --git a/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/funnelBarHorizontalTransforms.test.ts b/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/funnelBarHorizontalTransforms.test.ts
index f31b07199cef..39f8509b7d65 100644
--- a/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/funnelBarHorizontalTransforms.test.ts
+++ b/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/funnelBarHorizontalTransforms.test.ts
@@ -3,9 +3,11 @@ import { EntityTypes, FunnelStepReference, type FunnelStepWithConversionMetrics
import {
buildFunnelBarHorizontalCompareData,
buildFunnelBarHorizontalData,
+ type FunnelBarHorizontalSegmentMeta,
type FunnelBarHorizontalStepData,
FUNNEL_BAR_HORIZONTAL_FILLER_KEY,
FUNNEL_BAR_HORIZONTAL_SEGMENT_KEY_PREFIX,
+ resolveFunnelBarHorizontalHover,
} from './funnelBarHorizontalTransforms'
type StepOverrides = Partial<FunnelStepWithConversionMetrics> & {
@@ -436,6 +438,83 @@ describe('buildFunnelBarHorizontalData', () => {
})
})
+ describe('resolveFunnelBarHorizontalHover', () => {
+ // Aggregate steps inherit breakdown_value from their first variant (aggregateBreakdownResult
+ // spreads it) — mirrored here so the whole-step case proves the label gets cleared.
+ const step = makeStep({
+ count: 40,
+ fromBasisStep: 0.4,
+ name: 'Signed up',
+ breakdown_value: 'mobile',
+ nested_breakdown: [
+ makeStep({ count: 30, fromBasisStep: 0.5, breakdown_value: 'mobile' }),
+ makeStep({ count: 10, fromBasisStep: 0.25, breakdown_value: 'desktop' }),
+ ],
+ })
+
+ const segmentEntry = (
+ breakdownIndex: number | null,
+ color: string
+ ): {
+ series: { key: string; label: string; data: number[]; meta: FunnelBarHorizontalSegmentMeta }
+ value: number
+ color: string
+ yPixel: number
+ } => ({
+ series: {
+ key: `${FUNNEL_BAR_HORIZONTAL_SEGMENT_KEY_PREFIX}${breakdownIndex ?? 0}`,
+ label: '',
+ data: [0],
+ meta: { isDropOff: false, breakdownIndex },
+ },
+ value: 0,
+ color,
+ yPixel: 100,
+ })
+ const breakdownSeriesData = [segmentEntry(0, '#aaa'), segmentEntry(1, '#bbb')]
+
+ it.each([
+ {
+ description: 'hovering a later breakdown segment resolves that variant, not the first',
+ seriesData: breakdownSeriesData,
+ hoveredSeriesKey: `${FUNNEL_BAR_HORIZONTAL_SEGMENT_KEY_PREFIX}1`,
+ hoverPosition: null,
+ expected: { series: step.nested_breakdown![1], isDropOffHover: false, color: '#bbb' },
+ },
+ {
+ description:
+ 'hovering the filler on a breakdown bar resolves the whole step as drop-off, without the inherited breakdown label',
+ seriesData: breakdownSeriesData,
+ hoveredSeriesKey: FUNNEL_BAR_HORIZONTAL_FILLER_KEY,
+ hoverPosition: null,
+ expected: {
+ series: { ...step, breakdown: undefined, breakdown_value: undefined },
+ isDropOffHover: true,
+ color: undefined,
+ },
+ },
+ {
+ description: 'hovering the filler on a single-segment bar (compare) resolves its variant as drop-off',
+ seriesData: [segmentEntry(1, '#ccc')],
+ hoveredSeriesKey: FUNNEL_BAR_HORIZONTAL_FILLER_KEY,
+ hoverPosition: null,
+ expected: { series: step.nested_breakdown![1], isDropOffHover: true, color: '#ccc' },
+ },
+ {
+ description: 'without a hovered key, falls back to the first segment + cursor-past-end heuristic',
+ seriesData: breakdownSeriesData,
+ hoveredSeriesKey: undefined,
+ hoverPosition: { x: 150, y: 10 },
+ expected: { series: step.nested_breakdown![0], isDropOffHover: true, color: '#aaa' },
+ },
+ ])('$description', ({ seriesData, hoveredSeriesKey, hoverPosition, expected }) => {
+ const target = resolveFunnelBarHorizontalHover({ hoveredSeriesKey, seriesData, hoverPosition }, step, 1)
+ expect(target?.series).toEqual(expected.series)
+ expect(target?.isDropOffHover).toBe(expected.isDropOffHover)
+ expect(target?.color).toBe(expected.color)
+ })
+ })
+
describe('series keys', () => {
it('namespaces segment keys by breakdown index', () => {
const steps = [
diff --git a/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/funnelBarHorizontalTransforms.ts b/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/funnelBarHorizontalTransforms.ts
index 21ee6ff5b814..e1ced3a59af8 100644
--- a/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/funnelBarHorizontalTransforms.ts
+++ b/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/funnelBarHorizontalTransforms.ts
@@ -1,4 +1,4 @@
-import type { Series } from '@posthog/quill-charts'
+import type { Series, TooltipContext } from '@posthog/quill-charts'
import { getReferenceStep, getStepBreakdownSeries } from 'scenes/funnels/funnelUtils'
@@ -7,6 +7,7 @@ import { FunnelStepReference, type FunnelStepWithConversionMetrics } from '~/typ
import {
buildFunnelBarHorizontalFiller,
+ FUNNEL_BAR_HORIZONTAL_FILLER_KEY,
FUNNEL_BAR_HORIZONTAL_SEGMENT_KEY_PREFIX,
RATE_TO_PERCENT,
type FunnelBarHorizontalSegmentMeta,
@@ -119,6 +120,69 @@ export function buildFunnelBarHorizontalCompareData(
})
}
+export interface FunnelBarHorizontalHoverTarget {
+ /** The breakdown variant (or the whole step) the tooltip should describe. */
+ series: FunnelStepWithConversionMetrics
+ /** True when the cursor is over the drop-off filler rather than a converted segment. */
+ isDropOffHover: boolean
+ /** Swatch color for the tooltip header; unset for whole-step drop-off. */
+ color?: string
+}
+
+type FunnelBarHorizontalHoverContext = Pick<
+ TooltipContext<FunnelBarHorizontalSegmentMeta>,
+ 'hoveredSeriesKey' | 'seriesData' | 'hoverPosition'
+>
+
+/** Resolves which breakdown variant a hover maps to. `hoveredSeriesKey` identifies the exact
+ * stacked segment under the cursor (including the tooltip-hidden drop-off filler) — without it,
+ * `seriesData` lists every breakdown segment in declaration order and index 0 is just the first
+ * breakdown, not the hovered one. Returns `null` when there is nothing to describe. */
+export function resolveFunnelBarHorizontalHover(
+ context: FunnelBarHorizontalHoverContext,
+ step: FunnelStepWithConversionMetrics,
+ stepIndex: number
+): FunnelBarHorizontalHoverTarget | null {
+ const { hoveredSeriesKey, seriesData } = context
+ const variantAt = (breakdownIndex: number | null | undefined): FunnelStepWithConversionMetrics =>
+ breakdownIndex != null && step.nested_breakdown?.[breakdownIndex] ? step.nested_breakdown[breakdownIndex] : step
+
+ if (hoveredSeriesKey === FUNNEL_BAR_HORIZONTAL_FILLER_KEY) {
+ // Drop-off region. A lone visible segment (compare bar, plain funnel) shares the filler's
+ // variant, so resolve from it; multiple segments (breakdown) means the whole step's drop-off.
+ // The aggregate step inherits `breakdown_value` from its first variant (aggregateBreakdownResult
+ // spreads it), so clear it — the whole step's drop-off is not one breakdown's.
+ const entry = seriesData.length === 1 ? seriesData[0] : undefined
+ return {
+ series: entry
+ ? variantAt(entry.series.meta?.breakdownIndex)
+ : { ...step, breakdown: undefined, breakdown_value: undefined },
+ isDropOffHover: stepIndex > 0,
+ color: entry?.color,
+ }
+ }
+
+ const hoveredEntry =
+ hoveredSeriesKey != null ? seriesData.find((entry) => entry.series.key === hoveredSeriesKey) : undefined
+ if (hoveredEntry) {
+ return {
+ series: variantAt(hoveredEntry.series.meta?.breakdownIndex),
+ isDropOffHover: false,
+ color: hoveredEntry.color,
+ }
+ }
+
+ // No hovered identity (e.g. a pinned rebuild without a cursor): fall back to the first segment,
+ // inferring drop-off from the cursor sitting past the segment's value-axis end pixel.
+ const entry = seriesData[0]
+ if (!entry) {
+ return null
+ }
+ const isDropOffHover =
+ stepIndex > 0 && context.hoverPosition != null && entry.yPixel != null && context.hoverPosition.x > entry.yPixel
+ return { series: variantAt(entry.series.meta?.breakdownIndex), isDropOffHover, color: entry.color }
+}
+
function buildSingleSegment(
step: FunnelStepWithConversionMetrics,
options: BuildOptions
diff --git a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarTooltip.tsx b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarTooltip.tsx
index 3d4aa47f7c2b..3ba104a45313 100644
--- a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarTooltip.tsx
+++ b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarTooltip.tsx
@@ -66,6 +66,6 @@ export function FunnelStepsBarTooltip({
return quillTooltipEnabled ? (
<FunnelStepTooltip {...sharedProps} isDropOffHover={isDropOffHover} color={entry.color} />
) : (
- <FunnelTooltip {...sharedProps} />
+ <FunnelTooltip {...sharedProps} isDropOffHover={isDropOffHover} />
)
}