From a328415c22758b91deb54cb5280f579e400cfbe4 Mon Sep 17 00:00:00 2001 From: jos Date: Thu, 27 Aug 2015 15:10:58 +0200 Subject: [PATCH] Added loop protection to `layoutNetwork` --- lib/network/modules/LayoutEngine.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/network/modules/LayoutEngine.js b/lib/network/modules/LayoutEngine.js index 16c90538..8c42ce9a 100644 --- a/lib/network/modules/LayoutEngine.js +++ b/lib/network/modules/LayoutEngine.js @@ -188,6 +188,7 @@ class LayoutEngine { // if less than half of the nodes have a predefined position we continue if (positionDefined < 0.5 * this.body.nodeIndices.length) { + let MAX_LEVELS = 200; let levels = 0; let clusterThreshold = 100; // if there are a lot of nodes, we cluster before we run the algorithm. @@ -204,7 +205,7 @@ class LayoutEngine { this.body.modules.clustering.clusterOutliers(); } let after = this.body.nodeIndices.length; - if (before == after && levels % 3 !== 0) { + if ((before == after && levels % 3 !== 0) || levels > MAX_LEVELS) { this._declusterAll(); console.info("This network could not be positioned by this version of the improved layout algorithm."); return;