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.

fix(insights): match lifecycle series order to legacy chart (#60318)

Sam Pennington72079dbd77d2
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 25220001d7bf..3a0a91537950 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -2033,21 +2033,21 @@ snapshots:
insights-trendsbarchart--percent-stack-breakdown--light:
hash: v1.k794b7964.94dcced10754de4cf816cd83eb27f803082aee84fcf1b081bc98b8f4be366edd.KYJWPI86CCOx9TZf83eCCWbHwAlIqRJ8jcPZAK7-zyM
insights-trendslifecyclechart--stacked--dark:
- hash: v1.k794b7964.a0b63c471c3939cbe79812a900b8f887ec600442e98d21627b874b5d8832c592.xjKULqFFbTBlaBNOQ-FWvGL_P1LfLzY3V1t-lj-gSy0
+ hash: v1.k794b7964.0c556ee6fdcab5b92dfdc52f88803303ef884a0ab729ef82a4c6da51acb24c3f.QOa-WyWqTtPEFLJkamvn4q5CELTHgIvThx2ldXpfR0I
insights-trendslifecyclechart--stacked--light:
- hash: v1.k794b7964.06299a8e05030704231ec0ab4031ff3193330c613a3b7f9688db9ce7e932fe49.-8nYhPa8-aLNwcTVGon6dY_Rn4KRC-l_frb-ikmvk1I
+ hash: v1.k794b7964.a65059fedd22997962f3cca875571b75d337d4d4a35795e27c5154379a877e7c.ANRBq-VSdDBRCpI3opE7Mu4kXK2TL2MG7HwLnrSJHE4
insights-trendslifecyclechart--stacked-with-values-on-series--dark:
- hash: v1.k794b7964.e22cd804180d74ed539a09566d39a007c1218607709aeb38b4327b232097d0aa.YgSKLxUs3A8W3NeF3LLTH3Z4SxhKGMlMjYXv6JsM8B4
+ hash: v1.k794b7964.bc4c1f78bb5bc68955a459d215fca4bd5d459ea3992b5eca13ad40ee39ee4366.OX1_Hj6tCAyTwV7c24Xu-mTkSDv6PE_e0CofnkyQETM
insights-trendslifecyclechart--stacked-with-values-on-series--light:
- hash: v1.k794b7964.b8c4ee6cc4288293871d4c9dc83850e7e0cefa73bdc4a3984042c41953f01d26.PwlFs66ER2t5gbBToQJc2jL7ybJlg0K3h3CzWbUIRug
+ hash: v1.k794b7964.1da5ff8defc2fc0b153c290ef274d46e045a6b8f272100fc644e1d18d8435863.Rkn3WRzjDMlOtlNfweYDoTOhzGGvY_0JL7Jshsojgn4
insights-trendslifecyclechart--unstacked--dark:
- hash: v1.k794b7964.6b5f1e5ce04e682f39d957a57192db9dc38d29deae409146c45c275d8575341e.1wwEDPbO-jOXRNDOTT81-gPNbyMM2C5QpussoL6iEPA
+ hash: v1.k794b7964.a8cf1b1997745830adfb3ff10128cc607e058957c774fff1130fcb6ff404d866.krGwejVU2Th4ixNpXHRtz-e9X3orZ804ySTK-6yGkaI
insights-trendslifecyclechart--unstacked--light:
- hash: v1.k794b7964.3467d1d62a847176237a5278030dcd296df1283111f6260f86f2d467e2cc457b.xxTvFm43ZodSjCbtbMNLpjn20JZLLK6h4-MElnqQa5I
+ hash: v1.k794b7964.3417b88ceba60b38260452443223e486eac91f477061bc4662f76bb78f7c40e2.WOssmFNdeWS4-WAqpXRvxTO-Bpe_iL-lnRo-R0jHhCg
insights-trendslifecyclechart--unstacked-with-values-on-series--dark:
- hash: v1.k794b7964.51b27e46fb212a16b34a262aa0fd268060bc75f0664158514f7094ba20e3e19b.9e95m03noDYfUybRn95SPOcn1CmTppeZfkLIPxSSUlw
+ hash: v1.k794b7964.d11ad52519f19f8f938e0419e78f5c98a6097fa501cfea43d2baa3ba8aea3948.F_NC7gkGfnvJ6y7t6_cvfdk-dqMjcfJvhSYyg_Bn5bg
insights-trendslifecyclechart--unstacked-with-values-on-series--light:
- hash: v1.k794b7964.266358bb2f7faba7c50e0b2bd2b4924c2abd746d9c1c6c5f79ce50c04757a26e.ccDgypjgZFpI8NbSzW1piWaUjaREnUunrT5UU6mUH9E
+ hash: v1.k794b7964.90ea612a24c0b473fe99d7337abbb3faba6e46c16149cc88595b3dfb83a8d727.-fkbjzydqeaoOsdMYBHEM9jeX8-ZPVJZe3wSHTh5WBU
insights-trendslinechart--breakdown--dark:
hash: v1.k794b7964.26e070b747cdce14d42696be55405981bf7149f088bd0def208f50cd7f8abedd.VZhMtciuCaFsReKDPdj_svmfFGvxR_TsXGdwIPHd-34
insights-trendslinechart--breakdown--light:
@@ -4827,9 +4827,9 @@ snapshots:
scenes-app-insights-funnels--funnel-left-to-right-breakdown-edit--light:
hash: v1.k794b7964.414326f685dca45885b93d728ae8a75c7d8b600af35d76c9512a74a27e453006.IyZ8qHUwOv6qsBYvdUR1ZsK1Md_GNFCftDGvNZj78BQ
scenes-app-insights-funnels--funnel-left-to-right-edit--dark:
- hash: v1.k794b7964.293297b83994468984576e5c15fa2cbbb2c4c0a7a8234959b9deba539efa383b.xupnP9sdcp25xPBOMzrhSHwtRpKPLKHaqLDBncapvQA
+ hash: v1.k794b7964.c47bdb853ef9b6becfb675e2ca0bdbdb0c1b4385cf2442d50dd92752d90f7906.gaL7vRk-pWoOUkiPi-NGCd1W72x-M5l9jk5Qu-UcjwI
scenes-app-insights-funnels--funnel-left-to-right-edit--light:
- hash: v1.k794b7964.c63132bb5b13cbe97938ebdb2e59e320ebc338bd12b2d3bfd6af81e56270650a.3gc3UBg-8GVo4HkNBH7UrogK2q1uh9pXPDjTdYGT8nc
+ hash: v1.k794b7964.6c391cbc05b64230fbd8defdbb960b131fd433409817497873fb9ffc705cd360.dtIb8VK_HAoAvzi8YbVjGpt2Y8yONsVV7mEiD9DrclQ
scenes-app-insights-funnels--funnel-left-to-right-edit-viewports--medium--dark:
hash: v1.k794b7964.8887db0213a228a0f958496f8de814bd30d4735f99f8dcd886fbc9740a703afd.U7j0SBm9JuPzdVQVGChjxt-Iw1svrkRV06tAv9pg-mM
scenes-app-insights-funnels--funnel-left-to-right-edit-viewports--medium--light:
diff --git a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.stories.tsx b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.stories.tsx
index 86853a63280b..266786b3cf8f 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.stories.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/TrendsLifecycleChart.stories.tsx
@@ -140,8 +140,9 @@ function lifecycleInsight({ stacked, id, shortId, name, showValuesOnSeries }: Li
last_modified_at: '2023-07-11T12:00:00Z',
dashboards: [],
dashboard_tiles: [],
- // The order intentionally does NOT match the canonical new → resurrecting → returning →
- // dormant order — the transform sorts by status, so the chart should look the same.
+ // The order intentionally does NOT match the chart's rendered dormant → returning →
+ // resurrecting → new order — the transform sorts by status, so the chart should look
+ // the same regardless of how the API returns the rows.
result: [
lifecycleSeries('returning', [42, 38, 45, 40, 50, 47, 44]),
lifecycleSeries('new', [22, 30, 18, 24, 28, 20, 26]),
diff --git a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/trendsLifecycleChartTransforms.test.ts b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/trendsLifecycleChartTransforms.test.ts
index 442a6951936a..85b24bc51c1e 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/trendsLifecycleChartTransforms.test.ts
+++ b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/trendsLifecycleChartTransforms.test.ts
@@ -18,16 +18,16 @@ import {
} from './trendsLifecycleChartTransforms'
describe('buildTrendsLifecycleSeries', () => {
- it('orders series new → resurrecting → returning → dormant regardless of input order', () => {
+ it('orders series dormant → returning → resurrecting → new regardless of input order', () => {
const results: TrendsLifecycleResultLike[] = [
- { id: 'dormant', status: 'dormant', label: 'Pageview - dormant', data: [-1, -2, -3] },
- { id: 'returning', status: 'returning', label: 'Pageview - returning', data: [1, 2, 3] },
{ id: 'new', status: 'new', label: 'Pageview - new', data: [1, 2, 3] },
+ { id: 'returning', status: 'returning', label: 'Pageview - returning', data: [1, 2, 3] },
+ { id: 'dormant', status: 'dormant', label: 'Pageview - dormant', data: [-1, -2, -3] },
{ id: 'resurrecting', status: 'resurrecting', label: 'Pageview - resurrecting', data: [1, 2, 3] },
]
const series = buildTrendsLifecycleSeries(results)
- expect(series.map((s) => s.key)).toEqual(['new', 'resurrecting', 'returning', 'dormant'])
+ expect(series.map((s) => s.key)).toEqual(['dormant', 'returning', 'resurrecting', 'new'])
})
it('preserves dormant data as negative — diverging stack relies on the sign', () => {
@@ -46,7 +46,7 @@ describe('buildTrendsLifecycleSeries', () => {
{ id: 'dormant', status: 'dormant', label: 'Pageview - dormant', data: [-1, -2, -3] },
]
const series = buildTrendsLifecycleSeries(results)
- expect(series.map((s) => s.color)).toEqual(['#11ff11', '#22ff22', '#33ff33', '#44ff44'])
+ expect(series.map((s) => s.color)).toEqual(['#44ff44', '#33ff33', '#22ff22', '#11ff11'])
})
it('shortens series labels to capitalized status — used by both legend and tooltip', () => {
diff --git a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/trendsLifecycleChartTransforms.ts b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/trendsLifecycleChartTransforms.ts
index 39ce54975dbc..c18062525fb1 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/trendsLifecycleChartTransforms.ts
+++ b/products/product_analytics/frontend/insights/trends/TrendsLifecycleChart/trendsLifecycleChartTransforms.ts
@@ -41,12 +41,13 @@ export function buildTrendsLifecycleSeries<R extends TrendsLifecycleResultLike,
results: R[],
opts: BuildTrendsLifecycleSeriesOpts<R, M> = {}
): Series<M>[] {
- // Stable lifecycle order: new → resurrecting → returning → dormant.
- // d3.stack emits layers in series order, so dormant ends up at the bottom of the
- // diverging stack (its data is negative) and renders below the zero baseline.
+ // Stable lifecycle order: dormant → returning → resurrecting → new — matches the
+ // legacy lifecycle chart (`trendsDataLogic.ts:197`) so the legend reads top-down the
+ // same way. Dormant's data is negative, so the diverging stack still renders it below
+ // the zero baseline regardless of its position in the series array.
const ordered = results
.map((r, index) => ({ r, originalIndex: index }))
- .sort((a, b) => lifecycleStatusOrder(a.r.status) - lifecycleStatusOrder(b.r.status))
+ .sort((a, b) => lifecycleStatusOrder(b.r.status) - lifecycleStatusOrder(a.r.status))
return ordered.map(({ r, originalIndex }) => {
const excluded = opts.getHidden ? opts.getHidden(r, originalIndex) : false
diff --git a/products/product_analytics/frontend/insights/trends/shared/trendsSeriesMeta.ts b/products/product_analytics/frontend/insights/trends/shared/trendsSeriesMeta.ts
index dd8b730cd9c7..149bca2711bc 100644
--- a/products/product_analytics/frontend/insights/trends/shared/trendsSeriesMeta.ts
+++ b/products/product_analytics/frontend/insights/trends/shared/trendsSeriesMeta.ts
@@ -13,10 +13,9 @@ export type TrendsSeriesMeta = {
filter?: SeriesDatum['filter']
}
-/** Canonical lifecycle order: new → resurrecting → returning → dormant.
- * Used both as a status enumeration and as the stack order for the diverging stack —
- * dormant ends up at the bottom because its data is negative. Callers that need the
- * legacy descending order (`trendsDataLogic.ts:197`) can iterate in reverse. */
+/** Canonical lifecycle status enumeration: new → resurrecting → returning → dormant.
+ * The lifecycle chart renders series in the reverse order (dormant first) to match the
+ * legacy chart (`trendsDataLogic.ts:197`); see `trendsLifecycleChartTransforms.ts`. */
export const LIFECYCLE_STATUS_ORDER: readonly LifecycleToggle[] = ['new', 'resurrecting', 'returning', 'dormant']
export const buildTrendsSeriesMeta = (r: IndexedTrendResult): TrendsSeriesMeta => ({