From b7359339d3a511b84e1b3d7d9c3e83f30e5c3013 Mon Sep 17 00:00:00 2001 From: Daniel Pupius Date: Wed, 30 Apr 2025 13:10:40 -0700 Subject: [PATCH] Yet more map tweaks --- web/src/components/dashboard/NetworkMap.tsx | 97 ++------------------- web/src/lib/activity.ts | 4 +- 2 files changed, 9 insertions(+), 92 deletions(-) diff --git a/web/src/components/dashboard/NetworkMap.tsx b/web/src/components/dashboard/NetworkMap.tsx index 6bfa80f..d4d6938 100644 --- a/web/src/components/dashboard/NetworkMap.tsx +++ b/web/src/components/dashboard/NetworkMap.tsx @@ -37,12 +37,7 @@ export const NetworkMap = React.forwardRef<{ resetAutoZoom: () => void }, Networ // Get nodes data from the store const { nodes, gateways } = useAppSelector((state) => state.aggregator); - // Get the latest packet to detect when nodes receive packets - const latestPacket = useAppSelector((state) => - state.packets.packets.length > 0 ? state.packets.packets[0] : null - ); - - // Expose the resetAutoZoom function via ref + // Expose the resetAutoZoom function via ref React.useImperativeHandle(ref, () => ({ resetAutoZoom: () => { resetAutoZoom(); @@ -237,83 +232,6 @@ export const NetworkMap = React.forwardRef<{ resetAutoZoom: () => void }, Networ } }, [autoZoomEnabled, onAutoZoomChange]); - // Effect to detect when a node receives a packet and trigger animation - useEffect(() => { - if (latestPacket && latestPacket.data.from !== undefined) { - const nodeId = latestPacket.data.from; - const key = `node-${nodeId}`; - - // If we have this node on the map, animate it - if (markersRef.current[key]) { - animateNodeMarker(nodeId); - } - } - }, [latestPacket]); - - // Function to animate a node marker when it receives a packet - function animateNodeMarker(nodeId: number): void { - const key = `node-${nodeId}`; - const marker = markersRef.current[key]; - const node = nodesWithPosition.find(n => n.id === nodeId); - - if (!marker || !node) return; - - // Clear any existing animation for this node - if (animatingNodesRef.current[key]) { - clearTimeout(animatingNodesRef.current[key]); - } - - // Get the animated style - const iconStyle = getMarkerIcon(node, true); - - // Create updated content for the marker with animation style - const markerContent = document.createElement('div'); - markerContent.innerHTML = ` - - - - `; - - // Set cursor style - markerContent.style.cursor = 'pointer'; - - // Update the marker content with animated style - marker.content = markerContent; - - // Reset after a delay - animatingNodesRef.current[key] = window.setTimeout(() => { - // Reset to non-animated style - const normalStyle = getMarkerIcon(node, false); - - const normalContent = document.createElement('div'); - normalContent.innerHTML = ` - - - - `; - - normalContent.style.cursor = 'pointer'; - marker.content = normalContent; - - delete animatingNodesRef.current[key]; - }, 1000); // 1 second animation - } // Cleanup on unmount useEffect(() => { @@ -513,7 +431,7 @@ export const NetworkMap = React.forwardRef<{ resetAutoZoom: () => void }, Networ const statusDotColor = colors.fill; const infoContent = ` -
+

${nodeName}

@@ -696,17 +614,16 @@ interface MarkerIconConfig { } // Get marker icon for a node -function getMarkerIcon(node: MapNode, isAnimating: boolean = false): MarkerIconConfig { - // Get activity level and colors using the helper functions +function getMarkerIcon(node: MapNode): MarkerIconConfig { const activityLevel = getActivityLevel(node.lastHeard, node.isGateway); const colors = getNodeColors(activityLevel, node.isGateway); return { path: google.maps.SymbolPath.CIRCLE, - scale: isAnimating ? 14 : 10, // Increase size during animation + scale: 12, fillColor: colors.fill, - fillOpacity: isAnimating ? 0.8 : 1, // Slightly transparent during animation - strokeColor: isAnimating ? "#ffffff" : colors.stroke, - strokeWeight: isAnimating ? 3 : 2, // Thicker stroke during animation + fillOpacity: 0.8, + strokeColor: colors.stroke, + strokeWeight: 4, }; } diff --git a/web/src/lib/activity.ts b/web/src/lib/activity.ts index fb19500..40f41ca 100644 --- a/web/src/lib/activity.ts +++ b/web/src/lib/activity.ts @@ -29,7 +29,7 @@ export const TIME_THRESHOLDS = { // Color schemes for different node types export const COLORS = { - [NodeType.NODE]: { + [NodeType.GATEWAY]: { [ActivityLevel.RECENT]: { fill: "#4ade80", stroke: "#22c55e", @@ -58,7 +58,7 @@ export const COLORS = { statusDot: "bg-neutral-500" }, }, - [NodeType.GATEWAY]: { + [NodeType.NODE]: { [ActivityLevel.RECENT]: { "fill": "#93c5fd", "stroke": "#60a5fa",