From b44a9d40a773d540b944c2285d464211ec50e41a Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Tue, 9 Jul 2019 17:30:09 +0000 Subject: [PATCH] Improve intersecting group behavior --- GraphNode.js | 17 +++++++++++------ architype.css | 10 +++++----- utils.js | 10 ++++++++++ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/GraphNode.js b/GraphNode.js index fb3e4d8..c425d27 100644 --- a/GraphNode.js +++ b/GraphNode.js @@ -41,7 +41,6 @@ class GraphNode { } } - // TODO: move affinity to LayoutNode setAffinity(nodes) { const INF = 999999; @@ -55,9 +54,12 @@ class GraphNode { this.addAffinity(node, d => d <= 2 ? -INF : 0); } - // Keep one space around groups - if (this.groups.size && !intersects(this.groups, node.groups)) { - node.addAffinity(this, 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 @@ -67,8 +69,10 @@ class GraphNode { // Try to preserve pagerank left-to-right flow from initial positions let rankSign = Math.sign(node.pageRank - this.pageRank); - this.addAffinity(node, (d, v) => - [Math.sign(v[0]) == rankSign ? 0 : -1000, 0]); + if (rankSign != 0) { + this.addAffinity(node, (d, v) => + [Math.sign(v[0]) == rankSign ? 0 : -1000, 0]); + } } for (let to of this.links) { @@ -78,6 +82,7 @@ class GraphNode { 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); diff --git a/architype.css b/architype.css index 64c8f50..c63586a 100644 --- a/architype.css +++ b/architype.css @@ -8,7 +8,7 @@ --placeholder: rgba(255,255,255,0.2); --outline: #323434; --background: #202020; - --group-background: rgba(0,0,0,0.3); + --group-background: rgba(0,0,0,0.5); --node-background: #000000; --input: rgba(255,255,255,0.2); } @@ -136,7 +136,6 @@ body { text-align: center; font-size: 20px; - border-radius: 10%; overflow-wrap: anywhere; overflow: hidden; cursor: default; @@ -149,12 +148,13 @@ body { background: var(--node-background); justify-content: center; border: 1px solid white; + border-radius: 10%; z-index: 3; } .gridGroup { - width: calc(100% - 10px); - height: calc(100% - 30px); + width: 100%; + height: 100%; background: var(--group-background); justify-content: flex-start; margin-top: 20px; @@ -176,7 +176,7 @@ body { padding-top: 3px; overflow: hidden; overflow-wrap: anywhere; - z-index: 3; + z-index: 1; } .gridLines { diff --git a/utils.js b/utils.js index 22de960..19aed7a 100644 --- a/utils.js +++ b/utils.js @@ -25,5 +25,15 @@ function intersects(set1, set2) { return false; } +function asymDifference(set1, set2) { + let ret = new Set(); + for (let item of set1) { + if (!set2.has(item)) { + ret.add(item); + } + } + return ret; +} +