feat: harden analytics dashboard
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
Cell,
|
||||
} from "recharts";
|
||||
import { formatTokens } from "@/lib/utils";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
|
||||
interface RankItem {
|
||||
name: string;
|
||||
@@ -31,6 +32,7 @@ export function RankingBar({
|
||||
data: RankItem[];
|
||||
title: string;
|
||||
}) {
|
||||
const { t } = useI18n();
|
||||
if (!data.length) return null;
|
||||
const sliced = data.slice(0, 10);
|
||||
|
||||
@@ -54,7 +56,7 @@ export function RankingBar({
|
||||
color: "#c8d6e5",
|
||||
fontSize: "12px",
|
||||
}}
|
||||
formatter={(v) => [formatTokens(Number(v)), "Total Tokens"]}
|
||||
formatter={(v) => [formatTokens(Number(v)), t("th.totalToken")]}
|
||||
/>
|
||||
<Bar dataKey="total_tokens" radius={[0, 4, 4, 0]}>
|
||||
{sliced.map((_, i) => (
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { ResponsiveContainer, LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend } from "recharts";
|
||||
import { formatTokens, formatUSD } from "@/lib/utils";
|
||||
import { quotaToUsd } from "@/lib/metrics";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
|
||||
interface TrendPoint { date: string; calls: number; total_tokens: number; prompt_tokens: number; completion_tokens: number; quota?: number; }
|
||||
@@ -105,11 +106,11 @@ export function TrendChart({ data, metric = "total_tokens" }: { data: TrendPoint
|
||||
<LineChart data={data} margin={{ top: 5, right: 20, left: 10, bottom: 5 }}>
|
||||
<CartesianGrid strokeDasharray="3 3" stroke="var(--chart-grid)" />
|
||||
<XAxis dataKey="date" tickFormatter={formatDateLabel} tick={{ fontSize: 11 }} stroke="var(--chart-grid)" />
|
||||
<YAxis tickFormatter={(v) => formatUSD(v / 500000)} tick={{ fontSize: 11 }} stroke="var(--chart-grid)" />
|
||||
<YAxis tickFormatter={(v) => formatUSD(quotaToUsd(v))} tick={{ fontSize: 11 }} stroke="var(--chart-grid)" />
|
||||
<Tooltip
|
||||
contentStyle={tooltipStyle}
|
||||
labelFormatter={(label) => formatTooltipLabel(String(label))}
|
||||
formatter={(value) => [formatUSD(Number(value) / 500000), t("th.cost")]}
|
||||
formatter={(value) => [formatUSD(quotaToUsd(Number(value))), t("th.cost")]}
|
||||
/>
|
||||
<Legend />
|
||||
<Line type="monotone" dataKey="quota" name={t("th.cost")} stroke="var(--accent)" strokeWidth={2} dot={false} />
|
||||
|
||||
Reference in New Issue
Block a user