diff --git a/web/src/sections/Ecosystem.tsx b/web/src/sections/Ecosystem.tsx index 6f69e66..0c98ebe 100644 --- a/web/src/sections/Ecosystem.tsx +++ b/web/src/sections/Ecosystem.tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef, useState } from 'react'; +import { useCallback, useEffect, useRef, useState } from 'react'; import { Building2, Dumbbell, Shield, UserRound, type LucideIcon } from 'lucide-react'; import { Brandmark } from '../components/Brandmark'; import { Reveal } from '../components/Reveal'; @@ -53,14 +53,154 @@ interface Wire { y2: number; spread: number; id: string; + // v = ściana pionowa (podstawa trójkąta na bocznej krawędzi, rozrzut w y), + // h = ściana pozioma (podstawa na górnej/dolnej krawędzi, rozrzut w x) + axis: 'v' | 'h'; } +// promień wierzchołka na obwodzie rdzenia — dobrany do rozmiaru rdzenia const HUB_RADIUS = 78; +const HUB_RADIUS_STACK = 70; const SPREAD_PX = 52; // impulsy promieniowania wypełniają cały stożek: wachlarz od wierzchołka // do równomiernie rozmieszczonych punktów podstawy (frakcje ±1) const STREAKS = [-1, -0.66, -0.33, 0, 0.33, 0.66, 1]; +interface WireTarget { + el: HTMLElement | null; + id: string; + // ściana kafelka, do której biegnie promień (strona bliższa rdzenia) + side: 'left' | 'right' | 'top' | 'bottom'; +} + +function basePoint(r: DOMRect, cr: DOMRect, side: WireTarget['side']) { + switch (side) { + case 'left': + return { x: r.right - cr.left, y: r.top + r.height / 2 - cr.top }; + case 'right': + return { x: r.left - cr.left, y: r.top + r.height / 2 - cr.top }; + case 'top': + return { x: r.left + r.width / 2 - cr.left, y: r.bottom - cr.top }; + case 'bottom': + return { x: r.left + r.width / 2 - cr.left, y: r.top - cr.top }; + } +} + +/** + * Promienie—trójkąty mierzone w DOM: wierzchołek na obwodzie rdzenia, + * podstawy na ścianach kafelków. Współrzędne w % kontenera (viewBox 0–100). + */ +function measureWires( + container: HTMLElement, + hubEl: HTMLElement, + targets: WireTarget[], + hubRadius: number, +) { + const cr = container.getBoundingClientRect(); + if (!cr.width || !cr.height) return { wires: [] as Wire[], hub: { x: 50, y: 50 } }; + const hr = hubEl.getBoundingClientRect(); + const cx = hr.left + hr.width / 2 - cr.left; + const cy = hr.top + hr.height / 2 - cr.top; + const wires: 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; + const base = basePoint(r, cr, t.side); + wires.push({ + x1: ((cx + (dx / len) * hubRadius) / cr.width) * 100, + y1: ((cy + (dy / len) * hubRadius) / cr.height) * 100, + x2: (base.x / cr.width) * 100, + y2: (base.y / cr.height) * 100, + // połowa podstawy trójkąta jako % wymiaru kontenera w osi rozrzutu + spread: ((t.side === 'left' || t.side === 'right' ? SPREAD_PX / cr.height : SPREAD_PX / cr.width)) * 100, + id: t.id, + axis: t.side === 'left' || t.side === 'right' ? 'v' : 'h', + }); + } + return { wires, hub: { x: (cx / cr.width) * 100, y: (cy / cr.height) * 100 } }; +} + +/** Warstwy SVG: gradienty promieni + maska miękkiego zanikania od rdzenia. */ +function RayDefs({ + wires, + idPrefix, + hub, +}: { + wires: Wire[]; + idPrefix: string; + hub: { x: number; y: number }; +}) { + return ( + <> + + {wires.map((w) => ( + + + + + ))} + + + + + + + + + + {wires.map((w) => ( + + + {STREAKS.map((f, i) => ( + + ))} + + ))} + + + ); +} + /** * Diagram rdzenia (lg+): kafelki uczestników z naturalną wysokością (nic się nie * ucina) i promienie—trójkąty mierzone w DOM (ResizeObserver): wierzchołek na @@ -68,48 +208,30 @@ const STREAKS = [-1, -0.66, -0.33, 0, 0.33, 0.66, 1]; */ function HubDiagram() { const containerRef = useRef(null); + const hubRef = useRef(null); const trenerRef = useRef(null); const silowniaRef = useRef(null); const cwiczacyRef = useRef(null); const adminRef = useRef(null); const [wires, setWires] = useState([]); + const [hub, setHub] = useState({ x: 50, y: 50 }); useEffect(() => { const container = containerRef.current; if (!container) return; - const targets = [ - { el: trenerRef.current, side: 'left' as const, id: 'trener' }, - { el: silowniaRef.current, side: 'left' as const, id: 'silownia' }, - { el: cwiczacyRef.current, side: 'right' as const, id: 'cwiczacy' }, - { el: adminRef.current, side: 'right' as const, id: 'admin' }, - ]; - 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, - // połowa podstawy trójkąta jako % wysokości kontenera - spread: (SPREAD_PX / cr.height) * 100, - id: t.id, - }); - } - setWires(next); + const hubEl = hubRef.current; + if (!hubEl) return; + const targets: WireTarget[] = [ + { el: trenerRef.current, side: 'left', id: 'trener' }, + { el: silowniaRef.current, side: 'left', id: 'silownia' }, + { el: cwiczacyRef.current, side: 'right', id: 'cwiczacy' }, + { el: adminRef.current, side: 'right', id: 'admin' }, + ]; + const measured = measureWires(container, hubEl, targets, HUB_RADIUS); + setWires(measured.wires); + setHub(measured.hub); }; compute(); @@ -137,59 +259,13 @@ function HubDiagram() { preserveAspectRatio="none" className="absolute inset-0 h-full w-full" > - - {wires.map((w) => ( - - - - - ))} - - - - - - - - - - {wires.map((w) => ( - - - {STREAKS.map((f, i) => ( - - ))} - - ))} - + -
+

FitOS

@@ -222,6 +298,119 @@ function HubDiagram() { ); } +/** + * Diagram rdzenia pod lg: układ pionowy (telefon: ćwiczący, trener, rdzeń, + * siłownia, administrator — promienie tylko do dwóch najbliższych kafelków) + * lub dwie pary nad/pod rdzeniem (tablet sm+: promienie do wszystkich czterech). + */ +function StackDiagram() { + const containerRef = useRef(null); + const hubRef = useRef(null); + const cwiczacyRef = useRef(null); + const trenerRef = useRef(null); + const silowniaRef = useRef(null); + const adminRef = useRef(null); + const [wires, setWires] = useState([]); + const [hub, setHub] = useState({ x: 50, y: 50 }); + const [wide, setWide] = useState(() => + typeof window !== 'undefined' && typeof window.matchMedia === 'function' + ? window.matchMedia('(min-width: 640px)').matches + : true, + ); + + useEffect(() => { + if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return; + const mq = window.matchMedia('(min-width: 640px)'); + const onChange = () => setWide(mq.matches); + onChange(); + mq.addEventListener('change', onChange); + return () => mq.removeEventListener('change', onChange); + }, []); + + const compute = useCallback(() => { + const container = containerRef.current; + const hubEl = hubRef.current; + if (!container || !hubEl) return; + const targets: WireTarget[] = [ + { el: cwiczacyRef.current, side: 'top', id: 'cwiczacy' }, + { el: trenerRef.current, side: 'top', id: 'trener' }, + { el: silowniaRef.current, side: 'bottom', id: 'silownia' }, + { el: adminRef.current, side: 'bottom', id: 'admin' }, + ]; + // telefon (1 kolumna): promienie tylko do najbliższych — Trener i Siłownia; + // tablet (2 kolumny): rdzeń między parami — promienie do wszystkich czterech + const visible = wide ? targets : targets.filter((t) => t.id === 'trener' || t.id === 'silownia'); + const measured = measureWires(container, hubEl, visible, HUB_RADIUS_STACK); + setWires(measured.wires); + setHub(measured.hub); + }, [wide]); + + useEffect(() => { + compute(); + // jsdom nie zna ResizeObserver — wystarczy jednorazowy pomiar (i tak puste recty) + if (typeof ResizeObserver !== 'undefined') { + const observer = new ResizeObserver(compute); + if (containerRef.current) observer.observe(containerRef.current); + if (hubRef.current) observer.observe(hubRef.current); + window.addEventListener('resize', compute); + return () => { + observer.disconnect(); + window.removeEventListener('resize', compute); + }; + } + }, [compute]); + + return ( +
+ + +
+ +
+ +
+
+ +
+ +
+
+ + +
+
+ +

FitOS

+

rdzeń

+
+
+
+ + +
+ +
+
+ +
+ +
+
+
+
+ ); +} + /** Sekcja „Ekosystem” — rdzeń (od ogółu): mapa uczestników i legenda zazębień. */ export function Ecosystem() { return ( @@ -234,25 +423,8 @@ export function Ecosystem() { - {/* Telefon/tablet: rdzeń nad listą uczestników */} -
- -
-
- -

FitOS

-

rdzeń

-
-
-
-
- {PARTICIPANTS.map((p, i) => ( - - - - ))} -
-
+ {/* Telefon/tablet: rdzeń między parami uczestników z promieniowaniem */} + ); }