From 311c32b2c569463046c4832d9ff8ea2e13fbe0ed Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Mon, 8 Jul 2019 03:00:31 +0000 Subject: [PATCH] Try to stack like nodes --- GraphNode.js | 5 +++++ Layout.js | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/GraphNode.js b/GraphNode.js index 8bef2b7..a9e9157 100644 --- a/GraphNode.js +++ b/GraphNode.js @@ -58,6 +58,11 @@ class GraphNode { if (this.groups.size && !intersects(this.groups, node.groups)) { node.addAffinity(this, d => d <= 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); + } } for (let to of this.links) { diff --git a/Layout.js b/Layout.js index 78b2d45..dfd1a52 100644 --- a/Layout.js +++ b/Layout.js @@ -61,6 +61,10 @@ class Layout { let nodes = this.nodesFromGraphNodes(subgraph); this.groups_.push(new LayoutGroup(null, this.nodesByPos_, nodes)); } + for (let labelGroup of this.graph_.nodesByLabel.values()) { + let nodes = this.nodesFromGraphNodes(labelGroup); + this.groups_.push(new LayoutGroup(null, this.nodesByPos_, nodes)); + } } resolveLinks() {