diff --git a/src/app/(dashboard)/page.tsx b/src/app/(dashboard)/page.tsx index c2a3ab3..b8f5355 100644 --- a/src/app/(dashboard)/page.tsx +++ b/src/app/(dashboard)/page.tsx @@ -125,6 +125,49 @@ export default function SummaryPage() { const arcs: any[] = []; const minShareThreshold = countries.data.length > 3 ? totalTraffic * 0.0025 : 0; + const pushBidirectionalArcs = ( + origin: GeoLocation, + dest: GeoLocation, + downloadBytes: number, + uploadBytes: number, + countryCode: string + ) => { + const dl = downloadBytes || 0; + const ul = uploadBytes || 0; + if (ul > 0) { + arcs.push({ + startLat: origin.lat, + startLng: origin.lng, + endLat: dest.lat, + endLng: dest.lng, + fromLabel: origin.label, + toLabel: dest.label, + value: ul, + download: dl, + upload: ul, + countryCode, + direction: 'outbound', + curveSign: 1, + }); + } + if (dl > 0) { + arcs.push({ + startLat: dest.lat, + startLng: dest.lng, + endLat: origin.lat, + endLng: origin.lng, + fromLabel: dest.label, + toLabel: origin.label, + value: dl, + download: dl, + upload: ul, + countryCode, + direction: 'inbound', + curveSign: -0.65, + }); + } + }; + for (const row of countries.data) { const traffic = (row.download || 0) + (row.upload || 0); if (traffic === 0 || traffic < minShareThreshold) continue; @@ -134,50 +177,17 @@ export default function SummaryPage() { if (activeAgentUuid) { const origin = resolveOriginForAgent(activeAgentUuid, activeAgentLabel); - arcs.push({ - startLat: origin.lat, - startLng: origin.lng, - endLat: dest.lat, - endLng: dest.lng, - fromLabel: origin.label, - toLabel: dest.label, - value: traffic, - download: row.download, - upload: row.upload, - countryCode: row.country_code, - }); + pushBidirectionalArcs(origin, dest, row.download, row.upload, row.country_code); } else if (Array.isArray(row.agent_breakdown) && row.agent_breakdown.length > 0) { for (const ag of row.agent_breakdown) { const agTraffic = (ag.download || 0) + (ag.upload || 0); if (agTraffic === 0) continue; const origin = resolveOriginForAgent(ag.agent_uuid); - arcs.push({ - startLat: origin.lat, - startLng: origin.lng, - endLat: dest.lat, - endLng: dest.lng, - fromLabel: origin.label, - toLabel: dest.label, - value: agTraffic, - download: ag.download, - upload: ag.upload, - countryCode: row.country_code, - }); + pushBidirectionalArcs(origin, dest, ag.download, ag.upload, row.country_code); } } else { const origin = resolveOriginForAgent(null); - arcs.push({ - startLat: origin.lat, - startLng: origin.lng, - endLat: dest.lat, - endLng: dest.lng, - fromLabel: origin.label, - toLabel: dest.label, - value: traffic, - download: row.download, - upload: row.upload, - countryCode: row.country_code, - }); + pushBidirectionalArcs(origin, dest, row.download, row.upload, row.country_code); } } diff --git a/src/components/ui/GlobeMap.tsx b/src/components/ui/GlobeMap.tsx index e049124..b471d59 100644 --- a/src/components/ui/GlobeMap.tsx +++ b/src/components/ui/GlobeMap.tsx @@ -1,6 +1,6 @@ "use client"; -import React, { useMemo, useState } from 'react'; +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'; @@ -22,7 +22,6 @@ export const GlobeMap = ({ data }: GlobeMapProps) => { const { arcsData, pointsData, labelsData } = useGlobeData(data, isLight); - const mapBgColor = "transparent"; const mapBorderColor = isLight ? "#ffffff" : "#0ea5e9"; const mapFillColor = isLight ? "#4ade80" : "#0f172a"; const mapHoverFill = isLight ? "#22c55e" : "#1e293b"; @@ -78,6 +77,7 @@ export const GlobeMap = ({ data }: GlobeMapProps) => { {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 ( @@ -87,23 +87,18 @@ export const GlobeMap = ({ data }: GlobeMapProps) => { ); } - // Force the line to go straight across the map (the "front") - // by interpolating multiple points. This prevents d3-geo from - // wrapping around the dateline for long distances. 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 height = Math.min(dist * 0.15, 25); + for (let j = 0; j <= steps; j++) { const t = j / steps; - let lng = arc.startLng + (arc.endLng - arc.startLng) * t; - - // Dynamic arc height based on distance - const dist = Math.sqrt( - Math.pow(arc.endLng - arc.startLng, 2) + - Math.pow(arc.endLat - arc.startLat, 2) - ); - const height = Math.min(dist * 0.15, 25); - let lat = arc.startLat + (arc.endLat - arc.startLat) * t + Math.sin(t * Math.PI) * height; - + const lng = arc.startLng + (arc.endLng - arc.startLng) * t; + const lat = arc.startLat + (arc.endLat - arc.startLat) * t + Math.sin(t * Math.PI) * height * curveSign; coordinates.push([lng, lat]); } @@ -147,6 +142,22 @@ export const GlobeMap = ({ data }: GlobeMapProps) => { ))} + + {/* Direction & Node Legend Overlay */} +