: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(legends): fix lifecycle legend interactivity and stickiness legend options (#65533)
Sam Pennington2057c1b26337
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 0c7e9f6533d4..396cb8548327 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -2449,9 +2449,9 @@ snapshots:insights-funnellinechart--value-labels--light:hash: v1.k794b7964.e77fc0556d6cb2928d6f4733a2469335c193dc4e69d3709979b56c48b3336a26.-ANj2Y7kjX0XvQaWN4iIavrWM-Spk8vjpICJr4WX5_0insights-funnellinechart--with-legend--dark:- hash: v1.k794b7964.91d6de8992e7b49f3dbe2989778ae54a5e9478a6136e1f5b34eb1eab4356711f.lWuIgyArPItzhZJDTIwVB-xZL8uCnt67DTANC5OKtJY+ hash: v1.k794b7964.6c58b60fb6fe098f82269bb90abd93f328395da35d45ea130256987bcccc2214.Kd0RUQaPljabFqiPKo6FDiSeCCFlgwfYyJQgC8AtYLsinsights-funnellinechart--with-legend--light:- hash: v1.k794b7964.6b4d0969a75cf3df9e5c989ce373d153c77d1eedaedb72105ee78145fd9414e3.ve7yvcN4Bx2DPN9sNmeG1y-KKrJXxjH8IJdRtMg2nks+ hash: v1.k794b7964.814e7addc2f121aed26b646f3be6981ecabfcb72054ebcf671bf939ff599d945.BcXL3z4XlxOgh4GkOcGzIuuL7ydYn_p_2NS7CpmidvMinsights-funnellinechart-tooltip--breakdown-ordered-by-conversion--dark:hash: v1.k794b7964.28fcb86c4f61884b1c2d0d6956482149d06c7a49a8425aa040b4ae36e2ac6c50.i5loD1ggBoEypNfx7cLJUjqPTUWcUXid0YcZUP0igpMinsights-funnellinechart-tooltip--breakdown-ordered-by-conversion--light:@@ -2577,9 +2577,9 @@ snapshots:insights-trendslifecyclechart--stacked--light:hash: v1.k794b7964.6f542884e9d767dcf000afd0604296d1b7c88ffacae02136c6657f2ba2cc0b8d.btS_HEQZaP1c2kExtglIP7xO9JH4GOO37MLrDfhcnDoinsights-trendslifecyclechart--stacked-with-legend--dark:- hash: v1.k794b7964.ba94181c9fdbd95fedd01f0a5c95bf37dfc118059562a5226cb04a8b0a255b1e.lqtWGJivp6P4mYGM1kT8TcNtrtTBUTTVGslzkIpHlvM+ hash: v1.k794b7964.5ab4d649cc919964c17e19bea4ab57c3f97ae9a52449c84119baf0fa9d6fb151.DCQvKv1u3XpVfZoZZAMkP-Qwu-SEEhp485oJsdK0EXoinsights-trendslifecyclechart--stacked-with-legend--light:- hash: v1.k794b7964.79076f34da547d5a39452faa7c12816c2d4ef03808b9f776ad1668811d93ac75.mNTcJNgEByJoL3UgnHN059w00ckO4FcjkP2rwijx6kM+ hash: v1.k794b7964.57a2cdf284c58efefaedebf2cf80f70a839600edde39c17acb3f51088372e613.bOhwN6zBvOA46W2w1Mhbh62N4ZWahoxYauqwkrQuxf4insights-trendslifecyclechart--stacked-with-percentages-on-series--dark:hash: v1.k794b7964.a07939aacffaca561bf32b6d94c8c1fe24b401a097633e3ddc830dee3dd01564.jaqXSLUJl_Sv4mJP-_CUEyd1xXeNRTxmh7f4ueVidqMinsights-trendslifecyclechart--stacked-with-percentages-on-series--light:@@ -2597,9 +2597,9 @@ snapshots:insights-trendslifecyclechart--unstacked--light:hash: v1.k794b7964.1d01deb9c9081a6ad5e5554fa0efb1df960051a8663d037000599783bcdb3873._yrVG5fErPmwKntTMK9MmgqTrAsOdo20FXhPqKD-39kinsights-trendslifecyclechart--unstacked-with-legend--dark:- hash: v1.k794b7964.0a6b2c6d27f4e58b54a78e7f47d4eeb36c44de112fb490a81e5802dcb2b94963.tpAfdatCJe8kb1JeYVnr8wEK440Fh1MyXsOHH4L3GaY+ hash: v1.k794b7964.dcdc8528fb0e36f462200a73a591836d599009ad8d3ece4f49b66df4bad23138.7aHOY8gLlu50TfodzVnWHGx_zhse_p9u_yqLmYDF-sMinsights-trendslifecyclechart--unstacked-with-legend--light:- hash: v1.k794b7964.d65841df4ec54ae5ef9fe8e587726e948deb0990495febeaed6e01b54b344489.9gtJH0OMjPqla5w5ytrdJ-61swREv5xgnaIufdhsBfI+ hash: v1.k794b7964.ae1037a551d24f0d8a9bf5f94bc6cc8921eb3d979fb910426f9563f8d56f7f5b.tgvY_MUl5V_KREh7iWdPtwnpcHBSkvFkqPFRKmNTLr8insights-trendslifecyclechart--unstacked-with-percentages-on-series--dark:hash: v1.k794b7964.e89fef8b35437fb4e4dc345c809e7e8a8d84df5f4114e59e9eb7d773b310fb23.9GII3E9SZ9-KPi_lgA6rjSV23tfGVlVUXArAaYkdW-Qinsights-trendslifecyclechart--unstacked-with-percentages-on-series--light:diff --git a/frontend/src/queries/nodes/InsightViz/InsightDisplayConfig.test.tsx b/frontend/src/queries/nodes/InsightViz/InsightDisplayConfig.test.tsxindex fd13df4e5c8e..68c5b580fc21 100644--- a/frontend/src/queries/nodes/InsightViz/InsightDisplayConfig.test.tsx+++ b/frontend/src/queries/nodes/InsightViz/InsightDisplayConfig.test.tsx@@ -239,7 +239,12 @@ describe('InsightDisplayConfig', () => {makeLifecycleQuery(),{sections: ['Display'],- displayItems: ['Stack bars', 'Show values on series', 'Show percentages on series', 'Show legend'],+ displayItems: [+ 'Stack bars',+ 'Show values on series',+ 'Show percentages on series',+ 'Show legendBottom',+ ],},],]diff --git a/frontend/src/queries/nodes/InsightViz/insightDisplayOptions.tsx b/frontend/src/queries/nodes/InsightViz/insightDisplayOptions.tsxindex e4a862c3e3b3..baae076a1b91 100644--- a/frontend/src/queries/nodes/InsightViz/insightDisplayOptions.tsx+++ b/frontend/src/queries/nodes/InsightViz/insightDisplayOptions.tsx@@ -39,7 +39,6 @@ export function useInsightDisplayOptions(): { items: LemonMenuItems; count: numbtrendsFilter,hasLegend,showLegend,- usesInChartLegend,supportsValueOnSeries,showPercentStackView,supportsPercentStackView,@@ -50,6 +49,7 @@ export function useInsightDisplayOptions(): { items: LemonMenuItems; count: numbshowAnnotations,isNonTimeSeriesDisplay,interval,+ usesInChartLegend,} = useValues(insightVizDataLogic(insightProps))const { isTrendsFunnel } = useValues(funnelDataLogic(insightProps))const {@@ -77,15 +77,21 @@ export function useInsightDisplayOptions(): { items: LemonMenuItems; count: numbconst showMultipleYAxesConfig = (isTrends || isStickiness) && !hideContinuousChartOptionsconst showAlertThresholdLinesConfig = isTrends && !hideContinuousChartOptionsconst showAnnotationsConfig = (isTrends && !hideContinuousChartOptions) || isTrendsFunnel- const isLineDisplay = isDefaultTrendsLineDisplay(display, querySource) || displayMatches(display, LINE_DISPLAYS)+ // Stickiness defaults to its line chart when display is unset, same as trends does — but+ // isDefaultTrendsLineDisplay only matches TrendsQuery, so we handle the stickiness case here.+ const isLineDisplay =+ isDefaultTrendsLineDisplay(display, querySource) ||+ displayMatches(display, LINE_DISPLAYS) ||+ (!display && isStickiness)const isBarDisplay = displayMatches(display, BAR_DISPLAYS)const showAxisLabelsConfig = isTrends && (isLineDisplay || isBarDisplay)const showFunnelLegendConfig = isTrendsFunnel && hasBreakdownFilter(breakdownFilter)const isBoxPlot = display === ChartDisplayType.BoxPlotconst isCalendarHeatmap = display === ChartDisplayType.CalendarHeatmap- // The in-chart quill legend supports placement, so it gets a single "Legend" select (Hide +- // position) instead of the legacy show/hide checkbox. `usesInChartLegend` covers- // trends/stickiness/lifecycle; funnel trends draw their own in-chart legend too.+ // 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+ // also get the position selector since they render the quill legend via config.legend.const useQuillLegendOptions = usesInChartLegend || (quillLegendEnabled && showFunnelLegendConfig)const showDisplaySection =diff --git a/frontend/src/scenes/insights/insightVizDataLogic.ts b/frontend/src/scenes/insights/insightVizDataLogic.tsindex aae23ec916a5..b2e21bc06fb7 100644--- a/frontend/src/scenes/insights/insightVizDataLogic.ts+++ b/frontend/src/scenes/insights/insightVizDataLogic.ts@@ -485,12 +485,13 @@ export const insightVizDataLogic = kea<insightVizDataLogicType>([usesInChartLegend: [(s) => [s.featureFlags, s.isTrends, s.isStickiness, s.isLifecycle, s.display],(featureFlags, isTrends, isStickiness, isLifecycle, display): boolean => {- if (!featureFlags[FEATURE_FLAGS.PRODUCT_ANALYTICS_QUILL_LEGEND]) {- return false- }+ // Lifecycle always uses config.legend inside TimeSeriesBarChart — no flag gate needed.if (isLifecycle) {return true}+ if (!featureFlags[FEATURE_FLAGS.PRODUCT_ANALYTICS_QUILL_LEGEND]) {+ return false+ }return (isTrends || isStickiness) && (!display || DISPLAYS_WITH_IN_CHART_LEGEND.includes(display))},],diff --git a/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.test.tsx b/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.test.tsxindex 336a49360a03..e56297122235 100644--- a/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.test.tsx+++ b/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.test.tsx@@ -220,7 +220,7 @@ describe('FunnelLineChart', () => {})await screen.findByRole('img', { name: /chart with/i })- const legend = await screen.findByTestId('funnel-line-legend')+ const legend = await screen.findByTestId('hog-chart-timeseries-line-legend')const labels = Array.from(legend.children).map((el) => el.textContent?.trim())expect(labels).toEqual(['Spike', 'Bramble'])})@@ -247,7 +247,7 @@ describe('FunnelLineChart', () => {renderInsight({ query })await screen.findByRole('img', { name: /chart with/i })- expect(screen.queryByTestId('funnel-line-legend')).not.toBeInTheDocument()+ expect(screen.queryByTestId('hog-chart-timeseries-line-legend')).not.toBeInTheDocument()})it('assigns a distinct color to each breakdown series', async () => {@@ -259,7 +259,7 @@ describe('FunnelLineChart', () => {})await screen.findByRole('img', { name: /chart with/i })- const legend = await screen.findByTestId('funnel-line-legend')+ const legend = await screen.findByTestId('hog-chart-timeseries-line-legend')// The label span also carries an inline style now (max-width), so keep only the colored swatches.const swatchColors = Array.from(legend.querySelectorAll<HTMLElement>('span[style]')).map((el) => el.style.backgroundColor)diff --git a/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.tsx b/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.tsxindex b38e1355148d..9593a820bdb0 100644--- a/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.tsx+++ b/products/product_analytics/frontend/insights/funnels/FunnelLineChart/FunnelLineChart.tsx@@ -2,12 +2,16 @@ import { useValues } from 'kea'import posthog from 'posthog-js'import { useMemo, type ErrorInfo } from 'react'-import { ChartLegend, TimeSeriesLineChart, legendItemsFromSeries } from '@posthog/quill-charts'-import type { PointClickData, TimeSeriesLineChartConfig, TooltipConfig, TooltipContext } from '@posthog/quill-charts'+import { TimeSeriesLineChart } from '@posthog/quill-charts'+import type {+ ChartLegendConfig,+ PointClickData,+ TimeSeriesLineChartConfig,+ TooltipConfig,+ TooltipContext,+} from '@posthog/quill-charts'import { buildTheme } from 'lib/charts/utils/theme'-import { FEATURE_FLAGS } from 'lib/constants'-import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { funnelDataLogic } from 'scenes/funnels/funnelDataLogic'import { funnelPersonsModalLogic } from 'scenes/funnels/funnelPersonsModalLogic'import { hasBreakdown } from 'scenes/funnels/funnelUtils'@@ -26,6 +30,7 @@ import { isFunnelsQuery } from '~/queries/utils'import { ChartParams, type FlattenedFunnelStepByBreakdown } from '~/types'import { AnnotationsLayer } from '../../trends/shared/AnnotationsLayer'+import { buildBaseLegendConfig } from '../../trends/shared/buildBaseLegendConfig'import { FUNNEL_CONVERSION_SERIES_LABEL, type FunnelSeriesMeta } from '../shared/funnelSeriesMeta'import { buildFunnelLineSeries, buildFunnelLineTimeSeriesConfig, type IndexedFunnelStep } from './funnelChartTransforms'import { FunnelLineTooltip } from './FunnelLineTooltip'@@ -60,7 +65,7 @@ export function FunnelLineChart({}: Omit<ChartParams, 'filters'>): JSX.Element | null {const { isDarkModeOn } = useValues(themeLogic)const theme = useMemo(() => buildTheme(), [isDarkModeOn])- const { insightProps, insight } = useValues(insightLogic)+ const { insightProps, insight, canEditInsight } = useValues(insightLogic)const {indexedSteps,@@ -78,12 +83,6 @@ export function FunnelLineChart({labelGroupType,getFunnelsColor,} = useValues(funnelDataLogic(insightProps))- const { featureFlags } = useValues(featureFlagLogic)- // The legend has always rendered in-chart here; the flag only adds the configurable placement- // (defaulting to bottom to match the other in-chart legends). Without the flag it stays at top.- const legendPlacement = featureFlags[FEATURE_FLAGS.PRODUCT_ANALYTICS_QUILL_LEGEND]- ? ((legendPosition as 'top' | 'bottom' | 'left' | 'right') ?? 'bottom')- : 'top'const { canOpenPersonModal } = useValues(funnelPersonsModalLogic(insightProps))const { timezone, weekStartDay } = useValues(teamLogic)const { allCohorts } = useValues(cohortsModel)@@ -93,7 +92,7 @@ export function FunnelLineChart({const showPersonsModal = canOpenPersonModal && showPersonsModalPropconst steps = useMemo(() => (indexedSteps ?? []) as IndexedFunnelStep[], [indexedSteps])- const series = useMemo(+ const seriesBase = useMemo(() =>buildFunnelLineSeries(steps, {incompletenessOffsetFromEnd,@@ -106,26 +105,38 @@ export function FunnelLineChart({[steps, incompletenessOffsetFromEnd, getFunnelsColor])- const legendItems = useMemo(+ // Apply formatted breakdown labels so the chart's internal legend picks them up directly.+ const series = useMemo(+ () =>+ seriesBase.map((s) => ({+ ...s,+ label:+ s.meta && hasBreakdown(s.meta.breakdown_value)+ ? formatBreakdownLabel(+ s.meta.breakdown_value,+ breakdownFilter ?? undefined,+ allCohorts.results,+ formatPropertyValueForDisplay+ )+ : FUNNEL_CONVERSION_SERIES_LABEL,+ })),+ [seriesBase, breakdownFilter, allCohorts.results, formatPropertyValueForDisplay]+ )++ const legendConfig = useMemo<ChartLegendConfig>(() =>- 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 }+ buildBaseLegendConfig({+ show: !!showLegend && series.length > 1,+ legendPosition,+ canEditInsight,+ inSharedMode,}),- [series, theme, breakdownFilter, allCohorts.results, formatPropertyValueForDisplay]+ [showLegend, series.length, legendPosition, canEditInsight, inSharedMode])const chartConfig: TimeSeriesLineChartConfig = useMemo(- () =>- buildFunnelLineTimeSeriesConfig({+ () => ({+ ...buildFunnelLineTimeSeriesConfig({indexedSteps: steps,interval,timezone,@@ -137,6 +148,8 @@ export function FunnelLineChart({showCrosshair: true,tooltip: TOOLTIP_CONFIG,}),+ legend: legendConfig,+ }),[steps,interval,@@ -145,6 +158,7 @@ export function FunnelLineChart({incompletenessOffsetFromEnd,funnelsFilter?.showTrendLines,showValuesOnSeries,+ legendConfig,])@@ -199,25 +213,18 @@ export function FunnelLineChart({)return (- <ChartLegend- show={!!showLegend && legendItems.length > 1}- items={legendItems}- position={legendPlacement}- legendDataAttr="funnel-line-legend"+ <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}>- <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}- >- {showAnnotations && <AnnotationsLayer insightNumericId={insight.id || 'new'} dates={annotationDates} />}- </TimeSeriesLineChart>- </ChartLegend>+ {showAnnotations && <AnnotationsLayer insightNumericId={insight.id || 'new'} dates={annotationDates} />}+ </TimeSeriesLineChart>)}diff --git a/products/product_analytics/frontend/insights/stickiness/StickinessBarChart/StickinessBarChart.tsx b/products/product_analytics/frontend/insights/stickiness/StickinessBarChart/StickinessBarChart.tsxindex f3be0ba943b7..585f34105e01 100644--- a/products/product_analytics/frontend/insights/stickiness/StickinessBarChart/StickinessBarChart.tsx+++ b/products/product_analytics/frontend/insights/stickiness/StickinessBarChart/StickinessBarChart.tsx@@ -25,7 +25,7 @@ import {type TrendsSeriesMeta,} from '../../trends/shared/trendsSeriesMeta'import { TrendsTooltip } from '../../trends/shared/TrendsTooltip'-import { useTrendsLegendConfig } from '../../trends/shared/useTrendsLegendConfig'+import { useInsightsLegendConfig } from '../../trends/shared/useInsightsLegendConfig'import { handleStickinessChartClick } from '../StickinessLineChart/handleStickinessChartClick'import {buildStickinessLabels,@@ -45,7 +45,7 @@ export function StickinessBarChart({ context }: StickinessBarChartProps): JSX.Elconst theme = useMemo(() => buildTheme(), [])const { insightProps } = useValues(insightLogic)- const legendConfig = useTrendsLegendConfig({ insightProps })+ const legendConfig = useInsightsLegendConfig({ insightProps })const quillLegendEnabled = !!legendConfigconst {diff --git a/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/StickinessLineChart.tsx b/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/StickinessLineChart.tsxindex 23badcf62ac2..54def9175274 100644--- a/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/StickinessLineChart.tsx+++ b/products/product_analytics/frontend/insights/stickiness/StickinessLineChart/StickinessLineChart.tsx@@ -24,7 +24,7 @@ import {type TrendsSeriesMeta,} from '../../trends/shared/trendsSeriesMeta'import { TrendsTooltip } from '../../trends/shared/TrendsTooltip'-import { useTrendsLegendConfig } from '../../trends/shared/useTrendsLegendConfig'+import { useInsightsLegendConfig } from '../../trends/shared/useInsightsLegendConfig'import { handleStickinessChartClick } from './handleStickinessChartClick'import {buildStickinessLabels,@@ -45,7 +45,7 @@ export function StickinessLineChart({ context }: StickinessLineChartProps): JSX.const theme = useMemo(() => buildTheme(), [])const { insightProps } = useValues(insightLogic)- const legendConfig = useTrendsLegendConfig({ insightProps })+ const legendConfig = useInsightsLegendConfig({ insightProps })const quillLegendEnabled = !!legendConfigconst {diff --git a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsxindex 2f108cff19d5..05f46897f296 100644--- a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx+++ b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx@@ -39,7 +39,7 @@ import { TrendsAlertOverlays } from '../shared/TrendsAlertOverlays'import { trendsFilterToYFormatterConfig } from '../shared/trendsAxisFormat'import { buildTrendsSeriesMeta, type TrendsSeriesMeta } from '../shared/trendsSeriesMeta'import { TrendsTooltip } from '../shared/TrendsTooltip'-import { useTrendsLegendConfig } from '../shared/useTrendsLegendConfig'+import { useInsightsLegendConfig } from '../shared/useInsightsLegendConfig'import { getAggregatedDisplayLabel as getAggregatedDisplayLabelFn } from './getAggregatedDisplayLabel'import { handleTrendsBarAggregatedChartClick } from './handleTrendsBarAggregatedChartClick'import {@@ -90,7 +90,7 @@ export function TrendsBarChart({// Time-series bars (vertical) render the in-chart legend; the aggregated bar-value layout has// no legend (each bar is a breakdown row, not a series).- const legendConfig = useTrendsLegendConfig({ insightProps, inSharedMode })+ const legendConfig = useInsightsLegendConfig({ insightProps, inSharedMode })const {indexedResults,diff --git a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.test.tsx b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.test.tsxindex b72453dac3f2..32de007f333e 100644--- a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.test.tsx+++ b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.test.tsx@@ -140,8 +140,8 @@ describe('TrendsLifecycleChart', () => {})await screen.findByTestId('trend-lifecycle-graph')- const legend = await screen.findByTestId('trend-lifecycle-legend')// Status order must match buildTrendsLifecycleSeries' sort: dormant → returning → resurrecting → new.+ const legend = await screen.findByTestId('hog-chart-timeseries-bar-legend')const labels = Array.from(legend.children).map((el) => el.textContent?.trim())expect(labels).toEqual(['Dormant', 'Returning', 'Resurrecting', 'New'])})@@ -153,6 +153,6 @@ describe('TrendsLifecycleChart', () => {})await screen.findByTestId('trend-lifecycle-graph')- expect(screen.queryByTestId('trend-lifecycle-legend')).not.toBeInTheDocument()+ expect(screen.queryByTestId('hog-chart-timeseries-bar-legend')).not.toBeInTheDocument()})})diff --git a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.tsxindex 876325df421b..2119457d9457 100644--- a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.tsx+++ b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.tsx@@ -1,13 +1,11 @@import { useValues } from 'kea'import { useCallback, useMemo } from 'react'-import { ChartLegend, TimeSeriesBarChart, legendItemsFromSeries } from '@posthog/quill-charts'-import type { PointClickData, TooltipContext } from '@posthog/quill-charts'+import { TimeSeriesBarChart } from '@posthog/quill-charts'+import type { ChartLegendConfig, PointClickData, TooltipContext } from '@posthog/quill-charts'import { buildTheme } from 'lib/charts/utils/theme'import { getBarColorFromStatus } from 'lib/colors'-import { FEATURE_FLAGS } from 'lib/constants'-import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { formatAggregationAxisValue } from 'scenes/insights/aggregationAxisFormat'import { InsightEmptyState } from 'scenes/insights/EmptyStates'import { insightLogic } from 'scenes/insights/insightLogic'@@ -22,6 +20,7 @@ import { QueryContext } from '~/queries/types'import type { LifecycleToggle } from '~/types'import { AnnotationsLayer } from '../shared/AnnotationsLayer'+import { buildBaseLegendConfig } from '../shared/buildBaseLegendConfig'import { makeChartErrorHandler } from '../shared/chartErrorHandler'import {handleTrendsChartClick,@@ -50,7 +49,7 @@ const renderLifecycleSeriesLabel = (datum: SeriesDatum): React.ReactNode => datuexport function TrendsLifecycleChart({ context, inSharedMode = false }: TrendsLifecycleChartProps): JSX.Element | null {const theme = useMemo(() => buildTheme(), [])- const { insightProps, insight } = useValues(insightLogic)+ const { insightProps, insight, canEditInsight } = useValues(insightLogic)const {indexedResults,@@ -70,12 +69,14 @@ export function TrendsLifecycleChart({ context, inSharedMode = false }: TrendsLilegendPosition,} = useValues(trendsDataLogic(insightProps))const { timezone, weekStartDay, baseCurrency } = useValues(teamLogic)- const { featureFlags } = useValues(featureFlagLogic)- // The legend has always rendered in-chart here; the flag only adds the configurable placement- // (defaulting to bottom to match the other in-chart legends). Without the flag it stays at top.- const legendPlacement = featureFlags[FEATURE_FLAGS.PRODUCT_ANALYTICS_QUILL_LEGEND]- ? ((legendPosition as 'top' | 'bottom' | 'left' | 'right') ?? 'bottom')- : 'top'++ // Lifecycle statuses all share the same resultCustomizationKey (same action.order), so+ // useInsightsLegendConfig can't distinguish them — build the config inline and let the+ // chart manage toggle state internally.+ const legendConfig = useMemo<ChartLegendConfig>(+ () => buildBaseLegendConfig({ show: !!showLegend, legendPosition, canEditInsight, inSharedMode }),+ [showLegend, legendPosition, canEditInsight, inSharedMode]+ )const isStacked = lifecycleFilter?.stacked ?? true@@ -113,6 +114,7 @@ export function TrendsLifecycleChart({ context, inSharedMode = false }: TrendsLiallDays: currentPeriodResult?.days ?? [],valueLabels: showValuesOnSeries || showPercentagesOnSeries ? { formatter: valueLabelFormatter } : false,tooltip: LIFECYCLE_TOOLTIP_CONFIG,+ legend: legendConfig,}),[indexedResults,@@ -127,11 +129,10 @@ export function TrendsLifecycleChart({ context, inSharedMode = false }: TrendsLishowValuesOnSeries,showPercentagesOnSeries,valueLabelFormatter,+ legendConfig,])- const legendItems = useMemo(() => legendItemsFromSeries(series, theme), [series, theme])-const canHandleClick = !!context?.onDataPointClick || !!hasPersonsModalconst clickDeps = useMemo<TrendsChartClickDeps>(@@ -215,27 +216,18 @@ export function TrendsLifecycleChart({ context, inSharedMode = false }: TrendsLiconst annotationsDates = currentPeriodResult?.days ?? []return (- <ChartLegend- show={!!showLegend}- items={legendItems}- position={legendPlacement}- legendDataAttr="trend-lifecycle-legend"+ <TimeSeriesBarChart<TrendsSeriesMeta>+ series={series}+ labels={labels}+ config={config}+ theme={theme}+ tooltip={renderTooltip}+ onPointClick={canHandleClick ? onPointClick : undefined}+ className="BarGraph"+ dataAttr="trend-lifecycle-graph"+ onError={handleChartError}>- <TimeSeriesBarChart<TrendsSeriesMeta>- series={series}- labels={labels}- config={config}- theme={theme}- tooltip={renderTooltip}- onPointClick={canHandleClick ? onPointClick : undefined}- className="BarGraph"- dataAttr="trend-lifecycle-graph"- onError={handleChartError}- >- {showAnnotations && (- <AnnotationsLayer insightNumericId={insight.id || 'new'} dates={annotationsDates} />- )}- </TimeSeriesBarChart>- </ChartLegend>+ {showAnnotations && <AnnotationsLayer insightNumericId={insight.id || 'new'} dates={annotationsDates} />}+ </TimeSeriesBarChart>)}diff --git a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/trendsLifecycleChartTransforms.ts b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/trendsLifecycleChartTransforms.tsindex 302e9079ec42..283bde48572f 100644--- a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/trendsLifecycleChartTransforms.ts+++ b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/trendsLifecycleChartTransforms.ts@@ -112,6 +112,7 @@ export interface BuildTrendsLifecycleConfigOpts {allDays?: string[]valueLabels?: TimeSeriesBarChartConfig['valueLabels']tooltip?: TimeSeriesBarChartConfig['tooltip']+ legend?: TimeSeriesBarChartConfig['legend']}export function buildTrendsLifecycleConfig(opts: BuildTrendsLifecycleConfigOpts): TimeSeriesBarChartConfig {@@ -131,6 +132,7 @@ export function buildTrendsLifecycleConfig(opts: BuildTrendsLifecycleConfigOpts)// Only meaningful in stacked layout — dormant stacks below 0.divergingStack: opts.isStacked,tooltip: opts.tooltip,+ legend: opts.legend,}}diff --git a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsxindex 7dd5bd93f8c9..eaa519da5480 100644--- a/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx+++ b/products/product_analytics/frontend/insights/trends/TrendsLineChart/TrendsLineChart.tsx@@ -28,7 +28,7 @@ import { handleTrendsChartClick } from '../shared/handleTrendsChartClick'import { TrendsAlertOverlays } from '../shared/TrendsAlertOverlays'import { buildTrendsSeriesMeta, resolveGroupTypeLabel, type TrendsSeriesMeta } from '../shared/trendsSeriesMeta'import { TrendsTooltip } from '../shared/TrendsTooltip'-import { useTrendsLegendConfig } from '../shared/useTrendsLegendConfig'+import { useInsightsLegendConfig } from '../shared/useInsightsLegendConfig'import { buildTrendsLineTimeSeriesConfig, buildTrendsSeries } from './trendsChartTransforms'interface TrendsLineChartProps {@@ -45,7 +45,7 @@ export function TrendsLineChart({ context, inSharedMode = false }: TrendsLineChaconst theme = useMemo(() => buildTheme(), [isDarkModeOn])const { insightProps, insight } = useValues(insightLogic)- const legendConfig = useTrendsLegendConfig({ insightProps, inSharedMode })+ const legendConfig = useInsightsLegendConfig({ insightProps, inSharedMode })const quillLegendEnabled = !!legendConfigconst {diff --git a/products/product_analytics/frontend/insights/trends/shared/buildBaseLegendConfig.ts b/products/product_analytics/frontend/insights/trends/shared/buildBaseLegendConfig.tsnew file mode 100644index 000000000000..869332f04f22--- /dev/null+++ b/products/product_analytics/frontend/insights/trends/shared/buildBaseLegendConfig.ts@@ -0,0 +1,22 @@+import type { ChartLegendConfig } from '@posthog/quill-charts'++/** Returns the base `{ show, position, interactive }` legend shape shared by all chart types that+ * build their config inline (lifecycle, funnel). Call sites own the `show` expression — e.g. funnel+ * gates it on `series.length > 1`. */+export function buildBaseLegendConfig({+ show,+ legendPosition,+ canEditInsight,+ inSharedMode,+}: {+ show: boolean+ legendPosition: string | null | undefined+ canEditInsight: boolean+ inSharedMode?: boolean+}): ChartLegendConfig {+ return {+ show,+ position: (legendPosition ?? 'bottom') as ChartLegendConfig['position'],+ interactive: canEditInsight && !inSharedMode,+ }+}diff --git a/products/product_analytics/frontend/insights/trends/shared/useTrendsLegendConfig.tsx b/products/product_analytics/frontend/insights/trends/shared/useInsightsLegendConfig.tsxsimilarity index 84%rename from products/product_analytics/frontend/insights/trends/shared/useTrendsLegendConfig.tsxrename to products/product_analytics/frontend/insights/trends/shared/useInsightsLegendConfig.tsxindex 9797ef7563bb..c7dd1b492140 100644--- a/products/product_analytics/frontend/insights/trends/shared/useTrendsLegendConfig.tsx+++ b/products/product_analytics/frontend/insights/trends/shared/useInsightsLegendConfig.tsx@@ -13,19 +13,19 @@ import { InsightLogicProps } from '~/types'import { TrendsLegendItemContextMenu } from './TrendsLegendItemContextMenu'-interface UseTrendsLegendConfigOptions {+interface UseInsightsLegendConfigOptions {insightProps: InsightLogicPropsinSharedMode?: boolean}-/** Builds the quill in-chart legend config shared by the trends-family charts (line/area/cumulative,- * and bar next). Wires toggle persistence + the isolate/show-all context menu through trendsDataLogic- * so every trends chart renders one consistent legend. Returns `undefined` when the quill-legend flag- * is off, so callers fall back to the legacy side legend and skip pre-stripping hidden series. */-export function useTrendsLegendConfig({+/** Builds the quill in-chart legend config for trends-family charts. Returns `undefined` when the+ * quill-legend flag is off. Wires toggle persistence and the isolate/show-all context menu through+ * trendsDataLogic. Lifecycle and funnel charts build their legend config inline (they don't read+ * from trendsDataLogic or need the flag gate). */+export function useInsightsLegendConfig({insightProps,inSharedMode = false,-}: UseTrendsLegendConfigOptions): ChartLegendConfig | undefined {+}: UseInsightsLegendConfigOptions): ChartLegendConfig | undefined {const { featureFlags } = useValues(featureFlagLogic)const quillLegendEnabled = !!featureFlags[FEATURE_FLAGS.PRODUCT_ANALYTICS_QUILL_LEGEND]const { canEditInsight } = useValues(insightLogic)@@ -45,6 +45,7 @@ export function useTrendsLegendConfig({if (!quillLegendEnabled) {return undefined}+const hiddenKeys = (indexedResults ?? []).filter((r) => getTrendsHidden(r)).map((r) => String(r.id))const showContextMenu = legendInteractive && legendSeriesIsolationMenuEligiblereturn {