diff --git a/Layout.js b/Layout.js index bf99e8d..970b632 100644 --- a/Layout.js +++ b/Layout.js @@ -3,6 +3,7 @@ class Layout { this.graph_ = graph; this.nodes_ = []; + // TODO: value should be a set, not a single value, for groups this.nodesByPos_ = new StringMap(); this.nodesByGraphNode_ = new Map(); this.linksByPos_ = new StringMap(); diff --git a/LayoutGroup.js b/LayoutGroup.js index 3999fb3..03da1ac 100644 --- a/LayoutGroup.js +++ b/LayoutGroup.js @@ -6,7 +6,7 @@ class LayoutGroup { this.tension = 0; for (let node of nodes) { - node.groups.push(this); + node.groups.add(this); } } diff --git a/LayoutLink.js b/LayoutLink.js index 0fabad2..c3669c8 100644 --- a/LayoutLink.js +++ b/LayoutLink.js @@ -117,7 +117,13 @@ class LayoutLink { // arguments. That means that any costs applied to nodes must be applied // whether the node is from or to. Traversal is double-charged. for (let pos of [from, to]) { - if (this.nodesByPos_.has(pos)) { + let taken = this.nodesByPos_.get(pos); + if (taken instanceof LayoutGroup && + (this.from_.groups.has(taken) || + this.to_.groups.has(taken))) { + // We're going to or from this group, so traversing it is fine. + continue; + } else if (taken) { // Traversing nodes has higher cost cost += 5; }; diff --git a/LayoutNode.js b/LayoutNode.js index d22d9ec..3021110 100644 --- a/LayoutNode.js +++ b/LayoutNode.js @@ -3,7 +3,7 @@ class LayoutNode { this.graphNode_ = graphNode; this.nodesByPos_ = nodesByPos; this.pos = pos; - this.groups = []; + this.groups = new Set(); this.nodesByPos_.set(this.pos, this); }