Link: optimize so that no link {} is used, less than half the ram used

This commit is contained in:
Pitchaya Boonsarngsuk
2018-01-30 20:10:46 +00:00
parent 7ca8b2bbc3
commit 409777bc14
2 changed files with 29 additions and 22 deletions

View File

@@ -18,17 +18,16 @@ export default function(links) {
function force(alpha) {
// Each iteration in a tick
for (var k = 0, n = links.length; k < iterations; ++k) {
for (var k = 0, n = nodes.length, source, target, i, j, x, y, l; k < iterations; ++k) {
// For each link
for (var i = 0, link, source, target, x, y, l, b; i < n; ++i) {
link = links[i];
for (i = 1; i < n; i++) for (j = 0; j < i; j++) {
// jiggle so it wont divide / multiply by zero after this
source = link.source;
target = link.target;
source = nodes[i];
target = nodes[j];
x = target.x + target.vx - source.x - source.vx || jiggle();
y = target.y + target.vy - source.y - source.vy || jiggle();
l = Math.sqrt(x * x + y * y);
l = (l - distances[i]) / l * dataSizeFactor * alpha;
l = (l - distances[i*(i-1)/2+j]) / l * dataSizeFactor * alpha;
x *= l, y *= l;
target.vx -= x;
target.vy -= y;
@@ -46,8 +45,10 @@ export default function(links) {
function initializeDistance() {
if (!nodes) return;
for (var i = 0, n = links.length; i < n; ++i) {
distances[i] = +distance(links[i], i, links);
for (let i = 1, n = nodes.length; i < n; i++) {
for (let j = 0; j < i; j++) {
distances.push(distanceFunction(nodes[i], nodes[j], props, norm));
}
}
}