Skip to content

A modern and elegant dashboard for network traffic visualization and analysis.

feat: enhance Top Domains Chart with stacked traffic and self-fetching data, and include flag fonts.

luolei380f9d0a7f1b
diff --git a/apps/collector/src/db.ts b/apps/collector/src/db.ts
index 22f26fc..8f6ad3e 100644
--- a/apps/collector/src/db.ts
+++ b/apps/collector/src/db.ts
@@ -3068,6 +3068,7 @@ export class StatsDatabase {
domain: 'domain',
totalDownload: 'total_download',
totalUpload: 'total_upload',
+ totalTraffic: '(total_upload + total_download)',
totalConnections: 'total_connections',
lastSeen: 'last_seen',
};
@@ -3078,6 +3079,7 @@ export class StatsDatabase {
domain: 'domain',
totalDownload: 'totalDownload',
totalUpload: 'totalUpload',
+ totalTraffic: '(totalUpload + totalDownload)',
totalConnections: 'totalConnections',
lastSeen: 'lastSeen',
};
@@ -3213,6 +3215,7 @@ export class StatsDatabase {
ip: 'i.ip',
totalDownload: 'i.total_download',
totalUpload: 'i.total_upload',
+ totalTraffic: '(i.total_upload + i.total_download)',
totalConnections: 'i.total_connections',
lastSeen: 'i.last_seen',
};
@@ -3223,6 +3226,7 @@ export class StatsDatabase {
ip: 'agg.ip',
totalDownload: 'agg.totalDownload',
totalUpload: 'agg.totalUpload',
+ totalTraffic: '(agg.totalUpload + agg.totalDownload)',
totalConnections: 'agg.totalConnections',
lastSeen: 'agg.lastSeen',
};
diff --git a/apps/collector/src/realtime.ts b/apps/collector/src/realtime.ts
index 44c4f67..e6320da 100644
--- a/apps/collector/src/realtime.ts
+++ b/apps/collector/src/realtime.ts
@@ -163,6 +163,12 @@ function sortDomains(data: DomainStats[], sortBy: string, sortOrder: 'asc' | 'de
switch (sortBy) {
case 'domain':
return compareString(a.domain, b.domain, sortOrder);
+ case 'totalTraffic':
+ return compareNumber(
+ a.totalDownload + a.totalUpload,
+ b.totalDownload + b.totalUpload,
+ sortOrder,
+ );
case 'totalUpload':
return compareNumber(a.totalUpload, b.totalUpload, sortOrder);
case 'totalConnections':
@@ -181,6 +187,12 @@ function sortIPs(data: IPStats[], sortBy: string, sortOrder: 'asc' | 'desc'): IP
switch (sortBy) {
case 'ip':
return compareString(a.ip, b.ip, sortOrder);
+ case 'totalTraffic':
+ return compareNumber(
+ a.totalDownload + a.totalUpload,
+ b.totalDownload + b.totalUpload,
+ sortOrder,
+ );
case 'totalUpload':
return compareNumber(a.totalUpload, b.totalUpload, sortOrder);
case 'totalConnections':
diff --git a/apps/collector/src/websocket.ts b/apps/collector/src/websocket.ts
index 1818ae8..e2afffe 100644
--- a/apps/collector/src/websocket.ts
+++ b/apps/collector/src/websocket.ts
@@ -491,6 +491,7 @@ export class StatsWebSocketServer {
switch (value) {
case 'domain':
case 'totalUpload':
+ case 'totalTraffic':
case 'totalConnections':
case 'lastSeen':
case 'totalDownload':
@@ -505,6 +506,7 @@ export class StatsWebSocketServer {
switch (value) {
case 'ip':
case 'totalUpload':
+ case 'totalTraffic':
case 'totalConnections':
case 'lastSeen':
case 'totalDownload':
diff --git a/apps/web/app/[locale]/layout.tsx b/apps/web/app/[locale]/layout.tsx
index 78e8f3d..fc995df 100644
--- a/apps/web/app/[locale]/layout.tsx
+++ b/apps/web/app/[locale]/layout.tsx
@@ -64,6 +64,7 @@ export default async function RootLayout({
<head>
<link rel="manifest" href="/manifest.json" />
<link rel="apple-touch-icon" href="/icons/icon-192x192.png" />
+
<meta name="mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta
diff --git a/apps/web/app/[locale]/page.tsx b/apps/web/app/[locale]/page.tsx
index a040189..294952e 100644
--- a/apps/web/app/[locale]/page.tsx
+++ b/apps/web/app/[locale]/page.tsx
@@ -158,12 +158,10 @@ const OverviewContent = memo(function OverviewContent({
});
const DomainsContent = memo(function DomainsContent({
- data,
activeBackendId,
timeRange,
autoRefresh,
}: {
- data: StatsSummary | null;
activeBackendId?: number;
timeRange: TimeRange;
autoRefresh: boolean;
@@ -172,7 +170,6 @@ const DomainsContent = memo(function DomainsContent({
return (
<div className="space-y-6">
<TopDomainsChart
- data={data?.topDomains}
activeBackendId={activeBackendId}
timeRange={timeRange}
/>
@@ -605,7 +602,6 @@ export default function DashboardPage() {
case "domains":
return (
<DomainsContent
- data={data}
activeBackendId={activeBackendId}
timeRange={timeRange}
autoRefresh={autoRefresh}
diff --git a/apps/web/app/globals.css b/apps/web/app/globals.css
index 76ea37a..3219e50 100644
--- a/apps/web/app/globals.css
+++ b/apps/web/app/globals.css
@@ -1,6 +1,20 @@
@import "tailwindcss";
@import "@xyflow/react/dist/style.css";
+@font-face {
+ font-family: "CMTwemojiFlags";
+ src: url("/fonts/TwemojiMozilla-flags.woff2") format("woff2");
+ font-display: swap;
+ unicode-range: U+1F1E6-1F1FF, U+1F3F4, U+E0020-E007F;
+}
+
+@font-face {
+ font-family: "CMNotoEmojiFlags";
+ src: url("/fonts/NotoColorEmoji-flagsonly.ttf") format("truetype");
+ font-display: swap;
+ unicode-range: U+1F1E6-1F1FF;
+}
+
@custom-variant dark (&:is(.dark *));
@theme inline {
@@ -135,6 +149,7 @@
}
body {
@apply bg-background text-foreground antialiased;
+ font-family: var(--font-sans);
background-image:
radial-gradient(
ellipse at 0% 0%,
@@ -258,6 +273,10 @@
animation: fade-in-up 0.5s ease-out forwards;
}
+.emoji-flag-font {
+ font-family: "CMTwemojiFlags", "CMNotoEmojiFlags", "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", var(--font-geist-sans), system-ui;
+}
+
.animate-pulse-glow {
animation: pulse-glow 3s ease-in-out infinite;
}
diff --git a/apps/web/app/manifest.ts b/apps/web/app/manifest.ts
index 5b4277e..f4de692 100644
--- a/apps/web/app/manifest.ts
+++ b/apps/web/app/manifest.ts
@@ -10,7 +10,7 @@ export default function manifest(): MetadataRoute.Manifest {
display: "standalone",
background_color: "#0B0F19",
theme_color: "#3B82F6",
- orientation: "any",
+ orientation: "natural",
categories: ["utilities", "network"],
icons: [
{
diff --git a/apps/web/components/interactive-proxy-stats.tsx b/apps/web/components/interactive-proxy-stats.tsx
index b69ddee..44762e7 100644
--- a/apps/web/components/interactive-proxy-stats.tsx
+++ b/apps/web/components/interactive-proxy-stats.tsx
@@ -325,7 +325,7 @@ export function InteractiveProxyStats({
<button key={item.rawName} onClick={() => handleProxyClick(item.rawName)} className={cn("w-full p-2.5 rounded-xl border text-left transition-all duration-200", isSelected ? "border-primary bg-primary/5 ring-1 ring-primary/20" : "border-border/50 bg-card/50 hover:bg-card hover:border-primary/30")}>
<div className="flex items-center gap-2 mb-1.5">
<span className={cn("w-5 h-5 rounded-md text-[10px] font-bold flex items-center justify-center shrink-0", badgeColor)}>{item.rank + 1}</span>
- <span className="flex-1 text-sm font-medium truncate" title={rawDisplayName}>{rawDisplayName}</span>
+ <span className="emoji-flag-font flex-1 text-sm font-medium truncate" title={rawDisplayName}>{rawDisplayName}</span>
<span className="text-sm font-bold tabular-nums shrink-0">{formatBytes(item.value)}</span>
</div>
<div className="pl-7 space-y-1">
diff --git a/apps/web/components/interactive-proxy-stats.tsx.backup b/apps/web/components/interactive-proxy-stats.tsx.backup
deleted file mode 100644
index 6c1e7de..0000000
--- a/apps/web/components/interactive-proxy-stats.tsx.backup
+++ /dev/null
@@ -1,1001 +0,0 @@
-"use client";
-
-import { useState, useCallback, useMemo, useEffect } from "react";
-import { Server, ChevronLeft, ChevronRight, Loader2, BarChart3, Link2, Rows3, ArrowUpDown, ArrowDown, ArrowUp, Globe, Waypoints, ChevronDown, ChevronUp } from "lucide-react";
-import { useTranslations } from "next-intl";
-import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip as RechartsTooltip } from "recharts";
-import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Cell as BarCell, LabelList } from "recharts";
-import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
-import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
-import { Button } from "@/components/ui/button";
-import { Input } from "@/components/ui/input";
-import { ScrollArea } from "@/components/ui/scroll-area";
-import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuTrigger,
-} from "@/components/ui/dropdown-menu";
-import { formatBytes, formatNumber } from "@/lib/utils";
-import { cn } from "@/lib/utils";
-import { api } from "@/lib/api";
-import { Favicon } from "@/components/favicon";
-import type { ProxyStats, DomainStats, IPStats } from "@clashmaster/shared";
-
-interface InteractiveProxyStatsProps {
- data: ProxyStats[];
- activeBackendId?: number;
-}
-
-const COLORS = [
- "#3B82F6", "#8B5CF6", "#06B6D4", "#10B981", "#F59E0B",
- "#EF4444", "#EC4899", "#6366F1", "#14B8A6", "#F97316",
-];
-
-const CHART_COLORS = [
- "#3B82F6", "#8B5CF6", "#06B6D4", "#10B981", "#F59E0B",
- "#EF4444", "#EC4899", "#6366F1", "#14B8A6", "#F97316",
-];
-
-const PAGE_SIZE_OPTIONS = [10, 20, 50] as const;
-type PageSize = typeof PAGE_SIZE_OPTIONS[number];
-
-// Generate gradient based on IP - same as DomainsTable
-const getIPGradient = (ip: string) => {
- const colors = [
- "from-emerald-500 to-teal-400",
- "from-blue-500 to-cyan-400",
- "from-violet-500 to-purple-400",
- "from-orange-500 to-amber-400",
- "from-rose-500 to-pink-400",
- ];
- let hash = 0;
- for (let i = 0; i < ip.length; i++) {
- hash = ip.charCodeAt(i) + ((hash << 5) - hash);
- }
- return colors[Math.abs(hash) % colors.length];
-};
-
-// Simplify proxy name - remove all emojis and brackets like TopProxiesSimple
-function simplifyProxyName(name: string): string {
- if (!name) return "DIRECT";
- return name
- .replace(/[✈️🚀📹🚚🏠🐟🛡️⭐💎🔥⚡💨🌟🇨🇳🇺🇸🇯🇵🇭🇰🇸🇬🇬🇧🇩🇪🇫🇷🇹🇼🇰🇷]/gu, "")
- .replace(/^\s+|\s+$/g, "")
- .replace(/^\[.*?\]\s*/, "")
- .trim();
-}
-
-// Get emoji for proxy
-function getProxyEmoji(name: string): string {
- if (name.includes("🇺🇸")) return "🇺🇸";
- if (name.includes("🇯🇵")) return "🇯🇵";
- if (name.includes("🇸🇬")) return "🇸🇬";
- if (name.includes("🇭🇰")) return "🇭🇰";
- if (name.includes("🇹🇼")) return "🇹🇼";
- if (name.includes("🇰🇷")) return "🇰🇷";
- if (name === "DIRECT" || name === "Direct") return "🏠";
- return "🌐";
-}
-
-// Domain sort keys
-type DomainSortKey = "domain" | "totalDownload" | "totalUpload" | "totalConnections";
-type SortOrder = "asc" | "desc";
-
-// IP sort keys
-type IPSortKey = "ip" | "totalDownload" | "totalUpload" | "totalConnections";
-
-// Color palette for icons
-const ICON_COLORS = [
- { bg: "bg-blue-500", text: "text-white" },
- { bg: "bg-violet-500", text: "text-white" },
- { bg: "bg-emerald-500", text: "text-white" },
- { bg: "bg-amber-500", text: "text-white" },
- { bg: "bg-rose-500", text: "text-white" },
- { bg: "bg-cyan-500", text: "text-white" },
- { bg: "bg-indigo-500", text: "text-white" },
- { bg: "bg-teal-500", text: "text-white" },
-];
-
-const getDomainColor = (domain: string) => {
- let hash = 0;
- for (let i = 0; i < domain.length; i++) {
- hash = domain.charCodeAt(i) + ((hash << 5) - hash);
- }
- return ICON_COLORS[Math.abs(hash) % ICON_COLORS.length];
-};
-
-const getIPColor = (ip: string) => {
- let hash = 0;
- for (let i = 0; i < ip.length; i++) {
- hash = ip.charCodeAt(i) + ((hash << 5) - hash);
- }
- return ICON_COLORS[Math.abs(hash) % ICON_COLORS.length];
-};
-
-// Country flag emoji mapping
-const COUNTRY_FLAGS: Record<string, string> = {
- US: "🇺🇸", CN: "🇨🇳", JP: "🇯🇵", SG: "🇸🇬", HK: "🇭🇰",
- TW: "🇹🇼", KR: "🇰🇷", GB: "🇬🇧", DE: "🇩🇪", FR: "🇫🇷",
- NL: "🇳🇱", CA: "🇨🇦", AU: "🇦🇺", IN: "🇮🇳", BR: "🇧🇷",
- RU: "🇷🇺", SE: "🇸🇪", CH: "🇨🇭", IL: "🇮🇱", ID: "🇮🇩",
- LOCAL: "🏠",
-};
-
-function getCountryFlag(country: string): string {
- return COUNTRY_FLAGS[country] || COUNTRY_FLAGS[country.toUpperCase()] || "🌐";
-}
-
-// Custom label renderer for bar chart
-function renderCustomBarLabel(props: any) {
- const { x, y, width, value, height } = props;
- return (
- <text
- x={x + width + 6}
- y={y + height / 2}
- fill="currentColor"
- fontSize={11}
- dominantBaseline="central"
- textAnchor="start"
- style={{ fontVariantNumeric: "tabular-nums" }}
- >
- {formatBytes(value, 0)}
- </text>
- );
-}
-
-export function InteractiveProxyStats({ data, activeBackendId }: InteractiveProxyStatsProps) {
- const t = useTranslations("proxies");
- const domainsT = useTranslations("domains");
- const ipsT = useTranslations("ips");
-
- const [selectedProxy, setSelectedProxy] = useState<string | null>(null);
- const [proxyDomains, setProxyDomains] = useState<DomainStats[]>([]);
- const [proxyIPs, setProxyIPs] = useState<IPStats[]>([]);
- const [loading, setLoading] = useState(false);
- const [activeTab, setActiveTab] = useState("domains");
-
- // Pagination states
- const [domainPage, setDomainPage] = useState(1);
- const [domainPageSize, setDomainPageSize] = useState<PageSize>(10);
- const [domainSearch, setDomainSearch] = useState("");
- const [ipPage, setIpPage] = useState(1);
- const [ipPageSize, setIpPageSize] = useState<PageSize>(10);
- const [ipSearch, setIpSearch] = useState("");
-
- // Sort states
- const [domainSortKey, setDomainSortKey] = useState<DomainSortKey>("totalDownload");
- const [domainSortOrder, setDomainSortOrder] = useState<SortOrder>("desc");
- const [ipSortKey, setIpSortKey] = useState<IPSortKey>("totalDownload");
- const [ipSortOrder, setIpSortOrder] = useState<SortOrder>("desc");
-
- // Expanded states
- const [expandedDomain, setExpandedDomain] = useState<string | null>(null);
- const [expandedIP, setExpandedIP] = useState<string | null>(null);
-
- const chartData = useMemo(() => {
- if (!data) return [];
- return data.map((proxy, index) => ({
- name: simplifyProxyName(proxy.chain),
- rawName: proxy.chain,
- value: proxy.totalDownload + proxy.totalUpload,
- download: proxy.totalDownload,
- upload: proxy.totalUpload,
- connections: proxy.totalConnections,
- color: COLORS[index % COLORS.length],
- emoji: getProxyEmoji(proxy.chain),
- rank: index,
- }));
- }, [data]);
-
- const totalTraffic = useMemo(() => {
- return chartData.reduce((sum, item) => sum + item.value, 0);
- }, [chartData]);
-
- const maxTotal = useMemo(() => {
- if (!chartData.length) return 1;
- return Math.max(...chartData.map(p => p.value));
- }, [chartData]);
-
- // Domain sort handler
- const handleDomainSort = (key: DomainSortKey) => {
- if (domainSortKey === key) {
- setDomainSortOrder(domainSortOrder === "asc" ? "desc" : "asc");
- } else {
- setDomainSortKey(key);
- setDomainSortOrder("desc");
- }
- setDomainPage(1);
- };
-
- // IP sort handler
- const handleIPSort = (key: IPSortKey) => {
- if (ipSortKey === key) {
- setIpSortOrder(ipSortOrder === "asc" ? "desc" : "asc");
- } else {
- setIpSortKey(key);
- setIpSortOrder("desc");
- }
- setIpPage(1);
- };
-
- // Toggle expand handlers
- const toggleExpandDomain = (domain: string) => {
- setExpandedDomain(expandedDomain === domain ? null : domain);
- };
-
- const toggleExpandIP = (ip: string) => {
- setExpandedIP(expandedIP === ip ? null : ip);
- };
-
- // Sort icon component
- const DomainSortIcon = ({ column }: { column: DomainSortKey }) => {
- if (domainSortKey !== column) return <ArrowUpDown className="ml-1 h-3 w-3 text-muted-foreground" />;
- return domainSortOrder === "asc" ? (
- <ArrowUp className="ml-1 h-3 w-3 text-primary" />
- ) : (
- <ArrowDown className="ml-1 h-3 w-3 text-primary" />
- );
- };
-
- const IPSortIcon = ({ column }: { column: IPSortKey }) => {
- if (ipSortKey !== column) return <ArrowUpDown className="ml-1 h-3 w-3 text-muted-foreground" />;
- return ipSortOrder === "asc" ? (
- <ArrowUp className="ml-1 h-3 w-3 text-primary" />
- ) : (
- <ArrowDown className="ml-1 h-3 w-3 text-primary" />
- );
- };
-
- // Load proxy details
- const loadProxyDetails = useCallback(async (chain: string) => {
- setLoading(true);
- try {
- const [domains, ips] = await Promise.all([
- api.getProxyDomains(chain, activeBackendId),
- api.getProxyIPs(chain, activeBackendId),
- ]);
- setProxyDomains(domains);
- setProxyIPs(ips);
- // Reset pagination
- setDomainPage(1);
- setIpPage(1);
- setDomainSearch("");
- setIpSearch("");
- } catch (err) {
- console.error(`Failed to load details for ${chain}:`, err);
- setProxyDomains([]);
- setProxyIPs([]);
- } finally {
- setLoading(false);
- }
- }, [activeBackendId]);
-
- // Default select first proxy when data loads
- useEffect(() => {
- if (chartData.length > 0 && !selectedProxy) {
- const firstProxy = chartData[0].rawName;
- setSelectedProxy(firstProxy);
- loadProxyDetails(firstProxy);
- }
- }, [chartData, selectedProxy, loadProxyDetails]);
-
- const handleProxyClick = useCallback((chain: string) => {
- if (selectedProxy !== chain) {
- setSelectedProxy(chain);
- loadProxyDetails(chain);
- }
- }, [selectedProxy, loadProxyDetails]);
-
- const selectedProxyData = useMemo(() => {
- return chartData.find(p => p.rawName === selectedProxy);
- }, [chartData, selectedProxy]);
-
- // Filter, sort and paginate domains
- const filteredDomains = useMemo(() => {
- let result = proxyDomains;
- if (domainSearch) {
- result = proxyDomains.filter(d =>
- d.domain.toLowerCase().includes(domainSearch.toLowerCase())
- );
- }
- // Sort
- return [...result].sort((a, b) => {
- const aValue = a[domainSortKey];
- const bValue = b[domainSortKey];
- const modifier = domainSortOrder === "asc" ? 1 : -1;
- if (typeof aValue === "string" && typeof bValue === "string") {
- return aValue.localeCompare(bValue) * modifier;
- }
- return ((aValue as number) - (bValue as number)) * modifier;
- });
- }, [proxyDomains, domainSearch, domainSortKey, domainSortOrder]);
-
- const paginatedDomains = useMemo(() => {
- const start = (domainPage - 1) * domainPageSize;
- return filteredDomains.slice(start, start + domainPageSize);
- }, [filteredDomains, domainPage, domainPageSize]);
-
- const domainTotalPages = Math.ceil(filteredDomains.length / domainPageSize);
-
- // Filter, sort and paginate IPs
- const filteredIPs = useMemo(() => {
- let result = proxyIPs;
- if (ipSearch) {
- result = proxyIPs.filter(ip =>
- ip.ip.toLowerCase().includes(ipSearch.toLowerCase()) ||
- ip.domains.some(d => d.toLowerCase().includes(ipSearch.toLowerCase()))
- );
- }
- // Sort
- return [...result].sort((a, b) => {
- const aValue = a[ipSortKey];
- const bValue = b[ipSortKey];
- const modifier = ipSortOrder === "asc" ? 1 : -1;
- if (typeof aValue === "string" && typeof bValue === "string") {
- return aValue.localeCompare(bValue) * modifier;
- }
- return ((aValue as number) - (bValue as number)) * modifier;
- });
- }, [proxyIPs, ipSearch, ipSortKey, ipSortOrder]);
-
- const paginatedIPs = useMemo(() => {
- const start = (ipPage - 1) * ipPageSize;
- return filteredIPs.slice(start, start + ipPageSize);
- }, [filteredIPs, ipPage, ipPageSize]);
-
- const ipTotalPages = Math.ceil(filteredIPs.length / ipPageSize);
-
- // Chart data
- const domainChartData = useMemo(() => {
- if (!proxyDomains?.length) return [];
- return proxyDomains
- .slice(0, 10)
- .map((domain, index) => ({
- name: domain.domain.length > 22 ? domain.domain.slice(0, 22) + "..." : domain.domain,
- fullDomain: domain.domain,
- total: domain.totalDownload + domain.totalUpload,
- download: domain.totalDownload,
- upload: domain.totalUpload,
- connections: domain.totalConnections,
- color: CHART_COLORS[index % CHART_COLORS.length],
- }));
- }, [proxyDomains]);
-
- const getPageNumbers = (currentPage: number, totalPages: number) => {
- const pages: (number | string)[] = [];
- const maxVisible = 5;
-
- if (totalPages <= maxVisible) {
- for (let i = 1; i <= totalPages; i++) pages.push(i);
- } else {
- if (currentPage <= 3) {
- for (let i = 1; i <= 4; i++) pages.push(i);
- pages.push('...');
- pages.push(totalPages);
- } else if (currentPage >= totalPages - 2) {
- pages.push(1);
- pages.push('...');
- for (let i = totalPages - 3; i <= totalPages; i++) pages.push(i);
- } else {
- pages.push(1);
- pages.push('...');
- for (let i = currentPage - 1; i <= currentPage + 1; i++) pages.push(i);
- pages.push('...');
- pages.push(totalPages);
- }
- }
- return pages;
- };
-
- if (chartData.length === 0) {
- return (
- <Card>
- <CardContent className="p-12 text-center text-muted-foreground">
- {t("noData")}
- </CardContent>
- </Card>
- );
- }
-
- return (
- <div className="space-y-6">
- {/* Top Section: Three Column Layout */}
- <div className="grid grid-cols-1 lg:grid-cols-12 gap-6">
- {/* Left: Pie Chart (3 columns) */}
- <Card className="lg:col-span-3">
- <CardHeader className="pb-2">
- <CardTitle className="text-sm font-semibold text-muted-foreground uppercase tracking-wider">
- {t("distribution")}
- </CardTitle>
- </CardHeader>
- <CardContent>
- <div className="h-[200px] w-full">
- <ResponsiveContainer width="100%" height="100%">
- <PieChart>
- <Pie
- data={chartData}
- cx="50%"
- cy="50%"
- innerRadius={50}
- outerRadius={80}
- paddingAngle={2}
- dataKey="value">
- {chartData.map((entry, index) => (
- <Cell key={`cell-${index}`} fill={entry.color} />
- ))}
- </Pie>
- <RechartsTooltip
- content={({ active, payload }) => {
- if (active && payload && payload.length) {
- const item = payload[0].payload;
- return (
- <div className="bg-background border border-border p-3 rounded-lg shadow-lg">
- <p className="font-medium text-sm mb-1">{item.emoji} {item.name}</p>
- <p className="text-xs text-muted-foreground">{formatBytes(item.value)}</p>
- </div>
- );
- }
- return null;
- }}
- />
- </PieChart>
- </ResponsiveContainer>
- </div>
- </CardContent>
- </Card>
-
- {/* Middle: Proxy List (4 columns) - Style like TopProxiesSimple */}
- <Card className="lg:col-span-4">
- <CardHeader className="pb-2">
- <CardTitle className="text-sm font-semibold text-muted-foreground uppercase tracking-wider">
- {t("proxyNodes")}
- </CardTitle>
- </CardHeader>
- <CardContent className="p-3">
- <ScrollArea className="h-[280px] pr-3">
- <div className="space-y-2">
- {chartData.map((item) => {
- const percentage = totalTraffic > 0 ? (item.value / totalTraffic) * 100 : 0;
- const barPercent = (item.value / maxTotal) * 100;
- const isSelected = selectedProxy === item.rawName;
-
- // Badge color based on rank like TopProxiesSimple
- const badgeColor = item.rank === 0
- ? "bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400"
- : item.rank === 1
- ? "bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-300"
- : item.rank === 2
- ? "bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-400"
- : "bg-muted text-muted-foreground";
-
- return (
- <button
- key={item.rawName}
- onClick={() => handleProxyClick(item.rawName)}
- className={cn(
- "w-full p-2.5 rounded-xl border text-left transition-all duration-200",
- isSelected
- ? "border-primary bg-primary/5 ring-1 ring-primary/20"
- : "border-border/50 bg-card/50 hover:bg-card hover:border-primary/30"
- )}>
- {/* Row 1: Rank + Name + Total */}
- <div className="flex items-center gap-2 mb-1.5">
- <span className={cn(
- "w-5 h-5 rounded-md text-[10px] font-bold flex items-center justify-center shrink-0",
- badgeColor
- )}>
- {item.rank + 1}
- </span>
-
- <span className="flex-1 text-sm font-medium truncate" title={item.name}>
- {item.name}
- </span>
-
- <span className="text-sm font-bold tabular-nums shrink-0">
- {formatBytes(item.value)}
- </span>
- </div>
-
- {/* Row 2: Progress bar + Stats */}
- <div className="pl-7 space-y-1">
- {/* Progress bar - dual color like TopProxiesSimple */}
- <div className="h-1.5 rounded-full bg-muted overflow-hidden flex">
- <div
- className="h-full bg-blue-500 dark:bg-blue-400"
- style={{ width: `${(item.download / item.value) * barPercent}%` }}
- />
- <div
- className="h-full bg-purple-500 dark:bg-purple-400"
- style={{ width: `${(item.upload / item.value) * barPercent}%` }}
- />
- </div>
- {/* Stats */}
- <div className="flex items-center justify-between text-xs text-muted-foreground">
- <div className="flex items-center gap-2">
- <span className="text-blue-500 dark:text-blue-400">↓ {formatBytes(item.download)}</span>
- <span className="text-purple-500 dark:text-purple-400">↑ {formatBytes(item.upload)}</span>
- <span className="flex items-center gap-1 tabular-nums">
- <Link2 className="w-3 h-3" />
- {formatNumber(item.connections)}
- </span>
- </div>
- <span className="tabular-nums">{percentage.toFixed(1)}%</span>
- </div>
- </div>
- </button>
- );
- })}
- </div>
- </ScrollArea>
- </CardContent>
- </Card>
-
- {/* Right: Top Domains Chart (5 columns) */}
- <Card className="lg:col-span-5">
- <CardHeader className="pb-2">
- <div className="flex items-center justify-between">
- <CardTitle className="text-sm font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2">
- <BarChart3 className="h-4 w-4" />
- {t("topDomains")}
- </CardTitle>
- {selectedProxyData && (
- <span className="text-xs text-muted-foreground">
- {selectedProxyData.emoji} {selectedProxyData.name}
- </span>
- )}
- </div>
- </CardHeader>
- <CardContent>
- {loading ? (
- <div className="flex items-center justify-center py-8 h-[280px]">
- <div className="h-5 w-5 border-2 border-primary/30 border-t-primary rounded-full animate-spin" />
- </div>
- ) : domainChartData.length === 0 ? (
- <div className="text-center py-8 text-muted-foreground h-[280px] flex items-center justify-center">
- {domainsT("noResults")}
- </div>
- ) : (
- <div className="h-[280px] w-full">
- <ResponsiveContainer width="100%" height="100%">
- <BarChart
- data={domainChartData}
- layout="vertical"
- margin={{ top: 5, right: 50, left: 5, bottom: 5 }}
- >
- <CartesianGrid
- strokeDasharray="3 3"
- stroke="#888888"
- opacity={0.2}
- horizontal={false}
- />
- <XAxis
- type="number"
- tickFormatter={(value) => formatBytes(value, 0)}
- tick={{ fill: "#888888", fontSize: 10 }}
- tickLine={false}
- axisLine={false}
- />
- <YAxis
- type="category"
- dataKey="name"
- width={110}
- tick={{ fontSize: 11, fill: "currentColor" }}
- tickLine={false}
- axisLine={false}
- />
- <RechartsTooltip
- content={({ active, payload }) => {
- if (active && payload && payload.length) {
- const item = payload[0].payload;
- return (
- <div className="bg-background border border-border p-3 rounded-lg shadow-lg min-w-[200px] max-w-[90vw] sm:min-w-[280px]">
- <div className="flex items-center gap-2 mb-3">
- <Favicon domain={item.fullDomain} size="sm" />
- <span className="font-medium text-sm text-foreground truncate max-w-[200px]">
- {item.fullDomain}
- </span>
- </div>
- <div className="space-y-2 text-xs">
- <div className="flex justify-between items-center">
- <span className="text-muted-foreground">Total Traffic</span>
- <span className="font-semibold text-foreground">{formatBytes(item.total)}</span>
- </div>
- <div className="flex justify-between items-center">
- <span className="text-blue-500">Download</span>
- <span className="text-foreground">{formatBytes(item.download)}</span>
- </div>
- <div className="flex justify-between items-center">
- <span className="text-purple-500">Upload</span>
- <span className="text-foreground">{formatBytes(item.upload)}</span>
- </div>
- <div className="flex justify-between items-center pt-1 border-t border-border/50">
- <span className="text-emerald-500">Connections</span>
- <span className="text-foreground">{formatNumber(item.connections)}</span>
- </div>
- </div>
- </div>
- );
- }
- return null;
- }}
- cursor={{ fill: "rgba(128, 128, 128, 0.1)" }}
- />
- <Bar
- dataKey="total"
- radius={[0, 4, 4, 0]}
- maxBarSize={24}
- >
- {domainChartData.map((entry, index) => (
- <BarCell key={`cell-${index}`} fill={entry.color} />
- ))}
- <LabelList
- dataKey="total"
- position="right"
- content={renderCustomBarLabel}
- />
- </Bar>
- </BarChart>
- </ResponsiveContainer>
- </div>
- )}
- </CardContent>
- </Card>
- </div>
-
- {/* Bottom Section: Domain List & IP Addresses with pagination */}
- {selectedProxy && (
- <Tabs value={activeTab} onValueChange={setActiveTab} className="w-full">
- {/* Simplified Tabs - no icons, no counts, like Domains page */}
- <TabsList className="glass">
- <TabsTrigger value="domains">
- {domainsT("domainList")}
- </TabsTrigger>
- <TabsTrigger value="ips">
- {ipsT("ipList")}
- </TabsTrigger>
- </TabsList>
-
- <TabsContent value="domains" className="mt-4">
- <Card>
- {/* Header with search */}
- <div className="p-4 border-b border-border/50">
- <div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3">
- <div>
- <h3 className="text-base font-semibold">{domainsT("associatedDomains")}</h3>
- <p className="text-sm text-muted-foreground">
- {filteredDomains.length} {domainsT("domainsCount")}
- </p>
- </div>
- <div className="relative">
- <Input
- placeholder={domainsT("search")}
- value={domainSearch}
- onChange={(e) => {
- setDomainSearch(e.target.value);
- setDomainPage(1);
- }}
- className="h-9 w-full sm:w-[240px] bg-secondary/50 border-0"
- />
- </div>
- </div>
- </div>
-
- <CardContent className="p-0">
- {loading ? (
- <div className="flex items-center justify-center py-12">
- <Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />
- </div>
- ) : filteredDomains.length === 0 ? (
- <div className="text-center py-12 text-muted-foreground">
- {domainSearch ? domainsT("noResults") : "No domains found"}
- </div>
- ) : (
- <>
- {/* Domain List - Style like DomainsTable */}
- <div className="divide-y divide-border/30">
- {(() => {
- const totalDomainTraffic = filteredDomains.reduce(
- (sum, d) => sum + d.totalDownload + d.totalUpload, 0
- );
- return paginatedDomains.map((domain) => {
- const domainTraffic = domain.totalDownload + domain.totalUpload;
- const percent = totalDomainTraffic > 0 ? (domainTraffic / totalDomainTraffic) * 100 : 0;
- const downloadPercent = domainTraffic > 0 ? (domain.totalDownload / domainTraffic) * 100 : 0;
- const uploadPercent = domainTraffic > 0 ? (domain.totalUpload / domainTraffic) * 100 : 0;
-
- return (
- <div
- key={domain.domain}
- className="px-4 py-3 hover:bg-secondary/20 transition-colors"
- >
- <div className="flex items-center gap-3 mb-2">
- {/* Favicon like DomainsTable */}
- <Favicon domain={domain.domain} size="sm" className="shrink-0" />
- <span className="font-medium text-sm truncate flex-1" title={domain.domain}>
- {domain.domain}
- </span>
- <span className="text-xs text-muted-foreground tabular-nums">
- {percent.toFixed(1)}%
- </span>
- </div>
- <div className="w-full h-1.5 rounded-full bg-secondary/80 mb-2 overflow-hidden flex">
- <div
- className="h-full bg-blue-500"
- style={{ width: `${Math.max(percent * (downloadPercent / 100), 0.5)}%` }}
- />
- <div
- className="h-full bg-purple-500"
- style={{ width: `${Math.max(percent * (uploadPercent / 100), 0.5)}%` }}
- />
- </div>
- <div className="flex items-center justify-between">
- <div className="flex items-center gap-3 text-xs tabular-nums">
- <span className="text-blue-500">↓ {formatBytes(domain.totalDownload)}</span>
- <span className="text-purple-500">↑ {formatBytes(domain.totalUpload)}</span>
- </div>
- {/* Connection count badge like DomainsTable */}
- <span className="px-2 py-0.5 rounded-full bg-secondary text-xs font-medium">
- {formatNumber(domain.totalConnections)}
- </span>
- </div>
- </div>
- );
- });
- })()}
- </div>
-
- {/* Pagination */}
- {filteredDomains.length > 0 && (
- <div className="p-3 border-t border-border/50 bg-secondary/20">
- <div className="flex flex-col sm:flex-row items-center justify-between gap-3">
- <div className="flex items-center gap-2">
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button variant="ghost" size="sm" className="h-8 gap-1.5 text-muted-foreground hover:text-foreground">
- <Rows3 className="h-4 w-4" />
- <span>{domainPageSize} / {domainsT("page")}</span>
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="start">
- {PAGE_SIZE_OPTIONS.map((size) => (
- <DropdownMenuItem
- key={size}
- onClick={() => {
- setDomainPageSize(size);
- setDomainPage(1);
- }}
- className={domainPageSize === size ? "bg-primary/10" : ""}
- >
- {size} / {domainsT("page")}
- </DropdownMenuItem>
- ))}
- </DropdownMenuContent>
- </DropdownMenu>
- <span className="text-sm text-muted-foreground">
- {domainsT("total")} {filteredDomains.length}
- </span>
- </div>
- <div className="flex items-center gap-2">
- <p className="text-xs text-muted-foreground">
- {(domainPage - 1) * domainPageSize + 1}-{Math.min(domainPage * domainPageSize, filteredDomains.length)} / {filteredDomains.length}
- </p>
- <div className="flex items-center gap-1">
- <Button
- variant="ghost"
- size="icon"
- className="h-8 w-8"
- onClick={() => setDomainPage(p => Math.max(1, p - 1))}
- disabled={domainPage === 1}
- >
- <ChevronLeft className="h-4 w-4" />
- </Button>
- {getPageNumbers(domainPage, domainTotalPages).map((page, idx) => (
- page === '...' ? (
- <span key={`ellipsis-${idx}`} className="px-1 text-muted-foreground text-xs">...</span>
- ) : (
- <Button
- key={page}
- variant={domainPage === page ? "default" : "ghost"}
- size="sm"
- className="h-8 w-8 px-0 text-xs"
- onClick={() => setDomainPage(page as number)}
- >
- {page}
- </Button>
- )
- ))}
- <Button
- variant="ghost"
- size="icon"
- className="h-8 w-8"
- onClick={() => setDomainPage(p => Math.min(domainTotalPages, p + 1))}
- disabled={domainPage === domainTotalPages}
- >
- <ChevronRight className="h-4 w-4" />
- </Button>
- </div>
- </div>
- </div>
- </div>
- )}
- </>
- )}
- </CardContent>
- </Card>
- </TabsContent>
-
- <TabsContent value="ips" className="mt-4">
- <Card>
- {/* Header with search */}
- <div className="p-4 border-b border-border/50">
- <div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3">
- <div>
- <h3 className="text-base font-semibold">{ipsT("associatedIPs")}</h3>
- <p className="text-sm text-muted-foreground">
- {filteredIPs.length} IPs
- </p>
- </div>
- <div className="relative">
- <Input
- placeholder={ipsT("search")}
- value={ipSearch}
- onChange={(e) => {
- setIpSearch(e.target.value);
- setIpPage(1);
- }}
- className="h-9 w-full sm:w-[240px] bg-secondary/50 border-0"
- />
- </div>
- </div>
- </div>
-
- <CardContent className="p-0">
- {loading ? (
- <div className="flex items-center justify-center py-12">
- <Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />
- </div>
- ) : filteredIPs.length === 0 ? (
- <div className="text-center py-12 text-muted-foreground">
- {ipSearch ? ipsT("noResults") : "No IPs found"}
- </div>
- ) : (
- <>
- {/* IP List - Style like DomainsTable */}
- <div className="divide-y divide-border/30">
- {(() => {
- const totalIPTraffic = filteredIPs.reduce(
- (sum, ip) => sum + ip.totalDownload + ip.totalUpload, 0
- );
- return paginatedIPs.map((ip) => {
- const ipTraffic = ip.totalDownload + ip.totalUpload;
- const percent = totalIPTraffic > 0 ? (ipTraffic / totalIPTraffic) * 100 : 0;
- const downloadPercent = ipTraffic > 0 ? (ip.totalDownload / ipTraffic) * 100 : 0;
- const uploadPercent = ipTraffic > 0 ? (ip.totalUpload / ipTraffic) * 100 : 0;
- const gradient = getIPGradient(ip.ip);
-
- return (
- <div
- key={ip.ip}
- className="px-4 py-3 hover:bg-secondary/20 transition-colors"
- >
- <div className="flex items-center gap-3 mb-2">
- {/* IP Icon like DomainsTable - gradient + Server icon */}
- <div className={`w-6 h-6 rounded-md bg-gradient-to-br ${gradient} flex items-center justify-center shrink-0`}>
- <Server className="w-3 h-3 text-white" />
- </div>
- <code className="text-sm font-mono truncate flex-1">{ip.ip}</code>
- <span className="text-xs text-muted-foreground tabular-nums">
- {percent.toFixed(1)}%
- </span>
- </div>
- <div className="w-full h-1.5 rounded-full bg-secondary/80 mb-2 overflow-hidden flex">
- <div
- className="h-full bg-blue-500"
- style={{ width: `${Math.max(percent * (downloadPercent / 100), 0.5)}%` }}
- />
- <div
- className="h-full bg-purple-500"
- style={{ width: `${Math.max(percent * (uploadPercent / 100), 0.5)}%` }}
- />
- </div>
- <div className="flex items-center justify-between">
- <div className="flex items-center gap-3 text-xs tabular-nums">
- <span className="text-blue-500">↓ {formatBytes(ip.totalDownload)}</span>
- <span className="text-purple-500">↑ {formatBytes(ip.totalUpload)}</span>
- </div>
- {/* Connection count badge like DomainsTable */}
- <span className="px-2 py-0.5 rounded-full bg-secondary text-xs font-medium">
- {formatNumber(ip.totalConnections)}
- </span>
- </div>
- </div>
- );
- });
- })()}
- </div>
-
- {/* Pagination */}
- {filteredIPs.length > 0 && (
- <div className="p-3 border-t border-border/50 bg-secondary/20">
- <div className="flex flex-col sm:flex-row items-center justify-between gap-3">
- <div className="flex items-center gap-2">
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button variant="ghost" size="sm" className="h-8 gap-1.5 text-muted-foreground hover:text-foreground">
- <Rows3 className="h-4 w-4" />
- <span>{ipPageSize} / {ipsT("page")}</span>
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="start">
- {PAGE_SIZE_OPTIONS.map((size) => (
- <DropdownMenuItem
- key={size}
- onClick={() => {
- setIpPageSize(size);
- setIpPage(1);
- }}
- className={ipPageSize === size ? "bg-primary/10" : ""}
- >
- {size} / {ipsT("page")}
- </DropdownMenuItem>
- ))}
- </DropdownMenuContent>
- </DropdownMenu>
- <span className="text-sm text-muted-foreground">
- {ipsT("total")} {filteredIPs.length}
- </span>
- </div>
- <div className="flex items-center gap-2">
- <p className="text-xs text-muted-foreground">
- {(ipPage - 1) * ipPageSize + 1}-{Math.min(ipPage * ipPageSize, filteredIPs.length)} / {filteredIPs.length}
- </p>
- <div className="flex items-center gap-1">
- <Button
- variant="ghost"
- size="icon"
- className="h-8 w-8"
- onClick={() => setIpPage(p => Math.max(1, p - 1))}
- disabled={ipPage === 1}
- >
- <ChevronLeft className="h-4 w-4" />
- </Button>
- {getPageNumbers(ipPage, ipTotalPages).map((page, idx) => (
- page === '...' ? (
- <span key={`ellipsis-${idx}`} className="px-1 text-muted-foreground text-xs">...</span>
- ) : (
- <Button
- key={page}
- variant={ipPage === page ? "default" : "ghost"}
- size="sm"
- className="h-8 w-8 px-0 text-xs"
- onClick={() => setIpPage(page as number)}
- >
- {page}
- </Button>
- )
- ))}
- <Button
- variant="ghost"
- size="icon"
- className="h-8 w-8"
- onClick={() => setIpPage(p => Math.min(ipTotalPages, p + 1))}
- disabled={ipPage === ipTotalPages}
- >
- <ChevronRight className="h-4 w-4" />
- </Button>
- </div>
- </div>
- </div>
- </div>
- )}
- </>
- )}
- </CardContent>
- </Card>
- </TabsContent>
- </Tabs>
- )}
- </div>
- );
-}
diff --git a/apps/web/components/overview/top-proxies-simple.tsx b/apps/web/components/overview/top-proxies-simple.tsx
index 287ae5d..d57b5d3 100644
--- a/apps/web/components/overview/top-proxies-simple.tsx
+++ b/apps/web/components/overview/top-proxies-simple.tsx
@@ -137,11 +137,10 @@ export const TopProxiesSimple = React.memo(
</span>
<span
- className="flex-1 text-sm font-medium truncate"
+ className="emoji-flag-font flex-1 text-sm font-medium truncate"
title={proxyItem.chain}>
{displayName || proxyItem.chain}
</span>
-
<span className="text-sm font-bold tabular-nums shrink-0">
{formatBytes(total)}
</span>
diff --git a/apps/web/components/proxy-chain-badge.tsx b/apps/web/components/proxy-chain-badge.tsx
index ef0cd94..99a223d 100644
--- a/apps/web/components/proxy-chain-badge.tsx
+++ b/apps/web/components/proxy-chain-badge.tsx
@@ -63,7 +63,7 @@ function ChainFlow({ chain }: { chain: string }) {
<span key={`${segment}-${idx}`} className="inline-flex items-center gap-1">
<span
className={cn(
- "px-2 py-0.5 rounded-md border text-[11px] font-medium whitespace-nowrap",
+ "emoji-flag-font px-2 py-0.5 rounded-md border text-[11px] font-medium whitespace-nowrap",
getNodeTone(idx, displaySegments.length),
)}
>
@@ -115,7 +115,7 @@ export function ProxyChainBadge({
<span className={cn("inline-flex items-center gap-1.5 min-w-0", wrapperClassName)}>
<span
className={cn(
- "inline-flex items-center gap-1 rounded-md bg-secondary/60 text-foreground dark:bg-secondary/40 dark:text-foreground/80 text-[11px] font-medium",
+ "emoji-flag-font inline-flex items-center gap-1 rounded-md bg-secondary/60 text-foreground dark:bg-secondary/40 dark:text-foreground/80 text-[11px] font-medium",
truncateLabel
? "px-1.5 py-0.5 truncate max-w-[180px] lg:max-w-[220px]"
: "px-2 py-0.5 whitespace-nowrap",
diff --git a/apps/web/components/proxy-top-grid.tsx b/apps/web/components/proxy-top-grid.tsx
index 2c83988..f88659b 100644
--- a/apps/web/components/proxy-top-grid.tsx
+++ b/apps/web/components/proxy-top-grid.tsx
@@ -5,7 +5,11 @@ import { Server, Link2, ArrowUpDown, ArrowRight } from "lucide-react";
import { useTranslations } from "next-intl";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
-import { CountryFlag, extractCountryCodeFromText, stripLeadingFlagEmoji } from "@/components/country-flag";
+import {
+ CountryFlag,
+ extractCountryCodeFromText,
+ stripLeadingFlagEmoji,
+} from "@/components/country-flag";
import { formatBytes, formatNumber } from "@/lib/utils";
import type { ProxyStats } from "@clashmaster/shared";
@@ -17,13 +21,17 @@ interface ProxyTopGridProps {
type SortBy = "traffic" | "connections";
-const COLORS = ["#3B82F6", "#8B5CF6", "#06B6D4", "#10B981", "#F59E0B", "#EF4444"];
+const COLORS = [
+ "#3B82F6",
+ "#8B5CF6",
+ "#06B6D4",
+ "#10B981",
+ "#F59E0B",
+ "#EF4444",
+];
function normalizeProxyName(name: string): string {
- const normalized = name
- .replace(/^\["?/, "")
- .replace(/"?\]$/, "")
- .trim();
+ const normalized = name.replace(/^\["?/, "").replace(/"?\]$/, "").trim();
const parts = normalized
.split(">")
.map((part) => part.trim())
@@ -44,17 +52,23 @@ function getProxyCountryCode(name: string): string {
return extractCountryCodeFromText(cleaned) ?? "UNKNOWN";
}
-export function ProxyTopGrid({ data, limit = 5, onViewAll }: ProxyTopGridProps) {
+export function ProxyTopGrid({
+ data,
+ limit = 5,
+ onViewAll,
+}: ProxyTopGridProps) {
const [sortBy, setSortBy] = useState<SortBy>("traffic");
const t = useTranslations("topProxies");
const proxiesT = useTranslations("proxies");
const proxies = useMemo(() => {
if (!data) return [];
-
+
const sorted = [...data].sort((a, b) => {
if (sortBy === "traffic") {
- return (b.totalDownload + b.totalUpload) - (a.totalDownload + a.totalUpload);
+ return (
+ b.totalDownload + b.totalUpload - (a.totalDownload + a.totalUpload)
+ );
}
return b.totalConnections - a.totalConnections;
});
@@ -68,7 +82,8 @@ export function ProxyTopGrid({ data, limit = 5, onViewAll }: ProxyTopGridProps)
}));
}, [data, limit, sortBy]);
- const toggleSort = () => setSortBy(prev => prev === "traffic" ? "connections" : "traffic");
+ const toggleSort = () =>
+ setSortBy((prev) => (prev === "traffic" ? "connections" : "traffic"));
return (
<Card className="h-full flex flex-col">
@@ -78,16 +93,21 @@ export function ProxyTopGrid({ data, limit = 5, onViewAll }: ProxyTopGridProps)
<Server className="w-4 h-4" />
{t("title")}
</CardTitle>
- <Button
- variant="ghost"
- size="sm"
+ <Button
+ variant="ghost"
+ size="sm"
className="h-7 px-2 text-xs"
- onClick={toggleSort}
- >
+ onClick={toggleSort}>
{sortBy === "traffic" ? (
- <><ArrowUpDown className="w-3 h-3 mr-1" /> {proxiesT("sortByTraffic")}</>
+ <>
+ <ArrowUpDown className="w-3 h-3 mr-1" />{" "}
+ {proxiesT("sortByTraffic")}
+ </>
) : (
- <><Link2 className="w-3 h-3 mr-1" /> {proxiesT("sortByConnections")}</>
+ <>
+ <Link2 className="w-3 h-3 mr-1" />{" "}
+ {proxiesT("sortByConnections")}
+ </>
)}
</Button>
</div>
@@ -97,14 +117,15 @@ export function ProxyTopGrid({ data, limit = 5, onViewAll }: ProxyTopGridProps)
{proxies.map((proxy, index) => (
<div
key={proxy.chain}
- className="flex items-center gap-3 p-3 rounded-xl border border-border/50 bg-card/50 hover:bg-card transition-colors"
- >
+ className="flex items-center gap-3 p-3 rounded-xl border border-border/50 bg-card/50 hover:bg-card transition-colors">
{/* Rank */}
- <span className={`
+ <span
+ className={`
w-6 h-6 rounded-md text-xs font-bold flex items-center justify-center shrink-0
- ${index < 3
- ? "bg-primary/10 text-primary"
- : "bg-muted text-muted-foreground"
+ ${
+ index < 3
+ ? "bg-primary/10 text-primary"
+ : "bg-muted text-muted-foreground"
}
`}>
{index + 1}
@@ -147,7 +168,11 @@ export function ProxyTopGrid({ data, limit = 5, onViewAll }: ProxyTopGridProps)
{/* Footer */}
{onViewAll && (
<div className="mt-4 pt-3 border-t border-border/30">
- <Button variant="ghost" size="sm" className="w-full h-9 text-xs" onClick={onViewAll}>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="w-full h-9 text-xs"
+ onClick={onViewAll}>
{proxiesT("viewAll")}
<ArrowRight className="w-3 h-3 ml-1" />
</Button>
diff --git a/apps/web/components/top-domains-chart.tsx b/apps/web/components/top-domains-chart.tsx
index e18108e..1fd294a 100644
--- a/apps/web/components/top-domains-chart.tsx
+++ b/apps/web/components/top-domains-chart.tsx
@@ -13,7 +13,7 @@ import {
LabelList,
} from "recharts";
import { useTranslations } from "next-intl";
-import { BarChart3, Loader2 } from "lucide-react";
+import { BarChart3 } from "lucide-react";
import { keepPreviousData, useQuery } from "@tanstack/react-query";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
@@ -41,8 +41,7 @@ const CHART_CONFIG = {
100: { height: 1200, barSize: 14, showAllLabels: true },
} as const;
-// Vibrant color palette for bars
-const COLORS = [
+const DOMAIN_COLORS = [
"#3B82F6", // Blue
"#8B5CF6", // Purple
"#06B6D4", // Cyan
@@ -55,6 +54,24 @@ const COLORS = [
"#F97316", // Orange
];
+function hexToRgb(hex: string): { r: number; g: number; b: number } {
+ const clean = hex.replace("#", "");
+ const full = clean.length === 3
+ ? clean.split("").map((c) => c + c).join("")
+ : clean;
+ const int = parseInt(full, 16);
+ return {
+ r: (int >> 16) & 255,
+ g: (int >> 8) & 255,
+ b: int & 255,
+ };
+}
+
+function withAlpha(hex: string, alpha: number): string {
+ const { r, g, b } = hexToRgb(hex);
+ return `rgba(${r}, ${g}, ${b}, ${alpha})`;
+}
+
// Custom label renderer to prevent text wrapping in SVG
function renderCustomBarLabel(props: any) {
const { x, y, width, value, height } = props;
@@ -89,7 +106,7 @@ export function TopDomainsChart({ data, activeBackendId, timeRange }: TopDomains
{
offset: 0,
limit: topN,
- sortBy: "totalDownload",
+ sortBy: "totalTraffic",
sortOrder: "desc",
},
stableTimeRange,
@@ -98,7 +115,7 @@ export function TopDomainsChart({ data, activeBackendId, timeRange }: TopDomains
api.getDomains(activeBackendId, {
offset: 0,
limit: topN,
- sortBy: "totalDownload",
+ sortBy: "totalTraffic",
sortOrder: "desc",
start: stableTimeRange?.start,
end: stableTimeRange?.end,
@@ -110,10 +127,14 @@ export function TopDomainsChart({ data, activeBackendId, timeRange }: TopDomains
const domains = useMemo(() => {
const source = data ?? domainsQuery.data?.data ?? [];
return [...source]
- .sort((a, b) => b.totalDownload - a.totalDownload)
+ .sort(
+ (a, b) =>
+ b.totalDownload +
+ b.totalUpload -
+ (a.totalDownload + a.totalUpload),
+ )
.slice(0, topN);
}, [data, domainsQuery.data?.data, topN]);
- const isLoading = !data && domainsQuery.isLoading && !domainsQuery.data;
useEffect(() => {
if (!containerRef.current) return;
@@ -137,12 +158,12 @@ export function TopDomainsChart({ data, activeBackendId, timeRange }: TopDomains
const chartData = useMemo(() => {
if (!domains || domains.length === 0) return [];
const result = domains.map((domain: DomainStats, index: number) => ({
+ baseColor: DOMAIN_COLORS[index % DOMAIN_COLORS.length],
name: domain.domain,
fullDomain: domain.domain,
total: domain.totalDownload + domain.totalUpload,
download: domain.totalDownload,
upload: domain.totalUpload,
- color: COLORS[index % COLORS.length],
}));
// After first data load, mark as rendered so subsequent updates skip animation
if (result.length > 0) {
@@ -205,7 +226,7 @@ export function TopDomainsChart({ data, activeBackendId, timeRange }: TopDomains
</div>
<Tabs
value={topN.toString()}
- onValueChange={(v) => setTopN(parseInt(v) as TopOption)}>
+ onValueChange={(v) => setTopN(parseInt(v, 10) as TopOption)}>
<TabsList className="h-8">
{TOP_OPTIONS.map((n) => (
<TabsTrigger
@@ -261,13 +282,31 @@ export function TopDomainsChart({ data, activeBackendId, timeRange }: TopDomains
cursor={{ fill: "rgba(128, 128, 128, 0.1)" }}
/>
<Bar
- dataKey="total"
+ dataKey="download"
+ stackId="traffic"
+ radius={[0, 0, 0, 0]}
+ maxBarSize={config.barSize}
+ isAnimationActive={!hasRenderedRef.current}
+ animationDuration={600}>
+ {chartData.map((entry, index) => (
+ <Cell
+ key={`download-cell-${entry.fullDomain}-${index}`}
+ fill={withAlpha(entry.baseColor, 0.75)}
+ />
+ ))}
+ </Bar>
+ <Bar
+ dataKey="upload"
+ stackId="traffic"
radius={[0, 4, 4, 0]}
maxBarSize={config.barSize}
isAnimationActive={!hasRenderedRef.current}
animationDuration={600}>
{chartData.map((entry, index) => (
- <Cell key={`cell-${index}`} fill={entry.color} />
+ <Cell
+ key={`upload-cell-${entry.fullDomain}-${index}`}
+ fill={entry.baseColor}
+ />
))}
{showLabels && (
<LabelList
diff --git a/apps/web/public/fonts/NotoColorEmoji-flagsonly.ttf b/apps/web/public/fonts/NotoColorEmoji-flagsonly.ttf
new file mode 100644
index 0000000..6e1642e
Binary files /dev/null and b/apps/web/public/fonts/NotoColorEmoji-flagsonly.ttf differ
diff --git a/apps/web/public/fonts/TwemojiMozilla-flags.woff2 b/apps/web/public/fonts/TwemojiMozilla-flags.woff2
new file mode 100644
index 0000000..b87c4ce
Binary files /dev/null and b/apps/web/public/fonts/TwemojiMozilla-flags.woff2 differ