From 45bf2d689cc81f0635a38cbb3db9c25637c5491f Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sat, 13 Jul 2019 03:46:54 +0000 Subject: [PATCH] Complete affinity migration from Graph to Layout Fixes #6 --- Graph.js | 7 ------- GraphNode.js | 33 --------------------------------- Layout.js | 6 +++--- LayoutNode.js | 28 ++++++++++++++++++---------- 4 files changed, 21 insertions(+), 53 deletions(-) diff --git a/Graph.js b/Graph.js index a32407d..79a98f2 100644 --- a/Graph.js +++ b/Graph.js @@ -16,7 +16,6 @@ class Graph { this.setPageRank(); this.setSubgraph(); this.bucketNodes(); - this.setAffinity(); } processList(list, soft=false) { @@ -134,12 +133,6 @@ class Graph { nodes.sort(); } } - - setAffinity() { - for (let node of this.nodes) { - node.setAffinity(this.nodes); - } - } } diff --git a/GraphNode.js b/GraphNode.js index 85ae6dc..fa3da15 100644 --- a/GraphNode.js +++ b/GraphNode.js @@ -3,7 +3,6 @@ class GraphNode { this.links = []; this.linksIn = []; this.groups = new Set(); - this.affinity = []; this.pageRank = 0; this.subgraph = null; } @@ -41,38 +40,6 @@ class GraphNode { } } - // TODO: move this to LayoutNode, item by item - setAffinity(nodes) { - const INF = 999999; - - for (let node of nodes) { - } - - for (let link of this.links) { - // Stronger affinity for links - // Prefer to move toward the target instance - this.addAffinity(link.to, d => d <= 2 ? -INF : d * 11); - link.to.addAffinity(this, d => d <= 2 ? -INF : d * 9); - } - - // Affinity for groups - for (let group of this.groups) { - for (let node of group.nodes) { - this.addAffinity(node, d => d * 100); - } - } - } - - addAffinity(node, distanceToWeight) { - if (this == node) { - return; - } - this.affinity.push({ - node: node, - distanceToWeight: distanceToWeight, - }); - } - static process(item, soft=false) { if (item.label == '') { return null; diff --git a/Layout.js b/Layout.js index 918e27a..f585524 100644 --- a/Layout.js +++ b/Layout.js @@ -12,7 +12,7 @@ class Layout { this.setInitialPositions(); this.resolveGroups(); this.resolveLinks(); - this.resolveAffinity(); + this.setAffinity(); while (this.iterate()); this.addGroupPos(); this.drawLinks(); @@ -74,9 +74,9 @@ class Layout { } } - resolveAffinity() { + setAffinity() { for (let node of this.nodes_) { - node.resolveAffinity(this.nodesByGraphNode_); + node.setAffinity(this.nodesByGraphNode_); } } diff --git a/LayoutNode.js b/LayoutNode.js index 9c9764c..4d3353d 100644 --- a/LayoutNode.js +++ b/LayoutNode.js @@ -25,18 +25,9 @@ class LayoutNode { } } - resolveAffinity(nodesByGraphNode) { + setAffinity(nodesByGraphNode) { const INF = 999999; - // TODO: remove - // Transitional: copy GraphNode affinity - for (let aff of this.graphNode_.affinity) { - this.affinity_.push({ - node: nodesByGraphNode.get(aff.node), - distanceToWeight: aff.distanceToWeight, - }); - } - for (let node of nodesByGraphNode.values()) { // Weak affinity full mesh // Keep unassociated subgroups together @@ -78,6 +69,23 @@ class LayoutNode { }); } } + + for (let link of this.links) { + // Stronger affinity for links + // Prefer to move toward the target instance + this.addAffinity(link.to, d => d <= 2 ? -INF : d * 11); + link.to.addAffinity(this, d => d <= 2 ? -INF : d * 9); + } + + // Affinity for groups + for (let group of this.groups) { + if (!group.hasGraphGroup()) { + continue; + } + for (let node of group.nodes) { + this.addAffinity(node, d => d * 100); + } + } } addAffinity(node, distanceToWeight) {