From d1cac0f3af7ce1422563c06c819aa5ac37d24be5 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Wed, 26 Jun 2019 04:44:23 +0000 Subject: [PATCH] Set initial node positions --- architype.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/architype.js b/architype.js index 2202b4f..39b408e 100644 --- a/architype.js +++ b/architype.js @@ -143,6 +143,7 @@ class Architype { this.manifestNodes(graph); this.setPageRank(graph); this.bucketByPageRank(graph); + this.setInitialPositions(graph); return graph; } @@ -270,6 +271,17 @@ class Architype { bucket.sort(cmp); } } + + setInitialPositions(graph) { + let ranks = Array.from(graph.nodesByPageRank.keys()); + ranks.sort((a, b) => a - b); + for (let r = 0; r < ranks.length; ++r) { + let nodes = graph.nodesByPageRank.get(ranks[r]); + for (let n = 0; n < nodes.length; ++n) { + nodes[n].pos = [r, 0 - Math.floor(nodes.length / 2) + n]; + } + } + } } class ListenUtils {