: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
feat(funnels): add legend support to historical trends chart (#63048)
Christiaan Hendriksena848c0af1277
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex ab502ebe47fa..74c5528e0b8d 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -2196,6 +2196,10 @@ snapshots:hash: v1.k794b7964.45a7b21ee36a90050b24c80f6bdd6494bf521f54ba60970318ff3e1e0d08595b.ebE-5Jtv5yrhECpzULKlmaaQP38hfQ_xmjaGNJYxJysinsights-funnellinechart--value-labels--light:hash: v1.k794b7964.e77fc0556d6cb2928d6f4733a2469335c193dc4e69d3709979b56c48b3336a26.-ANj2Y7kjX0XvQaWN4iIavrWM-Spk8vjpICJr4WX5_0+ insights-funnellinechart--with-legend--dark:+ hash: v1.k794b7964.91d6de8992e7b49f3dbe2989778ae54a5e9478a6136e1f5b34eb1eab4356711f.lWuIgyArPItzhZJDTIwVB-xZL8uCnt67DTANC5OKtJY+ insights-funnellinechart--with-legend--light:+ hash: v1.k794b7964.6b4d0969a75cf3df9e5c989ce373d153c77d1eedaedb72105ee78145fd9414e3.ve7yvcN4Bx2DPN9sNmeG1y-KKrJXxjH8IJdRtMg2nksinsights-funnelpropertycorrelationtable--default--dark:hash: v1.k794b7964.c35a775de5f646fde698940d41eef4f82a28c73a3343a2cd5ae88bb65d5c7dda.zrfCnSRUrx6zbKiA_UyVw7m7hKgwbLbkgjnuwMUxk00insights-funnelpropertycorrelationtable--default--light:diff --git a/frontend/src/lib/components/Cards/InsightCard/legendToggle.test.ts b/frontend/src/lib/components/Cards/InsightCard/legendToggle.test.tsindex b931dbfd76b8..ac63b2d2fb6b 100644--- a/frontend/src/lib/components/Cards/InsightCard/legendToggle.test.ts+++ b/frontend/src/lib/components/Cards/InsightCard/legendToggle.test.ts@@ -20,6 +20,7 @@ describe('legendToggle', () => {trendsFilter: { display: ChartDisplayType.ActionsLineGraph },},},+ hogChartsFunnelEnabled: false,expected: true,},{@@ -31,6 +32,7 @@ describe('legendToggle', () => {trendsFilter: { display: ChartDisplayType.WorldMap },},},+ hogChartsFunnelEnabled: false,expected: false,},{@@ -42,6 +44,45 @@ describe('legendToggle', () => {funnelsFilter: { funnelVizType: 'steps' },},},+ hogChartsFunnelEnabled: false,+ expected: false,+ },+ {+ title: 'funnels historical trends with breakdown and hog charts enabled',+ query: {+ kind: NodeKind.InsightVizNode,+ source: {+ kind: NodeKind.FunnelsQuery,+ funnelsFilter: { funnelVizType: 'trends' },+ breakdownFilter: { breakdown: '$browser', breakdown_type: 'event' },+ },+ },+ hogChartsFunnelEnabled: true,+ expected: true,+ },+ {+ title: 'funnels historical trends with breakdown but hog charts disabled',+ query: {+ kind: NodeKind.InsightVizNode,+ source: {+ kind: NodeKind.FunnelsQuery,+ funnelsFilter: { funnelVizType: 'trends' },+ breakdownFilter: { breakdown: '$browser', breakdown_type: 'event' },+ },+ },+ hogChartsFunnelEnabled: false,+ expected: false,+ },+ {+ title: 'funnels historical trends without breakdown',+ query: {+ kind: NodeKind.InsightVizNode,+ source: {+ kind: NodeKind.FunnelsQuery,+ funnelsFilter: { funnelVizType: 'trends' },+ },+ },+ hogChartsFunnelEnabled: true,expected: false,},{@@ -50,6 +91,7 @@ describe('legendToggle', () => {kind: NodeKind.InsightVizNode,source: { kind: NodeKind.LifecycleQuery },},+ hogChartsFunnelEnabled: false,expected: true,},{@@ -61,15 +103,17 @@ describe('legendToggle', () => {trendsFilter: { display: ChartDisplayType.ActionsTable },},},+ hogChartsFunnelEnabled: false,expected: false,},{title: 'non-insight-viz (SQL)',query: { kind: NodeKind.DataVisualizationNode },+ hogChartsFunnelEnabled: false,expected: false,},- ])('returns $expected for $title', ({ query, expected }) => {- expect(canToggleLegendInInsightQuery(query as any)).toBe(expected)+ ])('returns $expected for $title', ({ query, expected, hogChartsFunnelEnabled }) => {+ expect(canToggleLegendInInsightQuery(query as any, hogChartsFunnelEnabled)).toBe(expected)})})@@ -90,6 +134,11 @@ describe('legendToggle', () => {filterKey: 'lifecycleFilter',display: undefined,},+ {+ kind: NodeKind.FunnelsQuery,+ filterKey: 'funnelsFilter',+ display: undefined,+ },])('sets showLegend true when unset ($kind)', ({ kind, filterKey, display }) => {const query = {kind: NodeKind.InsightVizNode,@@ -147,6 +196,23 @@ describe('legendToggle', () => {expect(getLegendToggleText(query)).toBe('Show legend')})+ it('reflects toggle state for funnels historical trends when hog charts are enabled', () => {+ const query = {+ kind: NodeKind.InsightVizNode,+ source: {+ kind: NodeKind.FunnelsQuery,+ funnelsFilter: { funnelVizType: 'trends' },+ breakdownFilter: { breakdown: '$browser', breakdown_type: 'event' },+ },+ } as any++ expect(getLegendToggleText(query, true)).toBe('Show legend')++ const next = toggleLegendInInsightQuery(query) as any+ expect(next.source.funnelsFilter?.showLegend).toBe(true)+ expect(getLegendToggleText(next, true)).toBe('Hide legend')+ })+it('after toggling unset legend, label reads hide', () => {const query = {kind: NodeKind.InsightVizNode,diff --git a/frontend/src/lib/components/Cards/InsightCard/legendToggle.ts b/frontend/src/lib/components/Cards/InsightCard/legendToggle.tsindex 6c833fd8d22b..da41f3d74758 100644--- a/frontend/src/lib/components/Cards/InsightCard/legendToggle.ts+++ b/frontend/src/lib/components/Cards/InsightCard/legendToggle.ts@@ -1,17 +1,37 @@import { DISPLAY_TYPES_WITHOUT_LEGEND } from 'lib/components/InsightLegend/utils'import { InsightVizNode } from '~/queries/schema/schema-general'-import { getShowLegend, isInsightVizNode, isLifecycleQuery, isStickinessQuery, isTrendsQuery } from '~/queries/utils'-import { QueryBasedInsightModel } from '~/types'+import {+ getShowLegend,+ hasBreakdownFilter,+ isFunnelsQuery,+ isInsightVizNode,+ isLifecycleQuery,+ isStickinessQuery,+ isTrendsQuery,+} from '~/queries/utils'+import { FunnelVizType, QueryBasedInsightModel } from '~/types'// Eligibility matches insightVizDataLogic `hasLegend` (trends / stickiness / lifecycle, excluding DISPLAY_TYPES_WITHOUT_LEGEND).-export function canToggleLegendInInsightQuery(query: QueryBasedInsightModel['query']): boolean {+export function canToggleLegendInInsightQuery(+ query: QueryBasedInsightModel['query'],+ hogChartsFunnelEnabled: boolean = false+): boolean {if (!isInsightVizNode(query)) {return false}const source = query.source++ if (isFunnelsQuery(source)) {+ return (+ hogChartsFunnelEnabled &&+ source.funnelsFilter?.funnelVizType === FunnelVizType.Trends &&+ hasBreakdownFilter(source.breakdownFilter)+ )+ }+const isTrends = isTrendsQuery(source)const isStickiness = isStickinessQuery(source)const isLifecycle = isLifecycleQuery(source)@@ -28,16 +48,22 @@ export function canToggleLegendInInsightQuery(query: QueryBasedInsightModel['quereturn !(display && DISPLAY_TYPES_WITHOUT_LEGEND.includes(display))}-export function isLegendEnabledInInsightQuery(query: QueryBasedInsightModel['query']): boolean {- if (!canToggleLegendInInsightQuery(query) || !isInsightVizNode(query)) {+export function isLegendEnabledInInsightQuery(+ query: QueryBasedInsightModel['query'],+ hogChartsFunnelEnabled: boolean = false+): boolean {+ if (!canToggleLegendInInsightQuery(query, hogChartsFunnelEnabled) || !isInsightVizNode(query)) {return false}return !!getShowLegend(query.source)}-export function getLegendToggleText(query: QueryBasedInsightModel['query']): string {- return isLegendEnabledInInsightQuery(query) ? 'Hide legend' : 'Show legend'+export function getLegendToggleText(+ query: QueryBasedInsightModel['query'],+ hogChartsFunnelEnabled: boolean = false+): string {+ return isLegendEnabledInInsightQuery(query, hogChartsFunnelEnabled) ? 'Hide legend' : 'Show legend'}export function toggleLegendInInsightQuery(query: QueryBasedInsightModel['query']): QueryBasedInsightModel['query'] {@@ -88,5 +114,18 @@ export function toggleLegendInInsightQuery(query: QueryBasedInsightModel['query'} as QueryBasedInsightModel['query']}+ if (isFunnelsQuery(source)) {+ return {+ ...viz,+ source: {+ ...source,+ funnelsFilter: {+ ...source.funnelsFilter,+ showLegend: nextShowLegend,+ },+ },+ } as QueryBasedInsightModel['query']+ }+return query}diff --git a/frontend/src/queries/nodes/InsightViz/InsightDisplayConfig.tsx b/frontend/src/queries/nodes/InsightViz/InsightDisplayConfig.tsxindex 1c765d4aba0c..9ef45c28742e 100644--- a/frontend/src/queries/nodes/InsightViz/InsightDisplayConfig.tsx+++ b/frontend/src/queries/nodes/InsightViz/InsightDisplayConfig.tsx@@ -141,6 +141,10 @@ export function InsightDisplayConfig(): JSX.Element {const isCumulativeLineDisplay = display === ChartDisplayType.ActionsLineGraphCumulativeconst showAxisLabelsConfig =isTrends && (isLineDisplay || isBarDisplay) && featureFlags[FEATURE_FLAGS.PRODUCT_ANALYTICS_HOG_CHARTS_TRENDS]+ const showFunnelLegendConfig =+ isTrendsFunnel &&+ hasBreakdownFilter(breakdownFilter) &&+ !!featureFlags[FEATURE_FLAGS.PRODUCT_ANALYTICS_HOG_CHARTS_FUNNEL]const isLineGraph = isLineDisplay && !isCumulativeLineDisplayconst isLinearScale = !yAxisScaleType || yAxisScaleType === 'linear'@@ -219,7 +223,7 @@ export function InsightDisplayConfig(): JSX.Element {...(isLifecycle ? [{ label: () => <LifecyclePercentagesFilter /> }] : []),...(supportsPercentStackView ? [{ label: () => <PercentStackViewFilter /> }] : []),...(supportsBarValueStacking ? [{ label: () => <StackBreakdownFilter /> }] : []),- ...(hasLegend ? [{ label: () => <ShowLegendFilter /> }] : []),+ ...(hasLegend || showFunnelLegendConfig ? [{ label: () => <ShowLegendFilter /> }] : []),...(display === ChartDisplayType.ActionsPie? [{ label: () => <ShowPieTotalFilter /> }]: []),@@ -401,7 +405,7 @@ export function InsightDisplayConfig(): JSX.Element {trendsFilter.aggregationAxisFormat !== 'numeric'? 1: 0) +- (hasLegend && showLegend ? 1 : 0) ++ ((hasLegend || showFunnelLegendConfig) && showLegend ? 1 : 0) +(!!yAxisScaleType && yAxisScaleType !== 'linear' ? 1 : 0) +(showAxisLabelsConfig && normalizeAxisLabel(trendsFilter?.xAxisLabel) ? 1 : 0) +(showAxisLabelsConfig && normalizeAxisLabel(trendsFilter?.yAxisLabel) ? 1 : 0) +diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex 8a312275e1b3..e26cf352b755 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -21651,6 +21651,11 @@"description": "Whether to render annotations on the chart. Only applies to historical-trends funnels.","type": "boolean"},+ "showLegend": {+ "default": false,+ "description": "Whether to show a legend describing the series. The legend only renders when the funnel has multiple series. Only applies to historical-trends funnels.",+ "type": "boolean"+ },"showTrendLines": {"description": "Display linear regression trend lines on the chart (only for historical trends viz)","type": "boolean"diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.tsindex 2db90f149f72..b416a59522a0 100644--- a/frontend/src/queries/schema/schema-general.ts+++ b/frontend/src/queries/schema/schema-general.ts@@ -1682,6 +1682,12 @@ export type FunnelsFilter = {goalLines?: GoalLine[]/** Display linear regression trend lines on the chart (only for historical trends viz) */showTrendLines?: boolean+ /**+ * Whether to show a legend describing the series. The legend only renders when the funnel has+ * multiple series. Only applies to historical-trends funnels.+ * @default false+ */+ showLegend?: boolean/** @default false */showValuesOnSeries?: boolean/** Breakdown table sorting. Format: 'column_key' or '-column_key' (descending) */diff --git a/frontend/src/queries/utils.ts b/frontend/src/queries/utils.tsindex 3fc03052cdaa..6690f9a64a75 100644--- a/frontend/src/queries/utils.ts+++ b/frontend/src/queries/utils.ts@@ -562,6 +562,8 @@ export const getShowLegend = (query: InsightQueryNode): boolean | undefined => {return query.trendsFilter?.showLegend} else if (isLifecycleQuery(query)) {return query.lifecycleFilter?.showLegend+ } else if (isFunnelsQuery(query)) {+ return query.funnelsFilter?.showLegend}return undefined}diff --git a/frontend/src/scenes/funnels/funnelDataLogic.ts b/frontend/src/scenes/funnels/funnelDataLogic.tsindex a478dd57d6a3..8e59bd5b9d51 100644--- a/frontend/src/scenes/funnels/funnelDataLogic.ts+++ b/frontend/src/scenes/funnels/funnelDataLogic.ts@@ -141,6 +141,7 @@ export const funnelDataLogic = kea<funnelDataLogicType>(['insightData','insightDataError','getTheme',+ 'showLegend','showValuesOnSeries','hasDataWarehouseSeries','labelGroupType',diff --git a/frontend/src/scenes/insights/insightLogic.tsx b/frontend/src/scenes/insights/insightLogic.tsxindex 106a3c54d306..601548177395 100644--- a/frontend/src/scenes/insights/insightLogic.tsx+++ b/frontend/src/scenes/insights/insightLogic.tsx@@ -474,7 +474,12 @@ export const insightLogic: LogicWrapper<insightLogicType> = kea<insightLogicType(s) => [s.query],(query) => !!query && canToggleDisplayLabelsInInsightQuery(query),],- canToggleLegendForInsight: [(s) => [s.query], (query) => !!query && canToggleLegendInInsightQuery(query)],+ canToggleLegendForInsight: [+ (s) => [s.query, s.featureFlags],+ (query, featureFlags) =>+ !!query &&+ canToggleLegendInInsightQuery(query, !!featureFlags[FEATURE_FLAGS.PRODUCT_ANALYTICS_HOG_CHARTS_FUNNEL]),+ ],canToggleAnnotationsForInsight: [(s) => [s.query],(query) => !!query && canToggleAnnotationsInInsightQuery(query),@@ -487,7 +492,13 @@ export const insightLogic: LogicWrapper<insightLogicType> = kea<insightLogicType(s) => [s.query],(query) => (query ? getDisplayLabelsToggleText(query) : 'Show values on series'),],- legendToggleTextForInsight: [(s) => [s.query], (query) => (query ? getLegendToggleText(query) : 'Show legend')],+ legendToggleTextForInsight: [+ (s) => [s.query, s.featureFlags],+ (query, featureFlags) =>+ query+ ? getLegendToggleText(query, !!featureFlags[FEATURE_FLAGS.PRODUCT_ANALYTICS_HOG_CHARTS_FUNNEL])+ : 'Show legend',+ ],annotationsToggleTextForInsight: [(s) => [s.query],(query) => (query ? getAnnotationsToggleText(query) : 'Hide annotations'),diff --git a/posthog/schema.py b/posthog/schema.pyindex a10ffe7d173e..6002152fdcc3 100644--- a/posthog/schema.py+++ b/posthog/schema.py@@ -21274,6 +21274,14 @@ class FunnelsFilter(BaseModel):default=True,description=("Whether to render annotations on the chart. Only applies to historical-trends funnels."),)+ showLegend: bool | None = Field(+ default=False,+ description=(+ "Whether to show a legend describing the series. The legend only renders"+ " when the funnel has multiple series. Only applies to historical-trends"+ " funnels."+ ),+ )showTrendLines: bool | None = Field(default=None,description=("Display linear regression trend lines on the chart (only for historical trends viz)"),diff --git a/products/dashboards/frontend/generated/api.schemas.ts b/products/dashboards/frontend/generated/api.schemas.tsindex 899d3ea336fb..1d695347fabe 100644--- a/products/dashboards/frontend/generated/api.schemas.ts+++ b/products/dashboards/frontend/generated/api.schemas.ts@@ -2361,6 +2361,8 @@ export interface FunnelsFilterApi {resultCustomizations?: FunnelsFilterApiResultCustomizations/** Whether to render annotations on the chart. Only applies to historical-trends funnels. */showAnnotations?: boolean | null+ /** Whether to show a legend describing the series. The legend only renders when the funnel has multiple series. Only applies to historical-trends funnels. */+ showLegend?: boolean | null/** Display linear regression trend lines on the chart (only for historical trends viz) */showTrendLines?: boolean | nullshowValuesOnSeries?: boolean | nulldiff --git a/products/product_analytics/frontend/generated/api.schemas.ts b/products/product_analytics/frontend/generated/api.schemas.tsindex e8149adeda5d..4d1170026757 100644--- a/products/product_analytics/frontend/generated/api.schemas.ts+++ b/products/product_analytics/frontend/generated/api.schemas.ts@@ -1896,6 +1896,8 @@ export interface FunnelsFilterApi {resultCustomizations?: FunnelsFilterApiResultCustomizations/** Whether to render annotations on the chart. Only applies to historical-trends funnels. */showAnnotations?: boolean | null+ /** Whether to show a legend describing the series. The legend only renders when the funnel has multiple series. Only applies to historical-trends funnels. */+ showLegend?: boolean | null/** Display linear regression trend lines on the chart (only for historical trends viz) */showTrendLines?: boolean | nullshowValuesOnSeries?: boolean | nulldiff --git a/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.stories.tsx b/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.stories.tsxindex 343cbc82fe6d..3456e31c3187 100644--- a/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.stories.tsx+++ b/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.stories.tsx@@ -103,6 +103,22 @@ export const ValueLabels: Story = {render: () => renderFunnelLineChart(funnelHistoricalTrendsFixture, { showValuesOnSeries: true }),}+const funnelHistoricalTrendsBreakdownFixture = {+ ...funnelHistoricalTrendsFixture,+ result: [+ { ...funnelHistoricalTrendsFixture.result[0], breakdown_value: ['Chrome'] },+ {+ ...funnelHistoricalTrendsFixture.result[0],+ data: funnelHistoricalTrendsFixture.result[0].data.map((value: number) => value * 0.5),+ breakdown_value: ['Firefox'],+ },+ ],+}++export const WithLegend: Story = {+ render: () => renderFunnelLineChart(funnelHistoricalTrendsBreakdownFixture, { showLegend: true }),+}+export const GoalLine: Story = {render: () =>renderFunnelLineChart(funnelHistoricalTrendsFixture, {diff --git a/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.test.tsx b/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.test.tsxindex 08b497d193a1..8eba7d59dd4c 100644--- a/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.test.tsx+++ b/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.test.tsx@@ -155,6 +155,66 @@ describe('FunnelLineChart', () => {})})+ describe('legend', () => {+ it('shows a legend item per breakdown series when showLegend is enabled', async () => {+ renderInsight({+ query: buildFunnelsQuery({+ breakdownFilter: { breakdown: 'hedgehog', breakdown_type: 'event' },+ funnelsFilter: { showLegend: true },+ }),+ featureFlags: HOG_CHARTS_FUNNEL_FLAG,+ })++ await screen.findByRole('img', { name: /chart with/i })+ const legend = await screen.findByTestId('funnel-line-legend')+ const labels = Array.from(legend.children).map((el) => el.textContent?.trim())+ expect(labels).toEqual(['Spike', 'Bramble'])+ })++ it.each([+ {+ desc: 'showLegend is unset (off by default)',+ query: buildFunnelsQuery({+ breakdownFilter: { breakdown: 'hedgehog', breakdown_type: 'event' },+ }),+ },+ {+ desc: 'showLegend is false',+ query: buildFunnelsQuery({+ breakdownFilter: { breakdown: 'hedgehog', breakdown_type: 'event' },+ funnelsFilter: { showLegend: false },+ }),+ },+ {+ desc: 'there is only a single series, even when showLegend is true',+ query: buildFunnelsQuery({ funnelsFilter: { showLegend: true } }),+ },+ ])('omits the legend when $desc', async ({ query }) => {+ renderInsight({ query, featureFlags: HOG_CHARTS_FUNNEL_FLAG })++ await screen.findByRole('img', { name: /chart with/i })+ expect(screen.queryByTestId('funnel-line-legend')).not.toBeInTheDocument()+ })++ it('assigns a distinct color to each breakdown series', async () => {+ renderInsight({+ query: buildFunnelsQuery({+ breakdownFilter: { breakdown: 'hedgehog', breakdown_type: 'event' },+ funnelsFilter: { showLegend: true },+ }),+ featureFlags: HOG_CHARTS_FUNNEL_FLAG,+ })++ await screen.findByRole('img', { name: /chart with/i })+ const legend = await screen.findByTestId('funnel-line-legend')+ const swatchColors = Array.from(legend.querySelectorAll<HTMLElement>('span[style]')).map(+ (el) => el.style.backgroundColor+ )+ expect(swatchColors).toHaveLength(2)+ expect(new Set(swatchColors).size).toBe(2)+ })+ })+describe('annotations', () => {it.each([{ inSharedMode: false, expectsBadges: true },diff --git a/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.tsx b/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.tsxindex 2b4a8b43573b..a9674b071964 100644--- a/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.tsx+++ b/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.tsx@@ -2,14 +2,16 @@ import { useValues } from 'kea'import posthog from 'posthog-js'import { useMemo, type ErrorInfo } from 'react'-import { TimeSeriesLineChart } from '@posthog/quill-charts'+import { ChartLegend, TimeSeriesLineChart, legendItemsFromSeries } from '@posthog/quill-charts'import type { PointClickData, TimeSeriesLineChartConfig, TooltipConfig, TooltipContext } from '@posthog/quill-charts'import { buildTheme } from 'lib/charts/utils/theme'import { funnelDataLogic } from 'scenes/funnels/funnelDataLogic'import { funnelPersonsModalLogic } from 'scenes/funnels/funnelPersonsModalLogic'+import { hasBreakdown } from 'scenes/funnels/funnelUtils'import { insightLogic } from 'scenes/insights/insightLogic'import type { SeriesDatum } from 'scenes/insights/InsightTooltip/insightTooltipUtils'+import { formatBreakdownLabel } from 'scenes/insights/utils'import { teamLogic } from 'scenes/teamLogic'import { openPersonsModal } from 'scenes/trends/persons-modal/PersonsModal'@@ -19,10 +21,10 @@ import type { Noun } from '~/models/groupsModel'import { groupsModel } from '~/models/groupsModel'import { propertyDefinitionsModel } from '~/models/propertyDefinitionsModel'import { isFunnelsQuery } from '~/queries/utils'-import { ChartParams, type FunnelStepWithConversionMetrics } from '~/types'+import { ChartParams, type FlattenedFunnelStepByBreakdown } from '~/types'import { AnnotationsLayer } from '../../trends/shared/AnnotationsLayer'-import type { FunnelSeriesMeta } from '../shared/funnelSeriesMeta'+import { FUNNEL_CONVERSION_SERIES_LABEL, type FunnelSeriesMeta } from '../shared/funnelSeriesMeta'import { buildFunnelLineSeries, buildFunnelLineTimeSeriesConfig, type IndexedFunnelStep } from './funnelChartTransforms'import { FunnelLineTooltip } from './FunnelLineTooltip'import { type FunnelLineChartClickDeps, handleFunnelLineChartClick } from './handleFunnelLineChartClick'@@ -66,6 +68,7 @@ export function FunnelLineChart({querySource,interval,insightData,+ showLegend,showValuesOnSeries,funnelsFilter,breakdownFilter,@@ -85,13 +88,32 @@ export function FunnelLineChart({() =>buildFunnelLineSeries(steps, {incompletenessOffsetFromEnd,- // getFunnelsColor is typed for the steps-viz datasets; for the trends viz it- // only reads `breakdown_value`, which IndexedFunnelStep carries.- getColor: (step) => getFunnelsColor(step as unknown as FunnelStepWithConversionMetrics),+ getColor: (step) =>+ getFunnelsColor({+ ...step,+ breakdownIndex: step.seriesIndex,+ } as unknown as FlattenedFunnelStepByBreakdown),}),[steps, incompletenessOffsetFromEnd, getFunnelsColor])+ const legendItems = useMemo(+ () =>+ legendItemsFromSeries(series, theme).map((item) => {+ const breakdownValue = series.find((s) => s.key === item.key)?.meta?.breakdown_value+ const label = hasBreakdown(breakdownValue)+ ? formatBreakdownLabel(+ breakdownValue,+ breakdownFilter ?? undefined,+ allCohorts.results,+ formatPropertyValueForDisplay+ )+ : FUNNEL_CONVERSION_SERIES_LABEL+ return { ...item, label }+ }),+ [series, theme, breakdownFilter, allCohorts.results, formatPropertyValueForDisplay]+ )+const chartConfig: TimeSeriesLineChartConfig = useMemo(() =>buildFunnelLineTimeSeriesConfig({@@ -167,18 +189,25 @@ export function FunnelLineChart({)return (- <TimeSeriesLineChart<FunnelSeriesMeta>- series={series}- labels={labels}- theme={theme}- config={chartConfig}- tooltip={renderTooltip}- onPointClick={showPersonsModal ? onPointClick : undefined}- className="LineGraph"- dataAttr="trend-line-graph-funnel"- onError={handleChartError}+ <ChartLegend+ show={!!showLegend && legendItems.length > 1}+ items={legendItems}+ position="top"+ legendDataAttr="funnel-line-legend">- {!inSharedMode && <AnnotationsLayer insightNumericId={insight.id || 'new'} dates={annotationDates} />}- </TimeSeriesLineChart>+ <TimeSeriesLineChart<FunnelSeriesMeta>+ series={series}+ labels={labels}+ theme={theme}+ config={chartConfig}+ tooltip={renderTooltip}+ onPointClick={showPersonsModal ? onPointClick : undefined}+ className="LineGraph"+ dataAttr="trend-line-graph-funnel"+ onError={handleChartError}+ >+ {!inSharedMode && <AnnotationsLayer insightNumericId={insight.id || 'new'} dates={annotationDates} />}+ </TimeSeriesLineChart>+ </ChartLegend>)}diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex c867c4b3695a..bbb557afdec1 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -2390,6 +2390,8 @@ export namespace Schemas {resultCustomizations?: FunnelsFilterResultCustomizations;/** Whether to render annotations on the chart. Only applies to historical-trends funnels. */showAnnotations?: boolean | null;+ /** Whether to show a legend describing the series. The legend only renders when the funnel has multiple series. Only applies to historical-trends funnels. */+ showLegend?: boolean | null;/** Display linear regression trend lines on the chart (only for historical trends viz) */showTrendLines?: boolean | null;showValuesOnSeries?: boolean | null;