From 88669ae03b542b17b233cea6d45a5adbfc4ecb28 Mon Sep 17 00:00:00 2001 From: Alex de Mulder Date: Tue, 13 Jan 2015 18:32:30 +0100 Subject: [PATCH] started implementation new hierarchical layout algorithm --- dist/vis.js | 39 +++++++------------ .../network/32_hierarchicaLayoutMethods.html | 9 ++++- lib/network/Network.js | 2 +- lib/network/mixins/HierarchicalLayoutMixin.js | 34 ++++++---------- 4 files changed, 32 insertions(+), 52 deletions(-) diff --git a/dist/vis.js b/dist/vis.js index d66f360a..137991dc 100644 --- a/dist/vis.js +++ b/dist/vis.js @@ -14018,8 +14018,7 @@ return /******/ (function(modules) { // webpackBootstrap this.redraw(); } else { - console.log('WARNING: infinite loop in redraw?') - throw new Error("bla") + console.log('WARNING: infinite loop in redraw?'); } this.redrawCount = 0; } @@ -22874,7 +22873,7 @@ return /******/ (function(modules) { // webpackBootstrap levelSeparation: 150, nodeSpacing: 100, direction: "UD", // UD, DU, LR, RL - layout: "hubsize" // hubsize, directed + layout: "hubsize" // hubsize, directed, uniqueDirected }, freezeForStabilization: false, smoothCurves: { @@ -34070,36 +34069,24 @@ return /******/ (function(modules) { // webpackBootstrap } }; + + /** - * this function allocates nodes in levels based on the recursive branching from the largest hubs. + * this function allocates nodes in levels based on the direction of the edges * * @param hubsize * @private */ exports._determineLevelsDirected = function() { - var nodeId, node; + var nodeId, node, firstNode; + var minLevel = 10000; // set first node to source - for (nodeId in this.nodes) { - if (this.nodes.hasOwnProperty(nodeId)) { - this.nodes[nodeId].level = 10000; - break; - } - } + firstNode = this.nodes[this.nodeIndices[0]]; + firstNode.level = minLevel; + this._setLevelDirected(minLevel,firstNode.edges,firstNode.id); - // branch from hubs - for (nodeId in this.nodes) { - if (this.nodes.hasOwnProperty(nodeId)) { - node = this.nodes[nodeId]; - if (node.level == 10000) { - this._setLevelDirected(10000,node.edges,node.id); - } - } - } - - - // branch from hubs - var minLevel = 10000; + // get the minimum level for (nodeId in this.nodes) { if (this.nodes.hasOwnProperty(nodeId)) { node = this.nodes[nodeId]; @@ -34107,7 +34094,7 @@ return /******/ (function(modules) { // webpackBootstrap } } - // branch from hubs + // subtract the minimum from the set so we have a range starting from 0 for (nodeId in this.nodes) { if (this.nodes.hasOwnProperty(nodeId)) { node = this.nodes[nodeId]; @@ -34213,7 +34200,7 @@ return /******/ (function(modules) { // webpackBootstrap /** - * this function is called recursively to enumerate the barnches of the largest hubs and give each node a level. + * this function is called recursively to enumerate the branched of the first node and give each node a level based on edge direction * * @param level * @param edges diff --git a/examples/network/32_hierarchicaLayoutMethods.html b/examples/network/32_hierarchicaLayoutMethods.html index 3b9901a0..7cdf485c 100644 --- a/examples/network/32_hierarchicaLayoutMethods.html +++ b/examples/network/32_hierarchicaLayoutMethods.html @@ -19,7 +19,7 @@