(taskId: string, cx: number, cy: number, steps: Array<{ id: string; x: number; y: number; label: string }>, onTick: (positions: Record<string, { x: number; y: number }>) => void)
| 9 | } |
| 10 | |
| 11 | export function buildTaskSim(taskId: string, cx: number, cy: number, steps: Array<{ id: string; x: number; y: number; label: string }>, onTick: (positions: Record<string, { x: number; y: number }>) => void): TaskSim { |
| 12 | const center: Node = { id: `t:${taskId}`, x: cx, y: cy, fx: cx, fy: cy, type: 'center' } |
| 13 | const nodes: Node[] = [center] |
| 14 | for (const s of steps) nodes.push({ id: `s:${s.id}`, x: s.x + 42, y: s.y + 14, type: 'step', taskId, label: s.label }) |
| 15 | const sim = forceSimulation(nodes) |
| 16 | .force('charge', forceManyBody().strength(-60)) |
| 17 | .force('radial', forceRadial(120, cx, cy).strength(0.09)) |
| 18 | .force('collide', forceCollide(36)) |
| 19 | .alpha(0.6) |
| 20 | .alphaDecay(0.08) |
| 21 | sim.on('tick', () => { |
| 22 | const out: Record<string, { x: number; y: number }> = {} |
| 23 | for (const n of nodes) if (n.type === 'step' && n.taskId && typeof n.x === 'number' && typeof n.y === 'number') out[`${n.taskId}::${n.label}`] = { x: n.x - 42, y: n.y - 14 } |
| 24 | if (Object.keys(out).length) onTick(out) |
| 25 | }) |
| 26 | return { sim: sim as any, nodes, center } |
| 27 | } |
| 28 | |
| 29 | export function recenterTaskSim(ts: TaskSim, cx: number, cy: number) { |
| 30 | ts.center.fx = cx; ts.center.fy = cy |
nothing calls this directly
no test coverage detected