diff --git a/GraphNode.js b/GraphNode.js index f1e9d47..85ae6dc 100644 --- a/GraphNode.js +++ b/GraphNode.js @@ -46,25 +46,6 @@ class GraphNode { const INF = 999999; for (let node of nodes) { - // Am I in any labeled groups that node is not? - // If so, preserve one space above the group - let labeled = new Set(Array.from(this.groups).filter(g => g.label != '')); - if (asymDifference(labeled, node.groups).size) { - node.addAffinity(this, (d, v) => - (v[0] == 0 && v[1] > 0 && v[1] < 2) ? -INF : 0); - } - - // Try to stack nodes with the same label - if (node.label == this.label) { - this.addAffinity(node, (d, v) => v[0] == 0 ? 200 : 500); - } - - // Try to preserve pagerank left-to-right flow from initial positions - let rankSign = Math.sign(node.pageRank - this.pageRank); - if (rankSign != 0) { - this.addAffinity(node, (d, v) => - [Math.sign(v[0]) == rankSign ? 0 : -1000, 0]); - } } for (let link of this.links) { diff --git a/LayoutGroup.js b/LayoutGroup.js index f5110f6..621921a 100644 --- a/LayoutGroup.js +++ b/LayoutGroup.js @@ -5,6 +5,8 @@ class LayoutGroup { this.nodes = new Set(nodes); this.tension = 0; + this.label = this.graphGroup_ ? this.graphGroup_.label : null; + for (let node of nodes) { node.groups.add(this); } diff --git a/LayoutNode.js b/LayoutNode.js index b3fe515..9c9764c 100644 --- a/LayoutNode.js +++ b/LayoutNode.js @@ -8,6 +8,7 @@ class LayoutNode { this.affinity_ = []; this.label = this.graphNode_.label; + this.pageRank = this.graphNode_.pageRank; this.subgraph = this.graphNode_.subgraph; this.nodesByPos_.set(this.pos, this); @@ -46,6 +47,26 @@ class LayoutNode { this.addAffinity(node, d => d <= 2 ? -INF : 0); } + // Am I in any labeled groups that node is not? + // If so, preserve one space above the group + let labeled = new Set(Array.from(this.groups).filter(g => !!g.label)); + if (asymDifference(labeled, node.groups).size) { + node.addAffinity(this, (d, v) => + (v[0] == 0 && v[1] > 0 && v[1] < 2) ? -INF : 0); + } + + // Try to stack nodes with the same label + if (node.label == this.label) { + this.addAffinity(node, (d, v) => v[0] == 0 ? 200 : 500); + } + + // Try to preserve pagerank left-to-right flow from initial positions + let rankSign = Math.sign(node.pageRank - this.pageRank); + if (rankSign != 0) { + this.addAffinity(node, (d, v) => + [Math.sign(v[0]) == rankSign ? 0 : -1000, 0]); + } + for (let group of this.groups) { // Ensure groups do not overlap if (group.nodes.has(node)) {