feat(dashboard): compact vertical map legend, clickable node detail popup, and full 6-bar labels in Top Apps/Protocols
This commit is contained in:
1 parent
6f50522173
commit
2482e0c670
3 files changed
+356
-262
No files matched your search
@@ -3,10 +3,9 @@
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/Card";
|
||||
import {
|
||||
ResponsiveContainer, BarChart, Bar, CartesianGrid, XAxis, YAxis,
|
||||
Tooltip as RechartsTooltip, PieChart, Pie, Cell
|
||||
Tooltip as RechartsTooltip, Cell
|
||||
} from "recharts";
|
||||
import { fmtBytes, formatAppLabel } from "@/lib/utils";
|
||||
|
||||
import { AppStat, ProtocolStat } from "@/lib/api-types";
|
||||
|
||||
interface TopWidgetsProps {
|
||||
@@ -18,11 +17,13 @@ interface TopWidgetsProps {
|
||||
};
|
||||
}
|
||||
|
||||
const COLORS = ['#3b82f6', '#10b981', '#f59e0b', '#8b5cf6', '#ec4899', '#3b82f6'];
|
||||
const APP_COLORS = ['#8b5cf6', '#3b82f6', '#06b6d4', '#10b981', '#f59e0b', '#ec4899', '#6366f1'];
|
||||
const PROTO_COLORS = ['#10b981', '#14b8a6', '#0ea5e9', '#8b5cf6', '#f59e0b', '#f43f5e', '#6366f1'];
|
||||
|
||||
export function TopWidgets({ topApps, topProtocols }: TopWidgetsProps) {
|
||||
const appsData = (topApps.data || []).map(app => ({
|
||||
...app,
|
||||
display_label: formatAppLabel(app.app_label),
|
||||
total_bytes: (app.download || 0) + (app.upload || 0)
|
||||
}));
|
||||
|
||||
@@ -30,124 +31,167 @@ export function TopWidgets({ topApps, topProtocols }: TopWidgetsProps) {
|
||||
...p,
|
||||
total: (p.download || 0) + (p.upload || 0)
|
||||
}));
|
||||
|
||||
return (
|
||||
<div className="col-span-1 lg:col-span-3 space-y-6 w-full min-w-0">
|
||||
<Card className="bg-card/80 backdrop-blur-xl border-border/50 flex-1 min-w-0">
|
||||
<CardHeader>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-lg text-white">Top Apps</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="w-full min-w-0">
|
||||
<CardContent className="w-full min-w-0 space-y-3">
|
||||
{(!appsData || appsData.length === 0) ? (
|
||||
<div className="h-[150px] flex items-center justify-center text-muted-foreground text-sm">
|
||||
No Data
|
||||
</div>
|
||||
) : (
|
||||
<div className="h-[150px] w-full min-w-0 relative">
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<BarChart data={appsData} margin={{ top: 10, right: 10, left: 0, bottom: 0 }}>
|
||||
<CartesianGrid strokeDasharray="3 3" stroke="rgba(255,255,255,0.05)" vertical={false} />
|
||||
<XAxis
|
||||
dataKey="app_label"
|
||||
stroke="#a1a1aa"
|
||||
fontSize={11}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickMargin={5}
|
||||
tickFormatter={(val) => {
|
||||
const formatted = formatAppLabel(val);
|
||||
return formatted.length > 12 ? `${formatted.substring(0, 10)}...` : formatted;
|
||||
}}
|
||||
/>
|
||||
<YAxis
|
||||
stroke="#a1a1aa"
|
||||
fontSize={11}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickFormatter={(value) => {
|
||||
if (value === 0) return '0';
|
||||
const k = 1024;
|
||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
||||
const i = Math.floor(Math.log(value) / Math.log(k));
|
||||
const scaled = parseFloat((value / Math.pow(k, i)).toFixed(1));
|
||||
return `${scaled}${sizes[i].charAt(0)}`;
|
||||
}}
|
||||
/>
|
||||
<RechartsTooltip
|
||||
cursor={{fill: 'rgba(255,255,255,0.05)'}}
|
||||
contentStyle={{
|
||||
backgroundColor: 'rgba(24, 24, 27, 0.9)',
|
||||
backdropFilter: 'blur(10px)',
|
||||
border: '1px solid rgba(255, 255, 255, 0.1)',
|
||||
borderRadius: '8px',
|
||||
color: '#fafafa',
|
||||
}}
|
||||
itemStyle={{ color: '#fafafa', fontSize: '13px', fontWeight: 500 }}
|
||||
formatter={(value: any) => [fmtBytes(value as number), 'Total Bandwidth']}
|
||||
/>
|
||||
<Bar dataKey="total_bytes" fill="#8b5cf6" radius={[4, 4, 0, 0]} />
|
||||
</BarChart>
|
||||
</ResponsiveContainer>
|
||||
</div>
|
||||
<>
|
||||
<div className="h-[155px] w-full min-w-0 relative">
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<BarChart data={appsData} margin={{ top: 10, right: 10, left: 0, bottom: 8 }}>
|
||||
<CartesianGrid strokeDasharray="3 3" stroke="rgba(255,255,255,0.05)" vertical={false} />
|
||||
<XAxis
|
||||
dataKey="display_label"
|
||||
stroke="#a1a1aa"
|
||||
fontSize={9.5}
|
||||
interval={0}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickMargin={6}
|
||||
tickFormatter={(val) => {
|
||||
const str = String(val || '');
|
||||
return str.length > 9 ? `${str.substring(0, 8)}..` : str;
|
||||
}}
|
||||
/>
|
||||
<YAxis
|
||||
stroke="#a1a1aa"
|
||||
fontSize={10}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickFormatter={(value) => {
|
||||
if (value === 0) return '0';
|
||||
const k = 1024;
|
||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
||||
const i = Math.floor(Math.log(value) / Math.log(k));
|
||||
const scaled = parseFloat((value / Math.pow(k, i)).toFixed(1));
|
||||
return `${scaled}${sizes[i].charAt(0)}`;
|
||||
}}
|
||||
/>
|
||||
<RechartsTooltip
|
||||
cursor={{fill: 'rgba(255,255,255,0.05)'}}
|
||||
contentStyle={{
|
||||
backgroundColor: 'rgba(24, 24, 27, 0.92)',
|
||||
backdropFilter: 'blur(10px)',
|
||||
border: '1px solid rgba(255, 255, 255, 0.1)',
|
||||
borderRadius: '8px',
|
||||
color: '#fafafa',
|
||||
}}
|
||||
itemStyle={{ color: '#fafafa', fontSize: '12px', fontWeight: 500 }}
|
||||
formatter={(value: any) => [fmtBytes(value as number), 'Total Bandwidth']}
|
||||
/>
|
||||
<Bar dataKey="total_bytes" radius={[4, 4, 0, 0]}>
|
||||
{appsData.map((_, idx) => (
|
||||
<Cell key={`app-cell-${idx}`} fill={APP_COLORS[idx % APP_COLORS.length]} />
|
||||
))}
|
||||
</Bar>
|
||||
</BarChart>
|
||||
</ResponsiveContainer>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-x-3 gap-y-1 pt-1 border-t border-white/5 text-[10px]">
|
||||
{appsData.map((app, idx) => (
|
||||
<div key={`app-leg-${idx}`} className="flex items-center justify-between gap-1.5 min-w-0">
|
||||
<span className="flex items-center gap-1.5 truncate text-slate-300">
|
||||
<span
|
||||
className="inline-block h-2 w-2 shrink-0 rounded-full"
|
||||
style={{ backgroundColor: APP_COLORS[idx % APP_COLORS.length] }}
|
||||
/>
|
||||
<span className="truncate" title={app.display_label}>{app.display_label}</span>
|
||||
</span>
|
||||
<span className="font-mono text-slate-400 shrink-0">{fmtBytes(app.total_bytes)}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card className="bg-card/80 backdrop-blur-xl border-border/50 flex-1 min-w-0">
|
||||
<CardHeader>
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-lg text-white">Top Protocols</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="w-full min-w-0">
|
||||
<CardContent className="w-full min-w-0 space-y-3">
|
||||
{(!protocolsData || protocolsData.length === 0) ? (
|
||||
<div className="h-[150px] flex items-center justify-center text-muted-foreground text-sm">
|
||||
No Data
|
||||
</div>
|
||||
) : (
|
||||
<div className="h-[150px] w-full min-w-0 relative">
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<BarChart data={protocolsData} margin={{ top: 10, right: 10, left: 0, bottom: 0 }}>
|
||||
<CartesianGrid strokeDasharray="3 3" stroke="rgba(255,255,255,0.05)" vertical={false} />
|
||||
<XAxis
|
||||
dataKey="protocol_label"
|
||||
stroke="#a1a1aa"
|
||||
fontSize={11}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickMargin={5}
|
||||
tickFormatter={(val) => {
|
||||
const formatted = val || '';
|
||||
return formatted.length > 12 ? `${formatted.substring(0, 10)}...` : formatted;
|
||||
}}
|
||||
/>
|
||||
<YAxis
|
||||
stroke="#a1a1aa"
|
||||
fontSize={11}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickFormatter={(value) => {
|
||||
if (value === 0) return '0';
|
||||
const k = 1024;
|
||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
||||
const i = Math.floor(Math.log(value) / Math.log(k));
|
||||
const scaled = parseFloat((value / Math.pow(k, i)).toFixed(1));
|
||||
return `${scaled}${sizes[i].charAt(0)}`;
|
||||
}}
|
||||
/>
|
||||
<RechartsTooltip
|
||||
cursor={{fill: 'rgba(255,255,255,0.05)'}}
|
||||
contentStyle={{
|
||||
backgroundColor: 'rgba(24, 24, 27, 0.9)',
|
||||
backdropFilter: 'blur(10px)',
|
||||
border: '1px solid rgba(255, 255, 255, 0.1)',
|
||||
borderRadius: '8px',
|
||||
color: '#fafafa',
|
||||
}}
|
||||
itemStyle={{ color: '#fafafa', fontSize: '13px', fontWeight: 500 }}
|
||||
formatter={(value: any) => [fmtBytes(value as number), 'Total Traffic']}
|
||||
/>
|
||||
<Bar dataKey="total" fill="#10b981" radius={[4, 4, 0, 0]} />
|
||||
</BarChart>
|
||||
</ResponsiveContainer>
|
||||
</div>
|
||||
<>
|
||||
<div className="h-[155px] w-full min-w-0 relative">
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<BarChart data={protocolsData} margin={{ top: 10, right: 10, left: 0, bottom: 8 }}>
|
||||
<CartesianGrid strokeDasharray="3 3" stroke="rgba(255,255,255,0.05)" vertical={false} />
|
||||
<XAxis
|
||||
dataKey="protocol_label"
|
||||
stroke="#a1a1aa"
|
||||
fontSize={9.5}
|
||||
interval={0}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickMargin={6}
|
||||
tickFormatter={(val) => {
|
||||
const formatted = String(val || '');
|
||||
return formatted.length > 9 ? `${formatted.substring(0, 8)}..` : formatted;
|
||||
}}
|
||||
/>
|
||||
<YAxis
|
||||
stroke="#a1a1aa"
|
||||
fontSize={10}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickFormatter={(value) => {
|
||||
if (value === 0) return '0';
|
||||
const k = 1024;
|
||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
||||
const i = Math.floor(Math.log(value) / Math.log(k));
|
||||
const scaled = parseFloat((value / Math.pow(k, i)).toFixed(1));
|
||||
return `${scaled}${sizes[i].charAt(0)}`;
|
||||
}}
|
||||
/>
|
||||
<RechartsTooltip
|
||||
cursor={{fill: 'rgba(255,255,255,0.05)'}}
|
||||
contentStyle={{
|
||||
backgroundColor: 'rgba(24, 24, 27, 0.92)',
|
||||
backdropFilter: 'blur(10px)',
|
||||
border: '1px solid rgba(255, 255, 255, 0.1)',
|
||||
borderRadius: '8px',
|
||||
color: '#fafafa',
|
||||
}}
|
||||
itemStyle={{ color: '#fafafa', fontSize: '12px', fontWeight: 500 }}
|
||||
formatter={(value: any) => [fmtBytes(value as number), 'Total Traffic']}
|
||||
/>
|
||||
<Bar dataKey="total" radius={[4, 4, 0, 0]}>
|
||||
{protocolsData.map((_, idx) => (
|
||||
<Cell key={`proto-cell-${idx}`} fill={PROTO_COLORS[idx % PROTO_COLORS.length]} />
|
||||
))}
|
||||
</Bar>
|
||||
</BarChart>
|
||||
</ResponsiveContainer>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-x-3 gap-y-1 pt-1 border-t border-white/5 text-[10px]">
|
||||
{protocolsData.map((proto, idx) => (
|
||||
<div key={`proto-leg-${idx}`} className="flex items-center justify-between gap-1.5 min-w-0">
|
||||
<span className="flex items-center gap-1.5 truncate text-slate-300">
|
||||
<span
|
||||
className="inline-block h-2 w-2 shrink-0 rounded-full"
|
||||
style={{ backgroundColor: PROTO_COLORS[idx % PROTO_COLORS.length] }}
|
||||
/>
|
||||
<span className="truncate" title={proto.protocol_label}>{proto.protocol_label}</span>
|
||||
</span>
|
||||
<span className="font-mono text-slate-400 shrink-0">{fmtBytes(proto.total)}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
+150
-115
@@ -3,7 +3,9 @@
|
||||
import React, { useState } from 'react';
|
||||
import { ComposableMap, Geographies, Geography, Line, Marker, ZoomableGroup } from "react-simple-maps";
|
||||
import { useTheme } from "next-themes";
|
||||
import { useGlobeData, GlobeDataInput } from './useGlobeData';
|
||||
import { X, MapPin, ArrowDownLeft, ArrowUpRight, Activity } from "lucide-react";
|
||||
import { fmtBytes } from "@/lib/utils";
|
||||
import { useGlobeData, GlobeDataInput, GlobePointData } from './useGlobeData';
|
||||
|
||||
const geoUrl = "/ne_110m_admin_0_countries.geojson";
|
||||
|
||||
@@ -14,15 +16,12 @@ interface GlobeMapProps {
|
||||
export const GlobeMap = ({ data }: GlobeMapProps) => {
|
||||
const { theme } = useTheme();
|
||||
const isLight = theme === 'light';
|
||||
|
||||
const [position, setPosition] = useState({ coordinates: [0, 20], zoom: 1 });
|
||||
function handleMoveEnd(newPosition: any) {
|
||||
setPosition(newPosition);
|
||||
}
|
||||
const [selectedPoint, setSelectedPoint] = useState<GlobePointData | null>(null);
|
||||
|
||||
const { arcsData, pointsData, labelsData } = useGlobeData(data, isLight);
|
||||
const destPoints = pointsData.filter((pt: any) => !pt.isOrigin);
|
||||
const originPoints = pointsData.filter((pt: any) => pt.isOrigin);
|
||||
const destPoints = pointsData.filter((pt) => !pt.isOrigin);
|
||||
const originPoints = pointsData.filter((pt) => pt.isOrigin);
|
||||
|
||||
const mapBorderColor = isLight ? "#ffffff" : "#0ea5e9";
|
||||
const mapFillColor = isLight ? "#4ade80" : "#0f172a";
|
||||
@@ -31,28 +30,12 @@ export const GlobeMap = ({ data }: GlobeMapProps) => {
|
||||
return (
|
||||
<div className="relative w-full h-[500px] rounded-xl overflow-hidden bg-transparent flex items-center justify-center cursor-grab active:cursor-grabbing">
|
||||
<style>{`
|
||||
@keyframes flowDashGlobe {
|
||||
to {
|
||||
stroke-dashoffset: -100;
|
||||
}
|
||||
}
|
||||
@keyframes flowDashGlobe { to { stroke-dashoffset: -100; } }
|
||||
@keyframes pulseOriginRing {
|
||||
0% {
|
||||
transform: scale(0.8);
|
||||
opacity: 0.9;
|
||||
}
|
||||
70% {
|
||||
transform: scale(2.2);
|
||||
opacity: 0;
|
||||
}
|
||||
100% {
|
||||
transform: scale(2.2);
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
.globe-animated-line {
|
||||
animation: flowDashGlobe 1.5s linear infinite;
|
||||
0% { transform: scale(0.8); opacity: 0.9; }
|
||||
70%, 100% { transform: scale(2.2); opacity: 0; }
|
||||
}
|
||||
.globe-animated-line { animation: flowDashGlobe 1.5s linear infinite; }
|
||||
.globe-origin-pulse {
|
||||
animation: pulseOriginRing 2s cubic-bezier(0, 0, 0.2, 1) infinite;
|
||||
transform-origin: center;
|
||||
@@ -61,45 +44,43 @@ export const GlobeMap = ({ data }: GlobeMapProps) => {
|
||||
`}</style>
|
||||
<ComposableMap
|
||||
projection="geoMercator"
|
||||
projectionConfig={{
|
||||
scale: 120,
|
||||
center: [0, 20]
|
||||
}}
|
||||
projectionConfig={{ scale: 120, center: [0, 20] }}
|
||||
width={800}
|
||||
height={500}
|
||||
style={{ width: "100%", height: "100%", outline: "none" }}
|
||||
>
|
||||
<ZoomableGroup
|
||||
zoom={position.zoom}
|
||||
center={position.coordinates as [number, number]}
|
||||
onMoveEnd={handleMoveEnd}
|
||||
minZoom={1}
|
||||
<ZoomableGroup
|
||||
zoom={position.zoom}
|
||||
center={position.coordinates as [number, number]}
|
||||
onMoveEnd={setPosition}
|
||||
minZoom={1}
|
||||
maxZoom={8}
|
||||
>
|
||||
<Geographies geography={geoUrl}>
|
||||
{({ geographies }) =>
|
||||
geographies.map((geo) => (
|
||||
<Geography
|
||||
key={geo.rsmKey}
|
||||
geography={geo}
|
||||
fill={mapFillColor}
|
||||
stroke={mapBorderColor}
|
||||
strokeWidth={0.5}
|
||||
style={{
|
||||
default: { outline: "none" },
|
||||
hover: { fill: mapHoverFill, outline: "none" },
|
||||
pressed: { outline: "none" },
|
||||
}}
|
||||
/>
|
||||
))
|
||||
}
|
||||
</Geographies>
|
||||
{({ geographies }) =>
|
||||
geographies.map((geo) => (
|
||||
<Geography
|
||||
key={geo.rsmKey}
|
||||
geography={geo}
|
||||
fill={mapFillColor}
|
||||
stroke={mapBorderColor}
|
||||
strokeWidth={0.5}
|
||||
onClick={() => setSelectedPoint(null)}
|
||||
style={{
|
||||
default: { outline: "none" },
|
||||
hover: { fill: mapHoverFill, outline: "none" },
|
||||
pressed: { outline: "none" },
|
||||
}}
|
||||
/>
|
||||
))
|
||||
}
|
||||
</Geographies>
|
||||
|
||||
{arcsData.map((arc: any, i: number) => {
|
||||
const isLocal = arc.startLng === arc.endLng && arc.startLat === arc.endLat;
|
||||
const color = Array.isArray(arc.color) ? arc.color[0] : arc.color || '#0ea5e9';
|
||||
const curveSign = typeof arc.curveSign === 'number' ? arc.curveSign : 1;
|
||||
|
||||
|
||||
if (isLocal) {
|
||||
return (
|
||||
<Marker key={`arc-${i}`} coordinates={[arc.startLng, arc.startLat]}>
|
||||
@@ -110,10 +91,7 @@ export const GlobeMap = ({ data }: GlobeMapProps) => {
|
||||
|
||||
const coordinates: [number, number][] = [];
|
||||
const steps = 30;
|
||||
const dist = Math.sqrt(
|
||||
Math.pow(arc.endLng - arc.startLng, 2) +
|
||||
Math.pow(arc.endLat - arc.startLat, 2)
|
||||
);
|
||||
const dist = Math.hypot(arc.endLng - arc.startLng, arc.endLat - arc.startLat);
|
||||
const height = Math.min(dist * 0.15, 25);
|
||||
|
||||
for (let j = 0; j <= steps; j++) {
|
||||
@@ -138,68 +116,125 @@ export const GlobeMap = ({ data }: GlobeMapProps) => {
|
||||
);
|
||||
})}
|
||||
|
||||
{/* External Country Destination Markers */}
|
||||
{destPoints.map((pt: any, i: number) => (
|
||||
<Marker key={`dest-marker-${i}`} coordinates={[pt.lng, pt.lat]}>
|
||||
<circle r={6} fill={pt.color} opacity={0.22} />
|
||||
<circle r={3.2} fill={pt.color} stroke="#0f172a" strokeWidth={0.8} opacity={0.95} />
|
||||
</Marker>
|
||||
))}
|
||||
|
||||
{/* Agent Server Origin Markers (Rendered on top with large pulsing red beacon) */}
|
||||
{originPoints.map((pt: any, i: number) => (
|
||||
<Marker key={`origin-marker-${i}`} coordinates={[pt.lng, pt.lat]}>
|
||||
<circle r={11} fill="#f43f5e" opacity={0.35} className="globe-origin-pulse" />
|
||||
<circle r={8} fill="#f43f5e" opacity={0.25} />
|
||||
<circle r={5.2} fill="#f43f5e" stroke="#ffffff" strokeWidth={1.5} />
|
||||
</Marker>
|
||||
))}
|
||||
|
||||
{labelsData.map((lbl: any, i: number) => (
|
||||
<Marker key={`label-${i}`} coordinates={[lbl.lng, lbl.lat]}>
|
||||
<text
|
||||
textAnchor="middle"
|
||||
y={-12}
|
||||
style={{
|
||||
fontFamily: "system-ui",
|
||||
fill: lbl.color,
|
||||
fontSize: `${lbl.size * 6}px`,
|
||||
fontWeight: "bold",
|
||||
pointerEvents: "none"
|
||||
}}
|
||||
{destPoints.map((pt, i) => (
|
||||
<Marker
|
||||
key={`dest-marker-${i}`}
|
||||
coordinates={[pt.lng, pt.lat]}
|
||||
onClick={(e) => { e.stopPropagation(); setSelectedPoint(pt); }}
|
||||
style={{ default: { cursor: "pointer" }, hover: { cursor: "pointer" }, pressed: { cursor: "pointer" } }}
|
||||
>
|
||||
{lbl.name}
|
||||
</text>
|
||||
</Marker>
|
||||
))}
|
||||
<circle r={9} fill="transparent" />
|
||||
<circle r={6} fill={pt.color} opacity={0.25} />
|
||||
<circle r={3.5} fill={pt.color} stroke="#ffffff" strokeWidth={1} opacity={0.98} />
|
||||
</Marker>
|
||||
))}
|
||||
|
||||
{originPoints.map((pt, i) => (
|
||||
<Marker
|
||||
key={`origin-marker-${i}`}
|
||||
coordinates={[pt.lng, pt.lat]}
|
||||
onClick={(e) => { e.stopPropagation(); setSelectedPoint(pt); }}
|
||||
style={{ default: { cursor: "pointer" }, hover: { cursor: "pointer" }, pressed: { cursor: "pointer" } }}
|
||||
>
|
||||
<circle r={12} fill="transparent" />
|
||||
<circle r={11} fill="#f43f5e" opacity={0.35} className="globe-origin-pulse" />
|
||||
<circle r={8} fill="#f43f5e" opacity={0.25} />
|
||||
<circle r={5.2} fill="#f43f5e" stroke="#ffffff" strokeWidth={1.5} />
|
||||
</Marker>
|
||||
))}
|
||||
|
||||
{labelsData.map((lbl: any, i: number) => (
|
||||
<Marker
|
||||
key={`label-${i}`}
|
||||
coordinates={[lbl.lng, lbl.lat]}
|
||||
onClick={(e) => { e.stopPropagation(); if (lbl.point) setSelectedPoint(lbl.point); }}
|
||||
style={{ default: { cursor: "pointer" }, hover: { cursor: "pointer" }, pressed: { cursor: "pointer" } }}
|
||||
>
|
||||
<text
|
||||
textAnchor="middle"
|
||||
y={-12}
|
||||
style={{ fontFamily: "system-ui", fill: lbl.color, fontSize: `${lbl.size * 6}px`, fontWeight: "bold" }}
|
||||
>
|
||||
{lbl.name}
|
||||
</text>
|
||||
</Marker>
|
||||
))}
|
||||
</ZoomableGroup>
|
||||
</ComposableMap>
|
||||
|
||||
{/* Keterangan / Noted Warna & Cara Baca Peta */}
|
||||
<div className="absolute bottom-3 left-3 right-3 sm:right-auto z-20 rounded-xl border border-white/15 bg-slate-950/90 px-3.5 py-2.5 text-[11px] text-slate-200 shadow-xl backdrop-blur-md">
|
||||
<div className="mb-1.5 text-[10px] font-bold uppercase tracking-wider text-slate-400">
|
||||
Keterangan Peta & Warna (Cara Baca):
|
||||
{selectedPoint && (
|
||||
<div className="absolute top-3 right-3 z-30 w-60 rounded-xl border border-white/15 bg-slate-950/95 p-3 text-slate-200 shadow-2xl backdrop-blur-md animate-fade-in">
|
||||
<div className="flex items-start justify-between gap-2 border-b border-white/10 pb-2">
|
||||
<div className="min-w-0">
|
||||
<span
|
||||
className={`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[9px] font-bold uppercase tracking-wider ${
|
||||
selectedPoint.isOrigin
|
||||
? "bg-rose-500/20 text-rose-400 border border-rose-500/30"
|
||||
: "bg-sky-500/20 text-sky-400 border border-sky-500/30"
|
||||
}`}
|
||||
>
|
||||
<MapPin className="h-2.5 w-2.5" />
|
||||
{selectedPoint.isOrigin ? "Lokasi Server Agent" : "Negara Tujuan / Luar"}
|
||||
</span>
|
||||
<h4 className="mt-1 text-xs font-bold text-white break-words">{selectedPoint.name}</h4>
|
||||
<p className="text-[9px] font-mono text-slate-400">
|
||||
Lat: {selectedPoint.lat.toFixed(4)}, Lng: {selectedPoint.lng.toFixed(4)}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSelectedPoint(null)}
|
||||
className="rounded-lg p-1 text-slate-400 hover:bg-white/10 hover:text-white transition-colors"
|
||||
aria-label="Close detail"
|
||||
>
|
||||
<X className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
<div className="mt-2 space-y-1 text-[10px]">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="flex items-center gap-1 text-emerald-400">
|
||||
<ArrowDownLeft className="h-3 w-3" /> Download (Luar → Agent)
|
||||
</span>
|
||||
<span className="font-mono font-semibold text-emerald-400">{fmtBytes(selectedPoint.download || 0)}</span>
|
||||
</div>
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="flex items-center gap-1 text-sky-400">
|
||||
<ArrowUpRight className="h-3 w-3" /> Upload (Agent → Luar)
|
||||
</span>
|
||||
<span className="font-mono font-semibold text-sky-400">{fmtBytes(selectedPoint.upload || 0)}</span>
|
||||
</div>
|
||||
<div className="flex items-center justify-between border-t border-white/10 pt-1">
|
||||
<span className="flex items-center gap-1 text-slate-300 font-medium">
|
||||
<Activity className="h-3 w-3 text-purple-400" /> Total Trafik
|
||||
</span>
|
||||
<span className="font-mono font-bold text-white">
|
||||
{fmtBytes((selectedPoint.download || 0) + (selectedPoint.upload || 0))}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-x-5 gap-y-1.5">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="relative flex h-3 w-3 shrink-0 items-center justify-center">
|
||||
<span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-rose-400 opacity-75" />
|
||||
<span className="relative inline-flex h-2.5 w-2.5 rounded-full border border-white bg-rose-500" />
|
||||
</span>
|
||||
<span><strong className="text-rose-400">Titik Merah:</strong> Lokasi Server Agent</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="inline-block h-2.5 w-2.5 shrink-0 rounded-full border border-slate-900 bg-sky-400" />
|
||||
<span><strong className="text-sky-400">Titik Biru:</strong> Negara Tujuan / Luar</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="inline-block h-1 w-5 shrink-0 rounded-full bg-sky-400 shadow-[0_0_6px_#38bdf8]" />
|
||||
<span><strong className="text-sky-400">Garis Biru (→):</strong> Upload (Agent ke Luar)</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="inline-block h-1 w-5 shrink-0 rounded-full bg-emerald-400 shadow-[0_0_6px_#34d399]" />
|
||||
<span><strong className="text-emerald-400">Garis Hijau (←):</strong> Download (Luar ke Agent)</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Legenda Berderet ke Bawah */}
|
||||
<div className="absolute bottom-3 left-3 z-20 flex flex-col gap-1 rounded-lg border border-white/10 bg-slate-950/85 px-2.5 py-2 text-[9px] leading-tight text-slate-300 shadow-lg backdrop-blur-md">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="relative flex h-2.5 w-2.5 shrink-0 items-center justify-center">
|
||||
<span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-rose-400 opacity-75" />
|
||||
<span className="relative inline-flex h-2 w-2 rounded-full border border-white bg-rose-500" />
|
||||
</span>
|
||||
<span><strong className="text-rose-400">Titik Merah:</strong> Lokasi Server Agent</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="inline-block h-2 w-2 shrink-0 rounded-full border border-white/80 bg-sky-400" />
|
||||
<span><strong className="text-sky-400">Titik Biru:</strong> Negara Tujuan / Luar</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="inline-block h-0.5 w-3.5 shrink-0 rounded-full bg-sky-400" />
|
||||
<span><strong className="text-sky-400">Garis Biru (→):</strong> Upload (Agent ke Luar)</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="inline-block h-0.5 w-3.5 shrink-0 rounded-full bg-emerald-400" />
|
||||
<span><strong className="text-emerald-400">Garis Hijau (←):</strong> Download (Luar ke Agent)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -17,6 +17,19 @@ export interface GlobeDataInput {
|
||||
curveSign?: number;
|
||||
}
|
||||
|
||||
export interface GlobePointData {
|
||||
lat: number;
|
||||
lng: number;
|
||||
size: number;
|
||||
color: string;
|
||||
name: string;
|
||||
value: number;
|
||||
upload: number;
|
||||
download: number;
|
||||
isOrigin: boolean;
|
||||
countryCode?: string;
|
||||
}
|
||||
|
||||
export function useGlobeData(data: GlobeDataInput[], isLight: boolean) {
|
||||
const arcsData = useMemo(() => {
|
||||
return data.map(d => {
|
||||
@@ -32,9 +45,9 @@ export function useGlobeData(data: GlobeDataInput[], isLight: boolean) {
|
||||
}, [data, isLight]);
|
||||
|
||||
const pointsData = useMemo(() => {
|
||||
const points: any[] = [];
|
||||
const originSet = new Set<string>();
|
||||
const destSet = new Set<string>();
|
||||
const originMap = new Map<string, GlobePointData>();
|
||||
const destMap = new Map<string, GlobePointData>();
|
||||
const pairSeen = new Set<string>();
|
||||
|
||||
arcsData.forEach(arc => {
|
||||
const isInbound = arc.direction === 'inbound';
|
||||
@@ -48,24 +61,33 @@ export function useGlobeData(data: GlobeDataInput[], isLight: boolean) {
|
||||
|
||||
const originKey = `${agentLat},${agentLng}`;
|
||||
const destKey = `${extLat},${extLng}`;
|
||||
|
||||
if (!destSet.has(destKey)) {
|
||||
points.push({
|
||||
const pairKey = `${originKey}->${destKey}`;
|
||||
const isFirstForPair = !pairSeen.has(pairKey);
|
||||
if (isFirstForPair) pairSeen.add(pairKey);
|
||||
|
||||
if (!destMap.has(destKey)) {
|
||||
destMap.set(destKey, {
|
||||
lat: extLat,
|
||||
lng: extLng,
|
||||
size: 0.1,
|
||||
color: isLight ? '#0284c7' : '#38bdf8',
|
||||
name: extLabel,
|
||||
value: arc.value,
|
||||
upload: arc.upload,
|
||||
download: arc.download,
|
||||
isOrigin: false
|
||||
value: 0,
|
||||
upload: 0,
|
||||
download: 0,
|
||||
isOrigin: false,
|
||||
countryCode: arc.countryCode,
|
||||
});
|
||||
destSet.add(destKey);
|
||||
}
|
||||
|
||||
if (!originSet.has(originKey)) {
|
||||
points.push({
|
||||
if (isFirstForPair) {
|
||||
const dp = destMap.get(destKey)!;
|
||||
dp.download += (arc.download || 0);
|
||||
dp.upload += (arc.upload || 0);
|
||||
dp.value = dp.download + dp.upload;
|
||||
}
|
||||
|
||||
if (!originMap.has(originKey)) {
|
||||
originMap.set(originKey, {
|
||||
lat: agentLat,
|
||||
lng: agentLng,
|
||||
size: 0.2,
|
||||
@@ -74,62 +96,55 @@ export function useGlobeData(data: GlobeDataInput[], isLight: boolean) {
|
||||
value: 0,
|
||||
upload: 0,
|
||||
download: 0,
|
||||
isOrigin: true
|
||||
isOrigin: true,
|
||||
countryCode: 'ID',
|
||||
});
|
||||
originSet.add(originKey);
|
||||
}
|
||||
if (isFirstForPair) {
|
||||
const op = originMap.get(originKey)!;
|
||||
op.download += (arc.download || 0);
|
||||
op.upload += (arc.upload || 0);
|
||||
op.value = op.download + op.upload;
|
||||
}
|
||||
});
|
||||
|
||||
return points;
|
||||
return [...Array.from(destMap.values()), ...Array.from(originMap.values())];
|
||||
}, [arcsData, isLight]);
|
||||
|
||||
const labelsData = useMemo(() => {
|
||||
const labels: any[] = [];
|
||||
const originSet = new Set();
|
||||
const destSet = new Set();
|
||||
const seen = new Set<string>();
|
||||
|
||||
arcsData.forEach(arc => {
|
||||
const isInbound = arc.direction === 'inbound';
|
||||
const agentLat = isInbound ? arc.endLat : arc.startLat;
|
||||
const agentLng = isInbound ? arc.endLng : arc.startLng;
|
||||
const agentLabel = isInbound ? arc.toLabel : arc.fromLabel;
|
||||
pointsData.forEach(pt => {
|
||||
const key = `${pt.isOrigin ? 'orig' : 'dest'}:${pt.lat},${pt.lng}`;
|
||||
if (seen.has(key)) return;
|
||||
seen.add(key);
|
||||
|
||||
const extLat = isInbound ? arc.startLat : arc.endLat;
|
||||
const extLng = isInbound ? arc.startLng : arc.endLng;
|
||||
const extLabel = isInbound ? arc.fromLabel : arc.toLabel;
|
||||
|
||||
const originKey = `${agentLat},${agentLng}`;
|
||||
const destKey = `${extLat},${extLng}`;
|
||||
|
||||
if (!destSet.has(destKey)) {
|
||||
// Shift and stagger coordinates (Southeast Asia, Europe, Caribbean, Indian Ocean, Latin America)
|
||||
const { lat, lng } = getStaggeredCoordinates(arc.countryCode || '', extLat, extLng);
|
||||
const size = SMALL_LABEL_COUNTRIES.has(arc.countryCode || '') ? 0.9 : 1.4;
|
||||
|
||||
if (!pt.isOrigin) {
|
||||
const { lat, lng } = getStaggeredCoordinates(pt.countryCode || '', pt.lat, pt.lng);
|
||||
const size = SMALL_LABEL_COUNTRIES.has(pt.countryCode || '') ? 0.9 : 1.4;
|
||||
labels.push({
|
||||
lat,
|
||||
lng,
|
||||
name: extLabel,
|
||||
name: pt.name,
|
||||
color: isLight ? '#0f172a' : '#f8fafc',
|
||||
size
|
||||
size,
|
||||
point: pt,
|
||||
});
|
||||
destSet.add(destKey);
|
||||
}
|
||||
|
||||
if (!originSet.has(originKey)) {
|
||||
} else {
|
||||
labels.push({
|
||||
lat: agentLat,
|
||||
lng: agentLng,
|
||||
name: agentLabel,
|
||||
lat: pt.lat,
|
||||
lng: pt.lng,
|
||||
name: pt.name,
|
||||
color: isLight ? '#0f172a' : '#f8fafc',
|
||||
size: 1.4
|
||||
size: 1.4,
|
||||
point: pt,
|
||||
});
|
||||
originSet.add(originKey);
|
||||
}
|
||||
});
|
||||
|
||||
return labels;
|
||||
}, [arcsData, isLight]);
|
||||
}, [pointsData, isLight]);
|
||||
|
||||
return { arcsData, pointsData, labelsData };
|
||||
}
|
||||
Reference in new issue
Block a user