: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
fix(insights): reduce embedded bar chart label spacing (#102841)
Daniel Parker41647335bc35
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 18ed72a6dcb7..93e78c1070a3 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -3536,6 +3536,10 @@ snapshots:hash: v1.k794b7964.e02ba31b6e04cffc9eb214f21a65ce0e414eaf4982625bc37da4d64aa553ffb0.oPix6yvyfc3ngjRWHpWDvtzd1s9m2pi838jOaGXQ7Nginsights-trendsbarchart--bar-value-50-breakdowns--light:hash: v1.k794b7964.ce7fbccc760b55b0301fcdeb207ab214e7641045ba7f5f2cf8d2f30e2669bcb6.8UMExS_ADGQkLT6To6P9PxRxguH7_UR5F8p1mSWqNFw+ insights-trendsbarchart--bar-value-embedded-narrow--dark:+ hash: v1.k794b7964.124355320709b76b2793e174f3e567bc3ebff636ca141259f7c1a6957174de97.7uqL2nE_Yrln4Yle7SBKWivovRwHWixY8oHoThArE1g+ insights-trendsbarchart--bar-value-embedded-narrow--light:+ hash: v1.k794b7964.8cef593146d4fa32e26825979fe8519f9c39c7f915851e7a1f2073bb6130be30.XB_jDffyHCmxdTgf_2hhq1COBcZZHN75YO3KN2j8US8insights-trendsbarchart--bar-value-single-breakdown--dark:hash: v1.k794b7964.6ae67f2e37c4535b9d36b89f81179ecf45c1fdc42069cc5a8baa6b1f07ebf1b5.Nst28ZQ5fdw4jL5VQG-kVeI1Pb1cG5ochKjm0sTmYbIinsights-trendsbarchart--bar-value-single-breakdown--light:diff --git a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.stories.tsx b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.stories.tsxindex ab5710dfb74d..195d7511db2f 100644--- a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.stories.tsx+++ b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.stories.tsx@@ -92,14 +92,17 @@ export default metalet uniqueNode = 0-function Stage({ children }: { children: React.ReactNode }): JSX.Element {+function Stage({ children, width = 720 }: { children: React.ReactNode; width?: number }): JSX.Element {return (// eslint-disable-next-line react/forbid-dom-props- <div style={{ height: 360, width: 720, display: 'flex', flexDirection: 'column' }}>{children}</div>+ <div style={{ height: 360, width, display: 'flex', flexDirection: 'column' }}>{children}</div>)}-function renderTrendsBarChart(insightFixture: any): JSX.Element {+function renderTrendsBarChart(+ insightFixture: any,+ { embedded = false, width = 720 }: { embedded?: boolean; width?: number } = {}+): JSX.Element {const [dashboardItemId] = useState(() => `TrendsBarChartStory.${uniqueNode++}` as InsightShortId)const cachedInsight = { ...insightFixture, short_id: dashboardItemId }@@ -114,8 +117,8 @@ function renderTrendsBarChart(insightFixture: any): JSX.Element {return (<BindLogic logic={insightLogic} props={insightProps}><BindLogic logic={dataNodeLogic} props={dataNodeLogicProps}>- <Stage>- <TrendsBarChart />+ <Stage width={width}>+ <TrendsBarChart embedded={embedded} /></Stage></BindLogic></BindLogic>@@ -549,6 +552,27 @@ export const BarValue50Breakdowns: Story = {render: () => renderTrendInsight(BAR_VALUE_50_BREAKDOWNS_INSIGHT),}+const SHORT_BREAKDOWN_LABELS = [+ ...Array.from({ length: 25 }, (_, index) => String(500 + index * 37)),+ 'Other (all remaining values)',+]++const BAR_VALUE_EMBEDDED_NARROW_INSIGHT = {+ ...BAR_VALUE_50_BREAKDOWNS_INSIGHT,+ id: 205,+ short_id: 'barValueEmbeddedNarrow',+ name: 'Users by screen height',+ result: BAR_VALUE_50_BREAKDOWNS.slice(0, SHORT_BREAKDOWN_LABELS.length).map((result, index) => ({+ ...result,+ label: SHORT_BREAKDOWN_LABELS[index],+ breakdown_value: SHORT_BREAKDOWN_LABELS[index],+ })),+}++export const BarValueEmbeddedNarrow: Story = {+ render: () => renderTrendsBarChart(BAR_VALUE_EMBEDDED_NARROW_INSIGHT, { embedded: true, width: 600 }),+}+// A single breakdown row should still fill the standard chart height — the lone bar must not// shrink. Guards the min-height floor on TrendsInsight--ActionsBarValue: drop it back to `auto`// and this snapshot collapses to a thin one-row bar instead of filling the container.diff --git a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsxindex e039ea56a413..f77f29cafd5d 100644--- a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx+++ b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx@@ -63,6 +63,7 @@ interface TrendsBarChartProps {const EMPTY_LABELS: string[] = []const AGGREGATED_TOOLTIP_CONFIG = { pinnable: false, placement: 'cursor' as const }+const EMBEDDED_MAX_CATEGORY_LABEL_WIDTH = 64type AggregationLabelFn = (groupTypeIndex: number | null | undefined) => { plural: string }@@ -301,7 +302,7 @@ export function TrendsBarChart({yAxisLabel: trendsFilter?.yAxisLabel,// Breakdown values become category (y-axis) labels here; truncate long ones (e.g. URLs)// so they don't grow the margin and push the plot off screen. Full value shows on hover.- maxCategoryLabelWidth: MAX_CATEGORY_LABEL_WIDTH,+ maxCategoryLabelWidth: embedded ? EMBEDDED_MAX_CATEGORY_LABEL_WIDTH : MAX_CATEGORY_LABEL_WIDTH,// Dashboard/card tiles are a fixed height, so cap the rows to those that fit. The full// insight page is `embedded: false` — even when opened from a dashboard (dashboardId in// the URL) — so it keeps the grow-to-fit-all behavior and renders every breakdown row.