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): show value and percentage together on pie slices (#80570)

Daniel Parker320494b3510e
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 81fea2353d11..6aac99d5f812 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -2821,9 +2821,13 @@ snapshots:
insights-trendspiechart--breakdown--light:
hash: v1.k794b7964.cd52243e5d45d2eb6397a1efffcb6b6c9a5f98ef4a265fab0abc5974c69c0999.o7kqH91XGiMQ5kLrepa2Q239mYYNmPIfReNgQ1Yitm4
insights-trendspiechart--breakdown-with-labels--dark:
- hash: v1.k794b7964.a1db52280a6847809525237e6d95e6bb391971fc5b2411e52f4de8678e216411.VAUJc_fxkrZphfILbhEle0WmBPCQpePnjb3OJRSXdng
+ hash: v1.k794b7964.9124fefd31f3ecfc8527722abfe6ca9acef42a2b794bf070088d9f248c1f7990.4Z7Us6eurT0pTvf6V30CMoVH_886UHYFCHkywPcEAsM
insights-trendspiechart--breakdown-with-labels--light:
- hash: v1.k794b7964.38531b76bea1607447173363d39eaedf7f1737b7d35fdd0a37604e1f747d374e.KTBq1R0DXgzatb3NFlpNjeFMMCivSMIxo94HFYKjqcI
+ hash: v1.k794b7964.dc0682ea67efaf5cfd942ac9fceda88aa381304aaf404b45a1ac0bdb40e1dab8.DKmd5t2iOJCCJCCN16BLCOFcGVFCSX-FfGKFNQ3iSTM
+ insights-trendspiechart--breakdown-with-value-and-percentage--dark:
+ hash: v1.k794b7964.3c11a1a4addd149737de271f5d7ae769b82f4acefb9fd35ee65338078012a328.B3l_O20nxIi2mzX2X0-N3PDuRGQ4PspU8RnwtpEfzuo
+ insights-trendspiechart--breakdown-with-value-and-percentage--light:
+ hash: v1.k794b7964.958cc72969776dcd098a5c9495453416071c907bcc9c7e6cb87edf7152cdde66.WZQXn3lgyOVUrPbyBrDY5Y8l3O8v2HiSh64osAq-414
insights-trendspiechart--default--dark:
hash: v1.k794b7964.6a12fde8bafde8512108c5b628d9b2e6e283d393ae2ed693704b4919c8a09a74.uLxKWKPhM06nOSIxUCw4GXdsfmp45YXAG0yss_yimaQ
insights-trendspiechart--default--light:
diff --git a/frontend/src/queries/nodes/InsightViz/DisplayOptions.tsx b/frontend/src/queries/nodes/InsightViz/DisplayOptions.tsx
index 55c598f15911..3de5a75b8039 100644
--- a/frontend/src/queries/nodes/InsightViz/DisplayOptions.tsx
+++ b/frontend/src/queries/nodes/InsightViz/DisplayOptions.tsx
@@ -31,6 +31,7 @@ import { ShowLegendFilter } from 'scenes/insights/EditorFilters/ShowLegendFilter
import { ShowMultipleYAxesFilter } from 'scenes/insights/EditorFilters/ShowMultipleYAxesFilter'
import { ShowPieTotalFilter } from 'scenes/insights/EditorFilters/ShowPieTotalFilter'
import { ShowTrendLinesFilter } from 'scenes/insights/EditorFilters/ShowTrendLinesFilter'
+import { SliceNamesFilter } from 'scenes/insights/EditorFilters/SliceNamesFilter'
import { StackBreakdownFilter } from 'scenes/insights/EditorFilters/StackBreakdownFilter'
import { ValueOnSeriesFilter } from 'scenes/insights/EditorFilters/ValueOnSeriesFilter'
import { RetentionCohortLabelStartIndexPicker } from 'scenes/insights/filters/RetentionCohortLabelStartIndexPicker'
@@ -117,24 +118,6 @@ function ExcludeOutliers(): JSX.Element {
)
}
-function PercentStack(): JSX.Element {
- const { insightProps } = useValues(insightLogic)
- const { display } = useValues(insightVizDataLogic(insightProps))
- const { showValuesOnSeries } = useValues(trendsDataLogic(insightProps))
-
- return (
- <PercentStackViewFilter
- // On a pie chart the percentage is rendered through the series value labels, so it has no
- // effect while those labels are hidden.
- disabledReason={
- display === ChartDisplayType.ActionsPie && showValuesOnSeries === false
- ? "Enable 'Show values on series' to use this option"
- : undefined
- }
- />
- )
-}
-
function ConfidenceInterval(): JSX.Element {
const { insightProps } = useValues(insightLogic)
const { querySource, trendsFilter } = useValues(insightVizDataLogic(insightProps))
@@ -263,8 +246,9 @@ export const DisplayOptions = {
LifecycleStacking: { label: () => <LifecycleStackingFilter /> },
LifecyclePercentages: { label: () => <LifecyclePercentagesFilter /> },
ValueLabels: { label: () => <ValueOnSeriesFilter /> },
- PercentStack: { label: () => <PercentStack /> },
+ PercentStack: { label: () => <PercentStackViewFilter /> },
StackBreakdown: { label: () => <StackBreakdownFilter /> },
+ SliceNames: { label: () => <SliceNamesFilter /> },
PieTotal: { label: () => <ShowPieTotalFilter /> },
AlertThresholdLines: { label: () => <ShowAlertThresholdLinesFilter /> },
AlertAnomalyPoints: { label: () => <ShowAlertAnomalyPointsFilter /> },
diff --git a/frontend/src/queries/nodes/InsightViz/InsightDisplayConfig.test.tsx b/frontend/src/queries/nodes/InsightViz/InsightDisplayConfig.test.tsx
index 48358da98d01..11c594305bd0 100644
--- a/frontend/src/queries/nodes/InsightViz/InsightDisplayConfig.test.tsx
+++ b/frontend/src/queries/nodes/InsightViz/InsightDisplayConfig.test.tsx
@@ -195,6 +195,7 @@ describe('InsightDisplayConfig', () => {
displayItems: [
'Show values on series',
'Show as % of total',
+ 'Show names on slices',
'Show total below chart',
// In-chart legend toggle + position select ("Bottom" is the prospective default)
'Show legendBottom',
diff --git a/frontend/src/queries/nodes/InsightViz/insightDisplayOptions.tsx b/frontend/src/queries/nodes/InsightViz/insightDisplayOptions.tsx
index 6195e7bd7ba9..cb8451fdb3fb 100644
--- a/frontend/src/queries/nodes/InsightViz/insightDisplayOptions.tsx
+++ b/frontend/src/queries/nodes/InsightViz/insightDisplayOptions.tsx
@@ -85,6 +85,10 @@ 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
+ // 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)
// When the chart draws its own positioned in-chart legend, show the position selector instead
// of the legacy show/hide checkbox. usesInChartLegend is the single source of truth (same
// selector used by InsightVizDisplay to suppress the side legend). Funnel trends with breakdown
@@ -143,8 +147,8 @@ export function useInsightDisplayOptions(): { items: LemonMenuItems; count: numb
if ((hasLegend || showFunnelLegendConfig) && !useQuillLegendOptions) {
displayItems.push(DisplayOptions.Legend)
}
- if (display === ChartDisplayType.ActionsPie) {
- displayItems.push(DisplayOptions.PieTotal)
+ if (isPie) {
+ displayItems.push(DisplayOptions.SliceNames, DisplayOptions.PieTotal)
}
if (showAlertThresholdLinesConfig) {
displayItems.push(DisplayOptions.AlertThresholdLines, DisplayOptions.AlertAnomalyPoints)
@@ -191,7 +195,7 @@ export function useInsightDisplayOptions(): { items: LemonMenuItems; count: numb
})
}
- if (!showPercentStackView && isTrends && !isCalendarHeatmap) {
+ if (showsRawValues && isTrends && !isCalendarHeatmap) {
items.push({
title: axisLabel(display || ChartDisplayType.ActionsLineGraph),
items: [DisplayOptions.Unit],
@@ -243,7 +247,8 @@ export function useInsightDisplayOptions(): { items: LemonMenuItems; count: numb
(supportsValueOnSeries && showValuesOnSeries ? 1 : 0) +
(isLifecycle && showPercentagesOnSeries ? 1 : 0) +
(showPercentStackView ? 1 : 0) +
- (!showPercentStackView &&
+ (isPie && trendsFilter?.showLabelsOnSeries ? 1 : 0) +
+ (showsRawValues &&
isTrends &&
trendsFilter?.aggregationAxisFormat &&
trendsFilter.aggregationAxisFormat !== 'numeric'
diff --git a/frontend/src/scenes/insights/EditorFilters/PercentStackViewFilter.tsx b/frontend/src/scenes/insights/EditorFilters/PercentStackViewFilter.tsx
index cd7f1624f140..027319b6eb3c 100644
--- a/frontend/src/scenes/insights/EditorFilters/PercentStackViewFilter.tsx
+++ b/frontend/src/scenes/insights/EditorFilters/PercentStackViewFilter.tsx
@@ -5,7 +5,7 @@ import { trendsDataLogic } from 'scenes/trends/trendsDataLogic'
import { insightLogic } from '../insightLogic'
-export function PercentStackViewFilter({ disabledReason }: { disabledReason?: string }): JSX.Element {
+export function PercentStackViewFilter(): JSX.Element {
const { insightProps } = useValues(insightLogic)
const { showPercentStackView } = useValues(trendsDataLogic(insightProps))
const { updateInsightFilter } = useActions(trendsDataLogic(insightProps))
@@ -19,7 +19,6 @@ export function PercentStackViewFilter({ disabledReason }: { disabledReason?: st
}}
label={<span className="font-normal">Show as % of total</span>}
size="small"
- disabledReason={disabledReason}
/>
)
}
diff --git a/frontend/src/scenes/insights/EditorFilters/SliceNamesFilter.tsx b/frontend/src/scenes/insights/EditorFilters/SliceNamesFilter.tsx
new file mode 100644
index 000000000000..de83df474aad
--- /dev/null
+++ b/frontend/src/scenes/insights/EditorFilters/SliceNamesFilter.tsx
@@ -0,0 +1,25 @@
+import { useActions, useValues } from 'kea'
+
+import { LemonCheckbox } from 'lib/lemon-ui/LemonCheckbox'
+import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
+
+import { insightLogic } from '../insightLogic'
+
+// Pie only — it's the one display that draws the series label on the chart itself.
+export function SliceNamesFilter(): JSX.Element {
+ const { insightProps } = useValues(insightLogic)
+ const { updateInsightFilter } = useActions(insightVizDataLogic(insightProps))
+ const { showLabelOnSeries } = useValues(insightVizDataLogic(insightProps))
+
+ return (
+ <LemonCheckbox
+ className="p-1 px-2"
+ checked={!!showLabelOnSeries}
+ onChange={() => {
+ updateInsightFilter({ showLabelsOnSeries: !showLabelOnSeries })
+ }}
+ label={<span className="font-normal">Show names on slices</span>}
+ size="small"
+ />
+ )
+}
diff --git a/packages/quill/packages/charts/AGENTS.md b/packages/quill/packages/charts/AGENTS.md
index 611aa11f7c88..34fc2c9518d5 100644
--- a/packages/quill/packages/charts/AGENTS.md
+++ b/packages/quill/packages/charts/AGENTS.md
@@ -4,21 +4,21 @@ Quick-reference for AI agents using `@posthog/quill-charts`. Canvas-rendered cha
## Choosing a chart
-| Chart | Use when |
-| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| LineChart | Categorical x-axis trends; area fills, fill-between (confidence ribbons) |
-| BarChart | Categorical comparisons — `barLayout: 'stacked' \| 'grouped' \| 'percent'`, `axisOrientation: 'horizontal'` for horizontal bars; end-cap rounding via top-level `barCornerRadius` (the same key across the time-series/combo configs) |
-| FunnelChart | Funnel steps as grouped vertical bars over a hatched drop-off track — one band per step, one bar per variant, valued as percent-of-first-step (0–100) |
-| ComboChart | Mixed bar/line/area series on one band x-axis — set `Series.type`; vertical-only, `barLayout: 'stacked' \| 'grouped' \| 'percent'` (percent stacks bar series to 100%; a line/area series needs its own `yAxisId: 'right'` axis — one sharing the bars' axis can't plot raw values against their [0,1] scale) |
-| TimeSeriesLineChart | Time-indexed labels (ISO strings) with timezone/interval-aware x-axis |
-| TimeSeriesBarChart | Same x-axis handling, bar rendering; supports per-series `yAxisId` axes |
-| TimeSeriesComboChart | Mixed bar + line/area on a time x-axis — `ComboChart` plus the time-series chrome (date x-axis, goal lines, legend, value labels) |
-| PieChart | Part-of-whole, one value per series; `innerRadiusRatio` for donut + `centerLabel`; on-slice labels via `showLabelOnSlice`/`showValueOnSlice`, positioned with `labelRadiusRatio` (0=center, 1=rim) and gated by `minSlicePercentForLabel`; `config.legend` for the built-in legend (a toggled-off slice is removed and the rest rescale to the full circle) |
-| BoxPlot | Distribution summaries — `{ min, p25, median, mean, p75, max }` per label |
-| Heatmap | 2D density grid (e.g. latency over time) — `xLabels` × `yLabels` (row 0 at the bottom), `cells[row][col]` counts → color intensity on one accent (log ramp by default, `colorScale: 'linear'` to opt out); single-cell tooltip resolved from the cursor, `onCellClick` reports `{ xIndex, yIndex, value }` |
-| Sparkline | Tiny inline trend, no axes — a gradient-filled line (default) or stacked bars via `type: 'bar'`; a flat `number[]` + `color`, or full `series` for multi-series; tooltip off by default, opt in with a `tooltip` render prop |
-| MetricCard | Headline number + sparkline + change pill (dashboard stat tiles) |
-| SlopeChart | Change between two points (slopegraph) — one line per series, left "before" → right "after"; `data: [start, end]` |
+| Chart | Use when |
+| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| LineChart | Categorical x-axis trends; area fills, fill-between (confidence ribbons) |
+| BarChart | Categorical comparisons — `barLayout: 'stacked' \| 'grouped' \| 'percent'`, `axisOrientation: 'horizontal'` for horizontal bars; end-cap rounding via top-level `barCornerRadius` (the same key across the time-series/combo configs) |
+| FunnelChart | Funnel steps as grouped vertical bars over a hatched drop-off track — one band per step, one bar per variant, valued as percent-of-first-step (0–100) |
+| ComboChart | Mixed bar/line/area series on one band x-axis — set `Series.type`; vertical-only, `barLayout: 'stacked' \| 'grouped' \| 'percent'` (percent stacks bar series to 100%; a line/area series needs its own `yAxisId: 'right'` axis — one sharing the bars' axis can't plot raw values against their [0,1] scale) |
+| TimeSeriesLineChart | Time-indexed labels (ISO strings) with timezone/interval-aware x-axis |
+| TimeSeriesBarChart | Same x-axis handling, bar rendering; supports per-series `yAxisId` axes |
+| TimeSeriesComboChart | Mixed bar + line/area on a time x-axis — `ComboChart` plus the time-series chrome (date x-axis, goal lines, legend, value labels) |
+| PieChart | Part-of-whole, one value per series; `innerRadiusRatio` for donut + `centerLabel`; on-slice labels via `showLabelOnSlice`/`showValueOnSlice`, positioned with `labelRadiusRatio` (0=center, 1=rim) and gated by `minSlicePercentForLabel`; `sliceValueDisplay` picks what the numeric line holds — `'value'`, `'percent'`, or `'both'` for `352 (18.4%)` (defaults to `'percent'` when `isPercent` is set, else `'value'`); `config.legend` for the built-in legend (a toggled-off slice is removed and the rest rescale to the full circle) |
+| BoxPlot | Distribution summaries — `{ min, p25, median, mean, p75, max }` per label |
+| Heatmap | 2D density grid (e.g. latency over time) — `xLabels` × `yLabels` (row 0 at the bottom), `cells[row][col]` counts → color intensity on one accent (log ramp by default, `colorScale: 'linear'` to opt out); single-cell tooltip resolved from the cursor, `onCellClick` reports `{ xIndex, yIndex, value }` |
+| Sparkline | Tiny inline trend, no axes — a gradient-filled line (default) or stacked bars via `type: 'bar'`; a flat `number[]` + `color`, or full `series` for multi-series; tooltip off by default, opt in with a `tooltip` render prop |
+| MetricCard | Headline number + sparkline + change pill (dashboard stat tiles) |
+| SlopeChart | Change between two points (slopegraph) — one line per series, left "before" → right "after"; `data: [start, end]` |
## Theme wiring
diff --git a/packages/quill/packages/charts/src/charts/PieChart/PieChart.test.tsx b/packages/quill/packages/charts/src/charts/PieChart/PieChart.test.tsx
index ec6634012714..7b1a11b3f321 100644
--- a/packages/quill/packages/charts/src/charts/PieChart/PieChart.test.tsx
+++ b/packages/quill/packages/charts/src/charts/PieChart/PieChart.test.tsx
@@ -74,6 +74,13 @@ describe('PieChart', () => {
expect(text).toContain('50%')
})
+ it('renders value and percentage on one line when sliceValueDisplay is both', () => {
+ const { chart } = renderHogChart(
+ <PieChart series={SERIES} theme={THEME} config={{ sliceValueDisplay: 'both' }} />
+ )
+ expect(sliceLabels(chart.element).join('|')).toContain('50 (50%)')
+ })
+
it('suppresses on-slice value labels when showValueOnSlice is false', () => {
const { chart } = renderHogChart(
<PieChart series={SERIES} theme={THEME} config={{ showValueOnSlice: false }} />
diff --git a/packages/quill/packages/charts/src/charts/PieChart/PieChart.tsx b/packages/quill/packages/charts/src/charts/PieChart/PieChart.tsx
index 65f0094be7be..1ac442329278 100644
--- a/packages/quill/packages/charts/src/charts/PieChart/PieChart.tsx
+++ b/packages/quill/packages/charts/src/charts/PieChart/PieChart.tsx
@@ -20,6 +20,7 @@ import { computePieLayout } from './computePieLayout'
import type { PieLayout } from './computePieLayout'
import { PieTooltip } from './PieTooltip'
import { SliceLabels } from './SliceLabels'
+import type { SliceValueDisplay } from './SliceLabels'
export interface PieChartConfig<Meta = unknown> {
/** 0 = pie (default), 0.5 = donut. Clamped to [0, 0.95]. */
@@ -28,6 +29,10 @@ export interface PieChartConfig<Meta = unknown> {
showValueOnSlice?: boolean
/** Show the breakdown label above the slice. Default false. */
showLabelOnSlice?: boolean
+ /** What the on-slice numeric line contains. Defaults to `'percent'` when `isPercent` is set,
+ * else `'value'`. `'both'` renders `value (percent)` on one line. Gated by
+ * `showValueOnSlice`, which stays the on/off switch for that line. */
+ sliceValueDisplay?: SliceValueDisplay
/** Render slice values as percentages of total. Drives both axes-label-style formatting
* and the on-slice / tooltip formatting. */
isPercent?: boolean
@@ -145,6 +150,7 @@ function PieChartInner<Meta = unknown>({
innerRadiusRatio = 0,
showValueOnSlice = true,
showLabelOnSlice = false,
+ sliceValueDisplay,
isPercent = false,
hoverGrowth = DEFAULT_HOVER_GROWTH,
hoverAnimationMs = DEFAULT_HOVER_ANIMATION_MS,
@@ -260,6 +266,7 @@ function PieChartInner<Meta = unknown>({
valueFormatter={valueFormatter}
showValueOnSlice={showValueOnSlice}
showLabelOnSlice={showLabelOnSlice}
+ sliceValueDisplay={sliceValueDisplay}
minSlicePercentForLabel={minSlicePercentForLabel}
labelRadiusRatio={labelRadiusRatio}
isPercent={isPercent}
diff --git a/packages/quill/packages/charts/src/charts/PieChart/SliceLabels.tsx b/packages/quill/packages/charts/src/charts/PieChart/SliceLabels.tsx
index bf398ca4d6ea..cd648a3efe76 100644
--- a/packages/quill/packages/charts/src/charts/PieChart/SliceLabels.tsx
+++ b/packages/quill/packages/charts/src/charts/PieChart/SliceLabels.tsx
@@ -7,6 +7,8 @@ import { FONT_FAMILY, measureLabelWidth } from '../../utils/text-measure'
export { nonCollidingKeys } from '../../core/label-collision'
export type { LabelBox } from '../../core/label-collision'
+export type SliceValueDisplay = 'value' | 'percent' | 'both'
+
export interface SliceLabelsProps {
valueFormatter?: (value: number) => string
/** Show the slice's value above the slice. Default true. */
@@ -14,6 +16,9 @@ export interface SliceLabelsProps {
/** Show the breakdown label above the slice. Default false. When both are true, the
* label sits above the value. */
showLabelOnSlice?: boolean
+ /** What the numeric line contains. Defaults to `'percent'` when `isPercent` is set, else
+ * `'value'`. `'both'` renders `value (percent)`. */
+ sliceValueDisplay?: SliceValueDisplay
/** Hide labels for slices with `fraction < threshold`. Default 0.05. */
minSlicePercentForLabel?: number
/** Where labels sit along the radius: 0 = center, 1 = outer edge. Default 0.5 (mid-slice). */
@@ -49,14 +54,23 @@ function formatPercent(fraction: number): string {
return `${Math.round(fraction * 1000) / 10}%`
}
+function formatSliceValue(display: SliceValueDisplay, value: string, percent: string): string {
+ if (display === 'percent') {
+ return percent
+ }
+ return display === 'both' ? `${value} (${percent})` : value
+}
+
export function SliceLabels({
valueFormatter = defaultFormatter,
showValueOnSlice = true,
showLabelOnSlice = false,
+ sliceValueDisplay,
minSlicePercentForLabel = 0.05,
labelRadiusRatio = 0.5,
isPercent = false,
}: SliceLabelsProps): React.ReactElement | null {
+ const valueDisplay: SliceValueDisplay = sliceValueDisplay ?? (isPercent ? 'percent' : 'value')
const { layout } = useRadialLayout()
if (!showValueOnSlice && !showLabelOnSlice) {
return null
@@ -75,7 +89,7 @@ export function SliceLabels({
lines.push(slice.series.label)
}
if (showValueOnSlice) {
- lines.push(isPercent ? formatPercent(slice.fraction) : valueFormatter(slice.value))
+ lines.push(formatSliceValue(valueDisplay, valueFormatter(slice.value), formatPercent(slice.fraction)))
}
const width = Math.max(0, ...lines.map((line) => measureLabelWidth(line, LABEL_FONT)))
boxes.push({
diff --git a/packages/quill/packages/charts/src/index.ts b/packages/quill/packages/charts/src/index.ts
index 5c543a372218..473aa15c8bc9 100644
--- a/packages/quill/packages/charts/src/index.ts
+++ b/packages/quill/packages/charts/src/index.ts
@@ -91,7 +91,7 @@ export type { PieChartConfig, PieChartProps } from './charts/PieChart/PieChart'
export { computePieLayout, cursorOffsetToAngle, sliceAt, defaultSliceValue } from './charts/PieChart/computePieLayout'
export type { PieLayout, PieSlice } from './charts/PieChart/computePieLayout'
export { SliceLabels } from './charts/PieChart/SliceLabels'
-export type { SliceLabelsProps } from './charts/PieChart/SliceLabels'
+export type { SliceLabelsProps, SliceValueDisplay } from './charts/PieChart/SliceLabels'
export { PieTooltip } from './charts/PieChart/PieTooltip'
export type { PieTooltipProps } from './charts/PieChart/PieTooltip'
export { useRadialLayout } from './core/radial-context'
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 b10a91f9c5dc..a224c4d8be83 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.stories.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.stories.tsx
@@ -96,20 +96,28 @@ export const MinHeightParent: Story = {
render: () => renderTrendsPieChart(trendsPieBreakdownFixture, MinHeightStage),
}
+function renderBreakdownPieWithFilter(trendsFilter: Record<string, unknown>): JSX.Element {
+ return renderTrendsPieChart({
+ ...trendsPieBreakdownFixture,
+ query: {
+ ...trendsPieBreakdownFixture.query,
+ source: {
+ ...trendsPieBreakdownFixture.query.source,
+ trendsFilter: { ...trendsPieBreakdownFixture.query.source.trendsFilter, ...trendsFilter },
+ },
+ },
+ })
+}
+
export const BreakdownWithLabels: Story = {
+ render: () => renderBreakdownPieWithFilter({ showLabelsOnSeries: true, showValuesOnSeries: true }),
+}
+
+export const BreakdownWithValueAndPercentage: Story = {
render: () =>
- renderTrendsPieChart({
- ...trendsPieBreakdownFixture,
- query: {
- ...trendsPieBreakdownFixture.query,
- source: {
- ...trendsPieBreakdownFixture.query.source,
- trendsFilter: {
- ...trendsPieBreakdownFixture.query.source.trendsFilter,
- showLabelOnSeries: true,
- showValuesOnSeries: true,
- },
- },
- },
+ renderBreakdownPieWithFilter({
+ showLabelsOnSeries: true,
+ showValuesOnSeries: true,
+ showPercentStackView: true,
}),
}
diff --git a/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.test.tsx b/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.test.tsx
index 267be9979bec..179f28ac641c 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.test.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.test.tsx
@@ -48,9 +48,20 @@ describe('TrendsPieChart (ActionsPie)', () => {
},
{
name: 'formats slice values as percentages in percent stack view',
- query: pieByHedgehog({ showPercentStackView: true }),
+ query: pieByHedgehog({ showValuesOnSeries: false, showPercentStackView: true }),
expectedLabels: ['57.9%', '21.1%', '10.5%', '10.5%'],
},
+ {
+ name: 'shows the value and the percentage together when both options are on',
+ query: pieByHedgehog({ showPercentStackView: true }),
+ expectedLabels: ['11 (57.9%)', '4 (21.1%)', '2 (10.5%)', '2 (10.5%)'],
+ },
+ {
+ // Name and value are separate lines, so a slice's text content reads as name then value.
+ name: 'prefixes the slice with its name when labels on series is on',
+ query: pieByHedgehog({ showLabelsOnSeries: true }),
+ expectedLabels: ['Spike11', 'Thistle4', 'Bramble2', 'Prickles2'],
+ },
])('$name', async ({ query, expectedLabels }) => {
renderInsight({ query })
await screen.findByLabelText(/pie chart with/i, undefined, { timeout: 5000 })
diff --git a/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.tsx
index c94dfddf1692..fb3e73c55cb2 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsPieChart/TrendsPieChart.tsx
@@ -128,16 +128,23 @@ export function TrendsPieChart({
[trendsFilter, baseCurrency]
)
+ // Values and percentages are independent on a pie: either one alone puts that number on the
+ // slice, and both together read as `352 (18.4%)`, matching the tooltip.
+ const showValue = !!showValuesOnSeries
+ const showPercent = isPercentStackView
+
const pieConfig: PieChartConfig<TrendsSeriesMeta> = useMemo(
() => ({
- showValueOnSlice: !!showValuesOnSeries,
+ showValueOnSlice: showValue || showPercent,
+ sliceValueDisplay: showValue && showPercent ? 'both' : showPercent ? 'percent' : 'value',
showLabelOnSlice: !!showLabelOnSeries,
isPercent: isPercentStackView,
disableHoverOffset: !!pieChartVizOptions?.disableHoverOffset,
legend: legendConfig,
}),
[
- showValuesOnSeries,
+ showValue,
+ showPercent,
showLabelOnSeries,
isPercentStackView,
pieChartVizOptions?.disableHoverOffset,