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): make donut a trends chart type (#86525)

Sam Pennington27642d61d50f
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index af5dffe6e44e..f2061e5aa9fc 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -3084,6 +3084,10 @@ snapshots:
hash: v1.k794b7964.6a12fde8bafde8512108c5b628d9b2e6e283d393ae2ed693704b4919c8a09a74.uLxKWKPhM06nOSIxUCw4GXdsfmp45YXAG0yss_yimaQ
insights-trendspiechart--default--light:
hash: v1.k794b7964.c2d804d7876a9ba388449487e49eb7bd737ea4ba68257c96a9cd6481989a7af6.AhOWv6SHzg8Xa_yN2Q8vV8Sr3PocOqpF-3ii5OJV_Ug
+ insights-trendspiechart--donut--dark:
+ hash: v1.k794b7964.2e725d7e97dd347113a5b7cc57e5200e4a14f11b20cc1e6513a928f51e066efa.db9VqgQ1zMEkeqv5NNyD_k-DEsyVBA6zARqZFIrYMB4
+ insights-trendspiechart--donut--light:
+ hash: v1.k794b7964.ad773dd40d22834aba5aa072345fe2a707ad4e0ba5769631f12a1a95eb1e4afe.rKpatgv7Utgx6ZtDcFZqe_feSR-Hu7614aJMtPjUf5E
insights-trendspiechart--min-height-parent--dark:
hash: v1.k794b7964.9b44378c8b23c54996de740b079e0029d0a474c9ca7f977b7d7aab07eece7f8e.DH5BI-XTKBTeGu8xAITjb7Ktz0BulqIqgPauao-MDpU
insights-trendspiechart--min-height-parent--light:
@@ -3293,9 +3297,9 @@ snapshots:
lemon-ui-icons1--shelf-c--light:
hash: v1.k794b7964.bcc72041caca2f6489c727b9b7e959b2aef82008a96be378607d714259a989c8.MMxMd03IZGikl5Kpd8piZkmHBNT4Vea4VWgpaZ8cNf4
lemon-ui-icons1--shelf-d--dark:
- hash: v1.k794b7964.90088b65c1799b3c4717d44c56dc7e46f78d8116ebf959b7f7539c43234c4ecc.pZvWLKRm4Fyuu57HD0XWw-FKvuRoB0oMZ2P8VtS7DmA
+ hash: v1.k794b7964.4c7daa2e1e3fa2be35ccd19051846f90c3e09bd639aefd6bc04c7b91065d774a._q44Zc8iL7uiQgo7UP44BxjuQEqZvD-LeOkBegmw1B8
lemon-ui-icons1--shelf-d--light:
- hash: v1.k794b7964.dd68e8a7aab00ab72d8a160d45678cfdea997986ca9ad8bb7afd3975e626d46f.NYhYaCh0r6bUQT7Tznin9JzB431fW7bnkUz6fWtj2CQ
+ hash: v1.k794b7964.29d9289514ad57d607aa72b27f1d0f9d160059a41e55b99291b8622977e7d458.QVPhsiT75MYVW_DW61heQU-62GxnrAy2XFvaiT41Gzo
lemon-ui-icons1--shelf-e--dark:
hash: v1.k794b7964.a6acc6d3a83a9b99c987d5b1d6d6f663dff6ce5dd78cb9e9d17af010736f66f1.tTNpKNbCq5Yktv4em0v5ak1b5H6uZc8SXc3qYncr3Fs
lemon-ui-icons1--shelf-e--light:
diff --git a/frontend/src/lib/components/ChartFilter/ChartFilter.tsx b/frontend/src/lib/components/ChartFilter/ChartFilter.tsx
index 305d82823d64..f56501bd11e9 100644
--- a/frontend/src/lib/components/ChartFilter/ChartFilter.tsx
+++ b/frontend/src/lib/components/ChartFilter/ChartFilter.tsx
@@ -4,7 +4,7 @@ import { IconGlobe, IconGraph, IconPieChart, IconRetentionHeatmap, IconTrends }
import { LemonSelect, LemonSelectOptions } from '@posthog/lemon-ui'
import { FEATURE_FLAGS } from 'lib/constants'
-import { Icon123, IconAreaChart, IconCumulativeChart, IconTableChart } from 'lib/lemon-ui/icons'
+import { Icon123, IconAreaChart, IconCumulativeChart, IconDonutChart, IconTableChart } from 'lib/lemon-ui/icons'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { insightLogic } from 'scenes/insights/insightLogic'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
@@ -169,6 +169,15 @@ export function ChartFilter(): JSX.Element {
<ChartFilterOptionLabel label="Pie chart" description="Proportions of a whole as a pie." />
),
},
+ {
+ value: ChartDisplayType.ActionsDonut,
+ icon: <IconDonutChart />,
+ label: 'Donut chart',
+ disabledReason: trendsOnlyDisabledReason,
+ labelInMenu: (
+ <ChartFilterOptionLabel label="Donut chart" description="Proportions of a whole as a ring." />
+ ),
+ },
{
value: ChartDisplayType.ActionsBarValue,
icon: <IconGraph className="rotate-90" />,
diff --git a/frontend/src/lib/components/InsightLegend/InsightLegendRow.tsx b/frontend/src/lib/components/InsightLegend/InsightLegendRow.tsx
index 974294541918..83cd0e9ce215 100644
--- a/frontend/src/lib/components/InsightLegend/InsightLegendRow.tsx
+++ b/frontend/src/lib/components/InsightLegend/InsightLegendRow.tsx
@@ -5,6 +5,7 @@ import { getSeriesBackgroundColor } from 'lib/colors'
import { captureLegendMenuAction } from 'lib/components/ChartLegendSeriesMenu/captureLegendMenuAction'
import { ChartLegendSeriesMenu } from 'lib/components/ChartLegendSeriesMenu/ChartLegendSeriesMenu'
import { InsightLabel } from 'lib/components/InsightLabel'
+import { PIE_DISPLAY_TYPES } from 'lib/constants'
import { LemonCheckbox } from 'lib/lemon-ui/LemonCheckbox'
import { formatAggregationAxisValue } from 'scenes/insights/aggregationAxisFormat'
import { insightLogic } from 'scenes/insights/insightLogic'
@@ -16,7 +17,6 @@ import { IndexedTrendResult } from 'scenes/trends/types'
import { cohortsModel } from '~/models/cohortsModel'
import { propertyDefinitionsModel } from '~/models/propertyDefinitionsModel'
-import { ChartDisplayType } from '~/types'
type InsightLegendRowProps = {
item: IndexedTrendResult
@@ -112,7 +112,7 @@ export function InsightLegendRow({ item, readOnly = false }: InsightLegendRowPro
disabledReason={!canEditInsight ? 'You need editor access to modify this insight.' : undefined}
/>
</div>
- {display === ChartDisplayType.ActionsPie && (
+ {display && PIE_DISPLAY_TYPES.includes(display) && (
<div className="text-secondary grow-0">
{formatAggregationAxisValue(trendsFilter, item.aggregated_value, baseCurrency)}
</div>
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index 5d0297f29fb1..2f8797d734eb 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -14,6 +14,7 @@ export const DISPLAY_TYPES_TO_CATEGORIES: Record<ChartDisplayType, ChartDisplayC
[ChartDisplayType.BoldNumber]: ChartDisplayCategory.TotalValue,
[ChartDisplayType.Metric]: ChartDisplayCategory.TimeSeries,
[ChartDisplayType.ActionsPie]: ChartDisplayCategory.TotalValue,
+ [ChartDisplayType.ActionsDonut]: ChartDisplayCategory.TotalValue,
[ChartDisplayType.ActionsBarValue]: ChartDisplayCategory.TotalValue,
[ChartDisplayType.ActionsTable]: ChartDisplayCategory.TotalValue,
[ChartDisplayType.WorldMap]: ChartDisplayCategory.TotalValue,
@@ -57,11 +58,14 @@ export const NON_VALUES_ON_SERIES_DISPLAY_TYPES = [
ChartDisplayType.ScatterPlot,
]
+/** Pie and donut render the same chart, so they share every pie-shaped behavior. */
+export const PIE_DISPLAY_TYPES = [ChartDisplayType.ActionsPie, ChartDisplayType.ActionsDonut]
+
/** Display types for which a percent stack view is available. */
export const PERCENT_STACK_VIEW_DISPLAY_TYPE = [
ChartDisplayType.ActionsBar,
ChartDisplayType.ActionsAreaGraph,
- ChartDisplayType.ActionsPie,
+ ...PIE_DISPLAY_TYPES,
]
export enum OrganizationMembershipLevel {
diff --git a/frontend/src/lib/lemon-ui/icons/icons.tsx b/frontend/src/lib/lemon-ui/icons/icons.tsx
index 67b16f5e9189..52009daf3ec7 100644
--- a/frontend/src/lib/lemon-ui/icons/icons.tsx
+++ b/frontend/src/lib/lemon-ui/icons/icons.tsx
@@ -427,6 +427,23 @@ export function IconTableChart(props: LemonIconProps): JSX.Element {
)
}
+/** Donut chart. Built like `IconPieChart`, which sits next to it in the chart type picker: a thin
+ * outlined body with a quarter cut out, and that quarter drawn again offset outwards.
+ * `@posthog/icons` has no donut glyph. */
+export function IconDonutChart(props: LemonIconProps): JSX.Element {
+ return (
+ <LemonIconBase {...props}>
+ <path
+ d="M18.5 13A7.5 7.5 0 1 1 11 5.5V9.6A3.4 3.4 0 1 0 14.4 13Z"
+ stroke="currentColor"
+ strokeWidth="1.5"
+ strokeLinejoin="round"
+ />
+ <path d="M12.7 3.8A7.5 7.5 0 0 1 20.2 11.3H16.1A3.4 3.4 0 0 0 12.7 7.9Z" fill="currentColor" />
+ </LemonIconBase>
+ )
+}
+
/*
* Insight type icon set. Drawn at the same visual weight as the left-nav icon family
* (~1.5-1.75 unit strokes, slim bars). Series blue is the base color; glyphs with several
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/TableDisplay.tsx b/frontend/src/queries/nodes/DataVisualization/Components/TableDisplay.tsx
index dfbf5f151e74..897f64106198 100644
--- a/frontend/src/queries/nodes/DataVisualization/Components/TableDisplay.tsx
+++ b/frontend/src/queries/nodes/DataVisualization/Components/TableDisplay.tsx
@@ -33,6 +33,7 @@ export const TableDisplay = ({ disabledReason }: TableDisplayProps): JSX.Element
[ChartDisplayType.BoldNumber]: 'Big number',
[ChartDisplayType.Metric]: 'Metric',
[ChartDisplayType.ActionsPie]: 'Pie chart',
+ [ChartDisplayType.ActionsDonut]: 'Donut chart',
[ChartDisplayType.ActionsBarValue]: 'Value chart',
[ChartDisplayType.ActionsTable]: 'Table',
[ChartDisplayType.WorldMap]: 'World map',
diff --git a/frontend/src/queries/nodes/InsightViz/InsightDisplayConfig.test.tsx b/frontend/src/queries/nodes/InsightViz/InsightDisplayConfig.test.tsx
index c8ccfe789837..ed1c69729926 100644
--- a/frontend/src/queries/nodes/InsightViz/InsightDisplayConfig.test.tsx
+++ b/frontend/src/queries/nodes/InsightViz/InsightDisplayConfig.test.tsx
@@ -204,6 +204,20 @@ describe('InsightDisplayConfig', () => {
],
},
],
+ [
+ 'trends donut',
+ makeTrendsQuery(ChartDisplayType.ActionsDonut),
+ {
+ sections: ['Display', 'Unit'],
+ displayItems: [
+ 'Show values on series',
+ 'Show as % of total',
+ 'Show names on slices',
+ 'Show total in center',
+ 'Show legendBottom',
+ ],
+ },
+ ],
[
'trends table',
makeTrendsQuery(ChartDisplayType.ActionsTable),
diff --git a/frontend/src/queries/nodes/InsightViz/insightDisplayOptions.tsx b/frontend/src/queries/nodes/InsightViz/insightDisplayOptions.tsx
index a0bf6e8e260c..9ae21f998407 100644
--- a/frontend/src/queries/nodes/InsightViz/insightDisplayOptions.tsx
+++ b/frontend/src/queries/nodes/InsightViz/insightDisplayOptions.tsx
@@ -3,6 +3,7 @@ import { useValues } from 'kea'
import { normalizeAxisLabel } from '@posthog/quill-charts'
import { smoothingOptions } from 'lib/components/SmoothingFilter/smoothings'
+import { PIE_DISPLAY_TYPES } from 'lib/constants'
import { LemonMenuItem, LemonMenuItems } from 'lib/lemon-ui/LemonMenu'
import { funnelDataLogic } from 'scenes/funnels/funnelDataLogic'
import { axisLabel } from 'scenes/insights/aggregationAxisFormat'
@@ -79,7 +80,7 @@ export function useInsightDisplayOptions(): { items: LemonMenuItems; count: numb
const showFunnelLegendConfig = isTrendsFunnel && hasBreakdownFilter(breakdownFilter)
const isBoxPlot = display === ChartDisplayType.BoxPlot
const isCalendarHeatmap = display === ChartDisplayType.CalendarHeatmap
- const isPie = display === ChartDisplayType.ActionsPie
+ const isPie = !!display && PIE_DISPLAY_TYPES.includes(display)
// Percent stacking swaps the raw values out for percentages, so there is no unit left to pick.
// A pie is the exception: it can show the value and the percentage together.
const showsRawValues = !showPercentStackView || (isPie && !!showValuesOnSeries)
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json
index 8fa255386351..131859f66d55 100644
--- a/frontend/src/queries/schema.json
+++ b/frontend/src/queries/schema.json
@@ -5188,6 +5188,10 @@
"const": "ActionsPie",
"type": "string"
},
+ {
+ "const": "ActionsDonut",
+ "type": "string"
+ },
{
"const": "ActionsBarValue",
"type": "string"
@@ -5313,6 +5317,7 @@
"BoldNumber",
"Metric",
"ActionsPie",
+ "ActionsDonut",
"ActionsBarValue",
"ActionsTable",
"WorldMap",
@@ -16003,6 +16008,7 @@
"BoldNumber",
"Metric",
"ActionsPie",
+ "ActionsDonut",
"ActionsBarValue",
"ActionsTable",
"WorldMap",
diff --git a/frontend/src/queries/utils.ts b/frontend/src/queries/utils.ts
index ffc310840ea1..2e6489f92bb1 100644
--- a/frontend/src/queries/utils.ts
+++ b/frontend/src/queries/utils.ts
@@ -498,6 +498,7 @@ const CANVAS_CHART_DISPLAY_TYPES = new Set<ChartDisplayType>([
ChartDisplayType.ActionsStackedBar,
ChartDisplayType.ActionsBarValue,
ChartDisplayType.ActionsPie,
+ ChartDisplayType.ActionsDonut,
ChartDisplayType.Metric,
ChartDisplayType.BoxPlot,
ChartDisplayType.SlopeGraph,
diff --git a/frontend/src/scenes/insights/EditorFilters/ShowPieTotalFilter.tsx b/frontend/src/scenes/insights/EditorFilters/ShowPieTotalFilter.tsx
index efa3532a29fa..13fd114b1657 100644
--- a/frontend/src/scenes/insights/EditorFilters/ShowPieTotalFilter.tsx
+++ b/frontend/src/scenes/insights/EditorFilters/ShowPieTotalFilter.tsx
@@ -11,13 +11,14 @@ import { insightVizDataLogic } from '../insightVizDataLogic'
export function ShowPieTotalFilter(): JSX.Element | null {
const { insightProps } = useValues(insightLogic)
- const { pieChartVizOptions } = useValues(trendsDataLogic(insightProps))
+ const { display, pieChartVizOptions } = useValues(trendsDataLogic(insightProps))
const { updateVizSpecificOptions } = useActions(insightVizDataLogic(insightProps))
const showTotal = !pieChartVizOptions?.hideAggregation
const toggleShowTotal = (): void => {
updateVizSpecificOptions({
+ // Donut stores its options under the pie key too, so the setting survives switching between them.
[ChartDisplayType.ActionsPie]: {
...pieChartVizOptions,
hideAggregation: showTotal,
@@ -30,7 +31,11 @@ export function ShowPieTotalFilter(): JSX.Element | null {
className="p-1 px-2"
onChange={toggleShowTotal}
checked={showTotal}
- label={<span className="font-normal">Show total below chart</span>}
+ label={
+ <span className="font-normal">
+ {display === ChartDisplayType.ActionsDonut ? 'Show total in center' : 'Show total below chart'}
+ </span>
+ }
size="small"
/>
)
diff --git a/frontend/src/scenes/insights/insightVizDataLogic.ts b/frontend/src/scenes/insights/insightVizDataLogic.ts
index 80b66f51a135..69ce7b8aaba3 100644
--- a/frontend/src/scenes/insights/insightVizDataLogic.ts
+++ b/frontend/src/scenes/insights/insightVizDataLogic.ts
@@ -9,7 +9,12 @@ import {
} from 'lib/components/InsightLegend/utils'
import { Intervals, intervals } from 'lib/components/IntervalFilter/intervals'
import { parseProperties } from 'lib/components/PropertyFilters/utils'
-import { FEATURE_FLAGS, NON_TIME_SERIES_DISPLAY_TYPES, NON_VALUES_ON_SERIES_DISPLAY_TYPES } from 'lib/constants'
+import {
+ FEATURE_FLAGS,
+ NON_TIME_SERIES_DISPLAY_TYPES,
+ NON_VALUES_ON_SERIES_DISPLAY_TYPES,
+ PIE_DISPLAY_TYPES,
+} from 'lib/constants'
import { dayjs } from 'lib/dayjs'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { dateMapping, is12HoursOrLess, isLessThan2Days } from 'lib/utils/dateFilters'
@@ -162,6 +167,7 @@ export const DISPLAYS_WITH_IN_CHART_LEGEND = [
ChartDisplayType.ActionsBar,
ChartDisplayType.ActionsUnstackedBar,
ChartDisplayType.ActionsPie,
+ ChartDisplayType.ActionsDonut,
]
// Omit must distribute over the query-node union: a plain Omit would collapse the update type
@@ -2301,7 +2307,7 @@ export const insightVizDataLogic = kea<insightVizDataLogicType>([
((isTrends || isStickiness || isLifecycle) &&
(insightFilter as TrendsFilter)?.showValuesOnSeries) ||
(isTrends &&
- (insightFilter as TrendsFilter)?.display === ChartDisplayType.ActionsPie &&
+ PIE_DISPLAY_TYPES.includes((insightFilter as TrendsFilter)?.display as ChartDisplayType) &&
(insightFilter as TrendsFilter)?.showValuesOnSeries === undefined)
)
},
diff --git a/frontend/src/scenes/insights/utils/cleanFilters.ts b/frontend/src/scenes/insights/utils/cleanFilters.ts
index 77b8463b3cfb..11bf39c63a0f 100644
--- a/frontend/src/scenes/insights/utils/cleanFilters.ts
+++ b/frontend/src/scenes/insights/utils/cleanFilters.ts
@@ -4,6 +4,7 @@ import {
NON_TIME_SERIES_DISPLAY_TYPES,
NON_VALUES_ON_SERIES_DISPLAY_TYPES,
PERCENT_STACK_VIEW_DISPLAY_TYPE,
+ PIE_DISPLAY_TYPES,
RETENTION_FIRST_OCCURRENCE_MATCHING_FILTERS,
RETENTION_MEAN_NONE,
ShownAsValue,
@@ -454,7 +455,7 @@ export function cleanFilters(
if (
!!trendLikeFilter.display &&
- trendLikeFilter.display === ChartDisplayType.ActionsPie &&
+ PIE_DISPLAY_TYPES.includes(trendLikeFilter.display) &&
trendLikeFilter.show_values_on_series === undefined
) {
trendLikeFilter.show_values_on_series = true
@@ -470,7 +471,7 @@ export function cleanFilters(
if (
!!trendLikeFilter.display &&
- trendLikeFilter.display === ChartDisplayType.ActionsPie &&
+ PIE_DISPLAY_TYPES.includes(trendLikeFilter.display) &&
trendLikeFilter.show_percent_stack_view === undefined
) {
trendLikeFilter.show_percent_stack_view = true
diff --git a/frontend/src/scenes/insights/utils/queryUtils.ts b/frontend/src/scenes/insights/utils/queryUtils.ts
index ebab270049bf..ac27ead090f5 100644
--- a/frontend/src/scenes/insights/utils/queryUtils.ts
+++ b/frontend/src/scenes/insights/utils/queryUtils.ts
@@ -250,6 +250,7 @@ const groupedChartDisplayTypes: Record<ChartDisplayType, ChartDisplayType> = {
[ChartDisplayType.BoldNumber]: ChartDisplayType.ActionsBarValue,
[ChartDisplayType.ActionsBarValue]: ChartDisplayType.ActionsBarValue,
[ChartDisplayType.ActionsPie]: ChartDisplayType.ActionsBarValue,
+ [ChartDisplayType.ActionsDonut]: ChartDisplayType.ActionsBarValue,
[ChartDisplayType.ActionsTable]: ChartDisplayType.ActionsBarValue,
// separate: different breakdown limit (250)
diff --git a/frontend/src/scenes/trends/Trends.tsx b/frontend/src/scenes/trends/Trends.tsx
index f9bbe4790d82..ab7b8751ddf4 100644
--- a/frontend/src/scenes/trends/Trends.tsx
+++ b/frontend/src/scenes/trends/Trends.tsx
@@ -3,6 +3,7 @@ import { Suspense } from 'react'
import { LemonButton } from '@posthog/lemon-ui'
+import { PIE_DISPLAY_TYPES } from 'lib/constants'
import { WrappingLoadingSkeleton } from 'lib/ui/WrappingLoadingSkeleton/WrappingLoadingSkeleton'
import { lazyWithRetry } from 'lib/utils/retryImport'
import { insightLogic } from 'scenes/insights/insightLogic'
@@ -81,7 +82,7 @@ export function TrendInsight({ view, context, embedded, inSharedMode, editMode }
/>
)
}
- if (display === ChartDisplayType.ActionsPie) {
+ if (display && PIE_DISPLAY_TYPES.includes(display)) {
return <TrendsPieChart context={context} inSharedMode={inSharedMode} showPersonsModal={showPersonsModal} />
}
if (display === ChartDisplayType.ActionsBarValue) {
diff --git a/frontend/src/scenes/trends/trendsDataLogic.ts b/frontend/src/scenes/trends/trendsDataLogic.ts
index 9a8a1c089c61..cf2cb53ec3ce 100644
--- a/frontend/src/scenes/trends/trendsDataLogic.ts
+++ b/frontend/src/scenes/trends/trendsDataLogic.ts
@@ -1,6 +1,7 @@
import { MakeLogicType, actions, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea'
import { DataColorTheme, DataColorToken } from 'lib/colors'
+import { PIE_DISPLAY_TYPES } from 'lib/constants'
import { dayjs } from 'lib/dayjs'
import { isMultiSeriesFormula } from 'lib/utils/strings'
import {
@@ -611,7 +612,7 @@ export const trendsDataLogic = kea<trendsDataLogicType>([
})
} else if (
display &&
- (display === ChartDisplayType.ActionsBarValue || display === ChartDisplayType.ActionsPie)
+ (display === ChartDisplayType.ActionsBarValue || PIE_DISPLAY_TYPES.includes(display))
) {
indexedResults.sort((a, b) => {
const aValue =
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index 79f4e965b7ab..145bc7872eb2 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -3086,6 +3086,7 @@ export enum ChartDisplayType {
BoldNumber = 'BoldNumber',
Metric = 'Metric',
ActionsPie = 'ActionsPie',
+ ActionsDonut = 'ActionsDonut',
ActionsBarValue = 'ActionsBarValue',
ActionsTable = 'ActionsTable',
WorldMap = 'WorldMap',
diff --git a/posthog/constants.py b/posthog/constants.py
index b8e8404fb1bb..8ee564bd6475 100644
--- a/posthog/constants.py
+++ b/posthog/constants.py
@@ -71,6 +71,7 @@ TRENDS_LINEAR = "ActionsLineGraph"
TRENDS_TABLE = "ActionsTable"
TRENDS_FUNNEL = "FunnelViz"
TRENDS_PIE = "ActionsPie"
+TRENDS_DONUT = "ActionsDonut"
TRENDS_PATHS = "PathsViz"
TRENDS_BAR = "ActionsBar"
TRENDS_BAR_VALUE = "ActionsBarValue"
@@ -84,6 +85,7 @@ TRENDS_BOX_PLOT = "BoxPlot"
NON_TIME_SERIES_DISPLAY_TYPES = [
TRENDS_TABLE,
TRENDS_PIE,
+ TRENDS_DONUT,
TRENDS_BAR_VALUE,
TRENDS_WORLD_MAP,
TRENDS_BOLD_NUMBER,
@@ -116,6 +118,7 @@ DISPLAY_TYPES = Literal[
"ActionsLineGraphCumulative",
"ActionsTable",
"ActionsPie",
+ "ActionsDonut",
"ActionsBar",
"ActionsBarValue",
"WorldMap",
diff --git a/posthog/hogql_queries/insights/trends/display.py b/posthog/hogql_queries/insights/trends/display.py
index 55411527a07a..dd48f178dd5b 100644
--- a/posthog/hogql_queries/insights/trends/display.py
+++ b/posthog/hogql_queries/insights/trends/display.py
@@ -18,6 +18,7 @@ class TrendsDisplay:
return (
self.display_type == ChartDisplayType.BOLD_NUMBER
or self.display_type == ChartDisplayType.ACTIONS_PIE
+ or self.display_type == ChartDisplayType.ACTIONS_DONUT
or self.display_type == ChartDisplayType.ACTIONS_BAR_VALUE
or self.display_type == ChartDisplayType.WORLD_MAP
or self.display_type == ChartDisplayType.CALENDAR_HEATMAP
diff --git a/posthog/schema_enums.py b/posthog/schema_enums.py
index f7896fb1a111..9da3a44231e4 100644
--- a/posthog/schema_enums.py
+++ b/posthog/schema_enums.py
@@ -531,6 +531,7 @@ class Display(StrEnum):
BOLD_NUMBER = "BoldNumber"
METRIC = "Metric"
ACTIONS_PIE = "ActionsPie"
+ ACTIONS_DONUT = "ActionsDonut"
ACTIONS_BAR_VALUE = "ActionsBarValue"
ACTIONS_TABLE = "ActionsTable"
WORLD_MAP = "WorldMap"
@@ -667,6 +668,7 @@ class ChartDisplayType(StrEnum):
BOLD_NUMBER = "BoldNumber"
METRIC = "Metric"
ACTIONS_PIE = "ActionsPie"
+ ACTIONS_DONUT = "ActionsDonut"
ACTIONS_BAR_VALUE = "ActionsBarValue"
ACTIONS_TABLE = "ActionsTable"
WORLD_MAP = "WorldMap"
diff --git a/posthog/schema_helpers.py b/posthog/schema_helpers.py
index 112a6ebfece7..81a221e8786c 100644
--- a/posthog/schema_helpers.py
+++ b/posthog/schema_helpers.py
@@ -191,6 +191,7 @@ def grouped_chart_display_types(display: ChartDisplayType) -> ChartDisplayType:
ChartDisplayType.ACTIONS_BAR_VALUE
| ChartDisplayType.BOLD_NUMBER
| ChartDisplayType.ACTIONS_PIE
+ | ChartDisplayType.ACTIONS_DONUT
| ChartDisplayType.ACTIONS_TABLE
):
# total value
diff --git a/posthog/tasks/alerts/utils.py b/posthog/tasks/alerts/utils.py
index 345d006effc1..9b01254da488 100644
--- a/posthog/tasks/alerts/utils.py
+++ b/posthog/tasks/alerts/utils.py
@@ -64,6 +64,7 @@ WRAPPER_NODE_KINDS = [NodeKind.DATA_TABLE_NODE, NodeKind.DATA_VISUALIZATION_NODE
NON_TIME_SERIES_DISPLAY_TYPES = {
ChartDisplayType.BOLD_NUMBER,
ChartDisplayType.ACTIONS_PIE,
+ ChartDisplayType.ACTIONS_DONUT,
ChartDisplayType.ACTIONS_BAR_VALUE,
ChartDisplayType.ACTIONS_TABLE,
ChartDisplayType.WORLD_MAP,
diff --git a/products/dashboards/frontend/generated/api.schemas.ts b/products/dashboards/frontend/generated/api.schemas.ts
index a8832e77253c..49af0ce87b7c 100644
--- a/products/dashboards/frontend/generated/api.schemas.ts
+++ b/products/dashboards/frontend/generated/api.schemas.ts
@@ -2513,6 +2513,7 @@ export const ChartDisplayTypeApi = {
BoldNumber: 'BoldNumber',
Metric: 'Metric',
ActionsPie: 'ActionsPie',
+ ActionsDonut: 'ActionsDonut',
ActionsBarValue: 'ActionsBarValue',
ActionsTable: 'ActionsTable',
WorldMap: 'WorldMap',
diff --git a/products/product_analytics/frontend/generated/api.schemas.ts b/products/product_analytics/frontend/generated/api.schemas.ts
index f4d5cb17d484..71abb76b507a 100644
--- a/products/product_analytics/frontend/generated/api.schemas.ts
+++ b/products/product_analytics/frontend/generated/api.schemas.ts
@@ -1675,6 +1675,7 @@ export const ChartDisplayTypeApi = {
BoldNumber: 'BoldNumber',
Metric: 'Metric',
ActionsPie: 'ActionsPie',
+ ActionsDonut: 'ActionsDonut',
ActionsBarValue: 'ActionsBarValue',
ActionsTable: 'ActionsTable',
WorldMap: 'WorldMap',
diff --git a/products/product_analytics/frontend/insights/trends/TrendsPieChart/DonutCenterLabel.tsx b/products/product_analytics/frontend/insights/trends/TrendsPieChart/DonutCenterLabel.tsx
new file mode 100644
index 000000000000..fddfb4ea0deb
--- /dev/null
+++ b/products/product_analytics/frontend/insights/trends/TrendsPieChart/DonutCenterLabel.tsx
@@ -0,0 +1,26 @@
+import { useRadialLayout } from '@posthog/quill-charts'
+
+const MIN_FONT_SIZE = 12
+const MAX_FONT_SIZE = 64
+/** Share of the hole's diameter the total is allowed to span. */
+const HOLE_FILL = 0.7
+/** Measured advance width of a bold digit in the app font, as a share of the font size. */
+const CHAR_WIDTH_EM = 0.55
+
+export function DonutCenterLabel({ children }: { children: string }): JSX.Element {
+ const { layout } = useRadialLayout()
+
+ // Fit the total to the ring's hole, which grows and shrinks with the chart, so the number reads
+ // the same on a dashboard card as on a full insight.
+ const available = layout.innerRadius * 2 * HOLE_FILL
+ const fontSize = Math.round(
+ Math.min(MAX_FONT_SIZE, Math.max(MIN_FONT_SIZE, available / (Math.max(children.length, 1) * CHAR_WIDTH_EM)))
+ )
+
+ return (
+ // eslint-disable-next-line react/forbid-dom-props
+ <div className="text-center font-bold leading-none" style={{ fontSize }}>
+ {children}
+ </div>
+ )
+}
diff --git a/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.stories.tsx b/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.stories.tsx
index a224c4d8be83..99f8c578eef2 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.stories.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.stories.tsx
@@ -11,7 +11,7 @@ import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'
import type { DataNodeLogicProps } from '~/queries/nodes/DataNode/dataNodeLogic'
import { insightVizDataNodeKey } from '~/queries/nodes/InsightViz/InsightViz'
import { getCachedResults } from '~/queries/nodes/InsightViz/utils'
-import type { InsightLogicProps, InsightShortId } from '~/types'
+import { ChartDisplayType, type InsightLogicProps, type InsightShortId } from '~/types'
import { TrendsPieChart } from './TrendsPieChart'
@@ -96,6 +96,23 @@ export const MinHeightParent: Story = {
render: () => renderTrendsPieChart(trendsPieBreakdownFixture, MinHeightStage),
}
+export const Donut: Story = {
+ render: () =>
+ renderTrendsPieChart({
+ ...trendsPieBreakdownFixture,
+ query: {
+ ...trendsPieBreakdownFixture.query,
+ source: {
+ ...trendsPieBreakdownFixture.query.source,
+ trendsFilter: {
+ ...trendsPieBreakdownFixture.query.source.trendsFilter,
+ display: ChartDisplayType.ActionsDonut,
+ },
+ },
+ },
+ }),
+}
+
function renderBreakdownPieWithFilter(trendsFilter: Record<string, unknown>): JSX.Element {
return renderTrendsPieChart({
...trendsPieBreakdownFixture,
diff --git a/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.tsx
index fb3e73c55cb2..84c50aa0b5e2 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.tsx
@@ -25,11 +25,13 @@ import { groupsModel } from '~/models/groupsModel'
import { propertyDefinitionsModel } from '~/models/propertyDefinitionsModel'
import { InsightVizNode } from '~/queries/schema/schema-general'
import { QueryContext } from '~/queries/types'
+import { ChartDisplayType } from '~/types'
import { InsightSeriesTooltip } from '../../shared/InsightSeriesTooltip'
import { getTrendsSeriesDisplayLabel } from '../shared/getTrendsSeriesDisplayLabel'
import type { TrendsSeriesMeta } from '../shared/trendsSeriesMeta'
import { useInsightsLegendConfig } from '../shared/useInsightsLegendConfig'
+import { DonutCenterLabel } from './DonutCenterLabel'
import { buildTrendsPieSeries } from './trendsPieTransforms'
interface TrendsPieChartProps {
@@ -38,6 +40,8 @@ interface TrendsPieChartProps {
showPersonsModal?: boolean
}
+const DONUT_INNER_RADIUS_RATIO = 0.6
+
const handleChartError = (error: Error, info: ErrorInfo): void => {
posthog.captureException(error, {
feature: 'trends-pie-chart',
@@ -60,6 +64,7 @@ export function TrendsPieChart({
const { aggregationLabel } = useValues(groupsModel)
const {
+ display,
indexedResults,
trendsFilter,
formula,
@@ -88,6 +93,7 @@ export function TrendsPieChart({
const onDataPointClick = context?.onDataPointClick
const showAggregation = !pieChartVizOptions?.hideAggregation
+ const isDonut = display === ChartDisplayType.ActionsDonut
// Share the line/bar label resolver so the legend humanizes event names ($pageview → Pageview)
// and honors series renames, instead of showing the raw event key.
@@ -140,6 +146,7 @@ export function TrendsPieChart({
showLabelOnSlice: !!showLabelOnSeries,
isPercent: isPercentStackView,
disableHoverOffset: !!pieChartVizOptions?.disableHoverOffset,
+ innerRadiusRatio: isDonut ? DONUT_INNER_RADIUS_RATIO : undefined,
legend: legendConfig,
}),
[
@@ -148,6 +155,7 @@ export function TrendsPieChart({
showLabelOnSeries,
isPercentStackView,
pieChartVizOptions?.disableHoverOffset,
+ isDonut,
legendConfig,
]
)
@@ -266,6 +274,13 @@ export function TrendsPieChart({
// center the whole group. In-app (right legend) the chart keeps filling the column.
const legendAtBottom = !!legendConfig.show && legendConfig.position === 'bottom'
+ // A donut's hollow center is the natural home for the total, so move it there instead of
+ // stranding it below the chart.
+ const centerLabel =
+ isDonut && showAggregation ? (
+ <DonutCenterLabel>{formatAggregationAxisValue(trendsFilter, total, baseCurrency)}</DonutCenterLabel>
+ ) : undefined
+
const pie = (
<PieChart<TrendsSeriesMeta>
series={series}
@@ -274,6 +289,7 @@ export function TrendsPieChart({
tooltip={renderTooltip}
onSliceClick={canHandleClick ? onSliceClick : undefined}
valueFormatter={valueFormatter}
+ centerLabel={centerLabel}
dataAttr="trend-pie-graph"
onError={handleChartError}
/>
@@ -285,7 +301,7 @@ export function TrendsPieChart({
// leaving `PieChart` with `outerRadius <= 0` and no slices. Mirrors the bar/line charts.
<div className={clsx('flex flex-col w-full flex-1 min-h-0', legendAtBottom && 'justify-center')}>
{legendAtBottom ? <div className="flex flex-col w-full min-h-0 max-h-full aspect-square">{pie}</div> : pie}
- {showAggregation && (
+ {showAggregation && !isDonut && (
<div className={clsx('text-7xl text-center font-bold m-0', legendAtBottom && 'mt-6')}>
{formatAggregationAxisValue(trendsFilter, total, baseCurrency)}
</div>
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 9ac1e07f7f24..f1fa378fe212 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -3452,6 +3452,7 @@ export namespace Schemas {
BoldNumber: 'BoldNumber',
Metric: 'Metric',
ActionsPie: 'ActionsPie',
+ ActionsDonut: 'ActionsDonut',
ActionsBarValue: 'ActionsBarValue',
ActionsTable: 'ActionsTable',
WorldMap: 'WorldMap',
diff --git a/services/mcp/src/tools/generated/query-wrappers.ts b/services/mcp/src/tools/generated/query-wrappers.ts
index 5b080af57074..1c47691fd4e3 100644
--- a/services/mcp/src/tools/generated/query-wrappers.ts
+++ b/services/mcp/src/tools/generated/query-wrappers.ts
@@ -505,6 +505,7 @@ const AssistantTrendsFilter = z.object({
'BoldNumber',
'Metric',
'ActionsPie',
+ 'ActionsDonut',
'ActionsBarValue',
'ActionsTable',
'WorldMap',
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/query-trends-actors.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/query-trends-actors.json
index 94953981c3c8..7f7d99911a18 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/query-trends-actors.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/query-trends-actors.json
@@ -3841,6 +3841,7 @@
"BoldNumber",
"Metric",
"ActionsPie",
+ "ActionsDonut",
"ActionsBarValue",
"ActionsTable",
"WorldMap",
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/query-trends.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/query-trends.json
index 1d880999a3a1..1cd4abce37fe 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/query-trends.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/query-trends.json
@@ -3638,6 +3638,7 @@
"BoldNumber",
"Metric",
"ActionsPie",
+ "ActionsDonut",
"ActionsBarValue",
"ActionsTable",
"WorldMap",