Browse Source

Added loop protection to `layoutNetwork`

webworkersNetwork
jos 9 years ago
parent
commit
a328415c22
1 changed files with 2 additions and 1 deletions
  1. +2
    -1
      lib/network/modules/LayoutEngine.js

+ 2
- 1
lib/network/modules/LayoutEngine.js View File

@ -188,6 +188,7 @@ class LayoutEngine {
// if less than half of the nodes have a predefined position we continue // if less than half of the nodes have a predefined position we continue
if (positionDefined < 0.5 * this.body.nodeIndices.length) { if (positionDefined < 0.5 * this.body.nodeIndices.length) {
let MAX_LEVELS = 200;
let levels = 0; let levels = 0;
let clusterThreshold = 100; let clusterThreshold = 100;
// if there are a lot of nodes, we cluster before we run the algorithm. // 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(); this.body.modules.clustering.clusterOutliers();
} }
let after = this.body.nodeIndices.length; let after = this.body.nodeIndices.length;
if (before == after && levels % 3 !== 0) {
if ((before == after && levels % 3 !== 0) || levels > MAX_LEVELS) {
this._declusterAll(); this._declusterAll();
console.info("This network could not be positioned by this version of the improved layout algorithm."); console.info("This network could not be positioned by this version of the improved layout algorithm.");
return; return;

Loading…
Cancel
Save