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(mcp-analytics): use hog-charts Metric for overview KPI tiles (#61217)

Sam Penningtoneec02d8934fb
diff --git a/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx b/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx
index f0250577d29d..2b141284be02 100644
--- a/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx
+++ b/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx
@@ -1,11 +1,16 @@
import { useValues } from 'kea'
+import { useMemo } from 'react'
import { IconBolt } from '@posthog/icons'
import { LemonSkeleton, Link } from '@posthog/lemon-ui'
-import { humanFriendlyDuration, humanFriendlyNumber } from 'lib/utils'
+import { buildTheme } from 'lib/charts/utils/theme'
+import { type ChartTheme, Metric } from 'lib/hog-charts'
+import { humanFriendlyDuration, humanFriendlyLargeNumber } from 'lib/utils'
import { urls } from 'scenes/urls'
+import { themeLogic } from '~/layout/navigation-3000/themeLogic'
+
import claudeLogo from './harness-logos/claude.svg'
import cursorLogo from './harness-logos/cursor.svg'
import openaiLogo from './harness-logos/openai.svg'
@@ -37,28 +42,21 @@ export function HarnessPill({ category, title }: { category: string; title?: str
)
}
-type TileColor = 'blue' | 'red' | 'green'
-
interface TileSpec {
label: string
metric: KPIMetric
href: string
format: (n: number) => string
- color: TileColor
+ /** Sparkline color, picked from the shared data-viz palette (theme.colors). */
+ color: string
loading: boolean
}
-const COLOR_STROKE: Record<TileColor, string> = {
- blue: '#185FA5',
- red: '#A32D2D',
- green: '#0F6E56',
-}
-
function formatNumber(n: number): string {
if (!isFinite(n)) {
return '—'
}
- return humanFriendlyNumber(Math.round(n))
+ return humanFriendlyLargeNumber(n)
}
function formatPercent(n: number): string {
@@ -78,65 +76,37 @@ function formatMs(n: number): string {
return humanFriendlyDuration(n / 1000, { secondsPrecision: 1 })
}
-function Sparkline({ values, stroke }: { values: number[]; stroke: string }): JSX.Element {
- const width = 60
- const height = 18
- if (values.length === 0) {
- return <svg width={width} height={height} aria-hidden />
- }
- const max = Math.max(...values, 1)
- const min = Math.min(...values, 0)
- const range = max - min || 1
- const stepX = values.length > 1 ? width / (values.length - 1) : width
- const points = values
- .map((v, i) => {
- const x = i * stepX
- const y = height - ((v - min) / range) * height
- return `${x.toFixed(1)},${y.toFixed(1)}`
- })
- .join(' ')
- return (
- <svg width={width} height={height} aria-hidden>
- <polyline fill="none" stroke={stroke} strokeWidth="1.2" points={points} />
- </svg>
- )
-}
-
-function DeltaPill({ metric }: { metric: KPIMetric }): JSX.Element {
- if (metric.deltaPct === null) {
- return <span className="text-[11px] font-medium text-secondary">—</span>
- }
- const rounded = Math.round(metric.deltaPct)
- if (rounded === 0) {
- return <span className="text-[11px] font-medium text-secondary">0%</span>
- }
- const isUp = rounded > 0
- const isGood = isUp ? metric.goodDirection === 'up' : metric.goodDirection === 'down'
- const colorClass = isGood ? 'text-success' : 'text-danger'
- const arrow = isUp ? '↑' : '↓'
- return (
- <span className={`text-[11px] font-medium ${colorClass}`}>
- {arrow} {Math.abs(rounded)}%
- </span>
- )
-}
+function KPITile({ tile, theme }: { tile: TileSpec; theme: ChartTheme }): JSX.Element {
+ const { metric } = tile
+ const hasSparkline = metric.sparkline.length > 0
+ const hasComparison = metric.deltaPct !== null
-function KPITile({ tile }: { tile: TileSpec }): JSX.Element {
return (
<Link
to={tile.href}
- className="flex flex-col gap-1 rounded-md bg-surface-secondary px-3.5 py-3 transition-colors hover:bg-surface-tertiary"
+ subtle
+ className="flex flex-col rounded-lg border border-primary bg-surface-primary px-3.5 py-3 shadow-sm transition-all hover:border-secondary hover:shadow-md"
>
- <div className="text-[11px] text-secondary">{tile.label}</div>
{tile.loading ? (
- <LemonSkeleton className="h-5 w-16" />
+ <div className="flex flex-col gap-2">
+ <LemonSkeleton className="h-3 w-16" />
+ <LemonSkeleton className="h-7 w-20" />
+ </div>
) : (
- <div className="text-xl font-medium leading-tight">{tile.format(tile.metric.value)}</div>
+ <Metric
+ className="text-primary"
+ title={tile.label}
+ value={metric.value}
+ data={hasSparkline ? metric.sparkline : undefined}
+ theme={theme}
+ color={tile.color}
+ goodDirection={metric.goodDirection}
+ formatValue={tile.format}
+ subtitle={hasComparison ? `vs. ${tile.format(metric.previousValue)} prior` : undefined}
+ sparklineHeight={50}
+ sparklineClassName="mt-3 -mx-3.5 -mb-3"
+ />
)}
- <div className="mt-1 flex items-center justify-between">
- <Sparkline values={tile.metric.sparkline} stroke={COLOR_STROKE[tile.color]} />
- <DeltaPill metric={tile.metric} />
- </div>
</Link>
)
}
@@ -154,6 +124,9 @@ export function MCPAnalyticsDashboardOverview(): JSX.Element {
harnessRows,
harnessRawRowsLoading,
} = useValues(mcpDashboardOverviewLogic)
+ const { isDarkModeOn } = useValues(themeLogic)
+
+ const theme = useMemo<ChartTheme>(() => buildTheme(), [isDarkModeOn])
const tiles: TileSpec[] = [
{
@@ -161,7 +134,7 @@ export function MCPAnalyticsDashboardOverview(): JSX.Element {
metric: kpis.sessions,
href: urls.mcpAnalyticsSessions(),
format: formatNumber,
- color: 'blue',
+ color: theme.colors[0], // --data-color-1 (blue)
loading: kpisLoading,
},
{
@@ -169,7 +142,7 @@ export function MCPAnalyticsDashboardOverview(): JSX.Element {
metric: kpis.toolCalls,
href: urls.mcpAnalyticsToolQuality(),
format: formatNumber,
- color: 'blue',
+ color: theme.colors[0], // --data-color-1 (blue)
loading: kpisLoading,
},
{
@@ -177,7 +150,7 @@ export function MCPAnalyticsDashboardOverview(): JSX.Element {
metric: kpis.errorRatePct,
href: urls.mcpAnalyticsSessions(),
format: formatPercent,
- color: 'red',
+ color: theme.colors[4], // --data-color-5 (red)
loading: kpisLoading,
},
{
@@ -185,7 +158,7 @@ export function MCPAnalyticsDashboardOverview(): JSX.Element {
metric: kpis.p95LatencyMs,
href: urls.mcpAnalyticsToolQuality(),
format: formatMs,
- color: 'blue',
+ color: theme.colors[0], // --data-color-1 (blue)
loading: kpisLoading,
},
{
@@ -193,7 +166,7 @@ export function MCPAnalyticsDashboardOverview(): JSX.Element {
metric: intentClusterCount,
href: urls.mcpAnalyticsIntentClustering(),
format: formatNumber,
- color: 'green',
+ color: theme.colors[6], // --data-color-7 (green)
loading: false,
},
]
@@ -204,7 +177,7 @@ export function MCPAnalyticsDashboardOverview(): JSX.Element {
<Block kicker="Health" question="Is the MCP healthy right now?">
<div className="grid grid-cols-2 gap-3 md:grid-cols-5">
{tiles.map((tile) => (
- <KPITile key={tile.label} tile={tile} />
+ <KPITile key={tile.label} tile={tile} theme={theme} />
))}
</div>
</Block>