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

Function forceDirected_noRepeat

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

Source from the content-addressed store, hash-verified

91}
92
93function forceDirected_noRepeat(layout, graph) {
94 for (let a = 0; a < graph.size; a++) {
95 for (let b = a + 1; b < graph.size; b++) {
96 let apart = layout[b].minus(layout[a]);
97 let distance = Math.max(1, apart.length);
98 let connected = graph.neighbors(a).has(b);
99 let size = forceSize(distance, connected);
100 let force = apart.times(1 / distance).times(size);
101 layout[a] = layout[a].plus(force);
102 layout[b] = layout[b].minus(force);
103 }
104 }
105}
106
107var skipDistance = 175;
108

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