: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): accept legacy showPieTotal on pre-existing pie charts (#66924)
Sam Pennington3428ae2ba593
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/Charts/PieChart.tsx b/frontend/src/queries/nodes/DataVisualization/Components/Charts/PieChart.tsxindex 3bf154b7d06c..5ad17d545184 100644--- a/frontend/src/queries/nodes/DataVisualization/Components/Charts/PieChart.tsx+++ b/frontend/src/queries/nodes/DataVisualization/Components/Charts/PieChart.tsx@@ -70,7 +70,8 @@ function LegacyPieChart({// are stamped with 'labels' when the type is picked (see dataVisualizationLogic).const sliceContent = chartSettings.pie?.sliceContent ?? 'values'// The total is a sum-of-values readout, so default it on only when slices show values.- const showPieTotal = chartSettings.pie?.showTotal ?? sliceContent === 'values'+ // `showPieTotal` is the legacy top-level toggle — honor it for charts saved before `pie`.+ const showPieTotal = chartSettings.pie?.showTotal ?? chartSettings.showPieTotal ?? sliceContent === 'values'const asPercent = (chartSettings.pie?.valueDisplay ?? 'absolute') === 'percentage'const absoluteFormatter = (value: number): string =>diff --git a/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlPieGraph.test.tsx b/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlPieGraph.test.tsxindex 50c2384742d8..7b126c896bc0 100644--- a/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlPieGraph.test.tsx+++ b/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlPieGraph.test.tsx@@ -98,6 +98,37 @@ describe('SqlPieGraph', () => {expect(screen.queryByText('100')).not.toBeInTheDocument()})+ it('honors the legacy top-level showPieTotal toggle on charts saved before `pie`', async () => {+ // Pre-PR insights stored the toggle as `chartSettings.showPieTotal`. It must still parse and+ // drive the total, otherwise those saved insights regress (validation + missing total).+ render(<SqlPieGraph {...baseProps({ showPieTotal: false }, [40, 30, 20, 10])} />)++ await waitForSlices()++ expect(screen.queryByText('100')).not.toBeInTheDocument()+ })++ it('lets the legacy showPieTotal turn the total on even when slice content hides it by default', async () => {+ // sliceContent 'labels' defaults the total off, so this only shows if the legacy true is honored.+ render(+ <SqlPieGraph {...baseProps({ showPieTotal: true, pie: { sliceContent: 'labels' } }, [40, 30, 20, 10])} />+ )++ await waitForSlices()++ expect(screen.getByText('100')).toBeInTheDocument()+ })++ it('prefers pie.showTotal over the legacy showPieTotal when both are set', async () => {+ // A chart re-saved with the new `pie` block must win over the stale top-level toggle, otherwise+ // toggling the total off in the new UI would silently regress to the legacy value.+ render(<SqlPieGraph {...baseProps({ showPieTotal: true, pie: { showTotal: false } }, [40, 30, 20, 10])} />)++ await waitForSlices()++ expect(screen.queryByText('100')).not.toBeInTheDocument()+ })+it('shows slice values as shares of the total when displaying percentages', async () => {render(<SqlPieGraphdiff --git a/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlPieGraph.tsx b/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlPieGraph.tsxindex 842a0dfe9bdf..54e7ec353e10 100644--- a/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlPieGraph.tsx+++ b/frontend/src/queries/nodes/DataVisualization/Components/Charts/SqlPieGraph.tsx@@ -45,7 +45,8 @@ export const SqlPieGraph = ({// are stamped with 'labels' when the type is picked (see dataVisualizationLogic).const sliceContent = chartSettings.pie?.sliceContent ?? 'values'// The total is a sum-of-values readout, so default it on only when slices show values.- const showPieTotal = chartSettings.pie?.showTotal ?? sliceContent === 'values'+ // `showPieTotal` is the legacy top-level toggle — honor it for charts saved before `pie`.+ const showPieTotal = chartSettings.pie?.showTotal ?? chartSettings.showPieTotal ?? sliceContent === 'values'const asPercent = (chartSettings.pie?.valueDisplay ?? 'absolute') === 'percentage'const absoluteFormatter = useCallback(diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex 0fab9c7e4b9e..b821f3de756f 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -12587,6 +12587,9 @@"showNullsAsZero": {"type": "boolean"},+ "showPieTotal": {+ "type": "boolean"+ },"showTotalRow": {"type": "boolean"},diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.tsindex c64c80749b26..73a16786c1d5 100644--- a/frontend/src/queries/schema/schema-general.ts+++ b/frontend/src/queries/schema/schema-general.ts@@ -1240,6 +1240,9 @@ export interface ChartSettings {showYAxisBorder?: booleanshowLegend?: booleanshowValuesOnSeries?: boolean+ // Deprecated: superseded by `pie.showTotal`. Retained so pre-existing pie-chart insights still+ // validate (ChartSettings is `extra="forbid"`). Read as a fallback in the pie chart components.+ showPieTotal?: booleanshowTotalRow?: booleanshowNullsAsZero?: booleanheatmap?: HeatmapSettingsdiff --git a/posthog/schema.py b/posthog/schema.pyindex ac003106aabf..8d6fa9903776 100644--- a/posthog/schema.py+++ b/posthog/schema.py@@ -13502,6 +13502,7 @@ class ChartSettings(BaseModel):seriesBreakdownColumn: str | None = NoneshowLegend: bool | None = NoneshowNullsAsZero: bool | None = None+ showPieTotal: bool | None = NoneshowTotalRow: bool | None = NoneshowValuesOnSeries: bool | None = NoneshowXAxisBorder: bool | None = Nonediff --git a/products/dashboards/frontend/generated/api.schemas.ts b/products/dashboards/frontend/generated/api.schemas.tsindex 75face1c316b..df693f9c427c 100644--- a/products/dashboards/frontend/generated/api.schemas.ts+++ b/products/dashboards/frontend/generated/api.schemas.ts@@ -7768,6 +7768,7 @@ export interface ChartSettingsApi {seriesBreakdownColumn?: string | nullshowLegend?: boolean | nullshowNullsAsZero?: boolean | null+ showPieTotal?: boolean | nullshowTotalRow?: boolean | nullshowValuesOnSeries?: boolean | nullshowXAxisBorder?: boolean | nulldiff --git a/products/product_analytics/frontend/generated/api.schemas.ts b/products/product_analytics/frontend/generated/api.schemas.tsindex 8323bc438fbd..b799469a68b4 100644--- a/products/product_analytics/frontend/generated/api.schemas.ts+++ b/products/product_analytics/frontend/generated/api.schemas.ts@@ -7105,6 +7105,7 @@ export interface ChartSettingsApi {seriesBreakdownColumn?: string | nullshowLegend?: boolean | nullshowNullsAsZero?: boolean | null+ showPieTotal?: boolean | nullshowTotalRow?: boolean | nullshowValuesOnSeries?: boolean | nullshowXAxisBorder?: boolean | nulldiff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 7336553f4138..27ade84f8ec5 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -7247,6 +7247,7 @@ export namespace Schemas {seriesBreakdownColumn?: string | null;showLegend?: boolean | null;showNullsAsZero?: boolean | null;+ showPieTotal?: boolean | null;showTotalRow?: boolean | null;showValuesOnSeries?: boolean | null;showXAxisBorder?: boolean | null;