From 8cbbf7d35ebccc09e383664e975256a5e69567c6 Mon Sep 17 00:00:00 2001 From: tisachi Date: Tue, 20 Oct 2026 02:20:19 +0200 Subject: [PATCH] Web: wykres rysowany scrollem w tle slownika pojec (stroke-dashoffset scrub) --- web/src/sections/Concepts.tsx | 146 +++++++++++++++++++++++++++------- 1 file changed, 116 insertions(+), 30 deletions(-) diff --git a/web/src/sections/Concepts.tsx b/web/src/sections/Concepts.tsx index 7ab46e5..a222d8f 100644 --- a/web/src/sections/Concepts.tsx +++ b/web/src/sections/Concepts.tsx @@ -1,4 +1,4 @@ -import type { ReactNode } from 'react'; +import { useEffect, useRef, type ReactNode } from 'react'; import { Activity, Dumbbell, @@ -13,6 +13,86 @@ import { StreakDots } from '../components/StreakDots'; import { cn } from '../lib/utils'; import { Section, SectionHeading } from './shared'; +// Wykres w tle sekcji — rysowany od lewej do prawej w rytm scrolla. +const CHART_PATH = 'M0,150 L130,118 L250,134 L380,86 L510,112 L650,58 L780,92 L900,44 L1000,66'; + +function ChartBackdrop() { + const wrapRef = useRef(null); + const lineRef = useRef(null); + const clipRef = useRef(null); + + useEffect(() => { + const wrap = wrapRef.current; + const line = lineRef.current; + const clip = clipRef.current; + if (!wrap || !line || !clip) return; + // jsdom nie implementuje getTotalLength — bez scrubbingu w testach + if (typeof line.getTotalLength !== 'function') return; + + const len = line.getTotalLength(); + line.style.strokeDasharray = String(len); + + const reduce = + typeof window.matchMedia === 'function' && + window.matchMedia('(prefers-reduced-motion: reduce)').matches; + + let raf = 0; + const update = () => { + const r = wrap.getBoundingClientRect(); + const vh = window.innerHeight; + const p = reduce ? 1 : Math.min(Math.max((vh - r.top) / (r.height + vh * 0.75), 0), 1); + line.style.strokeDashoffset = String(len * (1 - p)); + clip.setAttribute('width', String(p * 1000)); + }; + const onScroll = () => { + cancelAnimationFrame(raf); + raf = requestAnimationFrame(update); + }; + + update(); + window.addEventListener('scroll', onScroll, { passive: true }); + window.addEventListener('resize', onScroll); + return () => { + cancelAnimationFrame(raf); + window.removeEventListener('scroll', onScroll); + window.removeEventListener('resize', onScroll); + }; + }, []); + + return ( + + ); +} + // Słownik pojęć — podstawowe cegły systemu wyjaśnione obrazkiem, nie żargonem. // Dla osoby, która widzi FitOS po raz pierwszy: tu dowiaduje się, o co „chodzi”. @@ -223,36 +303,42 @@ const CONCEPTS: Concept[] = [ export function Concepts() { return (
- +
+ -
- {CONCEPTS.map((c, i) => ( - -
-
-
-
- {c.viz} -
-

- {c.desc} -

-
-
- ))} +
+ + +
+ {CONCEPTS.map((c, i) => ( + +
+
+
+
+ {c.viz} +
+

+ {c.desc} +

+
+
+ ))} +
+
);