From df811ec7fa659cbb55ad56c72991e22e69cc777b Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Mon, 8 Jul 2019 02:40:43 +0000 Subject: [PATCH] Pass vector to distanceToWeight, remove some useless affinities --- GraphNode.js | 11 +++++++++++ LayoutNode.js | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/GraphNode.js b/GraphNode.js index c4e4bf7..38172f0 100644 --- a/GraphNode.js +++ b/GraphNode.js @@ -43,7 +43,12 @@ class GraphNode { setAffinity(nodes) { const INF = 999999; + for (let node of nodes) { + if (node == this) { + continue; + } + // Weak affinity full mesh // Keep unassociated subgroups together this.addAffinity(node, d => d); @@ -58,14 +63,20 @@ class GraphNode { node.addAffinity(this, d => d <= 2 ? -INF : 0); } } + for (let to of this.links) { // Stronger affinity for links // Prefer to move toward the target instance this.addAffinity(to, d => d <= 2 ? -INF : d * 11); to.addAffinity(this, d => d <= 2 ? -INF : d * 9); } + for (let group of this.groups) { for (let node of group.nodes) { + if (node == this) { + continue; + } + this.addAffinity(node, d => d * 100); } } diff --git a/LayoutNode.js b/LayoutNode.js index 4b16dc9..0ecaf35 100644 --- a/LayoutNode.js +++ b/LayoutNode.js @@ -35,7 +35,7 @@ class LayoutNode { }; // Avoid calling sqrt(), since the results are used relatively let distanceSquared = vec[0] * vec[0] + vec[1] * vec[1]; - let weight = aff.distanceToWeight(distanceSquared); + let weight = aff.distanceToWeight(distanceSquared, vec); for (let i of [0, 1]) { this.vec[i] += (weight * vec[i]) / vecsum; }