diff --git a/Layout.js b/Layout.js index 7a3b2c0..6612e7c 100644 --- a/Layout.js +++ b/Layout.js @@ -2,6 +2,7 @@ class Layout { constructor(graph) { this.graph_ = graph; + this.nodes_ = []; this.nodesByPos_ = new Map(); this.nodesByGraphNode_ = new Map(); @@ -31,9 +32,9 @@ class Layout { Math.floor((nodes.length / 2) * SPACING) + (n * SPACING) + (node.subgraph * SPACING * maxRankNodes), ]; - this.nodesByGraphNode_.set( - node, - new LayoutNode(node, this.nodesByPos_, pos)); + let layoutNode = new LayoutNode(node, this.nodesByPos_, pos); + this.nodes_.push(layoutNode); + this.nodesByGraphNode_.set(node, layoutNode); } } } @@ -65,7 +66,7 @@ class Layout { } iterate() { - let objects = Array.from(this.nodesByPos_.values()); + let objects = Array.from(this.nodes_); objects.push(...this.groups_); this.setTension(objects); this.sortByMostTension(objects); @@ -127,14 +128,14 @@ class Layout { fixOrigin() { let min = [Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]; let max = [Number.MIN_SAFE_INTEGER, Number.MIN_SAFE_INTEGER]; - for (let node of this.nodesByPos_.values()) { + for (let node of this.nodes_) { for (let i of [0, 1]) { min[i] = Math.min(min[i], node.pos[i]); max[i] = Math.max(max[i], node.pos[i]); } } // Offset is negative minimum, e.g min -1 means +1 to all values - for (let node of this.nodesByPos_.values()) { + for (let node of this.nodes_) { for (let i of [0, 1]) { node.pos[i] -= min[i]; } @@ -153,7 +154,7 @@ class Layout { }, ]; - let nodes = Array.from(this.nodesByPos_.values()); + let nodes = Array.from(this.nodes_); for (let i of [1, 0]) { nodes.sort((a, b) => a.pos[i] - b.pos[i]); }