: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): identify series in trends tooltip breakdown rows (#78534)
Sam Pennington8595a871e228
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex a61a8773ad0c..8bc5581fb15d 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -2764,6 +2764,18 @@ snapshots:hash: v1.k794b7964.51c09169b5a57e217572bc35c0882b15252b4af936921569bf8d2a1d3a330f2f.red8aW6nElMIxDUdAHhilR3Ls2NgRChoEmFzfpGcgbUinsights-funneltrendstable--default--light:hash: v1.k794b7964.f4486460f4481d343ecf8e0890d94f8d4c3da70164008d53bc762b6900623bc1.MRfTllR3ODYt6mNxjI-nTmfYZk0V2cXLMRmUwbKFC1Q+ insights-insightseriestooltip--multiple-formulas-with-breakdown--dark:+ hash: v1.k794b7964.22f2cf6ee12533e9fdfd0baba36d6666f0150b38634851779d9a97f4b09694d8.Tv1jXUYahN-tvUG5OBD6KOCEoTwDLuaTAU9HDW-Iw-Q+ insights-insightseriestooltip--multiple-formulas-with-breakdown--light:+ hash: v1.k794b7964.d8f1d85a326c2fa64b2474d747f6c2fc55a04837d4047e51f7be8081f01a728a.Q9OOrfePNmj_B2IgRrjI3EQqdrLjhktX66EcbKWtUjQ+ insights-insightseriestooltip--multiple-series-with-breakdown--dark:+ hash: v1.k794b7964.031f10c603c56dbd8364ae1f6fa94b18e55ce719014e24709384fd6bf6c88688.GpRquOpsHiTezIUsbDSGLmIBniVxY82G2dkiitKXJFU+ insights-insightseriestooltip--multiple-series-with-breakdown--light:+ hash: v1.k794b7964.aab48f4950e5ed1da0ef48e75ad65d754aaecd0527b1779980ae997958dd56f2.7ogPLJVbfRr0y0iw4HkXOZMv2jeP2rDLkWxp7aU_HX4+ insights-insightseriestooltip--same-event-series-with-breakdown--dark:+ hash: v1.k794b7964.a7c95d36156152f07dd33f571dd0a9c67fe96f510036b4ffde9627d6b274992d.fqieVhz4-p-dy9eKlmOpM_4N4wcVXeIEjShMEha1ccc+ insights-insightseriestooltip--same-event-series-with-breakdown--light:+ hash: v1.k794b7964.7fbc4c70dcfb77807cd72d37140eff2468055091f79f04e7ea8bf201aee2dd25.oNUrG_LVzG8BURRQZdldu7oMzL9dyPcIPMUMx2f6f9kinsights-insightstable--aggregation--dark:hash: v1.k794b7964.531d5fdec5bc837da5dd1f334b850e6321fde25a7fb70834856ae88338214e28.RVObUcwlwFdjIrk0GTbySMzPeAWR7zUyPLsUtdIu57winsights-insightstable--aggregation--light:diff --git a/frontend/src/test/insight-testing/mocks.ts b/frontend/src/test/insight-testing/mocks.tsindex e8513adcfd3d..7d69c8a0b919 100644--- a/frontend/src/test/insight-testing/mocks.ts+++ b/frontend/src/test/insight-testing/mocks.ts@@ -33,9 +33,16 @@ export interface QueryBody {[key: string]: unknown}-function hasFormula(query: QueryBody): boolean {+/** Display labels the real runner would give each formula (custom name or "Formula (…)"). */+function formulaLabels(query: QueryBody): string[] {const tf = query.trendsFilter- return !!(tf?.formula || tf?.formulas?.length || tf?.formulaNodes?.length)+ if (tf?.formulaNodes?.length) {+ return (tf.formulaNodes as Array<{ formula?: string; custom_name?: string }>).map(+ (node) => node.custom_name ?? `Formula (${node.formula})`+ )+ }+ const formulas = tf?.formulas?.length ? tf.formulas : tf?.formula ? [tf.formula] : []+ return formulas.map((formula) => `Formula (${formula})`)}interface FunnelsQueryResponseLike {@@ -74,24 +81,54 @@ export function buildActorsResponse(} as ActorsQueryResponse}-// `isFormula` only models the single-formula shape: the real runner combines series per-// formula (`action: null`, `order` = formula index). This mock doesn't combine series, so-// it stamps `order: 0` on every row, which works for a single formula. A future multi-formula-// test would need this to derive the formula index per row (0 for A, 1 for B, …).-function buildTrendsResponse(series: SeriesData[], opts: { isFormula?: boolean } = {}): TrendsQueryResponse {+// A single formula keeps the legacy shape: every input row is returned with `action: null`+// and `order: 0`, without combining series. Multiple formulas mirror the real runner more+// closely: the first query series' rows act as the per-breakdown template, and each formula+// emits one result per template row (`order` = formula index, `label` = formula label), with+// values scaled per formula so rows stay distinguishable in assertions.+function buildTrendsResponse(series: SeriesData[], opts: { formulaLabels?: string[] } = {}): TrendsQueryResponse {+ const isFormula = !!opts.formulaLabels?.length+ if (opts.formulaLabels && opts.formulaLabels.length > 1) {+ const templateRows = series.filter((s) => (s.seriesIndex ?? 0) === 0)+ return {+ results: opts.formulaLabels.flatMap((label, formulaIdx) =>+ templateRows.map((s) => {+ const data = s.data.map((v) => v * (formulaIdx + 1))+ return {+ action: null,+ order: formulaIdx,+ label,+ count: data.reduce((a, b) => a + b, 0),+ aggregated_value: data.reduce((a, b) => a + b, 0),+ data,+ labels: s.labels ?? s.data.map((_, j) => `Day ${j + 1}`),+ days: s.days ?? s.data.map((_, j) => `2024-01-0${j + 1}`),+ breakdown_value: s.breakdown_value,+ compare: s.compare,+ compare_label: s.compare_label,+ }+ })+ ),+ } as TrendsQueryResponse+ }return {results: series.map((s, i) => {- const seriesOrder = s.compare || s.breakdown_value != null ? 0 : i+ // Breakdown/compare rows carry their parent series' identity (event name and+ // order), like the real runner. Plain rows keep their own label as the entity+ // name so fixtures can model several distinct series under one canned event.+ const isChildRow = s.compare || s.breakdown_value != null+ const seriesOrder = isChildRow ? (s.seriesIndex ?? 0) : i+ const entityName = (isChildRow ? s.eventName : undefined) ?? s.labelreturn {- action: opts.isFormula+ action: isFormula? null: {- id: `$${s.label.toLowerCase().replace(/\s+/g, '_')}`,+ id: `$${entityName.toLowerCase().replace(/\s+/g, '_')}`,type: 'events',- name: s.label,+ name: entityName,order: seriesOrder,},- order: opts.isFormula ? 0 : seriesOrder,+ order: isFormula ? 0 : seriesOrder,label: s.label,count: s.data.reduce((a, b) => a + b, 0),aggregated_value: s.data.reduce((a, b) => a + b, 0),@@ -113,13 +150,15 @@ function buildStickinessResponse(series: SeriesData[]): TrendsQueryResponse {return {results: series.map((s, i) => {const buckets = s.data.length- // Compare current/previous share one series identity (order 0), mirroring the real runner.- const seriesOrder = s.compare || s.breakdown_value != null ? 0 : i+ // Compare current/previous and breakdown rows share their series' identity, mirroring the real runner.+ const isChildRow = s.compare || s.breakdown_value != null+ const seriesOrder = isChildRow ? (s.seriesIndex ?? 0) : i+ const entityName = (isChildRow ? s.eventName : undefined) ?? s.labelreturn {action: {- id: `$${s.label.toLowerCase().replace(/\s+/g, '_')}`,+ id: `$${entityName.toLowerCase().replace(/\s+/g, '_')}`,type: 'events',- name: s.label,+ name: entityName,order: seriesOrder,},label: s.label,@@ -192,15 +231,15 @@ function resolveSeriesData(query: QueryBody): SeriesData[] {const breakdownProp = query.breakdownFilter?.breakdowns?.[0]?.property ?? query.breakdownFilter?.breakdown ?? nullconst isCompare = !!(query as Record<string, unknown>).compareFilter- return (query.series ?? []).flatMap((s) => {+ return (query.series ?? []).flatMap((s, seriesIndex) => {const eventName = s.event ?? s.name ?? 'Unknown'if (isCompare) {const compareSeries = lookupCompareSeries(eventName)if (compareSeries) {- return compareSeries+ return compareSeries.map((row) => ({ ...row, seriesIndex, eventName }))}}- return lookupSeries(eventName, breakdownProp ?? undefined)+ return lookupSeries(eventName, breakdownProp ?? undefined).map((row) => ({ ...row, seriesIndex, eventName }))})}@@ -241,7 +280,7 @@ export function setupInsightMocks({const defaults: MockResponse[] = [{match: (query) => query.kind === NodeKind.TrendsQuery,- response: (query) => buildTrendsResponse(resolveSeriesData(query), { isFormula: hasFormula(query) }),+ response: (query) => buildTrendsResponse(resolveSeriesData(query), { formulaLabels: formulaLabels(query) }),},{match: (query) => query.kind === NodeKind.StickinessQuery,diff --git a/frontend/src/test/insight-testing/test-data.ts b/frontend/src/test/insight-testing/test-data.tsindex a30fb39f8afd..332c43fa307d 100644--- a/frontend/src/test/insight-testing/test-data.ts+++ b/frontend/src/test/insight-testing/test-data.ts@@ -89,6 +89,10 @@ export interface SeriesData {breakdown_value?: string | numbercompare?: booleancompare_label?: string+ /** Index of the query series this row belongs to — stamped by the mock resolver. */+ seriesIndex?: number+ /** Event name of the query series this row belongs to — stamped by the mock resolver. */+ eventName?: string}type CannedSeries = SeriesData & { labels: string[]; days: string[] }@@ -113,6 +117,10 @@ export const trendsSeries = {{ label: 'Conker', data: [0, 0, 0, 0, 0], days, labels, breakdown_value: 'Conker' },{ label: 'Prickles', data: [0, 0, 1, 1, 0], days, labels, breakdown_value: 'Prickles' },] satisfies CannedSeries[],+ pageviewsByHedgehog: [+ { label: 'Spike', data: [30, 50, 90, 140, 60], days, labels, breakdown_value: 'Spike' },+ { label: 'Bramble', data: [15, 32, 44, 70, 35], days, labels, breakdown_value: 'Bramble' },+ ] satisfies CannedSeries[],withZeroCounts: [{ label: 'EmptySeries', data: [0, 0, 0, 0, 0], days, labels },{ label: 'ActiveSeries', data: [1, 2, 3, 2, 2], days, labels },@@ -153,7 +161,12 @@ interface EventSeriesConfig {}const seriesByEvent: Record<string, EventSeriesConfig> = {- $pageview: { default: trendsSeries.pageviews },+ $pageview: {+ default: trendsSeries.pageviews,+ breakdowns: {+ hedgehog: trendsSeries.pageviewsByHedgehog,+ },+ },Napped: {default: trendsSeries.napped,breakdowns: {diff --git a/products/product_analytics/frontend/insights/shared/InsightSeriesTooltip.stories.tsx b/products/product_analytics/frontend/insights/shared/InsightSeriesTooltip.stories.tsxnew file mode 100644index 000000000000..fa8898cc1a8a--- /dev/null+++ b/products/product_analytics/frontend/insights/shared/InsightSeriesTooltip.stories.tsx@@ -0,0 +1,188 @@+import type { Meta, StoryObj } from '@storybook/react'++import { TimeSeriesLineChart } from '@posthog/quill-charts'+import { Stage, playHoverAtFraction } from '@posthog/quill-charts/story-helpers'++import { useChartTheme } from 'lib/charts/hooks'++import type { BreakdownFilter } from '~/queries/schema/schema-general'++import type { TrendsSeriesMeta } from '../trends/shared/trendsSeriesMeta'+import { InsightSeriesTooltip } from './InsightSeriesTooltip'++const DAYS = ['2024-06-10', '2024-06-11', '2024-06-12', '2024-06-13', '2024-06-14']++const BOOLEAN_BREAKDOWN_FILTER: BreakdownFilter = { breakdown: 'is_subscribed', breakdown_type: 'event' }++interface FixtureSeries {+ label: string+ data: number[]+ /** Event name — omit for formula rows, which have no `action`. */+ event?: string+ /** Formula label carried as `series_name` for rows without an event. */+ seriesName?: string+ seriesOrder: number+ breakdown_value: string+}++function buildSeries(fixtures: FixtureSeries[]): {+ key: string+ label: string+ data: number[]+ meta: TrendsSeriesMeta+}[] {+ return fixtures.map((f, i) => ({+ key: String(i),+ label: f.label,+ data: f.data,+ meta: {+ action: f.event ? { id: f.event, name: f.event, type: 'events', order: f.seriesOrder } : undefined,+ series_name: f.seriesName,+ breakdown_value: f.breakdown_value,+ days: DAYS,+ order: f.seriesOrder,+ },+ }))+}++function TooltipChart({ fixtures }: { fixtures: FixtureSeries[] }): JSX.Element {+ const theme = useChartTheme()+ return (+ <Stage width={760}>+ <TimeSeriesLineChart<TrendsSeriesMeta>+ series={buildSeries(fixtures)}+ labels={DAYS}+ theme={theme}+ config={{ xAxis: { timezone: 'UTC', interval: 'day' } }}+ tooltip={(ctx) => (+ <InsightSeriesTooltip+ context={ctx}+ breakdownFilter={BOOLEAN_BREAKDOWN_FILTER}+ interval="day"+ timezone="UTC"+ />+ )}+ />+ </Stage>+ )+}++const meta: Meta<typeof InsightSeriesTooltip> = {+ title: 'Insights/InsightSeriesTooltip',+ component: InsightSeriesTooltip,+ parameters: {+ layout: 'centered',+ testOptions: { snapshotBrowsers: ['chromium'] },+ },+}+export default meta++type Story = StoryObj<typeof InsightSeriesTooltip>++// Two different events with a boolean breakdown: each row is prefixed with the+// series name so the repeated true/false values stay attributable.+export const MultipleSeriesWithBreakdown: Story = {+ render: () => (+ <TooltipChart+ fixtures={[+ {+ label: 'true',+ data: [45, 82, 134, 210, 95],+ event: '$pageview',+ seriesOrder: 0,+ breakdown_value: 'true',+ },+ {+ label: 'false',+ data: [20, 31, 46, 70, 38],+ event: '$pageview',+ seriesOrder: 0,+ breakdown_value: 'false',+ },+ {+ label: 'true',+ data: [8, 12, 21, 30, 14],+ event: 'signed_up',+ seriesOrder: 1,+ breakdown_value: 'true',+ },+ { label: 'false', data: [2, 4, 5, 9, 3], event: 'signed_up', seriesOrder: 1, breakdown_value: 'false' },+ ]}+ />+ ),+ play: async ({ canvasElement }) => await playHoverAtFraction(canvasElement, 0.5),+}++// The same event added twice (e.g. with different filters): names alone can't tell+// the series apart, so rows also carry the A/B letters from the insight editor.+export const SameEventSeriesWithBreakdown: Story = {+ render: () => (+ <TooltipChart+ fixtures={[+ {+ label: 'true',+ data: [45, 82, 134, 210, 95],+ event: '$pageview',+ seriesOrder: 0,+ breakdown_value: 'true',+ },+ {+ label: 'false',+ data: [20, 31, 46, 70, 38],+ event: '$pageview',+ seriesOrder: 0,+ breakdown_value: 'false',+ },+ {+ label: 'true',+ data: [8, 12, 21, 30, 14],+ event: '$pageview',+ seriesOrder: 1,+ breakdown_value: 'true',+ },+ { label: 'false', data: [2, 4, 5, 9, 3], event: '$pageview', seriesOrder: 1, breakdown_value: 'false' },+ ]}+ />+ ),+ play: async ({ canvasElement }) => await playHoverAtFraction(canvasElement, 0.5),+}++// Formula series have no `action`; their `order` and `series_name` keep the repeated+// breakdown values from separate formulas attributable.+export const MultipleFormulasWithBreakdown: Story = {+ render: () => (+ <TooltipChart+ fixtures={[+ {+ label: 'true',+ data: [45, 82, 134, 210, 95],+ seriesName: 'Formula (A+B)',+ seriesOrder: 0,+ breakdown_value: 'true',+ },+ {+ label: 'false',+ data: [20, 31, 46, 70, 38],+ seriesName: 'Formula (A+B)',+ seriesOrder: 0,+ breakdown_value: 'false',+ },+ {+ label: 'true',+ data: [8, 12, 21, 30, 14],+ seriesName: 'Formula (A-B)',+ seriesOrder: 1,+ breakdown_value: 'true',+ },+ {+ label: 'false',+ data: [2, 4, 5, 9, 3],+ seriesName: 'Formula (A-B)',+ seriesOrder: 1,+ breakdown_value: 'false',+ },+ ]}+ />+ ),+ play: async ({ canvasElement }) => await playHoverAtFraction(canvasElement, 0.5),+}diff --git a/products/product_analytics/frontend/insights/shared/InsightSeriesTooltip.tsx b/products/product_analytics/frontend/insights/shared/InsightSeriesTooltip.tsxindex 7a104a13db79..cba382b6cb62 100644--- a/products/product_analytics/frontend/insights/shared/InsightSeriesTooltip.tsx+++ b/products/product_analytics/frontend/insights/shared/InsightSeriesTooltip.tsx@@ -3,8 +3,10 @@ import { useCallback, useMemo } from 'react'import { DefaultTooltip, type TooltipContext } from '@posthog/quill-charts'+import { SeriesGlyph } from 'lib/components/SeriesGlyph'import { parseDateInTimezone } from 'lib/utils/datetime'import { percentage } from 'lib/utils/numbers'+import { alphabet } from 'lib/utils/strings'import { formatAggregationAxisValue } from 'scenes/insights/aggregationAxisFormat'import {getDatumTitle,@@ -23,6 +25,8 @@ import { ActionFilter, IntervalType } from '~/types'type InsightSeriesMetaBase = {action?: ActionFilter+ /** Series name for rows without an `action` — formula series carry their formula label here. */+ series_name?: stringbreakdown_value?: string | number | string[] | nullcompare_label?: SeriesDatum['compare_label']days?: string[]@@ -89,11 +93,22 @@ function formatRowValue(// ── SeriesLabel ────────────────────────────────────────────────────────────+/** How rows must identify the series they belong to:+ * `none` — single series (or no way to tell them apart), no identifier needed;+ * `name` — series names differ, the name alone identifies a row;+ * `letter-and-name` — several series share a display name (e.g. the same event added+ * twice with different math/filters), so the name is prefixed with the series letter+ * (A, B, …) shown in the insight editor. */+export type SeriesIdentification = 'none' | 'name' | 'letter-and-name'++/** `SeriesDatum` plus the series name for rows whose meta has no `action` (formula series). */+type TooltipSeriesDatum = SeriesDatum & { series_name?: string }+interface SeriesLabelProps {- datum: SeriesDatum+ datum: TooltipSeriesDatumbreakdownFilter?: BreakdownFilterformatCompareLabel?: (label: string, dateLabel?: string) => string- hasMultipleEvents: boolean+ seriesIdentification: SeriesIdentificationrenderSeriesOverride?: (datum: SeriesDatum) => React.ReactNode}@@ -108,7 +123,7 @@ export function SeriesLabel({datum,breakdownFilter,formatCompareLabel,- hasMultipleEvents,+ seriesIdentification,renderSeriesOverride,}: SeriesLabelProps): React.ReactNode {if (renderSeriesOverride) {@@ -118,8 +133,31 @@ export function SeriesLabel({const hasBreakdown =datum.breakdown_value !== undefined && datum.breakdown_value !== null && datum.breakdown_value !== ''+ const seriesLetter =+ seriesIdentification === 'letter-and-name' ? (+ <SeriesGlyph+ className="mr-1 shrink-0 size-3.5 border text-[0.5rem]"+ // The tooltip surface sets its own text color and stays light even in dark+ // mode, so theme vars like --text-3000 can end up invisible on it — inherit+ // the surface's ink instead.+ // eslint-disable-next-line react/forbid-dom-props+ style={{ color: 'currentColor', borderColor: 'currentColor' }}+ >+ {alphabet[datum.action?.order ?? datum.order]}+ </SeriesGlyph>+ ) : null+if (!hasBreakdown && !datum.compare_label) {- return datum.label+ // A plain row's label already is the series name, so only the letter can add anything.+ if (!seriesLetter) {+ return datum.label+ }+ return (+ <span className="inline-flex items-center w-full overflow-hidden">+ {seriesLetter}+ <span className="truncate min-w-0 flex-1">{datum.label}</span>+ </span>+ )}const comparePeriod = datum.compare_label@@ -134,16 +172,21 @@ export function SeriesLabel({? getDatumTitle({ ...datum, compare_label: undefined }, breakdownFilter, formatCompareLabel): null- const eventPrefix = hasMultipleEvents ? (- <span className="opacity-50 mr-1 shrink-0">- {(datum.action ? getDisplayNameFromEntityFilter(datum.action) : null) ?? datum.label} ·- </span>- ) : null+ const seriesPrefix =+ seriesIdentification !== 'none' ? (+ <span className="opacity-50 shrink-0 inline-flex items-center">+ {seriesLetter}+ <span>+ {(datum.action ? getDisplayNameFromEntityFilter(datum.action) : datum.series_name) ?? datum.label}+ · + </span>+ </span>+ ) : null// inline-flex: breakdown span truncates (flex-1), period label stays visible (shrink-0).return (<span className="inline-flex items-center w-full overflow-hidden">- {eventPrefix}+ {seriesPrefix}<span className="truncate min-w-0 flex-1">{breakdownTitle ?? datum.label}</span>{comparePeriod && <span className="shrink-0 opacity-60"> · {comparePeriod}</span>}</span>@@ -182,7 +225,7 @@ export function InsightSeriesTooltip<Meta extends InsightSeriesMetaBase>({// Quill delivers one entry per series key; map to SeriesDatum so existing// formatting helpers (getDatumTitle, formatAggregationValue, etc.) stay reusable.const datumByKey = useMemo(() => {- const m = new Map<string, SeriesDatum>()+ const m = new Map<string, TooltipSeriesDatum>()context.seriesData.forEach((entry, idx) => {const meta = (entry.series.meta ?? {}) as InsightSeriesMetaBasem.set(entry.series.key, {@@ -194,6 +237,7 @@ export function InsightSeriesTooltip<Meta extends InsightSeriesMetaBase>({color: entry.color,count: entry.value,action: meta.action,+ series_name: meta.series_name,breakdown_value: meta.breakdown_value ?? undefined,compare_label: meta.compare_label,date_label: meta.days?.[context.dataIndex],@@ -203,9 +247,23 @@ export function InsightSeriesTooltip<Meta extends InsightSeriesMetaBase>({return m}, [context.seriesData, context.dataIndex])- const hasMultipleEvents = useMemo(() => {- const events = new Set([...datumByKey.values()].map((d) => d.action?.id ?? d.action?.name))- return events.size > 1+ const seriesIdentification = useMemo((): SeriesIdentification => {+ // One entry per series entity — breakdown/compare rows of one series share its `order`.+ // Formula series have no `action`, but their `order` still identifies the formula they+ // came from, with `series_name` carrying the formula label.+ const nameByEntity = new Map<number | string, string>()+ for (const d of datumByKey.values()) {+ if (d.action) {+ const entityKey = d.action.order ?? `${d.action.type}:${d.action.id}`+ nameByEntity.set(entityKey, getDisplayNameFromEntityFilter(d.action) ?? '')+ } else if (d.series_name != null) {+ nameByEntity.set(d.order, d.series_name)+ }+ }+ if (nameByEntity.size <= 1) {+ return 'none'+ }+ return new Set(nameByEntity.values()).size < nameByEntity.size ? 'letter-and-name' : 'name'}, [datumByKey])const valueFormatter = useCallback(@@ -247,12 +305,12 @@ export function InsightSeriesTooltip<Meta extends InsightSeriesMetaBase>({datum={datum}breakdownFilter={breakdownFilter}formatCompareLabel={formatCompareLabel}- hasMultipleEvents={hasMultipleEvents}+ seriesIdentification={seriesIdentification}renderSeriesOverride={renderSeriesOverride}/>)},- [datumByKey, breakdownFilter, formatCompareLabel, hasMultipleEvents, renderSeriesOverride]+ [datumByKey, breakdownFilter, formatCompareLabel, seriesIdentification, renderSeriesOverride])const labelFormatter = useCallback((): React.ReactNode => {diff --git a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsxindex 9e39a02601ec..fa968bd59227 100644--- a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx+++ b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.test.tsx@@ -111,6 +111,46 @@ describe('TrendsLineChart', () => {expect(tooltip.row('Spike')).toContain('3')})+ it('prefixes rows with the series name when multiple series share a breakdown', async () => {+ renderInsight({+ query: buildTrendsQuery({+ series: [+ { kind: NodeKind.EventsNode, event: '$pageview', name: '$pageview' },+ { kind: NodeKind.EventsNode, event: 'Napped', name: 'Napped' },+ ],+ breakdownFilter: { breakdown: 'hedgehog', breakdown_type: 'event' },+ }),+ })++ await chart.clickAtIndex(2)++ // Each breakdown value appears once per series; without the prefix the rows+ // would be indistinguishable (e.g. two bare "Spike" rows).+ const tooltip = createInsightTooltipAccessor(chart.getTooltip()!)+ expect(tooltip.row('Pageview · Spike')).toContain('90')+ expect(tooltip.row('Napped · Spike')).toContain('3')+ })++ it('adds series letters when same-named series share a breakdown', async () => {+ renderInsight({+ query: buildTrendsQuery({+ series: [+ { kind: NodeKind.EventsNode, event: 'Napped', name: 'Napped' },+ { kind: NodeKind.EventsNode, event: 'Napped', name: 'Napped' },+ ],+ breakdownFilter: { breakdown: 'hedgehog', breakdown_type: 'event' },+ }),+ })++ await chart.clickAtIndex(2)++ // The name alone can't tell the two series apart, so rows get the A/B+ // letters from the insight editor.+ const tooltip = createInsightTooltipAccessor(chart.getTooltip()!)+ const spikeRows = tooltip.rows().filter((label) => label.includes('Spike'))+ expect(spikeRows.map((label) => label[0]).sort()).toEqual(['A', 'B'])+ })+it('shows every breakdown value when a formula is applied', async () => {renderInsight({query: buildTrendsQuery({@@ -128,6 +168,24 @@ describe('TrendsLineChart', () => {expect(tooltip.row('Prickles')).toContain('1')})+ it('prefixes rows with the formula name when multiple formulas share a breakdown', async () => {+ renderInsight({+ query: buildTrendsQuery({+ series: [{ kind: NodeKind.EventsNode, event: 'Napped', name: 'Napped' }],+ breakdownFilter: { breakdown: 'hedgehog', breakdown_type: 'event' },+ trendsFilter: { formulas: ['A', 'A*2'] },+ }),+ })++ await chart.clickAtIndex(2)++ // Formula rows carry no `action`; their `order` is what keeps the repeated+ // breakdown values from separate formulas attributable.+ const tooltip = createInsightTooltipAccessor(chart.getTooltip()!)+ expect(tooltip.row('Formula (A) · Spike')).toContain('3')+ expect(tooltip.row('Formula (A*2) · Spike')).toContain('6')+ })+it('shows current and previous period rows in compare mode', async () => {renderInsight({query: buildTrendsQuery({diff --git a/products/product_analytics/frontend/insights/trends/shared/trendsSeriesMeta.ts b/products/product_analytics/frontend/insights/trends/shared/trendsSeriesMeta.tsindex 8ca04ec18085..3d76a243d5f0 100644--- a/products/product_analytics/frontend/insights/trends/shared/trendsSeriesMeta.ts+++ b/products/product_analytics/frontend/insights/trends/shared/trendsSeriesMeta.ts@@ -6,6 +6,8 @@ import type { ActionFilter } from '~/types'export type TrendsSeriesMeta = {action?: ActionFilter+ /** Series name for results without an `action` — formula results carry their formula label here. */+ series_name?: stringbreakdown_value?: string | number | string[]compare_label?: SeriesDatum['compare_label']days?: string[]@@ -15,6 +17,9 @@ export type TrendsSeriesMeta = {export const buildTrendsSeriesMeta = (r: IndexedTrendResult): TrendsSeriesMeta => ({action: r.action ?? undefined,+ // Formula results have no `action`; their raw label (custom name or "Formula (…)") is the+ // only series name available for tooltip attribution.+ series_name: r.action ? undefined : r.label,breakdown_value: r.breakdown_value,compare_label: r.compare_label,days: r.days,