:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(hog-charts): group BarChart bar options under `bars` config (#60820)
Sam Pennington309c3b6b9169
diff --git a/frontend/src/lib/hog-charts/charts/BarChart/BarChart.stories.tsx b/frontend/src/lib/hog-charts/charts/BarChart/BarChart.stories.tsxindex 469ef3ef3102..fb21b7d779f4 100644--- a/frontend/src/lib/hog-charts/charts/BarChart/BarChart.stories.tsx+++ b/frontend/src/lib/hog-charts/charts/BarChart/BarChart.stories.tsx@@ -50,7 +50,7 @@ export const Grouped: Story = {export const WithBarTrack: Story = {render: () => {const theme = useReactiveTheme()- const config: BarChartConfig = { barLayout: 'grouped', showGrid: true, barTrack: true, barCornerRadius: 6 }+ const config: BarChartConfig = { barLayout: 'grouped', showGrid: true, bars: { track: true, cornerRadius: 6 } }return (<Stage><BarChart series={THREE_SERIES} labels={DAYS} config={config} theme={theme} />@@ -242,7 +242,7 @@ export const LargeDataset: Story = {export const CustomCornerRadius: Story = {render: () => {const theme = useReactiveTheme()- const config: BarChartConfig = { barLayout: 'grouped', showGrid: true, barCornerRadius: 12 }+ const config: BarChartConfig = { barLayout: 'grouped', showGrid: true, bars: { cornerRadius: 12 } }return (<Stage><BarChart series={TWO_SERIES} labels={DAYS} config={config} theme={theme} />diff --git a/frontend/src/lib/hog-charts/charts/BarChart/BarChart.tsx b/frontend/src/lib/hog-charts/charts/BarChart/BarChart.tsxindex 2820ac1a5589..913e98575ae2 100644--- a/frontend/src/lib/hog-charts/charts/BarChart/BarChart.tsx+++ b/frontend/src/lib/hog-charts/charts/BarChart/BarChart.tsx@@ -29,6 +29,7 @@ import {} from '../../core/scales'import type {BarChartConfig,+ BarsConfig,ChartDimensions,ChartDrawArgs,ChartScales,@@ -91,7 +92,7 @@ const HORIZONTAL_MIN_BAND_SIZE_DEFAULT = 24// Reserve room for chart-edge margins + worst-case x-axis title margin (matches useChartMargins).const HORIZONTAL_CHART_MARGIN_PX = DEFAULT_MARGINS.top + DEFAULT_MARGINS.bottom + X_AXIS_TITLE_MARGIN-function resolveBarShadow(barShadow: BarChartConfig['barShadow']): BarShadow | undefined {+function resolveBarShadow(barShadow: BarsConfig['shadow']): BarShadow | undefined {if (barShadow === true) {return DEFAULT_BAR_SHADOW}@@ -124,16 +125,18 @@ function BarChartInner<Meta = unknown>({yScaleType = 'linear',showGrid = false,barLayout = 'stacked',- barCornerRadius = 0,- barTrack = false,axisOrientation = 'vertical',xTickFormatter,+ } = config ?? {}+ const {+ cornerRadius: barCornerRadius = 0,+ track: barTrack = false,+ shadow: barShadow,divergingStack = false,maxBandRange,bandPadding,- barShadow,minBandSize,- } = config ?? {}+ } = config?.bars ?? {}const isHorizontal = axisOrientation === 'horizontal'const resolvedMinBandSize = minBandSize ?? (isHorizontal ? HORIZONTAL_MIN_BAND_SIZE_DEFAULT : 0)diff --git a/frontend/src/lib/hog-charts/charts/TimeSeriesBarChart/TimeSeriesBarChart.tsx b/frontend/src/lib/hog-charts/charts/TimeSeriesBarChart/TimeSeriesBarChart.tsxindex 4f9552391e7d..aeb19677e3e4 100644--- a/frontend/src/lib/hog-charts/charts/TimeSeriesBarChart/TimeSeriesBarChart.tsx+++ b/frontend/src/lib/hog-charts/charts/TimeSeriesBarChart/TimeSeriesBarChart.tsx@@ -111,11 +111,10 @@ export function TimeSeriesBarChart<Meta = unknown>({yAxisLabel: yAxis?.label,showGrid: yAxis?.showGrid,barLayout,- barCornerRadius,axisOrientation,showCrosshair,tooltip: tooltipConfig,- divergingStack,+ bars: { cornerRadius: barCornerRadius, divergingStack },}return (diff --git a/frontend/src/lib/hog-charts/core/scales.ts b/frontend/src/lib/hog-charts/core/scales.tsindex 3bd1e5d31d3f..2d3743d799b9 100644--- a/frontend/src/lib/hog-charts/core/scales.ts+++ b/frontend/src/lib/hog-charts/core/scales.ts@@ -3,7 +3,7 @@ import * as d3 from 'd3'import type { ChartDimensions, ChartScales, ResolveValueFn, Series } from './types'import { DEFAULT_Y_AXIS_ID } from './types'-/** Inner padding fraction applied to the band scale when `BarChartConfig.bandPadding` is unset. */+/** Inner padding fraction applied to the band scale when `BarChartConfig.bars.bandPadding` is unset. */export const DEFAULT_BAND_PADDING = 0.2type D3YScale = d3.ScaleLinear<number, number> | d3.ScaleLogarithmic<number, number>diff --git a/frontend/src/lib/hog-charts/core/types.ts b/frontend/src/lib/hog-charts/core/types.tsindex 0d71107921a6..d7ec7c7376ca 100644--- a/frontend/src/lib/hog-charts/core/types.ts+++ b/frontend/src/lib/hog-charts/core/types.ts@@ -205,34 +205,41 @@ export interface TooltipConfig {placement?: 'follow-data' | 'top'}-export interface BarChartConfig extends ChartConfig {- /** Defaults to `stacked`. */- barLayout?: 'stacked' | 'grouped' | 'percent'- /** Stacked bars only round the topmost segment. */- barCornerRadius?: number+/** Bar appearance + band-layout details. Grouped under {@link BarChartConfig.bars} to keep the+ * config flat at the top level. `barLayout` stays top-level as the primary discriminator. */+export interface BarsConfig {+ /** Corner radius in px for the rounded end(s) of a bar. Stacked bars only round the topmost+ * segment. Defaults to 0 (square). */+ cornerRadius?: number/** Draw a faint hatched track behind each bar, spanning the full plot height — for* funnel-style charts where every bar is a share of a whole. Only honored when* `barLayout: 'grouped'`; ignored for stacked/percent (the "share of a whole"* semantics don't apply when bars share a band). Defaults to `false`. */- barTrack?: boolean- /** Stacked layout only — use d3.stackOffsetDiverging so negative values stack- * below the zero baseline (positives above). Default `false` clamps negatives to 0. */+ track?: boolean+ /** Drop shadow under each bar so it reads as layered over a `track`. */+ shadow?: boolean | { color: string; blur: number; offsetX?: number; offsetY?: number }+ /** 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. */+ /** 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- /** Inner gap between bars as a fraction of the band slot (0–1). Outer padding is half- * this value, so `step = range / N`. Defaults to `DEFAULT_BAND_PADDING` in `scales.ts`. */+ /** Inner gap between bars as a fraction of the band slot (0–1). Outer padding is half this+ * value, so `step = range / N`. Defaults to `DEFAULT_BAND_PADDING` in `scales.ts`. */bandPadding?: number- /** Drop shadow under each bar so it reads as layered over a `barTrack`. */- barShadow?: boolean | { color: string; blur: number; offsetX?: number; offsetY?: number }- /** Horizontal bar charts only — minimum px per row. When many rows would otherwise crush- * into an unreadable strip, the chart expands its container height so each row has at- * least this much vertical space (label height + breathing room). Defaults to `24`.- * Pass `0` to opt out. */+ /** Horizontal bar charts only — minimum px per row. When many rows would otherwise crush into+ * an unreadable strip, the chart expands its container height so each row has at least this+ * much vertical space (label height + breathing room). Defaults to `24`. Pass `0` to opt out. */minBandSize?: number}+export interface BarChartConfig extends ChartConfig {+ /** Defaults to `stacked`. */+ barLayout?: 'stacked' | 'grouped' | 'percent'+ /** Bar appearance + band-layout details (corner rounding, track, shadow, padding…). */+ bars?: BarsConfig+}+export interface LineChartConfig extends ChartConfig {percentStackView?: boolean}diff --git a/frontend/src/lib/hog-charts/index.ts b/frontend/src/lib/hog-charts/index.tsindex 07a5397769da..e5588ee1d7f7 100644--- a/frontend/src/lib/hog-charts/index.ts+++ b/frontend/src/lib/hog-charts/index.ts@@ -58,6 +58,7 @@ export type { BaseChartContext, ChartHoverContextValue, ChartLayoutContextValue// Core typesexport type {BarChartConfig,+ BarsConfig,ChartConfig,ChartDimensions,ChartDrawArgs,diff --git a/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/FunnelBarHorizontalChart.tsx b/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/FunnelBarHorizontalChart.tsxindex 1ebe58c288ee..7c2424f08306 100644--- a/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/FunnelBarHorizontalChart.tsx+++ b/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/FunnelBarHorizontalChart.tsx@@ -78,13 +78,12 @@ export function FunnelBarHorizontalChart({const chartConfig = useMemo<BarChartConfig>(() => ({barLayout: 'stacked',- barCornerRadius: 4,+ bars: { cornerRadius: 4, bandPadding: BAR_PADDING },axisOrientation: 'horizontal',hideXAxis: true,hideYAxis: true,showGrid: false,animateHover: true,- bandPadding: BAR_PADDING,margins: { top: 0, right: 0, bottom: 0, left: GLYPH_COLUMN_WIDTH_PX },tooltip: { placement: 'top' },}),diff --git a/products/product_analytics/frontend/insights/funnels/FunnelHistogramChart/FunnelHistogramChart.tsx b/products/product_analytics/frontend/insights/funnels/FunnelHistogramChart/FunnelHistogramChart.tsxindex b760392ad955..5fd3d8f91943 100644--- a/products/product_analytics/frontend/insights/funnels/FunnelHistogramChart/FunnelHistogramChart.tsx+++ b/products/product_analytics/frontend/insights/funnels/FunnelHistogramChart/FunnelHistogramChart.tsx@@ -16,7 +16,7 @@ import { buildFunnelHistogramData } from './funnelHistogramTransforms'const CHART_CONFIG: BarChartConfig = {showGrid: true,- barCornerRadius: 4,+ bars: { cornerRadius: 4 },yTickFormatter: (value) => humanFriendlyNumber(value),// Value labels already show bucket counts; tooltip would just duplicate them.tooltip: { enabled: false },diff --git a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsxindex 54fa578a79cb..bdb540f11b98 100644--- a/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx+++ b/products/product_analytics/frontend/insights/funnels/FunnelStepsBarChart/FunnelStepsBarChart.tsx@@ -24,9 +24,7 @@ const STEP_WIDTH_PX = 320const baseChartConfig: BarChartConfig = {barLayout: 'grouped',showGrid: true,- barCornerRadius: 10,- barTrack: true,- barShadow: true,+ bars: { cornerRadius: 10, track: true, shadow: true },animateHover: true,hideXAxis: true,yTickFormatter: (value) => `${Math.round(value)}%`,@@ -71,7 +69,10 @@ export function FunnelStepsBarChart({const groupTypeLabel = aggregationLabel(querySource?.aggregation_group_type_index).pluralconst 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 chartConfig = useMemo<BarChartConfig>(+ () => ({ ...baseChartConfig, bars: { ...baseChartConfig.bars, maxBandRange: barsWidth } }),+ [barsWidth]+ )const onPointClick = useCallback((clickData: PointClickData<FunnelStepsBarSeriesMeta>): void => {