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.

feat(insights): hog-charts funnel steps polish + value-label hover lift (#60187)

Sam Pennington4e65bd7b5ec7
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 57584890a358..c01000261e2a 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -1937,7 +1937,7 @@ snapshots:
insights-funnellinechart--goal-line--light:
hash: v1.k794b7964.35b2f6e08b22e8b95c561f10f4a3eeee0ec5355d91aa166db2cc3595f2acc4ae.iqDGpipKH0res85GZFCYszkpygWdzEM7lweEmg62j6M
insights-funnellinechart--value-labels--dark:
- hash: v1.k794b7964.0c55587cfcea1fc34a6aede2eccbaac54ac296aa405d1272fc3c09efc1d02a6b.7kVLiv-W7Mk_5t8YKcXB2IM_ikwvMm5ssyT_uxoJvfw
+ hash: v1.k794b7964.9f05354844d8a29900c3fba2935a6ec9cf9dd96fc551f3f168676c542ed26756.2yYVFNpvKafjwUYgCe8YHYVPxzWp2rZk1BA035aMRPQ
insights-funnellinechart--value-labels--light:
hash: v1.k794b7964.746ea8a29d8e924baa6e7384d7a3a4a357727d37877668d15caae4fe2fcb4398.NoQWMVJ_C7Tw-ejmNiYdWnToUC5v0SdTi7OL5e6TrIo
insights-funnelpropertycorrelationtable--default--dark:
@@ -1945,13 +1945,13 @@ snapshots:
insights-funnelpropertycorrelationtable--default--light:
hash: v1.k794b7964.46127dfa894a9b46a595c1b48b9bd8996a2851ce5ae04e70c4f1ee43d2d818ec.dddj8FIYUsb6XDaYbe4eQ_k4bJ5NY2kvo6m3KFS3Vwg
insights-funnelstepsbarchart--breakdown--dark:
- hash: v1.k794b7964.4fdfbf1fced53a530a770c9e757892faefb8fb6ba5e2c664d175562441dc33af.4CZffzRTcE99pBKIvo6o7ggKeXPU7bmpzslEM0DFAEM
+ hash: v1.k794b7964.94617507a1b49bddbd663dc4498d6189977c559aab97b8190621e070230bc8b2.NMRs4pet51Wc-J6xIGjyQcv_VCAKl4ZZtr6RfYLaqUk
insights-funnelstepsbarchart--breakdown--light:
- hash: v1.k794b7964.d57f0a6959ac0bb6a84f2914bce51d44dafabd09b166d39c095263b3ab82e9e5.q_Zv6bRyEI9gx7WVcyh0YoQT4ym68bZJt5Xmy-NvS9Q
+ hash: v1.k794b7964.11a6150cd4d624ea803386b5295c61efe16cc0564548d7b035fb2605c6a8930b._GcZUhCuEWqr9LTrGqjFS6wjt5SKR9eJXTtK2ADXih4
insights-funnelstepsbarchart--default--dark:
- hash: v1.k794b7964.2ae1ba07ab95585978ce1828ce81125d0285e2e8a9c83b70d8040c809fe83005.XZhWCtYy8v4FXcMk-Oxruk9K0AvIy_V8Q1-CicVQHHg
+ hash: v1.k794b7964.4f5c0e9fb7907950d12c5ae90aef213eac07353a1e45102e4c5ec646413bcd40.2srh4MBJkGURgf-ZfiOmmEnkyVi1RvpRG-GW23QyykE
insights-funnelstepsbarchart--default--light:
- hash: v1.k794b7964.3c1fc6cc15dda94c60eb841cfeaa6496c9adb21171c49ee28c11c456de9a2b57.CMa3pHrAA_2KEuBwIPzWi5moIIiByHasJtnx-LVe0gQ
+ hash: v1.k794b7964.07679a2d2baaff185b71e5040a6e40e3c43cc38dd07b2277271e3b4950e648a6.I5hkW4tlRFnOGapBnuZ0-uJReW-Svbr9IBAU5a9JzRw
insights-insightstable--aggregation--dark:
hash: v1.k794b7964.7ca9378b33815143119b6263ad32770289133ce2faa21251189b505821d7d846.NXyGQGn0JrsrEWfzXtZTntAvvx5CSTKBLXWWdzgkCI8
insights-insightstable--aggregation--light:
@@ -4781,7 +4781,7 @@ snapshots:
scenes-app-insights-funnels--funnel-left-to-right-edit-viewports--wide--dark:
hash: v1.k794b7964.293297b83994468984576e5c15fa2cbbb2c4c0a7a8234959b9deba539efa383b.O7SwG4Drfr3z02hcLNC1LsLsGWddouhybBp4xZaUE-A
scenes-app-insights-funnels--funnel-left-to-right-edit-viewports--wide--light:
- hash: v1.k794b7964.c63132bb5b13cbe97938ebdb2e59e320ebc338bd12b2d3bfd6af81e56270650a.KSiw8WpvjWXIDh87ExL4cPnopVJlTXvzU8N8ruh6Hi8
+ hash: v1.k794b7964.6c391cbc05b64230fbd8defdbb960b131fd433409817497873fb9ffc705cd360.EIwByuofuT77yP259A9ffqfjSFwW9MrUDOvsZNA_aZM
scenes-app-insights-funnels--funnel-time-to-convert--dark:
hash: v1.k794b7964.d64808d2bfc36017f89b57feeaa373e20188738a622801207fa1beb59d02fdd9.cFuKF_Ow887Z3X3BoNhtTvkUWY2vips9HDBe-B02eQE
scenes-app-insights-funnels--funnel-time-to-convert--light:
diff --git a/frontend/src/lib/hog-charts/charts/BarChart/BarChart.tsx b/frontend/src/lib/hog-charts/charts/BarChart/BarChart.tsx
index 31d67520ab08..4b89ee38b2a8 100644
--- a/frontend/src/lib/hog-charts/charts/BarChart/BarChart.tsx
+++ b/frontend/src/lib/hog-charts/charts/BarChart/BarChart.tsx
@@ -1,10 +1,11 @@
import * as d3 from 'd3'
-import React, { useCallback, useMemo } from 'react'
+import React, { useCallback, useMemo, useRef } from 'react'
import { type BarChartPrivate, computeBarAtIndex, computeBarTrackRect, computeSeriesBars } from '../../core/bar-layout'
import {
BAR_TRACK_HOVER_ALPHA,
type BarRect,
+ type BarShadow,
drawBarHighlight,
drawBars,
drawBarTracks,
@@ -30,6 +31,7 @@ import type {
ChartScales,
ChartTheme,
CreateScalesFn,
+ DrawHoverResult,
PointClickData,
ResolvedSeries,
Series,
@@ -71,6 +73,19 @@ export interface BarChartProps<Meta = unknown> {
onError?: (error: Error, info: React.ErrorInfo) => void
}
+// Negative offsetY casts the shadow upward onto the visible track above the bar.
+const DEFAULT_BAR_SHADOW: BarShadow = { color: 'rgba(0,0,0,0.30)', blur: 12, offsetY: -4 }
+
+function resolveBarShadow(barShadow: BarChartConfig['barShadow']): BarShadow | undefined {
+ if (barShadow === true) {
+ return DEFAULT_BAR_SHADOW
+ }
+ if (barShadow === false || barShadow == null) {
+ return undefined
+ }
+ return barShadow
+}
+
export function BarChart<Meta = unknown>({ onError, ...rest }: BarChartProps<Meta>): React.ReactElement {
return (
<ChartErrorBoundary onError={onError}>
@@ -99,6 +114,8 @@ function BarChartInner<Meta = unknown>({
axisOrientation = 'vertical',
xTickFormatter,
divergingStack = false,
+ maxBandRange,
+ barShadow,
} = config ?? {}
const isHorizontal = axisOrientation === 'horizontal'
@@ -170,6 +187,7 @@ function BarChartInner<Meta = unknown>({
barLayout,
axisOrientation,
stackedSeries,
+ maxBandRange,
})
const tickAxisLength = isHorizontal ? dimensions.plotWidth : dimensions.plotHeight
@@ -196,10 +214,17 @@ 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()),
_private: barChartPrivate,
}
},
- [yScaleType, barLayout, axisOrientation, stackedData, isHorizontal, divergingStack]
+ [yScaleType, barLayout, axisOrientation, stackedData, isHorizontal, divergingStack, maxBandRange]
)
const drawStatic = useCallback(
@@ -269,25 +294,59 @@ function BarChartInner<Meta = unknown>({
}
}
+ const resolvedShadow = resolveBarShadow(barShadow)
+ // Clip to plot area so a 100% bar's upward shadow doesn't bleed past the chart edge.
+ if (resolvedShadow) {
+ ctx.save()
+ ctx.beginPath()
+ ctx.rect(dimensions.plotLeft, dimensions.plotTop, dimensions.plotWidth, dimensions.plotHeight)
+ ctx.clip()
+ ctx.shadowColor = resolvedShadow.color
+ ctx.shadowBlur = resolvedShadow.blur
+ ctx.shadowOffsetX = resolvedShadow.offsetX ?? 0
+ ctx.shadowOffsetY = resolvedShadow.offsetY ?? 0
+ }
for (const { series: s, bars } of seriesBars) {
drawBars(baseDrawCtx, s, bars, barCornerRadius)
}
+ if (resolvedShadow) {
+ ctx.restore()
+ }
},
- [showGrid, stackedData, barLayout, isHorizontal, topStackedKeyByAxis, barCornerRadius, barTrack, xTickFormatter]
+ [
+ showGrid,
+ stackedData,
+ barLayout,
+ isHorizontal,
+ topStackedKeyByAxis,
+ barCornerRadius,
+ barTrack,
+ xTickFormatter,
+ barShadow,
+ ]
)
+ // Restart the fade on bar → track moves (same hoverIndex, different visible state).
+ const lastHoverKeyRef = useRef<string | null>(null)
+
const drawHover = useCallback(
- ({ ctx, scales, series: coloredSeries, labels: drawLabels, hoverIndex, hoverPosition }: ChartDrawArgs) => {
+ ({
+ ctx,
+ scales,
+ series: coloredSeries,
+ labels: drawLabels,
+ hoverIndex,
+ hoverPosition,
+ hoverProgress,
+ resetHoverFade,
+ }: ChartDrawArgs): DrawHoverResult => {
const d3Scales = (scales._private as BarChartPrivate | undefined)?.__barChart
if (!d3Scales || hoverIndex < 0) {
- return
+ lastHoverKeyRef.current = null
+ return false
}
const hoveredLabel = drawLabels[hoverIndex]
- // Hoisted out of the per-series loop below — the value-axis range doesn't
- // depend on which series the cursor is over.
const [trackAxisStart = 0, trackAxisEnd = 0] = barTrack ? d3Scales.value.range() : []
- // Narrow to bars whose band-axis extent contains the cursor; an empty hit set
- // means the cursor is in a gap, so draw nothing.
let hitKeys: Set<string> | null = null
if (hoverPosition) {
const hits = seriesKeysAtCursor({
@@ -302,10 +361,16 @@ function BarChartInner<Meta = unknown>({
topStackedKeyByAxis,
})
if (hits.size === 0) {
- return
+ lastHoverKeyRef.current = null
+ return false
}
hitKeys = hits
}
+ // Key includes bar-vs-track per series so bar → track moves at the same
+ // hoverIndex still trigger a fade restart.
+ type DrawItem = { series: ResolvedSeries; bar: BarRect; isTrackHighlight: boolean }
+ const items: DrawItem[] = []
+ let composition = ''
for (const s of coloredSeries) {
if (s.visibility?.excluded) {
continue
@@ -329,18 +394,31 @@ function BarChartInner<Meta = unknown>({
if (!bar) {
continue
}
- // Over the track region above the bar: highlight the track instead of the bar.
- // A translucent series-color fill leaves the opaque bar unchanged but tints
- // the faint hatched track.
- if (
- barTrack &&
+ const isTrackHighlight =
+ barTrack === true &&
barLayout === 'grouped' &&
- hoverPosition &&
+ hoverPosition != null &&
cursorOutsideBarFillExtent(bar, hoverPosition, isHorizontal)
- ) {
+ items.push({ series: s, bar, isTrackHighlight })
+ composition += isTrackHighlight ? 't' : 'b'
+ }
+ if (items.length === 0) {
+ lastHoverKeyRef.current = null
+ return false
+ }
+ const currentKey = `${hoverIndex}:${composition}`
+ let alpha = hoverProgress
+ if (currentKey !== lastHoverKeyRef.current) {
+ alpha = resetHoverFade()
+ lastHoverKeyRef.current = currentKey
+ }
+ ctx.save()
+ ctx.globalAlpha = alpha
+ for (const { series: s, bar, isTrackHighlight } of items) {
+ if (isTrackHighlight) {
const parsed = d3.color(s.color)
- // Always translucent — falling back to `s.color` directly would paint
- // an opaque full-plot-height block if d3 can't parse the series color.
+ // Always translucent — `s.color` direct would paint an opaque full-height
+ // block if d3 can't parse the color.
let trackColor: string
if (parsed) {
parsed.opacity = BAR_TRACK_HOVER_ALPHA
@@ -359,6 +437,8 @@ function BarChartInner<Meta = unknown>({
drawBarHighlight(ctx, bar, highlightColor, barCornerRadius)
}
}
+ ctx.restore()
+ return true
},
[stackedData, barLayout, isHorizontal, topStackedKeyByAxis, barCornerRadius, barTrack]
)
diff --git a/frontend/src/lib/hog-charts/charts/LineChart.tsx b/frontend/src/lib/hog-charts/charts/LineChart.tsx
index 2bdb900493e3..14065c972a52 100644
--- a/frontend/src/lib/hog-charts/charts/LineChart.tsx
+++ b/frontend/src/lib/hog-charts/charts/LineChart.tsx
@@ -210,10 +210,11 @@ function LineChartInner<Meta = unknown>({
)
const drawHover = useCallback(
- ({ ctx, scales, series: coloredSeries, labels: drawLabels, hoverIndex, theme }: ChartDrawArgs) => {
+ ({ ctx, scales, series: coloredSeries, labels: drawLabels, hoverIndex, theme }: ChartDrawArgs): boolean => {
if (hoverIndex < 0) {
- return
+ return false
}
+ let drewAny = false
for (const s of coloredSeries) {
if (s.visibility?.excluded || s.fill?.lowerData) {
continue
@@ -229,8 +230,10 @@ function LineChartInner<Meta = unknown>({
const y = resolveYScaleForSeries(scales, s)(data[hoverIndex])
if (x != null && isFinite(y)) {
drawHighlightPoint(ctx, x, y, s.color, theme.backgroundColor ?? '#ffffff')
+ drewAny = true
}
}
+ return drewAny
},
[stackedData]
)
diff --git a/frontend/src/lib/hog-charts/charts/PieChart/PieChart.tsx b/frontend/src/lib/hog-charts/charts/PieChart/PieChart.tsx
index 1e18ef3d0fe7..2345daaafe14 100644
--- a/frontend/src/lib/hog-charts/charts/PieChart/PieChart.tsx
+++ b/frontend/src/lib/hog-charts/charts/PieChart/PieChart.tsx
@@ -146,25 +146,25 @@ function PieChartInner<Meta = unknown>({
}, [])
const drawHover = useCallback(
- (args: ChartDrawArgs) => {
+ (args: ChartDrawArgs): boolean => {
const layout = getLayoutFromArgs<Meta>(args)
if (!layout || args.hoverIndex < 0) {
- return
+ return false
}
// Single-slice charts have nothing to pop out — drawing the offset would visually
// shift the whole wheel.
if (layout.slices.length <= 1 || effectiveHoverOffset === 0) {
- return
+ return false
}
// The mask step below relies on `theme.backgroundColor` to erase the static-canvas
// copy of the slice. Without one, the popped-out slice would partially overlap the
// original and smear — better to skip the pop-out than render that.
if (!args.theme.backgroundColor) {
- return
+ return false
}
const slice = layout.slices[args.hoverIndex]
if (!slice) {
- return
+ return false
}
// Two-pass paint on the (always-cleared) overlay canvas:
// 1. Fill the slice's original footprint with the theme background. The overlay
@@ -183,6 +183,7 @@ function PieChartInner<Meta = unknown>({
fillStyle: slice.color,
withStroke: layout.slices.length > 1 ? args.theme.backgroundColor : undefined,
})
+ return true
},
[effectiveHoverOffset]
)
diff --git a/frontend/src/lib/hog-charts/core/Chart.tsx b/frontend/src/lib/hog-charts/core/Chart.tsx
index ebeda6276972..d128faadfa4b 100644
--- a/frontend/src/lib/hog-charts/core/Chart.tsx
+++ b/frontend/src/lib/hog-charts/core/Chart.tsx
@@ -21,6 +21,7 @@ import type {
ChartScales,
ChartTheme,
CreateScalesFn,
+ DrawHoverResult,
PointClickData,
ResolvedSeries,
ResolveValueFn,
@@ -55,6 +56,17 @@ const OVERLAY_CANVAS_STYLE: React.CSSProperties = {
pointerEvents: 'none',
}
const DEFAULT_AXIS_COLOR = 'rgba(0, 0, 0, 0.5)'
+const DEFAULT_HOVER_ANIMATION_MS = 150
+
+function resolveHoverAnimationMs(animateHover: boolean | number | undefined): number {
+ if (animateHover === true) {
+ return DEFAULT_HOVER_ANIMATION_MS
+ }
+ if (typeof animateHover === 'number') {
+ return animateHover
+ }
+ return 0
+}
function OverlayLayer({ children }: { children: React.ReactNode }): React.ReactElement {
return <div style={OVERLAY_STYLE}>{children}</div>
@@ -68,8 +80,9 @@ export interface ChartProps<Meta = unknown> {
createScales: CreateScalesFn
/** Static layer — grid, lines, areas, points. Redrawn only when chart inputs change. */
drawStatic: (args: ChartDrawArgs) => void
- /** Hover overlay — highlight rings only. Redrawn on every hoverIndex change. */
- drawHover: (args: ChartDrawArgs) => void
+ /** Hover overlay — highlight rings only. Return `false` if nothing was drawn (the
+ * hover-fade timer pauses while invisible). */
+ drawHover: (args: ChartDrawArgs) => DrawHoverResult
tooltip?: (ctx: TooltipContext<Meta>) => React.ReactNode
onPointClick?: (data: PointClickData<Meta>) => void
className?: string
@@ -121,8 +134,10 @@ export function Chart<Meta = unknown>({
showCrosshair = false,
axisOrientation = 'vertical',
isPercent = false,
+ animateHover,
margins: marginsOverride,
} = config ?? {}
+ const hoverAnimationMs = resolveHoverAnimationMs(animateHover)
const interactionAxis: 'x' | 'y' = axisOrientation === 'horizontal' ? 'y' : 'x'
const {
enabled: showTooltip = true,
@@ -204,6 +219,7 @@ export function Chart<Meta = unknown>({
theme,
drawStatic,
drawHover: composedDrawHover,
+ hoverAnimationMs,
})
const wrapperStyle = hoverIndex >= 0 && onPointClick ? WRAPPER_STYLE_POINTER : WRAPPER_STYLE_DEFAULT
diff --git a/frontend/src/lib/hog-charts/core/RadialChart.tsx b/frontend/src/lib/hog-charts/core/RadialChart.tsx
index 8b866621e74a..519a41c0e3cf 100644
--- a/frontend/src/lib/hog-charts/core/RadialChart.tsx
+++ b/frontend/src/lib/hog-charts/core/RadialChart.tsx
@@ -16,6 +16,7 @@ import type {
ChartMargins,
ChartScales,
ChartTheme,
+ DrawHoverResult,
ResolvedSeries,
Series,
TooltipContext,
@@ -65,7 +66,7 @@ export interface RadialChartProps<Meta = unknown> {
theme: ChartTheme
buildLayout: RadialLayoutBuilder<Meta>
drawStatic: (args: ChartDrawArgs) => void
- drawHover: (args: ChartDrawArgs) => void
+ drawHover: (args: ChartDrawArgs) => DrawHoverResult
tooltip?: (ctx: TooltipContext<Meta>) => React.ReactNode
showTooltip?: boolean
onSliceClick?: (payload: RadialSlicePayload<Meta>) => void
diff --git a/frontend/src/lib/hog-charts/core/canvas-renderer.test.ts b/frontend/src/lib/hog-charts/core/canvas-renderer.test.ts
index bb0391491251..3a9585102a74 100644
--- a/frontend/src/lib/hog-charts/core/canvas-renderer.test.ts
+++ b/frontend/src/lib/hog-charts/core/canvas-renderer.test.ts
@@ -607,6 +607,8 @@ describe('hog-charts canvas-renderer', () => {
hoverIndex,
hoverPosition: null,
theme: {} as ChartTheme,
+ hoverProgress: 1,
+ resetHoverFade: () => 0,
}
}
diff --git a/frontend/src/lib/hog-charts/core/canvas-renderer.ts b/frontend/src/lib/hog-charts/core/canvas-renderer.ts
index 7e5aaa9e129e..553104e7cee3 100644
--- a/frontend/src/lib/hog-charts/core/canvas-renderer.ts
+++ b/frontend/src/lib/hog-charts/core/canvas-renderer.ts
@@ -1,7 +1,7 @@
import * as d3 from 'd3'
import { yTickCountForHeight } from './scales'
-import type { ChartDimensions, ChartDrawArgs, ResolvedSeries } from './types'
+import type { ChartDimensions, ChartDrawArgs, DrawHoverResult, ResolvedSeries } from './types'
export interface DrawContext {
ctx: CanvasRenderingContext2D
@@ -478,8 +478,15 @@ export interface BarRect {
export const DEFAULT_BAR_CORNER_RADIUS = 4
-/** Hatch ranges (`series.stroke?.partial`) clamp against `series.data.length`; callers may
- * pre-filter `bars` without shifting the hatch boundary. */
+export interface BarShadow {
+ color: string
+ blur: number
+ offsetX?: number
+ offsetY?: number
+}
+
+/** Hatch ranges (`series.stroke?.partial`) clamp against `series.data.length`. Any ctx
+ * state (shadow / clip / globalAlpha) is the caller's responsibility. */
export function drawBars(
drawCtx: DrawContext,
series: ResolvedSeries,
@@ -587,7 +594,7 @@ export function drawHighlightPoint(
ctx.fill()
}
-type DrawHoverFn = (args: ChartDrawArgs) => void
+type DrawHoverFn = (args: ChartDrawArgs) => DrawHoverResult
interface ComposeDrawHoverOptions {
crosshairColor: string | undefined
@@ -610,6 +617,6 @@ export function composeDrawHoverWithCrosshair(
drawCrosshair(args.ctx, args.dimensions, coord, crosshairColor, axisOrientation)
}
}
- getDrawHover()(args)
+ return getDrawHover()(args)
}
}
diff --git a/frontend/src/lib/hog-charts/core/hooks/useChartDraw.ts b/frontend/src/lib/hog-charts/core/hooks/useChartDraw.ts
index cdd7a9d408a8..314805b6c09d 100644
--- a/frontend/src/lib/hog-charts/core/hooks/useChartDraw.ts
+++ b/frontend/src/lib/hog-charts/core/hooks/useChartDraw.ts
@@ -1,6 +1,7 @@
import { useEffect, useRef } from 'react'
-import type { ChartDimensions, ChartDrawArgs, ChartScales, ChartTheme, ResolvedSeries } from '../types'
+import type { ChartDimensions, ChartDrawArgs, ChartScales, ChartTheme, DrawHoverResult, ResolvedSeries } from '../types'
+import { useLatest } from './useLatest'
interface UseChartDrawOptions {
/** Context for the static layer (grid, lines, areas, points). Redrawn only when chart inputs change. */
@@ -15,7 +16,9 @@ interface UseChartDrawOptions {
hoverPosition: { x: number; y: number } | null
theme: ChartTheme
drawStatic: (args: ChartDrawArgs) => void
- drawHover: (args: ChartDrawArgs) => void
+ drawHover: (args: ChartDrawArgs) => DrawHoverResult
+ /** Duration (ms) of the hover-overlay fade-in. `0` disables. */
+ hoverAnimationMs?: number
}
function clearAndPrepare(ctx: CanvasRenderingContext2D, dimensions: ChartDimensions): void {
@@ -37,15 +40,25 @@ export function useChartDraw({
theme,
drawStatic,
drawHover,
+ hoverAnimationMs = 0,
}: UseChartDrawOptions): void {
- // Track the in-flight RAF id in a ref so each new effect run can cancel the previous
- // RAF before scheduling its own. Relying on the React cleanup ordering alone leaves
- // a window where a stale RAF from render N-1 can paint after render N's setup runs.
+ // Cancel the prior RAF on effect re-run — relying on cleanup ordering alone leaves a
+ // window where a stale RAF can paint after the new setup runs.
const staticRafRef = useRef<number | null>(null)
const hoverRafRef = useRef<number | null>(null)
+ const hoverAnimRef = useRef<{ idx: number; startTime: number }>({ idx: -1, startTime: 0 })
+ // Freezes the fade timer while invisible (cursor in a band gap) so the fade always
+ // starts at progress 0 when something visible first appears.
+ const drewVisibleRef = useRef(false)
+ // Mirror everything that changes per-mousemove so the hover effect's dep array stays
+ // small — otherwise we'd tear down and re-arm the RAF every mouse pixel.
+ const drawHoverRef = useLatest(drawHover)
+ const hoverPositionRef = useLatest(hoverPosition)
+ const seriesRef = useLatest(series)
+ const labelsRef = useLatest(labels)
+ const themeRef = useLatest(theme)
- // Static layer — redraws only when chart inputs change. Excluded `hoverIndex` from deps
- // on purpose so a hover sweep doesn't repaint every line/area/point per move.
+ // hoverIndex is deliberately not a dep — a hover sweep shouldn't repaint the static layer.
useEffect(() => {
if (staticRafRef.current != null) {
cancelAnimationFrame(staticRafRef.current)
@@ -57,7 +70,18 @@ export function useChartDraw({
staticRafRef.current = requestAnimationFrame(() => {
staticRafRef.current = null
clearAndPrepare(ctx, dimensions)
- drawStatic({ ctx, dimensions, scales, series, labels, hoverIndex: -1, hoverPosition: null, theme })
+ drawStatic({
+ ctx,
+ dimensions,
+ scales,
+ series,
+ labels,
+ hoverIndex: -1,
+ hoverPosition: null,
+ theme,
+ hoverProgress: 1,
+ resetHoverFade: () => 1,
+ })
ctx.restore()
})
return () => {
@@ -66,12 +90,11 @@ export function useChartDraw({
staticRafRef.current = null
}
}
- // hoverIndex deliberately omitted — see comment above.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ctx, dimensions, scales, series, labels, theme, drawStatic])
- // Hover overlay — redraws only when hoverIndex changes (or chart inputs do). Cheap path:
- // clears the overlay canvas and draws a few highlight rings per series, nothing else.
+ // The RAF loop ticks until hoverProgress reaches 1, then exits and waits for the next
+ // dep change. Timer is held in a ref so cancel/restart cycles resume the fade smoothly.
useEffect(() => {
if (hoverRafRef.current != null) {
cancelAnimationFrame(hoverRafRef.current)
@@ -80,17 +103,57 @@ export function useChartDraw({
if (!overlayCtx || !dimensions || !scales) {
return
}
- hoverRafRef.current = requestAnimationFrame(() => {
- hoverRafRef.current = null
+ // Restart the fade on hoverIndex change — invalidate drewVisible too so the next
+ // visible frame starts at progress 0, not where the previous bar's fade left off.
+ if (hoverIndex !== hoverAnimRef.current.idx) {
+ hoverAnimRef.current.idx = hoverIndex
+ hoverAnimRef.current.startTime = performance.now()
+ drewVisibleRef.current = false
+ }
+ const resetHoverFade = (): number => {
+ hoverAnimRef.current.startTime = performance.now()
+ return 0
+ }
+ const tick = (): void => {
+ // Pin progress to 0 while invisible — see drewVisibleRef comment above.
+ if (!drewVisibleRef.current) {
+ hoverAnimRef.current.startTime = performance.now()
+ }
+ const elapsed = performance.now() - hoverAnimRef.current.startTime
+ const hoverProgress = hoverAnimationMs > 0 ? Math.min(1, elapsed / hoverAnimationMs) : 1
clearAndPrepare(overlayCtx, dimensions)
- drawHover({ ctx: overlayCtx, dimensions, scales, series, labels, hoverIndex, hoverPosition, theme })
+ const drewVisible = drawHoverRef.current({
+ ctx: overlayCtx,
+ dimensions,
+ scales,
+ series: seriesRef.current,
+ labels: labelsRef.current,
+ hoverIndex,
+ hoverPosition: hoverPositionRef.current,
+ theme: themeRef.current,
+ hoverProgress,
+ resetHoverFade,
+ })
overlayCtx.restore()
- })
+ drewVisibleRef.current = drewVisible
+ // Recompute after the draw — the chart type may have called resetHoverFade
+ // mid-draw, which would leave the cached hoverProgress stale.
+ const liveElapsed = performance.now() - hoverAnimRef.current.startTime
+ const liveProgress = hoverAnimationMs > 0 ? Math.min(1, liveElapsed / hoverAnimationMs) : 1
+ if (drewVisible && liveProgress < 1 && hoverIndex >= 0) {
+ hoverRafRef.current = requestAnimationFrame(tick)
+ } else {
+ hoverRafRef.current = null
+ }
+ }
+ hoverRafRef.current = requestAnimationFrame(tick)
return () => {
if (hoverRafRef.current != null) {
cancelAnimationFrame(hoverRafRef.current)
hoverRafRef.current = null
}
}
- }, [overlayCtx, dimensions, scales, series, labels, hoverIndex, hoverPosition, theme, drawHover])
+ // series/labels/theme/hoverPosition/drawHover are read via refs — see top of hook.
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [overlayCtx, dimensions, scales, hoverIndex, hoverAnimationMs])
}
diff --git a/frontend/src/lib/hog-charts/core/hooks/useChartInteraction.ts b/frontend/src/lib/hog-charts/core/hooks/useChartInteraction.ts
index e49c4fc4f3f8..8243cf74dfee 100644
--- a/frontend/src/lib/hog-charts/core/hooks/useChartInteraction.ts
+++ b/frontend/src/lib/hog-charts/core/hooks/useChartInteraction.ts
@@ -94,7 +94,8 @@ export function useChartInteraction<Meta = unknown>({
scales.yAxes,
interactionAxis,
prev.hoverPosition,
- effectivePositionResolveRef.current
+ effectivePositionResolveRef.current,
+ scales.extent?.(labels[prev.dataIndex])
)
},
// resolveValueRef / effectivePositionResolveRef are stable
@@ -162,7 +163,8 @@ export function useChartInteraction<Meta = unknown>({
scales.yAxes,
interactionAxis,
{ x: mouseX, y: mouseY },
- effectivePositionResolve
+ effectivePositionResolve,
+ scales.extent?.(labels[index])
)
)
}
diff --git a/frontend/src/lib/hog-charts/core/interaction.ts b/frontend/src/lib/hog-charts/core/interaction.ts
index 9eecbc1ca3ba..942d25c7e30f 100644
--- a/frontend/src/lib/hog-charts/core/interaction.ts
+++ b/frontend/src/lib/hog-charts/core/interaction.ts
@@ -74,7 +74,10 @@ export function buildTooltipContext<Meta = unknown>(
/** Resolves the value used to *anchor* the tooltip per series. Defaults to `resolveValue`.
* Stacked charts pass the stacked-top resolver here so the anchor lands at the visual top
* of each segment while each tooltip row still shows its own value via `resolveValue`. */
- resolvePositionValue: ResolveValueFn = resolveValue
+ resolvePositionValue: ResolveValueFn = resolveValue,
+ /** Optional horizontal data-extent centered on the categorical axis position — bar charts
+ * pass band width so the tooltip can anchor at the band edge instead of its center. */
+ positionExtent?: number
): TooltipContext<Meta> | null {
if (dataIndex < 0 || dataIndex >= labels.length) {
return null
@@ -111,7 +114,11 @@ export function buildTooltipContext<Meta = unknown>(
valueAnchor = interactionAxis === 'y' ? Math.max(...valuePixels) : Math.min(...valuePixels)
}
- const position = interactionAxis === 'y' ? { x: valueAnchor, y: bandPixel } : { x: bandPixel, y: valueAnchor }
+ const position: TooltipContext<Meta>['position'] =
+ interactionAxis === 'y' ? { x: valueAnchor, y: bandPixel } : { x: bandPixel, y: valueAnchor }
+ if (positionExtent != null && positionExtent > 0) {
+ position.width = positionExtent
+ }
return {
dataIndex,
diff --git a/frontend/src/lib/hog-charts/core/scales.ts b/frontend/src/lib/hog-charts/core/scales.ts
index fb739e6471d7..f62830a80302 100644
--- a/frontend/src/lib/hog-charts/core/scales.ts
+++ b/frontend/src/lib/hog-charts/core/scales.ts
@@ -319,6 +319,8 @@ export function createBarScales(
bandPadding?: number
groupPadding?: number
stackedSeries?: Series[]
+ /** Cap on the band-axis range in px — clusters bars at the start of the plot when set. */
+ maxBandRange?: number
} = {}
): BarScaleSet {
const {
@@ -328,19 +330,19 @@ export function createBarScales(
bandPadding = 0.2,
groupPadding = 0.1,
stackedSeries,
+ maxBandRange,
} = options
const isHorizontal = axisOrientation === 'horizontal'
const tickCount = yTickCountForHeight(isHorizontal ? dimensions.plotWidth : dimensions.plotHeight)
+ const bandAxisStart = isHorizontal ? dimensions.plotTop : dimensions.plotLeft
+ const bandAxisExtent = isHorizontal ? dimensions.plotHeight : dimensions.plotWidth
+ const cappedExtent = maxBandRange != null ? Math.min(bandAxisExtent, maxBandRange) : bandAxisExtent
const band = d3
.scaleBand<string>()
.domain(labels)
- .range(
- isHorizontal
- ? [dimensions.plotTop, dimensions.plotTop + dimensions.plotHeight]
- : [dimensions.plotLeft, dimensions.plotLeft + dimensions.plotWidth]
- )
+ .range([bandAxisStart, bandAxisStart + cappedExtent])
.paddingInner(bandPadding)
.paddingOuter(bandPadding / 2)
diff --git a/frontend/src/lib/hog-charts/core/types.ts b/frontend/src/lib/hog-charts/core/types.ts
index cfecf6518266..a444ec6d5628 100644
--- a/frontend/src/lib/hog-charts/core/types.ts
+++ b/frontend/src/lib/hog-charts/core/types.ts
@@ -111,8 +111,11 @@ export interface TooltipContext<Meta = unknown> {
/** One entry per visible series with its value and color at this index. `fraction` is set
* for radial charts (share of total) so renderers don't need to look the slice back up. */
seriesData: { series: Series<Meta>; value: number; color: string; fraction?: number }[]
- /** Pixel position (relative to the chart container) for anchoring the tooltip. */
- position: { x: number; y: number }
+ /** 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
+ * rather than the band center. Point-style charts (lines, scatter) leave it unset. */
+ position: { x: number; y: number; width?: number }
/** Cursor position in canvas pixels, or `null` for non-mousemove snapshots (e.g. pinned rebuild). */
hoverPosition: { x: number; y: number } | null
/** Bounding rect of the canvas element, useful for portal-based tooltip positioning. */
@@ -180,6 +183,8 @@ export interface ChartConfig {
/** True for BarChart `barLayout: 'percent'` / LineChart `percentStackView`. Surfaced
* on layout context so overlays can default to a percent formatter. */
isPercent?: boolean
+ /** Fade-in the hover overlay when the hovered point changes. `true` = ~150ms. */
+ animateHover?: boolean | number
/** Per-side overrides applied on top of the computed chart margins. Useful for sparklines
* that want the plot area flush with the canvas edges (e.g. `{ left: 0, right: 0, top: 0, bottom: 0 }`).
* Should be referentially stable — pass a module-level constant rather than an inline object. */
@@ -210,6 +215,11 @@ export interface BarChartConfig extends ChartConfig {
/** Stacked layout only — use d3.stackOffsetDiverging so negative values stack
* below the zero baseline (positives above). Default `false` clamps negatives to 0. */
divergingStack?: boolean
+ /** Cap (px) on the band-axis range. Clusters bars at the start of the plot while
+ * gridlines still span the full width — useful for few-category funnel-style charts. */
+ maxBandRange?: number
+ /** Drop shadow under each bar so it reads as layered over a `barTrack`. */
+ barShadow?: boolean | { color: string; blur: number; offsetX?: number; offsetY?: number }
}
export interface LineChartConfig extends ChartConfig {
@@ -234,8 +244,16 @@ export interface ChartDrawArgs {
hoverPosition: { x: number; y: number } | null
/** Chart theme colors. */
theme: ChartTheme
+ /** Hover-fade progress (0..1). Apply as `ctx.globalAlpha` around highlight rendering. */
+ hoverProgress: number
+ /** Restart the hover-fade at progress 0; returns the new value to use this frame.
+ * Call when the chart type detects a visible-state change at the same hoverIndex. */
+ resetHoverFade: () => number
}
+/** `true` = drew a visible highlight; `false` = nothing visible (freeze the fade timer). */
+export type DrawHoverResult = boolean
+
/** Resolves the y-value for a series at a given data index. Used by interaction/tooltip layer. */
export type ResolveValueFn = (series: Series, dataIndex: number) => number
@@ -271,6 +289,10 @@ export interface ChartScales {
/** Per-axis y scales keyed by axis id. Present when dual axes are active.
* When absent, all series use `y` / `yTicks`. */
yAxes?: Record<string, YAxisScale>
+ /** Optional horizontal data-extent at a label — bar charts populate this with the
+ * band width so {@link TooltipContext.position.width} carries it through to the
+ * tooltip overlay. Point-style charts (line, scatter) leave it unset. */
+ extent?: (label: string) => number | undefined
/** Chart-type-private slot. Library code MUST NOT read this — it is populated by
* individual chart implementations (e.g. LineChart stashes raw d3 scales here so
* its `drawStatic` can use them) and is opaque to the base Chart and overlays.
diff --git a/frontend/src/lib/hog-charts/overlays/Tooltip.tsx b/frontend/src/lib/hog-charts/overlays/Tooltip.tsx
index 0d81a6c4856c..572c768dea3e 100644
--- a/frontend/src/lib/hog-charts/overlays/Tooltip.tsx
+++ b/frontend/src/lib/hog-charts/overlays/Tooltip.tsx
@@ -20,28 +20,30 @@ export function Tooltip<Meta = unknown>({
}: TooltipProps<Meta>): React.ReactElement {
const { theme } = useChartLayout()
const zIndex = theme.tooltipZIndex ?? DEFAULT_TOOLTIP_Z_INDEX
- // In `top` placement the y position is anchored to the canvas top and `position.y` is
- // unused, so we depend on the resolved y rather than `position.y` directly — otherwise
- // mousemove rebuilds the virtual reference and triggers a Floating-UI reposition pass
- // for nothing.
+ // `top` placement pins y to the canvas top, ignoring position.y (no per-mousemove reposition).
const y = placement === 'top' ? context.canvasBounds.top : context.canvasBounds.top + context.position.y
+ // Anchor at band's right edge via `right-start` so the tooltip lands beside the bar,
+ // not over it. Only used for `top` placement; `flip()` handles overflow.
+ const referenceWidth = placement === 'top' ? (context.position.width ?? 0) : 0
const virtualReference = useMemo<VirtualElement>(
() => ({
getBoundingClientRect() {
- const x = context.canvasBounds.left + context.position.x
+ const centerX = context.canvasBounds.left + context.position.x
+ const left = centerX - referenceWidth / 2
+ const right = centerX + referenceWidth / 2
return {
- x,
+ x: left,
y,
- width: 0,
+ width: referenceWidth,
height: 0,
top: y,
- right: x,
+ right,
bottom: y,
- left: x,
+ left,
}
},
}),
- [context.position.x, y, context.canvasBounds]
+ [context.position.x, y, referenceWidth, context.canvasBounds]
)
const { refs, floatingStyles } = useFloating({
diff --git a/frontend/src/lib/hog-charts/overlays/ValueLabels.tsx b/frontend/src/lib/hog-charts/overlays/ValueLabels.tsx
index eb26cd17b862..b525325994d6 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 { useChartLayout } from '../core/chart-context'
+import { useChart } from '../core/chart-context'
import { resolveYScaleForSeries } from '../core/scales'
import type { ChartScales, ResolvedSeries, ResolveValueFn } from '../core/types'
import { getTextMeasureCtx } from '../utils/text-measure'
@@ -26,6 +26,8 @@ const STACK_TOTAL_KEY = '__stack_total__'
interface Candidate {
key: string
seriesIndex: number
+ /** Matched against `hoverIndex` so the hovered candidate can lift. */
+ dataIndex: number
text: string
x: number
y: number
@@ -36,6 +38,8 @@ interface Candidate {
centerAnchor: boolean
}
+const HOVER_LIFT_PX = 6
+
function defaultLocaleFormatter(v: number): string {
return v.toLocaleString()
}
@@ -57,6 +61,7 @@ function pushCandidate(
isHorizontal: boolean,
key: string,
seriesIndex: number,
+ dataIndex: number,
color: string,
text: string,
categoricalCoord: number,
@@ -69,6 +74,7 @@ function pushCandidate(
out.push({
key,
seriesIndex,
+ dataIndex,
text,
x: isHorizontal ? valueCoord : categoricalCoord,
y: isHorizontal ? categoricalCoord : valueCoord,
@@ -140,6 +146,7 @@ function buildStackTotal(args: BuildCandidatesArgs, ctx: CanvasRenderingContext2
isHorizontal,
`${STACK_TOTAL_KEY}-${dIdx}`,
-1,
+ dIdx,
topColor,
valueFormatter(total, -1, dIdx),
categoricalCoord,
@@ -208,6 +215,7 @@ function buildPerSegment(args: BuildCandidatesArgs, ctx: CanvasRenderingContext2
isHorizontal,
`${s.key}-${dIdx}`,
sIdx,
+ dIdx,
s.color,
valueFormatter(displayValue, sIdx, dIdx),
categoricalCoord,
@@ -315,16 +323,30 @@ const LABEL_STYLE_BASE: React.CSSProperties = {
borderStyle: 'solid',
pointerEvents: 'none',
whiteSpace: 'nowrap',
+ transition: 'transform 150ms ease-out',
}
-function transformFor(c: Candidate, isHorizontal: boolean): string {
+function transformFor(c: Candidate, isHorizontal: boolean, hovered: boolean): string {
+ // Lift direction depends on which side of the value-axis the label sits on.
+ let liftX = 0
+ let liftY = 0
+ if (hovered) {
+ if (c.centerAnchor) {
+ liftY = -HOVER_LIFT_PX
+ } else if (isHorizontal) {
+ liftX = c.above ? HOVER_LIFT_PX : -HOVER_LIFT_PX
+ } else {
+ liftY = c.above ? -HOVER_LIFT_PX : HOVER_LIFT_PX
+ }
+ }
+ const lift = liftX === 0 && liftY === 0 ? '' : ` translate(${liftX}px, ${liftY}px)`
if (c.centerAnchor) {
- return 'translate(-50%, -50%)'
+ return `translate(-50%, -50%)${lift}`
}
if (isHorizontal) {
- return c.above ? 'translateY(-50%)' : 'translate(-100%, -50%)'
+ return (c.above ? 'translateY(-50%)' : 'translate(-100%, -50%)') + lift
}
- return c.above ? 'translate(-50%, -100%)' : 'translateX(-50%)'
+ return (c.above ? 'translate(-50%, -100%)' : 'translateX(-50%)') + lift
}
export function ValueLabels({
@@ -332,7 +354,7 @@ export function ValueLabels({
minGap = 4,
mode = 'per-segment',
}: ValueLabelsProps): React.ReactElement | null {
- const { series, scales, labels, theme, resolvePositionValue, axis } = useChartLayout()
+ const { series, scales, labels, theme, resolvePositionValue, axis, hoverIndex } = useChart()
const isHorizontal = axis.orientation === 'horizontal'
const isPercent = axis.isPercent
@@ -365,22 +387,26 @@ export function ValueLabels({
return (
<>
- {visible.map((c) => (
- <div
- key={c.key}
- data-attr="hog-chart-value-label"
- style={{
- ...LABEL_STYLE_BASE,
- backgroundColor: c.color,
- borderColor,
- left: Math.round(c.x),
- top: Math.round(c.y),
- transform: transformFor(c, isHorizontal),
- }}
- >
- {c.text}
- </div>
- ))}
+ {visible.map((c) => {
+ const isHovered = c.dataIndex === hoverIndex
+ return (
+ <div
+ key={c.key}
+ data-attr="hog-chart-value-label"
+ style={{
+ ...LABEL_STYLE_BASE,
+ backgroundColor: c.color,
+ borderColor,
+ left: Math.round(c.x),
+ top: Math.round(c.y),
+ transform: transformFor(c, isHorizontal, isHovered),
+ willChange: isHovered ? 'transform' : undefined,
+ }}
+ >
+ {c.text}
+ </div>
+ )
+ })}
</>
)
}
diff --git a/frontend/src/scenes/data-pipelines/event-filtering/EventFilterScene.tsx b/frontend/src/scenes/data-pipelines/event-filtering/EventFilterScene.tsx
index ee74d9e8f82e..e4c4a1667950 100644
--- a/frontend/src/scenes/data-pipelines/event-filtering/EventFilterScene.tsx
+++ b/frontend/src/scenes/data-pipelines/event-filtering/EventFilterScene.tsx
@@ -116,7 +116,7 @@ export function EventFilterScene(): JSX.Element {
}
}
},
- [filterForm.filter_tree, updateTreeNode, setFilterFormValue]
+ [filterForm.filter_tree, updateTreeNode, setFilterFormValue, nodeIds]
)
const activeNode = activeId ? getNodeAtPath(filterForm.filter_tree, nodeIds.pathOf(activeId) ?? []) : null
diff --git a/products/product_analytics/frontend/insights/funnels/FunnelHistogramChart/FunnelHistogramChart.tsx b/products/product_analytics/frontend/insights/funnels/FunnelHistogramChart/FunnelHistogramChart.tsx
index 8a6447d4195d..b760392ad955 100644
--- a/products/product_analytics/frontend/insights/funnels/FunnelHistogramChart/FunnelHistogramChart.tsx
+++ b/products/product_analytics/frontend/insights/funnels/FunnelHistogramChart/FunnelHistogramChart.tsx
@@ -18,7 +18,8 @@ const CHART_CONFIG: BarChartConfig = {
showGrid: true,
barCornerRadius: 4,
yTickFormatter: (value) => humanFriendlyNumber(value),
- tooltip: { placement: 'top' },
+ // Value labels already show bucket counts; tooltip would just duplicate them.
+ tooltip: { enabled: false },
}
const handleChartError = (error: Error, info: ErrorInfo): void => {
diff --git a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx
index 674b7ca888b2..54fa578a79cb 100644
--- a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx
+++ b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx
@@ -3,7 +3,7 @@ import posthog from 'posthog-js'
import { useCallback, useMemo, type ErrorInfo } from 'react'
import { buildTheme } from 'lib/charts/utils/theme'
-import { BarChart } from 'lib/hog-charts'
+import { BarChart, DEFAULT_MARGINS } from 'lib/hog-charts'
import type { BarChartConfig, PointClickData, TooltipContext } from 'lib/hog-charts'
import { StepLegend } from 'scenes/funnels/FunnelBarVertical/StepLegend'
import { funnelDataLogic } from 'scenes/funnels/funnelDataLogic'
@@ -17,22 +17,22 @@ import { ChartParams, type FunnelStepWithConversionMetrics } from '~/types'
import { FunnelStepsBarTooltip } from './FunnelStepsBarTooltip'
import { buildFunnelStepsBarData, type FunnelStepsBarSeriesMeta } from './funnelStepsBarTransforms'
-// Both axes are hidden: steps are identified by the legend row below, and the per-step
-// conversion rate is shown there too. This lets the bars span the full width so the
-// legend columns line up with them without measuring the chart's plot area.
-const CHART_CONFIG: BarChartConfig = {
+// Per-step width — caps bars and legend column width together so few-step funnels don't
+// stretch across the whole chart with huge gaps. Gridlines still span the full width.
+const STEP_WIDTH_PX = 320
+
+const baseChartConfig: BarChartConfig = {
barLayout: 'grouped',
showGrid: true,
- barCornerRadius: 6,
+ barCornerRadius: 10,
barTrack: true,
+ barShadow: true,
+ animateHover: true,
hideXAxis: true,
- hideYAxis: true,
+ yTickFormatter: (value) => `${Math.round(value)}%`,
tooltip: { placement: 'top' },
}
-// Floor per-step width — below this the legend text overlaps; scroll horizontally instead.
-const MIN_STEP_WIDTH_PX = 210
-
const handleChartError = (error: Error, info: ErrorInfo): void => {
posthog.captureException(error, {
feature: 'funnels-steps-bar-chart',
@@ -70,6 +70,8 @@ export function FunnelStepsBarChart({
const groupTypeLabel = aggregationLabel(querySource?.aggregation_group_type_index).plural
const showTime = steps.some((step) => step.average_conversion_time != null)
+ const barsWidth = steps.length * STEP_WIDTH_PX
+ const chartConfig = useMemo<BarChartConfig>(() => ({ ...baseChartConfig, maxBandRange: barsWidth }), [barsWidth])
const onPointClick = useCallback(
(clickData: PointClickData<FunnelStepsBarSeriesMeta>): void => {
@@ -103,34 +105,35 @@ export function FunnelStepsBarChart({
return (
<div className="flex w-full flex-1 flex-col overflow-x-auto" data-attr="funnel-steps-bar-chart">
- <div
- className="flex flex-1 flex-col"
- // eslint-disable-next-line react/forbid-dom-props
- style={{ minWidth: steps.length * MIN_STEP_WIDTH_PX }}
- >
+ <div className="flex flex-1 flex-col">
<div className="flex min-h-[150px] flex-1">
<BarChart<FunnelStepsBarSeriesMeta>
series={series}
labels={labels}
theme={theme}
- config={CHART_CONFIG}
+ config={chartConfig}
tooltip={renderTooltip}
onPointClick={showPersonsModal ? onPointClick : undefined}
onError={handleChartError}
/>
</div>
- <div className="flex">
- {steps.map((step, stepIndex) => (
- <div key={stepIndex} className="min-w-0 flex-1 overflow-hidden">
- <StepLegend
- step={step}
- stepIndex={stepIndex}
- showTime={showTime}
- showPersonsModal={showPersonsModal}
- inCardView={inCardView}
- />
- </div>
- ))}
+ {/* Legend padding matches the chart's left margin and bars-width so
+ legend columns align with the bars above. */}
+ {/* eslint-disable-next-line react/forbid-dom-props */}
+ <div className="flex" style={{ paddingLeft: DEFAULT_MARGINS.left }}>
+ <div className="flex" style={{ width: barsWidth }}>
+ {steps.map((step, stepIndex) => (
+ <div key={stepIndex} className="min-w-0 flex-1 overflow-hidden">
+ <StepLegend
+ step={step}
+ stepIndex={stepIndex}
+ showTime={showTime}
+ showPersonsModal={showPersonsModal}
+ inCardView={inCardView}
+ />
+ </div>
+ ))}
+ </div>
</div>
</div>
</div>
diff --git a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarTooltip.tsx b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarTooltip.tsx
index 3a49dc92568f..dd7281212c51 100644
--- a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarTooltip.tsx
+++ b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarTooltip.tsx
@@ -33,7 +33,6 @@ export function FunnelStepsBarTooltip({
return (
<FunnelTooltip
- embedded
showPersonsModal={showPersonsModal}
stepIndex={stepIndex}
series={series}