From 91afac2eccc8e69d487a841582b4f66450480761 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Tue, 9 Jul 2019 04:57:52 +0000 Subject: [PATCH] Allow lines to or from the same node to overlap --- LayoutLink.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/LayoutLink.js b/LayoutLink.js index d0d0fcc..e94896e 100644 --- a/LayoutLink.js +++ b/LayoutLink.js @@ -71,7 +71,9 @@ class LayoutLink { } for (let hop of this.path) { - getOrSet(this.linksByPos_, hop, new Set()).add(this); + let links = getOrSet(this.linksByPos_, hop, new Set()); + links.add('f' + this.from_.pos.toString()); + links.add('t' + this.to_.pos.toString()); } } @@ -101,8 +103,16 @@ class LayoutLink { // Traversing nodes has higher cost cost += 5; } else if (this.linksByPos_.has(pos)) { - // Overlapping links have cost - cost += 2; + // Overlapping links have cost, but not if they are from or to the same + // node we are (which render as merging or splitting lines). Allowing + // that saves space. We XOR because we want to force apart lines between + // the same pair, e.g. for redundant or cyclical links. + let links = this.linksByPos_.get(pos); + let hasFrom = links.has('f' + this.from_.pos.toString()); + let hasTo = links.has('t' + this.to_.pos.toString()); + if (!(hasFrom || hasTo) || (hasFrom && hasTo)) { + cost += 2; + } } }