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.

feat(cdp): render the invocations sparkline with quill charts (#81936)

Sam Pennington31d8c99e7cc1
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 26ace7c8ab5d..a755b6b6392f 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -6298,6 +6298,10 @@ snapshots:
hash: v1.k794b7964.f3c8bc6697db692d759f57d5f1cba413b909e22923e87c65d0c223e613144076.sfVPBgq0NjbXJfcc8nye_vNXKKoaNiKVdX2kKdYWjug
scenes-app-hogfunctions-destination--runs-with-data--light:
hash: v1.k794b7964.7ebd6b1de8b3532192340ab4748697c7175fbb3e36227394abac3397e7fb36d5.g74q_2eAZTmStVOVUVR9w1MEZmTHfWR6PBmaj1xImiM
+ scenes-app-hogfunctions-invocationssparkline--with-activity--dark:
+ hash: v1.k794b7964.280a3bc355fbb852d9fa1d263e5b64b78075ab6c6736a681179d889b12509511.PXK7NUJxJ9CwB10xyOU3hwZ008ZQxMZnSz5_qfwYbRc
+ scenes-app-hogfunctions-invocationssparkline--with-activity--light:
+ hash: v1.k794b7964.fbda17e1097127a5e6f150791ea4f23188ea94b08f0c9296627184eeb9a913cd.j9uzkPUbG1EM3WLJ3QR02UGc6Wxqd7dn7FhSDvX7m4Q
scenes-app-identitymatching--identity-matching-empty--dark:
hash: v1.k794b7964.30bea223b948150a5eb1a169b853333dd9815447869ccbbdc30c1cffe2b78cd2.v7d6U5tiu6DTfHv0ZI3PW0Ps99p-BlQI_MZc7DuESbM
scenes-app-identitymatching--identity-matching-empty--light:
diff --git a/frontend/src/scenes/hog-functions/invocations/InvocationsSparkline.stories.tsx b/frontend/src/scenes/hog-functions/invocations/InvocationsSparkline.stories.tsx
new file mode 100644
index 000000000000..766471382f19
--- /dev/null
+++ b/frontend/src/scenes/hog-functions/invocations/InvocationsSparkline.stories.tsx
@@ -0,0 +1,45 @@
+import { Meta, StoryObj } from '@storybook/react'
+
+import { dayjs } from 'lib/dayjs'
+
+import { type SparklineData } from './hogInvocationsLogic'
+import { InvocationsSparkline } from './InvocationsSparkline'
+
+const meta: Meta<typeof InvocationsSparkline> = {
+ title: 'Scenes-App/HogFunctions/InvocationsSparkline',
+ component: InvocationsSparkline,
+ parameters: {
+ layout: 'centered',
+ testOptions: { snapshotBrowsers: ['chromium'] },
+ },
+ decorators: [
+ (Story) => (
+ <div className="w-[760px]">
+ <Story />
+ </div>
+ ),
+ ],
+}
+export default meta
+
+type Story = StoryObj<typeof InvocationsSparkline>
+
+/** Anchored to a fixed date so the bars and axis ticks are identical across snapshot runs. */
+function exampleData(): SparklineData {
+ const start = dayjs('2026-06-01T00:00:00Z')
+ const dates = Array.from({ length: 48 }, (_, i) => start.add(i, 'hour').toISOString())
+ const wave = (i: number, phase: number, scale: number): number =>
+ Math.max(0, Math.round(scale * (1 + Math.sin(i / 5 + phase))))
+ return {
+ dates,
+ series: [
+ { name: 'failed', color: 'danger', values: dates.map((_, i) => (i % 7 === 0 ? wave(i, 1, 6) : 0)) },
+ { name: 'running', color: 'warning', values: dates.map((_, i) => wave(i, 2, 4)) },
+ { name: 'succeeded', color: 'success', values: dates.map((_, i) => wave(i, 0, 40)) },
+ ],
+ }
+}
+
+export const WithActivity: Story = {
+ render: () => <InvocationsSparkline data={exampleData()} loading={false} onDateRangeChange={() => {}} />,
+}
diff --git a/frontend/src/scenes/hog-functions/invocations/InvocationsSparkline.tsx b/frontend/src/scenes/hog-functions/invocations/InvocationsSparkline.tsx
index 003dc42316f7..d571a56770ee 100644
--- a/frontend/src/scenes/hog-functions/invocations/InvocationsSparkline.tsx
+++ b/frontend/src/scenes/hog-functions/invocations/InvocationsSparkline.tsx
@@ -3,13 +3,23 @@ import { useCallback, useMemo, useState } from 'react'
import { IconChevronDown } from '@posthog/icons'
import { LemonButton, SpinnerOverlay } from '@posthog/lemon-ui'
+import {
+ createXAxisTickCallback,
+ type DateRangeZoomData,
+ DefaultTooltip,
+ type Series,
+ TimeSeriesBarChart,
+ type TimeSeriesBarChartConfig,
+} from '@posthog/quill-charts'
-import { AnyScaleOptions, Sparkline } from 'lib/components/Sparkline'
+import { useChartConfig, useChartTheme } from 'lib/charts/hooks'
+import { getColorVar } from 'lib/colors'
import { dayjs } from 'lib/dayjs'
import { cn } from 'lib/utils/css-classes'
+import { humanFriendlyNumber } from 'lib/utils/numbers'
import { teamLogic } from 'scenes/teamLogic'
-import { SparklineData, projectTimezoneOf } from './hogInvocationsLogic'
+import { projectTimezoneOf, SparklineData } from './hogInvocationsLogic'
interface InvocationsSparklineProps {
data: SparklineData | null
@@ -29,54 +39,40 @@ export function InvocationsSparkline({
// labels would fall back to UTC while the team is still loading and the bars would not.
const projectTimezone = projectTimezoneOf(currentTeam)
- const { timeUnit, tickFormat } = useMemo(() => {
- const dates = data?.dates ?? []
- if (dates.length < 2) {
- return { timeUnit: 'hour' as const, tickFormat: 'HH:mm' }
- }
- const hoursDiff = dayjs(dates[dates.length - 1]).diff(dayjs(dates[0]), 'hour')
- if (hoursDiff <= 6) {
- return { timeUnit: 'minute' as const, tickFormat: 'HH:mm' }
- }
- if (hoursDiff <= 48) {
- return { timeUnit: 'hour' as const, tickFormat: 'HH:mm' }
- }
- return { timeUnit: 'day' as const, tickFormat: 'D MMM' }
- }, [data?.dates])
+ const dates = useMemo(() => data?.dates ?? [], [data?.dates])
- const withXScale = useCallback(
- (scale: AnyScaleOptions): AnyScaleOptions =>
- ({
- ...scale,
- type: 'timeseries',
- ticks: {
- display: true,
- maxRotation: 0,
- maxTicksLimit: 6,
- font: { size: 10, lineHeight: 1 },
- callback: (value: string | number) => dayjs(value).tz(projectTimezone).format(tickFormat),
- },
- time: { unit: timeUnit },
- }) as AnyScaleOptions,
- [timeUnit, tickFormat, projectTimezone]
+ const series = useMemo<Series[]>(
+ () =>
+ (data?.series ?? []).map((timeseries) => ({
+ key: timeseries.name,
+ label: timeseries.name,
+ data: timeseries.values,
+ color: getColorVar(timeseries.color),
+ })),
+ [data?.series]
)
- const onSelectionChange = useCallback(
- (sel: { startIndex: number; endIndex: number }): void => {
- const dates = data?.dates ?? []
- const from = dates[sel.startIndex]
- // `+1` so the selection end aligns with the *next* bucket boundary,
- // mirroring how the logs sparkline emits ranges. If we hit past
- // the end of the buckets, leave dateTo undefined (= "up to now").
- const to = dates[sel.endIndex + 1]
+ const theme = useChartTheme()
+ const config = useChartConfig<TimeSeriesBarChartConfig>(
+ () => ({
+ xAxis: { tickFormatter: createXAxisTickCallback({ allDays: dates, timezone: projectTimezone }) },
+ }),
+ [dates, projectTimezone]
+ )
+
+ const onDateRangeZoom = useCallback(
+ ({ startIndex, endIndex }: DateRangeZoomData): void => {
+ const from = dates[startIndex]
+ // +1 ends the range at the next bucket boundary; past the last bucket leaves dateTo
+ // undefined, which the runs list reads as "up to now".
+ const to = dates[endIndex + 1]
if (from) {
onDateRangeChange(from, to)
}
},
- [data?.dates, onDateRangeChange]
+ [dates, onDateRangeChange]
)
- const labels = useMemo(() => (data?.dates ?? []).map((d) => dayjs(d).toISOString()), [data?.dates])
const hasAnyData = (data?.series ?? []).some((s) => s.values.some((v) => v > 0))
return (
@@ -93,17 +89,26 @@ export function InvocationsSparkline({
</LemonButton>
</div>
{!collapsed && (
- <div className="relative h-24">
+ // Quill's chart root is flex-1, so the sized container has to be a flex column for h-24 to apply.
+ <div className="relative h-24 flex flex-col">
{hasAnyData ? (
- <Sparkline
- labels={labels}
- data={data!.series}
- className="w-full h-full"
- onSelectionChange={onSelectionChange}
- withXScale={withXScale}
- renderLabel={(label) => dayjs(label).tz(projectTimezone).format('D MMM YYYY HH:mm')}
- hideZerosInTooltip
- sortTooltipByCount
+ <TimeSeriesBarChart
+ series={series}
+ labels={dates}
+ theme={theme}
+ config={config}
+ onDateRangeZoom={onDateRangeZoom}
+ tooltip={(ctx) => (
+ <DefaultTooltip
+ {...ctx}
+ hideZeroRows
+ sortedByValue
+ valueFormatter={(value) => humanFriendlyNumber(value)}
+ labelFormatter={(label) =>
+ dayjs(label).tz(projectTimezone).format('D MMM YYYY HH:mm')
+ }
+ />
+ )}
/>
) : !loading ? (
<div className="h-full text-muted text-xs flex items-center justify-center">