All files / src/graph-runtime layout.ts

100% Statements 19/19
71.42% Branches 5/7
100% Functions 5/5
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 203x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
/** Initial node positions — random cloud; force simulation forms organic clusters. */
export const GRAPH_RUNTIME_LAYOUT = `
  function seedPositions() {
    if (!nodes.length) return;
    const spread =
      payload.kind === "delivery"
        ? Math.max(140, Math.sqrt(nodes.length) * 52)
        : Math.max(200, Math.sqrt(nodes.length) * 72);
    for (const n of nodes) {
      const angle = Math.random() * Math.PI * 2;
      const radius = spread * Math.sqrt(Math.random());
      n.x = Math.cos(angle) * radius;
      n.y = Math.sin(angle) * radius;
      n.vx = (Math.random() - 0.5) * 4;
      n.vy = (Math.random() - 0.5) * 4;
      n.pinned = false;
    }
  }
`.trim()