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): remove posthog tokens from library code (#58207)

Sam Pennington7954f491d672
diff --git a/frontend/src/lib/charts/types.ts b/frontend/src/lib/charts/types.ts
index 3dc42f1494da..dca6476f3ae1 100644
--- a/frontend/src/lib/charts/types.ts
+++ b/frontend/src/lib/charts/types.ts
@@ -8,4 +8,5 @@ export interface ChartTheme {
crosshairColor?: string
tooltipBackground?: string
tooltipColor?: string
+ tooltipZIndex?: number | string
}
diff --git a/frontend/src/lib/charts/utils/theme.ts b/frontend/src/lib/charts/utils/theme.ts
index 5515501feb39..da93686acf83 100644
--- a/frontend/src/lib/charts/utils/theme.ts
+++ b/frontend/src/lib/charts/utils/theme.ts
@@ -14,6 +14,7 @@ export function buildTheme(overrides?: Partial<ChartTheme>): ChartTheme {
crosshairColor: graphColors.crosshair ?? undefined,
tooltipBackground: graphColors.tooltipBackground ?? undefined,
tooltipColor: graphColors.tooltipTitle ?? undefined,
+ tooltipZIndex: 'var(--z-chart-tooltip)',
}
if (!overrides) {
diff --git a/frontend/src/lib/hog-charts/charts/BarChart/BarChart.stories.tsx b/frontend/src/lib/hog-charts/charts/BarChart/BarChart.stories.tsx
index c7119e297ed1..ded038788711 100644
--- a/frontend/src/lib/hog-charts/charts/BarChart/BarChart.stories.tsx
+++ b/frontend/src/lib/hog-charts/charts/BarChart/BarChart.stories.tsx
@@ -1,9 +1,10 @@
import { Meta, StoryObj } from '@storybook/react'
-import { BarChart, ReferenceLine, ValueLabels } from 'lib/hog-charts'
-import type { BarChartConfig, Series } from 'lib/hog-charts'
-
+import type { BarChartConfig, Series } from '../../core/types'
+import { ReferenceLine } from '../../overlays/ReferenceLine'
+import { ValueLabels } from '../../overlays/ValueLabels'
import { Stage, useReactiveTheme } from '../../story-helpers'
+import { BarChart } from './BarChart'
const DAYS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
diff --git a/frontend/src/lib/hog-charts/charts/LineChart.stories.tsx b/frontend/src/lib/hog-charts/charts/LineChart.stories.tsx
index b665bc75bd76..584700eb034b 100644
--- a/frontend/src/lib/hog-charts/charts/LineChart.stories.tsx
+++ b/frontend/src/lib/hog-charts/charts/LineChart.stories.tsx
@@ -1,9 +1,12 @@
import { Meta, StoryObj } from '@storybook/react'
-import { ciRanges, DEFAULT_Y_AXIS_ID, LineChart, ReferenceLine, trendLine, ValueLabels } from 'lib/hog-charts'
-import type { LineChartConfig, Series } from 'lib/hog-charts'
-
+import type { LineChartConfig, Series } from '../core/types'
+import { DEFAULT_Y_AXIS_ID } from '../core/types'
+import { ReferenceLine } from '../overlays/ReferenceLine'
+import { ValueLabels } from '../overlays/ValueLabels'
import { playHoverAtFraction, Stage, useReactiveTheme } from '../story-helpers'
+import { ciRanges, trendLine } from '../utils/statistics'
+import { LineChart } from './LineChart'
const DAYS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
const BASIC: LineChartConfig = { showGrid: true }
diff --git a/frontend/src/lib/hog-charts/charts/TimeSeriesBarChart/TimeSeriesBarChart.stories.tsx b/frontend/src/lib/hog-charts/charts/TimeSeriesBarChart/TimeSeriesBarChart.stories.tsx
index 953f438919db..83d3cb3bf9e6 100644
--- a/frontend/src/lib/hog-charts/charts/TimeSeriesBarChart/TimeSeriesBarChart.stories.tsx
+++ b/frontend/src/lib/hog-charts/charts/TimeSeriesBarChart/TimeSeriesBarChart.stories.tsx
@@ -1,9 +1,9 @@
import { Meta, StoryObj } from '@storybook/react'
-import { TimeSeriesBarChart } from 'lib/hog-charts'
-import type { Series, TimeInterval, YAxisConfig } from 'lib/hog-charts'
-
+import type { Series } from '../../core/types'
import { Stage, useReactiveTheme } from '../../story-helpers'
+import type { TimeInterval } from '../../utils/dates'
+import type { YAxisConfig } from '../../utils/use-axis-formatters'
import {
CURRENCY_SERIES,
DAILY_LABELS,
@@ -20,6 +20,7 @@ import {
PERCENTAGE_SERIES,
SERIES,
} from '../time-series-fixtures'
+import { TimeSeriesBarChart } from './TimeSeriesBarChart'
const meta: Meta = {
title: 'Components/HogCharts/TimeSeriesBarChart',
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 ad07876a5ea9..8392169242ca 100644
--- a/frontend/src/lib/hog-charts/charts/TimeSeriesLineChart/TimeSeriesLineChart.stories.tsx
+++ b/frontend/src/lib/hog-charts/charts/TimeSeriesLineChart/TimeSeriesLineChart.stories.tsx
@@ -1,9 +1,10 @@
import { Meta, StoryObj } from '@storybook/react'
-import { ciRanges, TimeSeriesLineChart } from 'lib/hog-charts'
-import type { Series, TimeInterval, YAxisConfig } from 'lib/hog-charts'
-
+import type { Series } from '../../core/types'
import { Stage, useReactiveTheme } from '../../story-helpers'
+import type { TimeInterval } from '../../utils/dates'
+import { ciRanges } from '../../utils/statistics'
+import type { YAxisConfig } from '../../utils/use-axis-formatters'
import {
CURRENCY_SERIES,
DAILY_LABELS,
@@ -20,6 +21,7 @@ import {
PERCENTAGE_SERIES,
SERIES,
} from '../time-series-fixtures'
+import { TimeSeriesLineChart } from './TimeSeriesLineChart'
const meta: Meta = {
title: 'Components/HogCharts/TimeSeriesLineChart',
diff --git a/frontend/src/lib/hog-charts/core/ChartErrorBoundary.tsx b/frontend/src/lib/hog-charts/core/ChartErrorBoundary.tsx
index 115ce24b6af2..02d9e6c93be9 100644
--- a/frontend/src/lib/hog-charts/core/ChartErrorBoundary.tsx
+++ b/frontend/src/lib/hog-charts/core/ChartErrorBoundary.tsx
@@ -17,7 +17,7 @@ const DEFAULT_FALLBACK_STYLE: React.CSSProperties = {
width: '100%',
height: '100%',
minHeight: 100,
- color: 'var(--text-secondary, #666)',
+ color: '#666',
fontSize: 13,
}
diff --git a/frontend/src/lib/hog-charts/core/types.ts b/frontend/src/lib/hog-charts/core/types.ts
index 3a0de680b7bb..94b84fd047d6 100644
--- a/frontend/src/lib/hog-charts/core/types.ts
+++ b/frontend/src/lib/hog-charts/core/types.ts
@@ -7,6 +7,7 @@ export interface ChartTheme {
crosshairColor?: string
tooltipBackground?: string
tooltipColor?: string
+ tooltipZIndex?: number | string
}
/** Default axis id used when a series doesn't specify one. */
diff --git a/frontend/src/lib/hog-charts/overlays/DefaultTooltip.tsx b/frontend/src/lib/hog-charts/overlays/DefaultTooltip.tsx
index 11764197bd83..59ad3b18d242 100644
--- a/frontend/src/lib/hog-charts/overlays/DefaultTooltip.tsx
+++ b/frontend/src/lib/hog-charts/overlays/DefaultTooltip.tsx
@@ -1,8 +1,20 @@
+import { useChartLayout } from '../core/chart-context'
import type { TooltipContext } from '../core/types'
+const DEFAULT_TOOLTIP_BG = '#1d2330'
+const DEFAULT_TOOLTIP_COLOR = '#ffffff'
+
export function DefaultTooltip({ label, seriesData }: TooltipContext): React.ReactElement {
+ const { theme } = useChartLayout()
return (
- <div className="bg-bg-light text-primary border border-border px-3 py-2 rounded-lg shadow-lg text-[13px]">
+ <div
+ className="px-3 py-2 rounded-lg shadow-lg text-[13px]"
+ // eslint-disable-next-line react/forbid-dom-props
+ style={{
+ backgroundColor: theme.tooltipBackground ?? DEFAULT_TOOLTIP_BG,
+ color: theme.tooltipColor ?? DEFAULT_TOOLTIP_COLOR,
+ }}
+ >
<div className="font-semibold mb-1">{label}</div>
{seriesData.map((s) => (
<div key={s.series.key} className="flex items-center gap-2">
diff --git a/frontend/src/lib/hog-charts/overlays/ReferenceLine.stories.tsx b/frontend/src/lib/hog-charts/overlays/ReferenceLine.stories.tsx
index 4bd82e644b12..f841b3be4e52 100644
--- a/frontend/src/lib/hog-charts/overlays/ReferenceLine.stories.tsx
+++ b/frontend/src/lib/hog-charts/overlays/ReferenceLine.stories.tsx
@@ -1,9 +1,10 @@
import { Meta, StoryObj } from '@storybook/react'
-import { LineChart, ReferenceLine } from 'lib/hog-charts'
-import type { LineChartConfig, ReferenceLineFillSide, ReferenceLineVariant, Series } from 'lib/hog-charts'
-
+import { LineChart } from '../charts/LineChart'
+import type { LineChartConfig, Series } from '../core/types'
import { Stage, useReactiveTheme } from '../story-helpers'
+import { ReferenceLine } from './ReferenceLine'
+import type { ReferenceLineFillSide, ReferenceLineVariant } from './ReferenceLine'
const LABELS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
diff --git a/frontend/src/lib/hog-charts/overlays/ReferenceLine.tsx b/frontend/src/lib/hog-charts/overlays/ReferenceLine.tsx
index 6192137be086..38e7d51e758e 100644
--- a/frontend/src/lib/hog-charts/overlays/ReferenceLine.tsx
+++ b/frontend/src/lib/hog-charts/overlays/ReferenceLine.tsx
@@ -55,7 +55,7 @@ interface ResolvedStyle {
const VARIANT_DEFAULTS: Record<ReferenceLineVariant, ResolvedStyle> = {
goal: { color: 'rgba(0, 0, 0, 0.4)', stroke: 'dashed', width: 2 },
- alert: { color: 'var(--danger)', stroke: 'dashed', width: 2 },
+ alert: { color: '#db3707', stroke: 'dashed', width: 2 },
marker: { color: 'rgba(0, 0, 0, 0.5)', stroke: 'solid', width: 1 },
}
diff --git a/frontend/src/lib/hog-charts/overlays/Tooltip.tsx b/frontend/src/lib/hog-charts/overlays/Tooltip.tsx
index 895c8b32c465..0d81a6c4856c 100644
--- a/frontend/src/lib/hog-charts/overlays/Tooltip.tsx
+++ b/frontend/src/lib/hog-charts/overlays/Tooltip.tsx
@@ -1,6 +1,7 @@
import { flip, FloatingPortal, offset, shift, useFloating, type VirtualElement } from '@floating-ui/react'
import React, { useLayoutEffect, useMemo } from 'react'
+import { useChartLayout } from '../core/chart-context'
import type { TooltipContext } from '../core/types'
interface TooltipProps<Meta> {
@@ -10,12 +11,15 @@ interface TooltipProps<Meta> {
}
const TOOLTIP_MIDDLEWARE = [offset(12), flip(), shift({ padding: 8 })]
+const DEFAULT_TOOLTIP_Z_INDEX = 9999
export function Tooltip<Meta = unknown>({
context,
renderTooltip,
placement = 'follow-data',
}: TooltipProps<Meta>): React.ReactElement {
+ const { theme } = useChartLayout()
+ const zIndex = theme.tooltipZIndex ?? DEFAULT_TOOLTIP_Z_INDEX
// In `top` placement the y position is anchored to the canvas top and `position.y` is
// unused, so we depend on the resolved y rather than `position.y` directly — otherwise
// mousemove rebuilds the virtual reference and triggers a Floating-UI reposition pass
@@ -63,7 +67,7 @@ export function Tooltip<Meta = unknown>({
...floatingStyles,
pointerEvents: context.isPinned ? 'auto' : 'none',
width: 'max-content',
- zIndex: 'var(--z-chart-tooltip)',
+ zIndex,
}}
>
{renderTooltip(context)}
diff --git a/frontend/src/lib/hog-charts/overlays/ValueLabels.stories.tsx b/frontend/src/lib/hog-charts/overlays/ValueLabels.stories.tsx
index 0f61fa415154..591371bcd7ef 100644
--- a/frontend/src/lib/hog-charts/overlays/ValueLabels.stories.tsx
+++ b/frontend/src/lib/hog-charts/overlays/ValueLabels.stories.tsx
@@ -1,9 +1,9 @@
import { Meta, StoryObj } from '@storybook/react'
-import { LineChart, ValueLabels } from 'lib/hog-charts'
-import type { LineChartConfig, Series } from 'lib/hog-charts'
-
+import { LineChart } from '../charts/LineChart'
+import type { LineChartConfig, Series } from '../core/types'
import { Stage, useReactiveTheme } from '../story-helpers'
+import { ValueLabels } from './ValueLabels'
const LABELS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']