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.

chore(hog-charts): drop dead config props from TimeSeriesLineChart (#57765)

Sam Pennington12c9809a16c2
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index f16c6c0307f1..194ba1e90021 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -572,10 +572,6 @@ snapshots:
hash: v1.k794b7964.8f27aa8ee4161d4041693a5549046f0e348aab5fdccc466ea461d6a0f5cf97e2.KEpUtlvBURMPzv1Vyq9Pvf8i_sDKoF3t7fZO8Ed1yPs
components-hogcharts-referenceline--vertical-reference-lines--light:
hash: v1.k794b7964.c5c09ab055b1b0fde7a5d73279e6a1adba9cc4165d0883ea8c641d4cd68ebf2b.hb7hZ9GBhWL6oRE5jtOZuUEer6xZ5dTyjpH0qB4Dfpk
- components-hogcharts-timeserieslinechart--anomalies--dark:
- hash: v1.k794b7964.fc7e9b233a0ff0847a5dcade2aaa7004f453c1af65a443adeecb526540ffa0a8.h18dCehQgzalv7JwGX-pqrA-zgiB0WsMqioFp0lX5EY
- components-hogcharts-timeserieslinechart--anomalies--light:
- hash: v1.k794b7964.ec037285360c27f8362e5476fbb5eb9c02eff034c83c40d91915b2456adafa85.Ls5QZuxtjPy-4OamK69F1DVapsxQ6sKdNf9dGJdzMCg
components-hogcharts-timeserieslinechart--basic--dark:
hash: v1.k794b7964.529535e435c93c8f004cdba8f2ba29681dd679eb9bfbaff745a5f00c3b424ffd.2Kq3-2B9F2VNlkrFY-dge3vntnfrudonJ-Lle1s8m5E
components-hogcharts-timeserieslinechart--basic--light:
diff --git a/frontend/src/lib/hog-charts/charts/TimeSeriesLineChart/TimeSeriesLineChart.stories.tsx b/frontend/src/lib/hog-charts/charts/TimeSeriesLineChart/TimeSeriesLineChart.stories.tsx
index f16806233c4f..580ba772c638 100644
--- a/frontend/src/lib/hog-charts/charts/TimeSeriesLineChart/TimeSeriesLineChart.stories.tsx
+++ b/frontend/src/lib/hog-charts/charts/TimeSeriesLineChart/TimeSeriesLineChart.stories.tsx
@@ -1,7 +1,7 @@
import { Meta, StoryObj } from '@storybook/react'
-import { DEFAULT_Y_AXIS_ID, TimeSeriesLineChart } from 'lib/hog-charts'
-import type { AnomalyMarker, Series, TimeInterval, YAxisConfig } from 'lib/hog-charts'
+import { createXAxisTickCallback, TimeSeriesLineChart } from 'lib/hog-charts'
+import type { Series, TimeInterval, YAxisConfig } from 'lib/hog-charts'
import { ciRanges } from 'lib/statistics'
import { Stage, useReactiveTheme } from '../../story-helpers'
@@ -88,6 +88,7 @@ interface DateAxisCellProps {
function DateAxisCell({ title, labels, series, interval, timezone }: DateAxisCellProps): JSX.Element {
const theme = useReactiveTheme()
+ const tickFormatter = createXAxisTickCallback({ timezone, interval, allDays: labels })
return (
// eslint-disable-next-line react/forbid-dom-props
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
@@ -98,7 +99,7 @@ function DateAxisCell({ title, labels, series, interval, timezone }: DateAxisCel
labels={labels}
theme={theme}
config={{
- xAxis: { timezone, interval },
+ xAxis: { tickFormatter },
yAxis: { showGrid: true },
}}
/>
@@ -166,29 +167,6 @@ export const YAxisFormats: Story = {
),
}
-export const Anomalies: Story = {
- render: () => {
- const theme = useReactiveTheme()
- const series: Series[] = [{ key: 'visits', label: 'Visits', data: [20, 35, 28, 60, 45, 70, 52] }]
- // Severity drives color — low (amber), medium (orange), high (red).
- const anomalies: AnomalyMarker[] = [
- { dataIndex: 1, value: 35, color: '#f59e0b', yAxisId: DEFAULT_Y_AXIS_ID },
- { dataIndex: 3, value: 60, color: '#f97316', yAxisId: DEFAULT_Y_AXIS_ID },
- { dataIndex: 5, value: 70, color: '#ef4444', yAxisId: DEFAULT_Y_AXIS_ID },
- ]
- return (
- <Stage>
- <TimeSeriesLineChart
- series={series}
- labels={DAYS}
- theme={theme}
- config={{ yAxis: { showGrid: true }, anomalies }}
- />
- </Stage>
- )
- },
-}
-
const DERIVED_SERIES: Series[] = [
{ key: 'visits', label: 'Visits', data: [20, 35, 28, 60, 45, 70, 52] },
{ key: 'signups', label: 'Sign-ups', data: [4, 8, 6, 14, 11, 19, 13] },
diff --git a/frontend/src/lib/hog-charts/charts/TimeSeriesLineChart/TimeSeriesLineChart.test.tsx b/frontend/src/lib/hog-charts/charts/TimeSeriesLineChart/TimeSeriesLineChart.test.tsx
index 93c7164f46a2..0bb6c2f5fac6 100644
--- a/frontend/src/lib/hog-charts/charts/TimeSeriesLineChart/TimeSeriesLineChart.test.tsx
+++ b/frontend/src/lib/hog-charts/charts/TimeSeriesLineChart/TimeSeriesLineChart.test.tsx
@@ -1,7 +1,6 @@
import { cleanup } from '@testing-library/react'
import type { ChartTheme, Series } from '../../core/types'
-import type { AnomalyMarker } from '../../overlays/AnomalyPointsLayer'
import { renderHogChart, setupJsdom, setupSyncRaf } from '../../testing'
import { TimeSeriesLineChart } from './TimeSeriesLineChart'
@@ -32,50 +31,18 @@ describe('TimeSeriesLineChart', () => {
expect(chart.xTicks()).toHaveLength(0)
})
- it('builds an x-axis tick formatter from xAxis.timezone + xAxis.interval', () => {
- const allDays = ['2025-04-01 14:00:00', '2025-04-01 15:00:00', '2025-04-01 16:00:00']
- const { chart } = renderHogChart(
- <TimeSeriesLineChart
- series={[{ key: 'a', label: 'A', data: [1, 2, 3] }]}
- labels={['14:00', '15:00', '16:00']}
- theme={THEME}
- config={{ xAxis: { timezone: 'UTC', interval: 'hour', allDays } }}
- />
- )
- expect(chart.xTicks()).toEqual(['14:00', '15:00', '16:00'])
- })
-
- it('explicit xAxis.tickFormatter wins over timezone+interval', () => {
+ it('forwards an explicit xAxis.tickFormatter to the chart', () => {
const explicit = (_v: string, i: number): string => `tick-${i}`
const { chart } = renderHogChart(
<TimeSeriesLineChart
series={[{ key: 'a', label: 'A', data: [1, 2, 3] }]}
labels={['14:00', '15:00', '16:00']}
theme={THEME}
- config={{
- xAxis: {
- tickFormatter: explicit,
- timezone: 'UTC',
- interval: 'hour',
- allDays: ['2025-04-01 14:00:00', '2025-04-01 15:00:00', '2025-04-01 16:00:00'],
- },
- }}
+ config={{ xAxis: { tickFormatter: explicit } }}
/>
)
expect(chart.xTicks()).toEqual(['tick-0', 'tick-1', 'tick-2'])
})
-
- it('does not auto-format when only one of timezone or interval is provided', () => {
- const { chart } = renderHogChart(
- <TimeSeriesLineChart
- series={[{ key: 'a', label: 'A', data: [1, 2, 3] }]}
- labels={LABELS}
- theme={THEME}
- config={{ xAxis: { timezone: 'UTC' } }}
- />
- )
- expect(chart.xTicks()).toEqual(LABELS)
- })
})
describe('config.yAxis', () => {
@@ -220,37 +187,6 @@ describe('TimeSeriesLineChart', () => {
})
})
- describe('config.anomalies', () => {
- it.each([
- ['omitted', undefined],
- ['empty', [] as AnomalyMarker[]],
- ])('does not render anomaly points when anomalies is %s', (_, anomalies) => {
- const { chart } = renderHogChart(
- <TimeSeriesLineChart
- series={SERIES}
- labels={LABELS}
- theme={THEME}
- config={anomalies === undefined ? undefined : { anomalies }}
- />
- )
- expect(chart.anomalyPoints()).toHaveLength(0)
- })
-
- it('renders one anomaly point per marker', () => {
- const markers: AnomalyMarker[] = [
- { dataIndex: 1, value: 2, color: '#f00', yAxisId: 'left' },
- { dataIndex: 2, value: 3, color: '#0f0', yAxisId: 'left' },
- ]
- const { chart } = renderHogChart(
- <TimeSeriesLineChart series={SERIES} labels={LABELS} theme={THEME} config={{ anomalies: markers }} />
- )
- const points = chart.anomalyPoints()
- expect(points).toHaveLength(2)
- expect(points[0].color).toBe('rgb(255, 0, 0)')
- expect(points[1].color).toBe('rgb(0, 255, 0)')
- })
- })
-
describe('derived-series wiring', () => {
it.each([
['confidenceIntervals', { confidenceIntervals: [{ seriesKey: 'a', lower: [0, 1, 2], upper: [2, 3, 4] }] }],
diff --git a/frontend/src/lib/hog-charts/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx b/frontend/src/lib/hog-charts/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx
index 5f23377615e3..0f835a3d0ab4 100644
--- a/frontend/src/lib/hog-charts/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx
+++ b/frontend/src/lib/hog-charts/charts/TimeSeriesLineChart/TimeSeriesLineChart.tsx
@@ -8,18 +8,11 @@ import type {
TooltipConfig,
TooltipContext,
} from '../../core/types'
-import { AnomalyPointsLayer, type AnomalyMarker } from '../../overlays/AnomalyPointsLayer'
import { ReferenceLines } from '../../overlays/ReferenceLine'
import { ValueLabels } from '../../overlays/ValueLabels'
import { buildGoalLineReferenceLines, type GoalLineConfig } from '../../utils/goal-lines'
-import {
- useXTickFormatter,
- useYTickFormatter,
- type XAxisConfig,
- type YAxisConfig,
-} from '../../utils/use-axis-formatters'
+import { useYTickFormatter, type XAxisConfig, type YAxisConfig } from '../../utils/use-axis-formatters'
import { LineChart } from '../LineChart'
-import { applyInProgressToSeries, type InProgressConfig } from './utils/in-progress'
import {
useDerivedSeries,
type ConfidenceIntervalConfig,
@@ -37,7 +30,6 @@ export type { ConfidenceIntervalConfig, MovingAverageConfig, TrendLineConfig }
export interface TimeSeriesLineChartConfig {
xAxis?: XAxisConfig
yAxis?: YAxisConfig
- inProgress?: InProgressConfig
valueLabels?: boolean | ValueLabelsConfig
goalLines?: GoalLineConfig[]
confidenceIntervals?: ConfidenceIntervalConfig[]
@@ -45,8 +37,6 @@ export interface TimeSeriesLineChartConfig {
trendLines?: TrendLineConfig[]
/** Comparison series keys mapped to their primary. Comparison series render dimmed. */
comparisonOf?: Record<string, string>
- /** Anomaly markers rendered as filled circles on top of the chart. */
- anomalies?: AnomalyMarker[]
/** Render area-fill series as a 100% stacked view; y-axis becomes 0–100%. */
percentStackView?: boolean
/** Show a vertical crosshair line that follows the cursor. */
@@ -93,45 +83,34 @@ export function TimeSeriesLineChart<Meta = unknown>({
const {
xAxis,
yAxis,
- inProgress,
valueLabels,
goalLines,
confidenceIntervals,
movingAverage,
trendLines,
comparisonOf,
- anomalies,
percentStackView,
showCrosshair,
tooltip: tooltipConfig,
} = config ?? {}
- const xTickFormatter = useXTickFormatter(xAxis, labels)
const yTickFormatter = useYTickFormatter(yAxis)
const valueLabelsConfig = resolveValueLabelsConfig(valueLabels)
- const seriesWithInProgress = useMemo(
- () => applyInProgressToSeries(series, inProgress),
- // inProgress.fromIndex is the only field applyInProgressToSeries reads; depending
- // on `inProgress` itself would invalidate on every inline-config render.
- // eslint-disable-next-line react-hooks/exhaustive-deps
- [series, inProgress?.fromIndex]
- )
-
// Stable primitive key so callers can pass `valueLabels: { seriesKeys: ['a'] }` inline
// without re-running the transform on every render.
const seriesKeysSignature = valueLabelsConfig?.seriesKeys?.join(' ')
const seriesAfterValueLabels = useMemo(() => {
const seriesKeys = valueLabelsConfig?.seriesKeys
if (!seriesKeys) {
- return seriesWithInProgress
+ return series
}
const allowed = new Set(seriesKeys)
- return seriesWithInProgress.map((s) =>
+ return series.map((s) =>
allowed.has(s.key) ? s : { ...s, visibility: { ...s.visibility, fromValueLabels: true } }
)
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [seriesWithInProgress, seriesKeysSignature])
+ }, [series, seriesKeysSignature])
const finalSeries = useDerivedSeries(seriesAfterValueLabels, {
confidenceIntervals,
@@ -146,7 +125,7 @@ export function TimeSeriesLineChart<Meta = unknown>({
const lineChartConfig: LineChartConfig = {
yScaleType: yAxis?.scale,
- xTickFormatter,
+ xTickFormatter: xAxis?.tickFormatter,
yTickFormatter,
hideXAxis: xAxis?.hide,
hideYAxis: yAxis?.hide,
@@ -170,7 +149,6 @@ export function TimeSeriesLineChart<Meta = unknown>({
>
{referenceLines.length > 0 && <ReferenceLines lines={referenceLines} />}
{valueLabelsConfig && <ValueLabels valueFormatter={valueLabelFormatter} />}
- {anomalies && anomalies.length > 0 && <AnomalyPointsLayer markers={anomalies} />}
{children}
</LineChart>
)
diff --git a/frontend/src/lib/hog-charts/charts/TimeSeriesLineChart/utils/in-progress.test.ts b/frontend/src/lib/hog-charts/charts/TimeSeriesLineChart/utils/in-progress.test.ts
deleted file mode 100644
index 7ba15276b0eb..000000000000
--- a/frontend/src/lib/hog-charts/charts/TimeSeriesLineChart/utils/in-progress.test.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-import type { Series } from '../../../core/types'
-import { applyInProgressToSeries } from './in-progress'
-
-const SERIES: Series[] = [
- { key: 'a', label: 'A', data: [1, 2, 3, 4] },
- { key: 'b', label: 'B', data: [5, 6, 7, 8] },
-]
-
-describe('applyInProgressToSeries', () => {
- it('returns the original reference when inProgress is undefined', () => {
- expect(applyInProgressToSeries(SERIES, undefined)).toBe(SERIES)
- })
-
- it('sets stroke.partial.fromIndex on each series when configured', () => {
- const result = applyInProgressToSeries(SERIES, { fromIndex: 2 })
- expect(result[0].stroke?.partial?.fromIndex).toBe(2)
- expect(result[1].stroke?.partial?.fromIndex).toBe(2)
- })
-
- it("preserves a series' explicit stroke.partial", () => {
- const explicitPartial = { fromIndex: 99, pattern: [4, 4] as number[] }
- const series: Series[] = [{ key: 'a', label: 'A', data: [1, 2, 3], stroke: { partial: explicitPartial } }]
- const result = applyInProgressToSeries(series, { fromIndex: 1 })
- expect(result[0].stroke?.partial).toBe(explicitPartial)
- })
-})
diff --git a/frontend/src/lib/hog-charts/charts/TimeSeriesLineChart/utils/in-progress.ts b/frontend/src/lib/hog-charts/charts/TimeSeriesLineChart/utils/in-progress.ts
deleted file mode 100644
index 26cfce253324..000000000000
--- a/frontend/src/lib/hog-charts/charts/TimeSeriesLineChart/utils/in-progress.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import type { Series } from '../../../core/types'
-
-export interface InProgressConfig {
- fromIndex: number
-}
-
-export function applyInProgressToSeries<Meta = unknown>(
- series: Series<Meta>[],
- inProgress: InProgressConfig | undefined
-): Series<Meta>[] {
- if (inProgress?.fromIndex === undefined) {
- return series
- }
- const fromIndex = inProgress.fromIndex
- return series.map((s) =>
- s.stroke?.partial !== undefined ? s : { ...s, stroke: { ...s.stroke, partial: { fromIndex } } }
- )
-}
diff --git a/frontend/src/lib/hog-charts/index.ts b/frontend/src/lib/hog-charts/index.ts
index 150ab3ca2a59..22eb1bae170e 100644
--- a/frontend/src/lib/hog-charts/index.ts
+++ b/frontend/src/lib/hog-charts/index.ts
@@ -12,7 +12,6 @@ export type {
TrendLineConfig,
ValueLabelsConfig,
} from './charts/TimeSeriesLineChart/TimeSeriesLineChart'
-export type { InProgressConfig } from './charts/TimeSeriesLineChart/utils/in-progress'
// Base chart (for building new chart types)
export { Chart } from './core/Chart'
diff --git a/frontend/src/lib/hog-charts/utils/use-axis-formatters.ts b/frontend/src/lib/hog-charts/utils/use-axis-formatters.ts
index f8197ac8f3a7..bbcdf505ea28 100644
--- a/frontend/src/lib/hog-charts/utils/use-axis-formatters.ts
+++ b/frontend/src/lib/hog-charts/utils/use-axis-formatters.ts
@@ -1,17 +1,10 @@
import { useMemo } from 'react'
-import { createXAxisTickCallback, type TimeInterval } from './dates'
import { buildYTickFormatter, type YFormatterConfig } from './y-formatters'
export interface XAxisConfig {
- /** Custom tick label formatter. When set, it wins over the date-axis auto formatter. */
tickFormatter?: (value: string, index: number) => string | null
hide?: boolean
- timezone?: string
- interval?: TimeInterval
- /** Raw date strings underlying each label, used to compute boundary-aware ticks.
- * If omitted, falls back to `labels`. */
- allDays?: string[]
}
export interface YAxisConfig extends YFormatterConfig {
@@ -22,25 +15,6 @@ export interface YAxisConfig extends YFormatterConfig {
showGrid?: boolean
}
-export function useXTickFormatter(
- xAxis: XAxisConfig | undefined,
- labels: string[]
-): ((value: string, index: number) => string | null) | undefined {
- return useMemo(() => {
- if (xAxis?.tickFormatter) {
- return xAxis.tickFormatter
- }
- if (!xAxis?.timezone || !xAxis?.interval) {
- return undefined
- }
- return createXAxisTickCallback({
- timezone: xAxis.timezone,
- interval: xAxis.interval,
- allDays: xAxis.allDays ?? labels,
- })
- }, [xAxis?.tickFormatter, xAxis?.timezone, xAxis?.interval, xAxis?.allDays, labels])
-}
-
export function useYTickFormatter(yAxis: YAxisConfig | undefined): ((value: number) => string) | undefined {
return useMemo(() => {
if (yAxis?.tickFormatter) {