MCPcopy Create free account
hub / github.com/CaviraOSS/PageLM / buildTaskSim

Function buildTaskSim

frontend/src/components/planner/mindmap/engine.ts:11–27  ·  view source on GitHub ↗
(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)

Source from the content-addressed store, hash-verified

9}
10
11export 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
29export function recenterTaskSim(ts: TaskSim, cx: number, cy: number) {
30 ts.center.fx = cx; ts.center.fy = cy

Callers

nothing calls this directly

Calls 4

alphaDecayMethod · 0.80
alphaMethod · 0.80
forceMethod · 0.80
onMethod · 0.80

Tested by

no test coverage detected