: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(mcp): show times on hourly trends chart axes (#125148)
Sam Penningtonfcb362bb439b
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 4bad9e9a8dbd..c2d18bc2665d 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -6338,6 +6338,8 @@ snapshots:hash: v1.k794b7964.22187bb708adf85f40ea196df123bc4f11384eeef88ab0ec4d8e5fde8cd07165.IDxL-VRfm6bgHZPh_Z9MVj3g0ssz3su3PHGzNaTf-Vkmcp-apps-trends--donut--light:hash: v1.k794b7964.2ecaef94116d43c67f8eb8b41f6df93f350896e36be23dabf15d17ed794f894e.ZtobinT9oCgMvwrL2sfTGim519QmGqoi8xB_Pu4HObQ+ mcp-apps-trends--hourly--light:+ hash: v1.k794b7964.66d121717bd447b82472ac1c504f3b4c4d40ef88522fba75d65bf9fc7700936a.fa0X-fIVAnuCL6El4ETSemfqunqWZ1fLX4TsmB2V0fUmcp-apps-trends--multi-series--light:hash: v1.k794b7964.590c3b62c9f76c72da6ee2ee2a4cf22c27881b373690f0dd05039b3276674e2d.-MNk8IwYc1MD_AJwE11zBCWPKHS311soE8tuEewecRcmcp-apps-trends--pie--light:diff --git a/services/mcp/src/ui-apps/components/Trends.stories.tsx b/services/mcp/src/ui-apps/components/Trends.stories.tsxindex 934f6a6e1445..5e072433dd7c 100644--- a/services/mcp/src/ui-apps/components/Trends.stories.tsx+++ b/services/mcp/src/ui-apps/components/Trends.stories.tsx@@ -53,6 +53,19 @@ export const MultiSeries: Story = {name: 'Multi-series',}+const HOURS = Array.from({ length: 9 }, (_, index) => {+ const hour = (20 + index) % 24+ return `2025-05-${hour >= 20 ? '26' : '27'} ${String(hour).padStart(2, '0')}:00:00`+})++export const Hourly: Story = {+ render: () =>+ renderTrends({ ...trendsQuery('ActionsLineGraph'), interval: 'hour' }, [+ { label: 'Pageviews', data: [42, 38, 51, 30, 12, 8, 6, 9, 15], days: HOURS },+ ]),+ name: 'Hourly',+}+export const AreaChart: Story = {render: () =>renderTrends(trendsQuery('ActionsAreaGraph'), [diff --git a/services/mcp/src/ui-apps/components/TrendsVisualizer.tsx b/services/mcp/src/ui-apps/components/TrendsVisualizer.tsxindex 7ed5ecefab30..b8f84883e19a 100644--- a/services/mcp/src/ui-apps/components/TrendsVisualizer.tsx+++ b/services/mcp/src/ui-apps/components/TrendsVisualizer.tsx@@ -12,6 +12,7 @@ import {SlopeChart,TimeSeriesBarChart,TimeSeriesLineChart,+ type TimeInterval,type TooltipContext,} from '@posthog/quill-charts'@@ -60,9 +61,9 @@ const TOOLTIP_CONFIG = { pinnable: true, placement: 'cursor' as const }const LEGEND_CONFIG = { show: true, position: 'bottom' } as const// DefaultTooltip shows the raw x label; format it like the axis.-const renderDateTooltip = (ctx: TooltipContext): ReactElement => (- <DefaultTooltip {...ctx} label={formatTooltipDate(ctx.label)} />-)+const dateTooltip =+ (interval: string | undefined) =>+ (ctx: TooltipContext): ReactElement => <DefaultTooltip {...ctx} label={formatTooltipDate(ctx.label, interval)} />function calculateTotal(results: TrendsResultItem[]): number {return results.reduce((sum, item) => {@@ -182,6 +183,12 @@ export function TrendsVisualizer({}const labels = results[0]?.days ?? results[0]?.labels ?? []+ // Trends returns each day as wall-clock time with no offset, so reading it as UTC keeps it as written.+ const xAxisDates = {+ interval: (query?.interval ?? 'day') as TimeInterval,+ timezone: 'UTC',+ allDays: labels.map(String),+ }const trendResults = results.map((item, i) => ({id: i,label: getSeriesLabel(item, i),@@ -234,7 +241,7 @@ export function TrendsVisualizer({isPercentStackView,isGrouped: effectiveType === 'bar',valueLabels,- xAxisTickFormatter: (value) => formatDate(value),+ ...xAxisDates,tooltip: TOOLTIP_CONFIG,})return (@@ -243,7 +250,7 @@ export function TrendsVisualizer({labels={labels}theme={theme}config={showLegend ? { ...config, legend: LEGEND_CONFIG } : config}- tooltip={renderDateTooltip}+ tooltip={dateTooltip(xAxisDates.interval)}>{overlay}</TimeSeriesBarChart>@@ -263,7 +270,7 @@ export function TrendsVisualizer({ciRanges,valueLabels,showCrosshair: true,- xAxisTickFormatter: (value) => formatDate(value),+ ...xAxisDates,tooltip: TOOLTIP_CONFIG,})return (@@ -272,7 +279,7 @@ export function TrendsVisualizer({labels={labels}theme={theme}config={showLegend ? { ...config, legend: LEGEND_CONFIG } : config}- tooltip={renderDateTooltip}+ tooltip={dateTooltip(xAxisDates.interval)}>{overlay}</TimeSeriesLineChart>diff --git a/services/mcp/src/ui-apps/components/types.ts b/services/mcp/src/ui-apps/components/types.tsindex 42a1fbb6c989..0730f332d1eb 100644--- a/services/mcp/src/ui-apps/components/types.ts+++ b/services/mcp/src/ui-apps/components/types.ts@@ -41,6 +41,7 @@ export interface TrendsFilter {export interface TrendsQuery {kind: 'TrendsQuery'+ interval?: stringtrendsFilter?: TrendsFilterseries?: Array<{event?: stringdiff --git a/services/mcp/src/ui-apps/components/utils.ts b/services/mcp/src/ui-apps/components/utils.tsindex 17f4ac79a2de..e9f235434a89 100644--- a/services/mcp/src/ui-apps/components/utils.ts+++ b/services/mcp/src/ui-apps/components/utils.ts@@ -86,7 +86,10 @@ export function formatDate(dateStr: string): string {return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric' })}-export function formatTooltipDate(dateStr: string): string {+const SUB_DAY_INTERVALS = new Set(['second', 'minute', 'hour'])+const WALL_CLOCK_TIME = /^\d{4}-\d{2}-\d{2}[T ](\d{2}:\d{2})/++export function formatTooltipDate(dateStr: string, interval?: string): string {if (!ISO_DATE_PREFIX.test(dateStr)) {return dateStr}@@ -94,7 +97,9 @@ export function formatTooltipDate(dateStr: string): string {if (Number.isNaN(date.getTime())) {return dateStr}- return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' })+ const day = date.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' })+ const time = interval && SUB_DAY_INTERVALS.has(interval) ? WALL_CLOCK_TIME.exec(dateStr)?.[1] : undefined+ return time ? `${day} ${time}` : day}export function getSeriesLabel(item: { label?: string; action?: { name?: string } }, index: number): string {