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(retention): render xAxis labels on the chart (#59390)

Georgis Andonisafa98a5e21c8
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index a37fefb6a278..e6a3ace03c6f 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -1805,9 +1805,9 @@ snapshots:
filters-taxonomic-filter-headless--events-and-actions--light:
hash: v1.k794b7964.4c46126fae8b4602d33f7dfaf8ba91fe8cb791a1503818af95781f7c56d7660b.ZFpzmwxeyS5PPX0nav7YjNFbxVB9gNyL1n5_a_q-ngk
filters-taxonomic-filter-headless--properties--dark:
- hash: v1.k794b7964.992b733364963bfdd834c5eee2781fb28f73ac9e75dabc3b47cdd9bf0d6255e8.jA9dtaFdvpn5RK5xlra2ks_CfnnnC20bpWjhmxZMk5U
+ hash: v1.k794b7964.4ee695e5751c6f73e9742ab0cfeecf61b5adfe829cf3a0d49ab2877cae8b212f.jPN9l5TDgLRy9NzHenXHCU903UDg8-GdeGpf4PXt7aA
filters-taxonomic-filter-headless--properties--light:
- hash: v1.k794b7964.aca1f38a817b9b361e86522b1e89332e0a2b12022d59375e6c12690037e1768b._zsm8oxXgNz_ZRU9u5lAVUZUIl8PLcVDnGgPQ02AHmg
+ hash: v1.k794b7964.11a9db84696f65275d33fc80c627e3b57af968268caa793f1e467f0ff0fc466f._VccLmBRlm7Rsh5XwjBR8FHl69wOWTuMceeYVGe8lPA
filters-taxonomic-filter-headless--suggested-filters-with-recents--dark:
hash: v1.k794b7964.c3a6cd419610bc486261efa753816547f080f00c838bde0b8720cf12067b3b22.nxBtExiDfJ3USkhV9RY1VPU_U2dGyEYCMFbhvtOcuVs
filters-taxonomic-filter-headless--suggested-filters-with-recents--light:
@@ -3639,7 +3639,7 @@ snapshots:
replay-overview-tab-other-watchers--with-multiple-viewers--light:
hash: v1.k794b7964.d22f44e2d1941831f0698d29070517a7fa85cae0b3ffa10476509ce250050336.QJ6jRfOXmXeuYSA8-eNNZarZ9j2Sq9L8UZFT7spV2KU
replay-player-controller--default--dark:
- hash: v1.k794b7964.d16b928e8a845476fab0f3ebf713e8eb1c6f5888a12ecd5ee1e6fa61c8025e38.SlH6ZmNtP4Yl8TC7S6qnUqvqIi5i73E-NIQodSPfuZM
+ hash: v1.k794b7964.f9f275cbe293a453074a159e0b51856ece99ae281e791ffb67ab5c26330bf94d.M8RFmCHwm2YpbrHTHaJbTKJQvBvwe5-nl5fdF_7BITc
replay-player-controller--default--light:
hash: v1.k794b7964.9671cba9155a320fed566c2af1c303352509d9577bcd45608a3b280840aafe47.f9uZQir37Iop3BwxpCBxCU-l-rdkww4mcYVPdEcuNOo
replay-player-controller--narrow--dark:
diff --git a/frontend/src/lib/hog-charts/utils/dates.test.ts b/frontend/src/lib/hog-charts/utils/dates.test.ts
index 3b96058c5162..2011efba0151 100644
--- a/frontend/src/lib/hog-charts/utils/dates.test.ts
+++ b/frontend/src/lib/hog-charts/utils/dates.test.ts
@@ -226,7 +226,7 @@ describe('createXAxisTickCallback', () => {
it.each(expected.map((exp, i) => ({ index: i, expected: exp })))(
'formats index $index as $expected',
({ index, expected: exp }) => {
- expect(callback('ignored', index)).toBe(exp)
+ expect(callback?.('ignored', index)).toBe(exp)
}
)
})
@@ -238,9 +238,9 @@ describe('createXAxisTickCallback', () => {
allDays: ['2025-04-01 00:00:00', '2025-04-01 01:00:00', '2025-04-01 02:00:00'],
timezone: 'America/New_York',
})
- expect(callback('ignored', 0)).toBe('00:00')
- expect(callback('ignored', 1)).toBe('01:00')
- expect(callback('ignored', 2)).toBe('02:00')
+ expect(callback?.('ignored', 0)).toBe('00:00')
+ expect(callback?.('ignored', 1)).toBe('01:00')
+ expect(callback?.('ignored', 2)).toBe('02:00')
})
it.each([
@@ -253,16 +253,23 @@ describe('createXAxisTickCallback', () => {
allDays: ['2023-06-01', '2023-07-01', '2023-08-01'],
timezone: 'US/Pacific',
})
- expect(callback('ignored', 0)).toBe('June')
- expect(callback('ignored', 1)).toBe('July')
- expect(callback('ignored', 2)).toBe('August')
+ expect(callback?.('ignored', 0)).toBe('June')
+ expect(callback?.('ignored', 1)).toBe('July')
+ expect(callback?.('ignored', 2)).toBe('August')
})
})
describe('fallbacks', () => {
- it('returns raw value when allDays is empty', () => {
- const callback = createXAxisTickCallback({ interval: 'day', allDays: [], timezone: 'UTC' })
- expect(callback('2025-04-01', 0)).toBe('2025-04-01')
+ it.each([
+ { scenario: 'allDays is empty', allDays: [] as (string | number)[] },
+ { scenario: 'allDays contains numbers (non-date axis)', allDays: [1, 2, 3, 4, 5] as (string | number)[] },
+ {
+ scenario: 'allDays contains unparseable date strings',
+ allDays: ['not-a-date'] as (string | number)[],
+ },
+ ])('returns undefined when $scenario, deferring to the default formatter', ({ allDays }) => {
+ const callback = createXAxisTickCallback({ interval: 'day', allDays, timezone: 'UTC' })
+ expect(callback).toBeUndefined()
})
it('returns raw value when index is out of bounds', () => {
@@ -271,37 +278,7 @@ describe('createXAxisTickCallback', () => {
allDays: ['2025-04-01'],
timezone: 'UTC',
})
- expect(callback('some-label', 5)).toBe('some-label')
- })
-
- it('returns raw value when days are numbers and no prefix is provided', () => {
- const callback = createXAxisTickCallback({
- interval: 'day',
- allDays: [1, 2, 3, 4, 5],
- timezone: 'UTC',
- })
- expect(callback(1, 0)).toBe('1')
- expect(callback(3, 2)).toBe('3')
- })
-
- it('formats numbers with a prefix when provided', () => {
- const callback = createXAxisTickCallback({
- interval: 'day',
- allDays: [1, 2, 3, 4, 5],
- timezone: 'UTC',
- numericTickPrefix: 'Day',
- })
- expect(callback(1, 0)).toBe('Day 1')
- expect(callback(3, 2)).toBe('Day 3')
- })
-
- it('returns raw value for unparseable dates', () => {
- const callback = createXAxisTickCallback({
- interval: 'day',
- allDays: ['not-a-date'],
- timezone: 'UTC',
- })
- expect(callback('fallback', 0)).toBe('fallback')
+ expect(callback?.('some-label', 5)).toBe('some-label')
})
})
})
diff --git a/frontend/src/lib/hog-charts/utils/dates.ts b/frontend/src/lib/hog-charts/utils/dates.ts
index e73a2cae3d18..db3e6b771802 100644
--- a/frontend/src/lib/hog-charts/utils/dates.ts
+++ b/frontend/src/lib/hog-charts/utils/dates.ts
@@ -8,7 +8,6 @@ interface CreateXAxisTickCallbackArgs {
interval?: TimeInterval
allDays: (string | number)[]
timezone: string
- numericTickPrefix?: string
}
type TickMode =
@@ -22,10 +21,9 @@ export function createXAxisTickCallback({
interval,
allDays,
timezone,
- numericTickPrefix,
-}: CreateXAxisTickCallbackArgs): (value: string | number, index: number) => string | null {
+}: CreateXAxisTickCallbackArgs): ((value: string | number, index: number) => string | null) | undefined {
if (allDays.length === 0 || typeof allDays[0] !== 'string') {
- return (value) => (numericTickPrefix ? `${numericTickPrefix} ${String(value)}` : String(value))
+ return
}
const parsedDates = allDays.map((d) => parseDateForAxis(String(d), timezone))
@@ -33,7 +31,7 @@ export function createXAxisTickCallback({
const last = parsedDates[parsedDates.length - 1]
if (!first?.isValid() || !last?.isValid()) {
- return (value) => String(value)
+ return
}
const resolvedInterval = interval ?? inferInterval(parsedDates)
diff --git a/frontend/src/scenes/insights/views/LineGraph/LineGraph.tsx b/frontend/src/scenes/insights/views/LineGraph/LineGraph.tsx
index a0f779812c97..febc9261fb1a 100644
--- a/frontend/src/scenes/insights/views/LineGraph/LineGraph.tsx
+++ b/frontend/src/scenes/insights/views/LineGraph/LineGraph.tsx
@@ -64,6 +64,14 @@ function truncateString(str: string, num: number): string {
return str
}
+/** Generate per-bucket labels for stickiness ("Day 0", "Day 1", …). The API's own labels include
+ * a "X day(s)" suffix that's redundant when paired with the interval prefix, so we use the index. */
+function formatIntervalLabels(labels: string[], interval: string | null | undefined): string[] {
+ const unit = interval ?? 'day'
+ const prefix = `${unit.slice(0, 1).toUpperCase()}${unit.slice(1)}`
+ return labels.map((_, i) => `${prefix} ${i}`)
+}
+
const INCOMPLETE_SEGMENT_BORDER_DASH = [10, 10]
// Chart.js locks up the main thread when rendering too many series, effectively
// freezing the browser. Cap the dataset count to keep the UI responsive.
@@ -343,6 +351,8 @@ export function LineGraph_({
const { timezone, isTrends, isStickiness, isFunnels, breakdownFilter, interval, insightData } = useValues(
insightVizDataLogic(insightProps)
)
+
+ const displayLabels = isStickiness ? formatIntervalLabels(labels, interval) : labels
const { theme, getTrendsColor, getTrendsHidden, hoveredDatasetIndex, currentPeriodResult } = useValues(
trendsDataLogic(insightProps)
)
@@ -690,9 +700,6 @@ export function LineGraph_({
interval: interval ?? 'day',
allDays: currentPeriodResult?.days ?? [],
timezone,
- numericTickPrefix: isStickiness
- ? `${(interval ?? 'day').slice(0, 1).toUpperCase()}${(interval ?? 'day').slice(1)}`
- : undefined,
})
const gridOptions: Partial<GridLineOptions> = {
@@ -1263,7 +1270,7 @@ export function LineGraph_({
return {
type: (isBar ? GraphType.Bar : type) as ChartType,
- data: { labels, datasets: processedDatasets },
+ data: { labels: displayLabels, datasets: processedDatasets },
options,
plugins: [ChartDataLabels, ...(showTrendLines ? [chartTrendline as any] : [])],
}
@@ -1281,7 +1288,7 @@ export function LineGraph_({
type,
isArea,
showTrendLines,
- labels,
+ displayLabels,
legend?.display,
hideTooltip,
showTooltip,