Download source/src/WorkGraph.jsx from Lets-Fafo/fafo: direct link, hf CLI and curl.
- Browser
- Download file 4.36 kB
-
https://huggingface.co/spaces/Lets-Fafo/fafo/resolve/main/source/src/WorkGraph.jsx
- Command line
-
hf download hf://spaces/Lets-Fafo/fafo/source/src/WorkGraph.jsx
-
curl -L -o WorkGraph.jsx https://huggingface.co/spaces/Lets-Fafo/fafo/resolve/main/source/src/WorkGraph.jsx
4.36 kB
| import { useEffect, useState } from 'react' | |
| // The FAFO mark is a hexagonal node graph. This is the same geometry, used for what it stands for: | |
| // one work order moving through the governed state machine, lighting the audit trail as it goes. | |
| const C = 260 | |
| const deg = (a) => (a * Math.PI) / 180 | |
| const pt = (r, a) => [C + r * Math.cos(deg(a)), C + r * Math.sin(deg(a))] | |
| const OUTER = 205 | |
| const INNER = 102 | |
| const vertexAngles = [-90, -30, 30, 90, 150, 210] // pointy-top outer hexagon | |
| const midAngles = [-60, 0, 60, 120, 180, 240] // outer edge midpoints and inner (flat-top) vertices | |
| const nodes = {} | |
| vertexAngles.forEach((a, i) => (nodes[`v${i}`] = pt(OUTER, a))) | |
| midAngles.forEach((a, i) => (nodes[`m${i}`] = pt(OUTER * Math.cos(deg(30)), a))) | |
| midAngles.forEach((a, i) => (nodes[`i${i}`] = pt(INNER, a))) | |
| nodes.c = [C, C] | |
| const edges = [] | |
| for (let i = 0; i < 6; i++) { | |
| edges.push([`v${i}`, `m${i}`], [`m${i}`, `v${(i + 1) % 6}`]) // outer ring through midpoints | |
| edges.push([`i${i}`, `i${(i + 1) % 6}`]) // inner ring | |
| edges.push([`m${i}`, `i${i}`]) // midpoint to inner vertex | |
| edges.push([`i${i}`, 'c']) // inner vertex to centre | |
| } | |
| // The governed path: each stop is a real state in the work order lifecycle. | |
| const PATH = [ | |
| { id: 'v0', label: 'Intent', dx: 0, dy: -22, anchor: 'middle' }, | |
| { id: 'm0', label: 'Contract', dx: 16, dy: -8, anchor: 'start' }, | |
| { id: 'i0', label: 'Grounding', dx: 16, dy: 4, anchor: 'start' }, | |
| { id: 'c', label: 'Execution', dx: 0, dy: 30, anchor: 'middle' }, | |
| { id: 'i3', label: 'Evidence', dx: -16, dy: 4, anchor: 'end' }, | |
| { id: 'm3', label: 'Gatekeeper', dx: -16, dy: 22, anchor: 'end' }, | |
| { id: 'v4', label: 'Closed', dx: -14, dy: 6, anchor: 'end' }, | |
| ] | |
| const pathEdges = PATH.slice(1).map((s, i) => [PATH[i].id, s.id].sort().join('|')) | |
| const edgeKey = (e) => [...e].sort().join('|') | |
| export default function WorkGraph() { | |
| const [step, setStep] = useState(0) | |
| const [reduced, setReduced] = useState(false) | |
| useEffect(() => { | |
| const mq = window.matchMedia('(prefers-reduced-motion: reduce)') | |
| const sync = () => setReduced(mq.matches) | |
| sync() | |
| mq.addEventListener('change', sync) | |
| return () => mq.removeEventListener('change', sync) | |
| }, []) | |
| useEffect(() => { | |
| if (reduced) return | |
| // Steps 1..7 light the path; step 8 holds the finished trail before it clears. | |
| const id = setInterval(() => setStep((s) => (s + 1) % (PATH.length + 2)), 1100) | |
| return () => clearInterval(id) | |
| }, [reduced]) | |
| const lit = reduced ? PATH.length : Math.min(step, PATH.length) | |
| const litIds = new Set(PATH.slice(0, lit).map((s) => s.id)) | |
| const litEdges = new Set(pathEdges.slice(0, Math.max(0, lit - 1))) | |
| const current = lit > 0 && lit <= PATH.length ? PATH[lit - 1] : null | |
| return ( | |
| <figure className="work-graph"> | |
| <svg viewBox="0 0 520 520" role="img" aria-label="A work order moving through FAFO's governed states: intent, contract, grounding, execution, evidence, gatekeeper, closed."> | |
| <g className="graph-edges"> | |
| {edges.map((e) => { | |
| const [a, b] = e | |
| const k = edgeKey(e) | |
| return ( | |
| <line | |
| key={k} | |
| x1={nodes[a][0]} | |
| y1={nodes[a][1]} | |
| x2={nodes[b][0]} | |
| y2={nodes[b][1]} | |
| className={litEdges.has(k) ? 'is-lit' : undefined} | |
| /> | |
| ) | |
| })} | |
| </g> | |
| <g className="graph-nodes"> | |
| {Object.entries(nodes).map(([id, [x, y]]) => ( | |
| <circle | |
| key={id} | |
| cx={x} | |
| cy={y} | |
| r={id === 'c' ? 11 : 9} | |
| className={[litIds.has(id) ? 'is-lit' : '', current && current.id === id ? 'is-current' : ''].join(' ').trim() || undefined} | |
| /> | |
| ))} | |
| </g> | |
| <g className="graph-labels"> | |
| {PATH.map((s, i) => { | |
| const [x, y] = nodes[s.id] | |
| return ( | |
| <text key={s.id} x={x + s.dx} y={y + s.dy} textAnchor={s.anchor} className={i < lit ? 'is-lit' : undefined}> | |
| {s.label} | |
| </text> | |
| ) | |
| })} | |
| </g> | |
| </svg> | |
| <figcaption> | |
| <span>One work order through the governed state machine</span> | |
| <span>Illustrative, not a live feed</span> | |
| </figcaption> | |
| </figure> | |
| ) | |
| } | |