diff --git a/web/src/sections/Ecosystem.tsx b/web/src/sections/Ecosystem.tsx index f125406..303ba09 100644 --- a/web/src/sections/Ecosystem.tsx +++ b/web/src/sections/Ecosystem.tsx @@ -1,3 +1,4 @@ +import { useEffect, useRef, useState } from 'react'; import { ArrowRight, Building2, @@ -78,62 +79,99 @@ const TRACK_LINKS: { id: TrackId; label: string }[] = [ { id: 'admin', label: 'Dla administratora' }, ]; -/** Sekcja „Ekosystem” — rdzeń (od ogółu): mapa uczestników i legenda zazębień. */ -export function Ecosystem() { - return ( -
- +interface Wire { + x1: number; + y1: number; + x2: number; + y2: number; + delay: string; +} - {/* Diagram rdzenia (lg+): przerywane wiązania z przepływem + kafelki dryfujące - niezależnie od animacji wejścia (dryf na wewnętrznym spanie) */} - - {/* Wiązania w % kontenera — końce dotykają krawędzi kafelków (w-[32%] h-[42%]) - niezależnie od szerokości (preserveAspectRatio="none" skaluje obie osie) */} +const HUB_RADIUS = 78; + +/** + * Diagram rdzenia (lg+): kafelki uczestników z naturalną wysokością (nic się nie + * ucina), przerywane wiązania mierzone w DOM (ResizeObserver) i delikatny dryf. + */ +function HubDiagram() { + const containerRef = useRef(null); + const trenerRef = useRef(null); + const silowniaRef = useRef(null); + const cwiczacyRef = useRef(null); + const [wires, setWires] = useState([]); + + useEffect(() => { + const container = containerRef.current; + if (!container) return; + + const targets = [ + { el: trenerRef.current, side: 'left' as const, delay: '0s' }, + { el: silowniaRef.current, side: 'left' as const, delay: '-0.5s' }, + { el: cwiczacyRef.current, side: 'right' as const, delay: '-0.9s' }, + ]; + + const compute = () => { + const cr = container.getBoundingClientRect(); + if (!cr.width || !cr.height) return; + const cx = cr.width / 2; + const cy = cr.height / 2; + const next: Wire[] = []; + for (const t of targets) { + if (!t.el) continue; + const r = t.el.getBoundingClientRect(); + const midX = r.left + r.width / 2 - cr.left; + const midY = r.top + r.height / 2 - cr.top; + const dx = midX - cx; + const dy = midY - cy; + const len = Math.hypot(dx, dy) || 1; + next.push({ + x1: ((cx + (dx / len) * HUB_RADIUS) / cr.width) * 100, + y1: ((cy + (dy / len) * HUB_RADIUS) / cr.height) * 100, + x2: (((t.side === 'left' ? r.right : r.left) - cr.left) / cr.width) * 100, + y2: (midY / cr.height) * 100, + delay: t.delay, + }); + } + setWires(next); + }; + + compute(); + // jsdom nie zna ResizeObserver — wystarczy jednorazowy pomiar (i tak puste recty) + if (typeof ResizeObserver !== 'undefined') { + const observer = new ResizeObserver(compute); + observer.observe(container); + window.addEventListener('resize', compute); + return () => { + observer.disconnect(); + window.removeEventListener('resize', compute); + }; + } + }, []); + + return ( + +
@@ -144,22 +182,37 @@ export function Ecosystem() {
-
-
- +
+
+
-
-
- +
+
+
-
-
- +
+
+
- +
+ + ); +} + +/** Sekcja „Ekosystem” — rdzeń (od ogółu): mapa uczestników i legenda zazębień. */ +export function Ecosystem() { + return ( +
+ + + {/* Telefon/tablet: rdzeń nad listą uczestników */}