2026-06-10 14:38:44 +02:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
BarChart,
|
|
|
|
|
Bar,
|
|
|
|
|
XAxis,
|
|
|
|
|
YAxis,
|
|
|
|
|
CartesianGrid,
|
|
|
|
|
Tooltip,
|
|
|
|
|
ResponsiveContainer,
|
|
|
|
|
} from "recharts";
|
|
|
|
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
|
|
|
|
import { Skeleton } from "@/components/ui/skeleton";
|
2026-07-03 19:24:00 +02:00
|
|
|
import { useIsMobile } from "@/hooks/use-is-mobile";
|
2026-06-10 14:38:44 +02:00
|
|
|
import type { AgentUsageRow } from "@/types";
|
|
|
|
|
|
|
|
|
|
interface AgentUsageChartProps {
|
|
|
|
|
data: AgentUsageRow[] | undefined;
|
|
|
|
|
isLoading: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fmtK(n: number): string {
|
|
|
|
|
if (n >= 1_000) return (n / 1_000).toFixed(0) + "k";
|
|
|
|
|
return String(n);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function AgentUsageChart({ data, isLoading }: AgentUsageChartProps) {
|
2026-07-03 19:24:00 +02:00
|
|
|
const isMobile = useIsMobile();
|
|
|
|
|
// Fewer bars on a phone — 10 labels at ~30deg rotation still overlap below
|
|
|
|
|
// ~400px, so cap the label density instead of shrinking text further.
|
2026-06-10 14:38:44 +02:00
|
|
|
const chartData = [...(data ?? [])]
|
|
|
|
|
.sort((a, b) => b.total_tokens - a.total_tokens)
|
2026-07-03 19:24:00 +02:00
|
|
|
.slice(0, isMobile ? 6 : 10)
|
2026-06-10 14:38:44 +02:00
|
|
|
.map((row) => ({
|
|
|
|
|
name: row.agent_slug,
|
|
|
|
|
Tokens: row.total_tokens,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Card>
|
|
|
|
|
<CardHeader className="pb-2">
|
|
|
|
|
<CardTitle className="text-base">Agent Tokens Today</CardTitle>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent>
|
|
|
|
|
{isLoading ? (
|
|
|
|
|
<Skeleton className="h-52 w-full" />
|
|
|
|
|
) : (
|
|
|
|
|
<ResponsiveContainer width="100%" height={208}>
|
|
|
|
|
<BarChart
|
|
|
|
|
data={chartData}
|
|
|
|
|
margin={{ top: 4, right: 8, left: 0, bottom: 24 }}
|
|
|
|
|
>
|
|
|
|
|
<CartesianGrid strokeDasharray="3 3" className="opacity-20" />
|
|
|
|
|
<XAxis
|
|
|
|
|
dataKey="name"
|
2026-07-03 19:24:00 +02:00
|
|
|
tick={{ fontSize: isMobile ? 9 : 10 }}
|
|
|
|
|
angle={isMobile ? -45 : -30}
|
2026-06-10 14:38:44 +02:00
|
|
|
textAnchor="end"
|
2026-07-03 19:24:00 +02:00
|
|
|
interval={0}
|
2026-06-10 14:38:44 +02:00
|
|
|
axisLine={false}
|
|
|
|
|
tickLine={false}
|
|
|
|
|
/>
|
|
|
|
|
<YAxis
|
|
|
|
|
tickFormatter={fmtK}
|
|
|
|
|
tick={{ fontSize: 10 }}
|
|
|
|
|
axisLine={false}
|
|
|
|
|
tickLine={false}
|
|
|
|
|
width={36}
|
|
|
|
|
/>
|
|
|
|
|
<Tooltip
|
|
|
|
|
formatter={(value) => [
|
|
|
|
|
fmtK(typeof value === "number" ? value : 0),
|
|
|
|
|
"Tokens",
|
|
|
|
|
]}
|
|
|
|
|
contentStyle={{ fontSize: 12 }}
|
|
|
|
|
/>
|
2026-06-29 05:38:21 +02:00
|
|
|
<Bar
|
|
|
|
|
dataKey="Tokens"
|
|
|
|
|
fill="var(--chart-1)"
|
|
|
|
|
radius={[3, 3, 0, 0]}
|
|
|
|
|
/>
|
2026-06-10 14:38:44 +02:00
|
|
|
</BarChart>
|
|
|
|
|
</ResponsiveContainer>
|
|
|
|
|
)}
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
}
|