MCPcopy Index your code
hub / github.com/marijnh/Eloquent-JavaScript / forceDirected_simple

Function forceDirected_simple

code/chapter/22_fast.js:58–70  ·  view source on GitHub ↗
(layout, graph)

Source from the content-addressed store, hash-verified

56}
57
58function forceDirected_simple(layout, graph) {
59 for (let a = 0; a < graph.size; a++) {
60 for (let b = 0; b < graph.size; b++) {
61 if (a == b) continue;
62 let apart = layout[b].minus(layout[a]);
63 let distance = Math.max(1, apart.length);
64 let connected = graph.neighbors(a).has(b);
65 let size = forceSize(distance, connected);
66 let force = apart.times(1 / distance).times(size);
67 layout[a] = layout[a].plus(force);
68 }
69 }
70}
71
72function pause() {
73 return new Promise(done => setTimeout(done, 0))

Callers

nothing calls this directly

Calls 6

forceSizeFunction · 0.85
neighborsMethod · 0.80
timesMethod · 0.80
minusMethod · 0.45
hasMethod · 0.45
plusMethod · 0.45

Tested by

no test coverage detected