File size: 4,359 Bytes
4f81136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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>
  )
}