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(charts): prevent duplicate time labels collapsing points (#90311)

Sam Pennington6b25c37516c2
diff --git a/frontend/src/scenes/retention/retentionGraphLogic.test.ts b/frontend/src/scenes/retention/retentionGraphLogic.test.ts
index 9238fcf5e12b..d15ccb9452aa 100644
--- a/frontend/src/scenes/retention/retentionGraphLogic.test.ts
+++ b/frontend/src/scenes/retention/retentionGraphLogic.test.ts
@@ -32,7 +32,7 @@ const breakdownQuery: RetentionQuery = {
const breakdownRows = [
cohortRow('2024-01-01T00:00:00Z', 'Chrome'),
- cohortRow('2024-01-02T00:00:00Z', 'Chrome'),
+ cohortRow('2025-01-01T00:00:00Z', 'Chrome'),
cohortRow('2024-01-01T00:00:00Z', BREAKDOWN_OTHER_STRING_LABEL),
]
@@ -102,6 +102,7 @@ describe('retentionGraphLogic', () => {
['Chrome', 'Chrome'],
[BREAKDOWN_OTHER_DISPLAY, BREAKDOWN_OTHER_STRING_LABEL],
])
+ expect(logic.values.xAxisLabels).toEqual(['2024-01-01T00:00:00.000Z', '2025-01-01T00:00:00.000Z'])
})
it('per-cohort series keep rawBreakdownValue unset when filtered to one breakdown value', async () => {
diff --git a/frontend/src/scenes/retention/retentionGraphLogic.ts b/frontend/src/scenes/retention/retentionGraphLogic.ts
index 997909325edb..c3a533f31a00 100644
--- a/frontend/src/scenes/retention/retentionGraphLogic.ts
+++ b/frontend/src/scenes/retention/retentionGraphLogic.ts
@@ -408,13 +408,7 @@ export const retentionGraphLogic = kea<retentionGraphLogicType>([
// When an interval is selected, show cohort dates on x-axis
if (selectedInterval !== null && selectedInterval !== undefined) {
- const formatCohortLabel = (cohort: ProcessedRetentionPayload): string => {
- if (cohort.date) {
- return period === 'Hour' ? cohort.date.format('MMM D, h A') : cohort.date.format('MMM D')
- }
- return cohort.label
- }
- return filteredResults.map(formatCohortLabel)
+ return [...new Set(filteredResults.map((cohort) => cohort.date?.toISOString() ?? cohort.label))]
}
const unit = dateOptionPlurals[period || 'Day']
diff --git a/frontend/src/scenes/web-analytics/pagePerformanceLogic.test.ts b/frontend/src/scenes/web-analytics/pagePerformanceLogic.test.ts
index 7cc04eac699e..0cc3a4e152c9 100644
--- a/frontend/src/scenes/web-analytics/pagePerformanceLogic.test.ts
+++ b/frontend/src/scenes/web-analytics/pagePerformanceLogic.test.ts
@@ -187,10 +187,10 @@ describe('pagePerformanceLogic', () => {
comparedWindow
)
- expect(mergePagePerformanceSeries(human, crawler, 'day')).toEqual([
- { label: 'Aug 3', visitors: 50, google: 20, llm: 3, crawls: 0 },
- { label: 'Aug 4', visitors: 0, google: 0, llm: 0, crawls: 700 },
- { label: 'Aug 5', visitors: 40, google: 10, llm: 2, crawls: 0 },
+ expect(mergePagePerformanceSeries(human, crawler)).toEqual([
+ { label: '2026-08-03T05:00:00.000Z', visitors: 50, google: 20, llm: 3, crawls: 0 },
+ { label: '2026-08-04T05:00:00.000Z', visitors: 0, google: 0, llm: 0, crawls: 700 },
+ { label: '2026-08-05T05:00:00.000Z', visitors: 40, google: 10, llm: 2, crawls: 0 },
])
})
diff --git a/frontend/src/scenes/web-analytics/pagePerformanceLogic.ts b/frontend/src/scenes/web-analytics/pagePerformanceLogic.ts
index 3a151d371198..78f2e3ffb0d3 100644
--- a/frontend/src/scenes/web-analytics/pagePerformanceLogic.ts
+++ b/frontend/src/scenes/web-analytics/pagePerformanceLogic.ts
@@ -351,8 +351,7 @@ export const parsePagePerformanceOverviewResponse = (
/** Aligns the human and crawler series onto one bucket axis — either query can miss a bucket entirely. */
export const mergePagePerformanceSeries = (
human: ParsedOverviewResponse,
- crawler: ParsedOverviewResponse,
- bucketSize: PagePerformanceBucket
+ crawler: ParsedOverviewResponse
): OverviewSeriesPoint[] => {
const byBucket = new Map<number, OverviewSeriesPoint>()
@@ -363,7 +362,7 @@ export const mergePagePerformanceSeries = (
return existing
}
const point: OverviewSeriesPoint = {
- label: formatBucketLabel(bucket, bucketSize),
+ label: bucket.toISOString(),
visitors: 0,
google: 0,
llm: 0,
@@ -418,16 +417,6 @@ const BUCKET_HOGQL_FN: Record<PagePerformanceBucket, string> = {
week: 'toStartOfWeek',
}
-const BUCKET_LABEL_FORMAT: Record<PagePerformanceBucket, string> = {
- hour: 'MMM D, HH:mm',
- day: 'MMM D',
- week: 'MMM D',
-}
-
-// The bucket is parsed with `dayjs.tz(..., timezone)`, so it already carries the target offset.
-const formatBucketLabel = (bucket: dayjs.Dayjs, bucketSize: PagePerformanceBucket): string =>
- bucket.format(BUCKET_LABEL_FORMAT[bucketSize])
-
export interface MetricCellValue {
current: number
previous: number
@@ -1346,7 +1335,7 @@ export const pagePerformanceLogic = kea<pagePerformanceLogicType>([
performQuery(overviewNode(values.overviewCrawlerQuery), { signal }),
])
breakpoint()
- const { window: dateWindow, bucketSize } = values
+ const { window: dateWindow } = values
const human = parsePagePerformanceOverviewResponse(
humanResponse.columns,
humanResponse.results,
@@ -1370,7 +1359,7 @@ export const pagePerformanceLogic = kea<pagePerformanceLogicType>([
pages: human.totals.pages ?? 0,
serverLogs: crawler.totals.server_logs ?? 0,
},
- mergePagePerformanceSeries(human, crawler, bucketSize)
+ mergePagePerformanceSeries(human, crawler)
)
} catch (error) {
if (isCancellation(error)) {
diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitHistoryChart.tsx b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitHistoryChart.tsx
index e7f5f673feb7..ab48c0ec5c4b 100644
--- a/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitHistoryChart.tsx
+++ b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitHistoryChart.tsx
@@ -7,7 +7,7 @@ import { getColorVar } from 'lib/colors'
import { dayjs } from 'lib/dayjs'
import { getBucketOption, RateLimitHistoryBucket } from './rateLimitConfigLogic'
-import { buildRateLimitBarChartConfig, formatBucketLabel, getBucketTimeline } from './RateLimitSimulationChart'
+import { buildRateLimitBarChartConfig, getBucketTimeline } from './RateLimitSimulationChart'
function fillHistoryBuckets(history: RateLimitHistoryBucket[], bucketMinutes: number): RateLimitHistoryBucket[] {
const bucketMs = getBucketOption(bucketMinutes).minutes * 60_000
@@ -44,7 +44,7 @@ export function RateLimitHistoryChart({
return {
isEmpty: recorded.every((c) => c === 0) && dropped.every((c) => c === 0) && bypassed.every((c) => c === 0),
- labels: filled.map((b) => formatBucketLabel(b.bucket, bucketMinutes)),
+ labels: filled.map((b) => b.bucket),
series: [
{ key: 'recorded', label: 'Recorded', data: recorded },
{ key: 'dropped', label: 'Dropped', data: dropped, color: getColorVar('danger') },
@@ -54,7 +54,7 @@ export function RateLimitHistoryChart({
}, [history, bucketMinutes])
const theme = useChartTheme()
- const config = useChartConfig(() => buildRateLimitBarChartConfig('stacked'), [])
+ const config = useChartConfig(() => buildRateLimitBarChartConfig('stacked', bucketMinutes), [bucketMinutes])
if (isEmpty) {
return (
diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitSimulationChart.test.tsx b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitSimulationChart.test.tsx
new file mode 100644
index 000000000000..d40baff63703
--- /dev/null
+++ b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitSimulationChart.test.tsx
@@ -0,0 +1,43 @@
+import { cleanup, render } from '@testing-library/react'
+
+import { TimeSeriesBarChart } from '@posthog/quill-charts'
+
+import { dayjs } from 'lib/dayjs'
+
+import { RateLimitSimulationChart } from './RateLimitSimulationChart'
+
+jest.mock('@posthog/quill-charts', () => ({
+ ...jest.requireActual('@posthog/quill-charts'),
+ TimeSeriesBarChart: jest.fn(() => <div data-testid="rate-limit-chart" />),
+}))
+
+jest.mock('lib/charts/hooks', () => ({
+ useChartTheme: () => ({ colors: ['#000'] }),
+ useChartConfig: (buildConfig: () => unknown) => buildConfig(),
+}))
+
+const mockTimeSeriesBarChart = jest.mocked(TimeSeriesBarChart)
+
+describe('RateLimitSimulationChart', () => {
+ beforeEach(() => {
+ jest.useFakeTimers().setSystemTime(new Date('2024-11-03T08:00:00.000Z'))
+ mockTimeSeriesBarChart.mockClear()
+ })
+
+ afterEach(() => {
+ cleanup()
+ jest.useRealTimers()
+ })
+
+ it('keeps ISO labels distinct across a repeated local hour', () => {
+ render(<RateLimitSimulationChart volume={[]} rateLimit={null} bucketMinutes={60} />)
+
+ const labels = mockTimeSeriesBarChart.mock.calls[0][0].labels
+ const repeatedHourLabels = labels.filter(
+ (label) => dayjs(label).tz('America/New_York').format('MMM D, HH:mm') === 'Nov 3, 01:00'
+ )
+
+ expect(repeatedHourLabels).toEqual(['2024-11-03T05:00:00.000Z', '2024-11-03T06:00:00.000Z'])
+ expect(new Set(labels).size).toBe(labels.length)
+ })
+})
diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitSimulationChart.tsx b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitSimulationChart.tsx
index 4d9689565ae6..c8cc0be791a0 100644
--- a/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitSimulationChart.tsx
+++ b/products/error_tracking/frontend/scenes/ErrorTrackingConfigurationScene/rate_limit/RateLimitSimulationChart.tsx
@@ -1,6 +1,11 @@
import { useMemo } from 'react'
-import { type Series, TimeSeriesBarChart, type TimeSeriesBarChartConfig } from '@posthog/quill-charts'
+import {
+ type Series,
+ type TimeInterval,
+ TimeSeriesBarChart,
+ type TimeSeriesBarChartConfig,
+} from '@posthog/quill-charts'
import { useChartConfig, useChartTheme } from 'lib/charts/hooks'
import { getColorVar } from 'lib/colors'
@@ -45,21 +50,28 @@ function fillBuckets(volume: ExceptionVolumeBucket[], bucketMinutes: number): Ex
}))
}
-export function formatBucketLabel(iso: string, bucketMinutes: number): string {
- const ts = dayjs(iso)
+function bucketInterval(bucketMinutes: number): TimeInterval {
if (bucketMinutes >= 1440) {
- return ts.format('MMM D')
+ return 'day'
}
- return ts.format('MMM D, HH:mm')
+ if (bucketMinutes >= 60) {
+ return 'hour'
+ }
+ return 'minute'
}
/** Shared config for the rate limit bar charts: hidden bucket ticks, stacked bars, default tooltip
* with a total row. */
export function buildRateLimitBarChartConfig(
- barLayout: NonNullable<TimeSeriesBarChartConfig['barLayout']>
+ barLayout: NonNullable<TimeSeriesBarChartConfig['barLayout']>,
+ bucketMinutes: number
): TimeSeriesBarChartConfig {
return {
- xAxis: { hide: true },
+ xAxis: {
+ hide: true,
+ timezone: dayjs.tz.guess(),
+ interval: bucketInterval(bucketMinutes),
+ },
showAxisLines: { x: false, y: true },
barLayout,
legend: { show: false },
@@ -85,7 +97,7 @@ export function RateLimitSimulationChart({
const { labels, series } = useMemo(() => {
const filled = fillBuckets(volume, bucketMinutes)
- const labels = filled.map((b) => formatBucketLabel(b.bucket, bucketMinutes))
+ const labels = filled.map((b) => b.bucket)
const counts = filled.map((b) => b.count)
if (!hasLimit || rateLimit === null) {
@@ -111,7 +123,7 @@ export function RateLimitSimulationChart({
const theme = useChartTheme()
const config = useChartConfig<TimeSeriesBarChartConfig>(() => {
- const base = buildRateLimitBarChartConfig(hasLimit ? 'stacked' : 'grouped')
+ const base = buildRateLimitBarChartConfig(hasLimit ? 'stacked' : 'grouped', bucketMinutes)
if (!hasLimit || rateLimit === null) {
return base
}
diff --git a/products/product_analytics/frontend/insights/retention/RetentionBarChart/RetentionBarChart.tsx b/products/product_analytics/frontend/insights/retention/RetentionBarChart/RetentionBarChart.tsx
index 833f1d7b1146..2b0bc8d60543 100644
--- a/products/product_analytics/frontend/insights/retention/RetentionBarChart/RetentionBarChart.tsx
+++ b/products/product_analytics/frontend/insights/retention/RetentionBarChart/RetentionBarChart.tsx
@@ -60,6 +60,7 @@ export function RetentionBarChart({ inSharedMode = false }: RetentionBarChartPro
filteredTrendSeries,
labelGroupType,
shouldShowMeanPerBreakdown,
+ timezone,
xAxisLabels,
getRetentionColor,
} = useValues(retentionGraphLogic(insightProps))
@@ -151,8 +152,17 @@ export function RetentionBarChart({ inSharedMode = false }: RetentionBarChartPro
const goalLines = retentionFilter?.goalLines ?? EMPTY_GOAL_LINES
const barConfig = useChartConfig(
- () => buildRetentionBarChartConfig({ isPercentage, goalLines, series, tooltip: INSIGHT_TOOLTIP_CONFIG }),
- [isPercentage, goalLines, series]
+ () =>
+ buildRetentionBarChartConfig({
+ isPercentage,
+ goalLines,
+ series,
+ tooltip: INSIGHT_TOOLTIP_CONFIG,
+ isIntervalView,
+ period,
+ timezone,
+ }),
+ [isPercentage, goalLines, series, isIntervalView, period, timezone]
)
if (filteredTrendSeries.length === 0 && hasValidBreakdown) {
diff --git a/products/product_analytics/frontend/insights/retention/RetentionLineChart/RetentionLineChart.tsx b/products/product_analytics/frontend/insights/retention/RetentionLineChart/RetentionLineChart.tsx
index cdd2cbdfe729..330c26d388b9 100644
--- a/products/product_analytics/frontend/insights/retention/RetentionLineChart/RetentionLineChart.tsx
+++ b/products/product_analytics/frontend/insights/retention/RetentionLineChart/RetentionLineChart.tsx
@@ -63,6 +63,7 @@ export function RetentionLineChart({ inSharedMode = false }: RetentionLineChartP
labelGroupType,
shouldShowMeanPerBreakdown,
showTrendLines,
+ timezone,
xAxisLabels,
getRetentionColor,
} = useValues(retentionGraphLogic(insightProps))
@@ -162,10 +163,13 @@ export function RetentionLineChart({ inSharedMode = false }: RetentionLineChartP
showTrendLines,
series,
tooltip: INSIGHT_TOOLTIP_CONFIG,
+ isIntervalView,
+ period,
+ timezone,
}),
curve: chartStyleCurve(retentionFilter?.chartStyle),
}),
- [isPercentage, goalLines, showTrendLines, series, retentionFilter?.chartStyle]
+ [isPercentage, goalLines, showTrendLines, series, isIntervalView, period, timezone, retentionFilter?.chartStyle]
)
if (filteredTrendSeries.length === 0 && hasValidBreakdown) {
diff --git a/products/product_analytics/frontend/insights/retention/shared/retentionChartTransforms.test.ts b/products/product_analytics/frontend/insights/retention/shared/retentionChartTransforms.test.ts
index 48141ab2f756..0a75bc7894c2 100644
--- a/products/product_analytics/frontend/insights/retention/shared/retentionChartTransforms.test.ts
+++ b/products/product_analytics/frontend/insights/retention/shared/retentionChartTransforms.test.ts
@@ -167,6 +167,20 @@ describe('retentionChartTransforms', () => {
})
})
+ it.each([
+ ['line', buildRetentionLineChartConfig],
+ ['bar', buildRetentionBarChartConfig],
+ ])('formats %s interval-view dates in the team timezone', (_name, buildConfig) => {
+ const config = buildConfig({
+ isPercentage: true,
+ series: [],
+ isIntervalView: true,
+ period: 'Day',
+ timezone: 'America/Chicago',
+ })
+ expect(config.xAxis).toEqual({ interval: 'day', timezone: 'America/Chicago' })
+ })
+
describe('buildRetentionLineChartConfig', () => {
const baseSeries: Series<RetentionSeriesMeta>[] = buildRetentionSeries(
[makeEntry({ index: 0 }), makeEntry({ index: 1 })],
diff --git a/products/product_analytics/frontend/insights/retention/shared/retentionChartTransforms.ts b/products/product_analytics/frontend/insights/retention/shared/retentionChartTransforms.ts
index 73c54c2645e4..d88faa01027b 100644
--- a/products/product_analytics/frontend/insights/retention/shared/retentionChartTransforms.ts
+++ b/products/product_analytics/frontend/insights/retention/shared/retentionChartTransforms.ts
@@ -3,8 +3,10 @@ import type {
Series,
TimeSeriesBarChartConfig,
TimeSeriesLineChartConfig,
+ TimeInterval,
TooltipConfig,
TrendLineConfig,
+ XAxisConfig,
YAxisConfig,
} from '@posthog/quill-charts'
@@ -91,6 +93,9 @@ export interface BuildRetentionChartConfigOpts {
showTrendLines?: boolean
series: Series<RetentionSeriesMeta>[]
tooltip?: TooltipConfig
+ isIntervalView?: boolean
+ period?: string
+ timezone?: string
}
function buildTrendLines(
@@ -107,8 +112,21 @@ function buildGoalLines(goalLines: GoalLineLike[] | null | undefined): GoalLineC
return schemaGoalLinesToConfigs(goalLines)
}
+const TIME_INTERVAL_BY_RETENTION_PERIOD: Record<string, TimeInterval> = {
+ Hour: 'hour',
+ Day: 'day',
+ Week: 'week',
+ Month: 'month',
+}
+
+function buildXAxis(opts: BuildRetentionChartConfigOpts): XAxisConfig | undefined {
+ const interval = opts.period ? TIME_INTERVAL_BY_RETENTION_PERIOD[opts.period] : undefined
+ return opts.isIntervalView && interval && opts.timezone ? { interval, timezone: opts.timezone } : undefined
+}
+
export function buildRetentionLineChartConfig(opts: BuildRetentionChartConfigOpts): TimeSeriesLineChartConfig {
return {
+ xAxis: buildXAxis(opts),
yAxis: {
format: opts.isPercentage ? 'percentage' : 'numeric',
scale: 'linear',
@@ -124,6 +142,7 @@ export function buildRetentionBarChartConfig(
opts: BuildRetentionChartConfigOpts
): TimeSeriesBarChartConfig & { yAxis?: YAxisConfig } {
return {
+ xAxis: buildXAxis(opts),
yAxis: {
format: opts.isPercentage ? 'percentage' : 'numeric',
scale: 'linear',