diff --git a/Architype.js b/Architype.js index 706ba43..a1c149e 100644 --- a/Architype.js +++ b/Architype.js @@ -77,7 +77,7 @@ class Architype { } onResize(e) { - this.fixSizes(this.graph_.nodes); + this.fixSizes(); } exportGraphviz() { diff --git a/GraphNode.js b/GraphNode.js index 6694aa9..59e09b4 100644 --- a/GraphNode.js +++ b/GraphNode.js @@ -50,19 +50,19 @@ class GraphNode { // Keep one space between subgraphs if (this.subgraph != node.subgraph) { - this.addAffinity(node, d => d < 1.5 ? -INF : 0); + 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 < 1.5 ? -INF : 0); + node.addAffinity(this, d => d <= 2 ? -INF : 0); } } for (let to of this.links) { // Stronger affinity for links // Prefer to move toward the target instance - this.addAffinity(to, d => d < 1.5 ? -INF : d * 11); - to.addAffinity(this, d => d < 1.5 ? -INF : d * 9); + this.addAffinity(to, d => d <= 2 ? -INF : d * 11); + to.addAffinity(this, d => d <= 2 ? -INF : d * 9); } for (let group of this.groups.values()) { for (let node of group.nodes) { diff --git a/Layout.js b/Layout.js index 6612e7c..96fb746 100644 --- a/Layout.js +++ b/Layout.js @@ -67,9 +67,14 @@ class Layout { iterate() { let objects = Array.from(this.nodes_); - objects.push(...this.groups_); this.setTension(objects); this.sortByMostTension(objects); + for (let group of this.groups_) { + // Groups go in the list after nodes, and nodes must have tension set + // properly first. + group.setTension(); + objects.push(group); + } let newOffset = null; let newTension = this.getTotalTension(objects); diff --git a/LayoutGroup.js b/LayoutGroup.js index e953413..8be8649 100644 --- a/LayoutGroup.js +++ b/LayoutGroup.js @@ -9,7 +9,6 @@ class LayoutGroup { // tension this.vec = [0, 0]; for (let node of this.nodes.values()) { - node.setTension(); for (let i of [0, 1]) { this.vec[i] += node.vec[i]; }; diff --git a/LayoutNode.js b/LayoutNode.js index 934522c..4500641 100644 --- a/LayoutNode.js +++ b/LayoutNode.js @@ -26,8 +26,9 @@ class LayoutNode { vec[i] = aff.node.pos[i] - this.pos[i]; vecsum += Math.abs(vec[i]); }; - let distance = Math.sqrt(Math.pow(vec[0], 2) + Math.pow(vec[1], 2)); - let weight = aff.distanceToWeight(distance); + // Avoid calling sqrt(), since the results are used relatively + let distanceSquared = vec[0] * vec[0] + vec[1] * vec[1]; + let weight = aff.distanceToWeight(distanceSquared); for (let i of [0, 1]) { this.vec[i] += (weight * vec[i]) / vecsum; }