Browse Source

cleaned up hierarchical code

v3_develop
Alex de Mulder 10 years ago
parent
commit
f5fce4efc8
4 changed files with 46 additions and 51 deletions
  1. +22
    -22
      dist/vis.js
  2. +2
    -7
      examples/network/32_hierarchicaLayoutMethods.html
  3. +1
    -1
      lib/network/Network.js
  4. +21
    -21
      lib/network/mixins/HierarchicalLayoutMixin.js

+ 22
- 22
dist/vis.js View File

@ -22873,7 +22873,7 @@ return /******/ (function(modules) { // webpackBootstrap
levelSeparation: 150,
nodeSpacing: 100,
direction: "UD", // UD, DU, LR, RL
layout: "hubsize" // hubsize, directed, uniqueDirected
layout: "hubsize" // hubsize, directed
},
freezeForStabilization: false,
smoothCurves: {
@ -33903,23 +33903,6 @@ return /******/ (function(modules) { // webpackBootstrap
*/
exports._setupHierarchicalLayout = function() {
if (this.constants.hierarchicalLayout.enabled == true && this.nodeIndices.length > 0) {
if (this.constants.hierarchicalLayout.direction == "RL" || this.constants.hierarchicalLayout.direction == "DU") {
this.constants.hierarchicalLayout.levelSeparation = this.constants.hierarchicalLayout.levelSeparation < 0 ? this.constants.hierarchicalLayout.levelSeparation : this.constants.hierarchicalLayout.levelSeparation * -1;
}
else {
this.constants.hierarchicalLayout.levelSeparation = Math.abs(this.constants.hierarchicalLayout.levelSeparation);
}
if (this.constants.hierarchicalLayout.direction == "RL" || this.constants.hierarchicalLayout.direction == "LR") {
if (this.constants.smoothCurves.enabled == true) {
this.constants.smoothCurves.type = "vertical";
}
}
else {
if (this.constants.smoothCurves.enabled == true) {
this.constants.smoothCurves.type = "horizontal";
}
}
// get the size of the largest hubs and check if the user has defined a level for a node.
var hubsize = 0;
var node, nodeId;
@ -33959,7 +33942,7 @@ return /******/ (function(modules) { // webpackBootstrap
this._determineLevels(hubsize);
}
else {
this._determineLevelsDirected();
this._determineLevelsDirected(false);
}
}
@ -34156,6 +34139,23 @@ return /******/ (function(modules) { // webpackBootstrap
this.constants.smoothCurves.dynamic = false;
}
this._configureSmoothCurves();
var config = this.constants.hierarchicalLayout;
config.levelSeparation = Math.abs(config.levelSeparation);
if (config.direction == "RL" || config.direction == "DU") {
config.levelSeparation *= -1;
}
if (config.direction == "RL" || config.direction == "LR") {
if (this.constants.smoothCurves.enabled == true) {
this.constants.smoothCurves.type = "vertical";
}
}
else {
if (this.constants.smoothCurves.enabled == true) {
this.constants.smoothCurves.type = "horizontal";
}
}
};
@ -34243,9 +34243,9 @@ return /******/ (function(modules) { // webpackBootstrap
*/
exports._setLevelDirected = function(level, edges, parentId) {
this.nodes[parentId].hierarchyEnumerated = true;
var childNode, direction;
for (var i = 0; i < edges.length; i++) {
var childNode = null;
var direction = 1;
direction = 1;
if (edges[i].toId == parentId) {
childNode = edges[i].from;
direction = -1;
@ -34259,9 +34259,9 @@ return /******/ (function(modules) { // webpackBootstrap
}
for (var i = 0; i < edges.length; i++) {
var childNode = null;
if (edges[i].toId == parentId) {childNode = edges[i].from;}
else {childNode = edges[i].to;}
if (childNode.edges.length > 1 && childNode.hierarchyEnumerated === false) {
this._setLevelDirected(childNode.level, childNode.edges, childNode.id);
}

+ 2
- 7
examples/network/32_hierarchicaLayoutMethods.html View File

@ -19,7 +19,7 @@
<script type="text/javascript">
var network = null;
var layoutMethod = "direction";
var layoutMethod = "hubsize";
function destroy() {
if (network !== null) {
@ -83,10 +83,6 @@
from: 2,
to: 8
});
edges.push({
from: 10,
to: 2
});
edges.push({
from: 2,
to: 9
@ -134,9 +130,8 @@
</div>
Layout method:
<select id="layout">
<option value="direction">direction</option>
<option value="hubsize">hubsize</option>
<option value="direction">direction</option>
</select><br/>
<br />

+ 1
- 1
lib/network/Network.js View File

@ -181,7 +181,7 @@ function Network (container, data, options) {
levelSeparation: 150,
nodeSpacing: 100,
direction: "UD", // UD, DU, LR, RL
layout: "hubsize" // hubsize, directed, uniqueDirected
layout: "hubsize" // hubsize, directed
},
freezeForStabilization: false,
smoothCurves: {

+ 21
- 21
lib/network/mixins/HierarchicalLayoutMixin.js View File

@ -18,23 +18,6 @@ exports._resetLevels = function() {
*/
exports._setupHierarchicalLayout = function() {
if (this.constants.hierarchicalLayout.enabled == true && this.nodeIndices.length > 0) {
if (this.constants.hierarchicalLayout.direction == "RL" || this.constants.hierarchicalLayout.direction == "DU") {
this.constants.hierarchicalLayout.levelSeparation = this.constants.hierarchicalLayout.levelSeparation < 0 ? this.constants.hierarchicalLayout.levelSeparation : this.constants.hierarchicalLayout.levelSeparation * -1;
}
else {
this.constants.hierarchicalLayout.levelSeparation = Math.abs(this.constants.hierarchicalLayout.levelSeparation);
}
if (this.constants.hierarchicalLayout.direction == "RL" || this.constants.hierarchicalLayout.direction == "LR") {
if (this.constants.smoothCurves.enabled == true) {
this.constants.smoothCurves.type = "vertical";
}
}
else {
if (this.constants.smoothCurves.enabled == true) {
this.constants.smoothCurves.type = "horizontal";
}
}
// get the size of the largest hubs and check if the user has defined a level for a node.
var hubsize = 0;
var node, nodeId;
@ -74,7 +57,7 @@ exports._setupHierarchicalLayout = function() {
this._determineLevels(hubsize);
}
else {
this._determineLevelsDirected();
this._determineLevelsDirected(false);
}
}
@ -271,6 +254,23 @@ exports._changeConstants = function() {
this.constants.smoothCurves.dynamic = false;
}
this._configureSmoothCurves();
var config = this.constants.hierarchicalLayout;
config.levelSeparation = Math.abs(config.levelSeparation);
if (config.direction == "RL" || config.direction == "DU") {
config.levelSeparation *= -1;
}
if (config.direction == "RL" || config.direction == "LR") {
if (this.constants.smoothCurves.enabled == true) {
this.constants.smoothCurves.type = "vertical";
}
}
else {
if (this.constants.smoothCurves.enabled == true) {
this.constants.smoothCurves.type = "horizontal";
}
}
};
@ -358,9 +358,9 @@ exports._setLevel = function(level, edges, parentId) {
*/
exports._setLevelDirected = function(level, edges, parentId) {
this.nodes[parentId].hierarchyEnumerated = true;
var childNode, direction;
for (var i = 0; i < edges.length; i++) {
var childNode = null;
var direction = 1;
direction = 1;
if (edges[i].toId == parentId) {
childNode = edges[i].from;
direction = -1;
@ -374,9 +374,9 @@ exports._setLevelDirected = function(level, edges, parentId) {
}
for (var i = 0; i < edges.length; i++) {
var childNode = null;
if (edges[i].toId == parentId) {childNode = edges[i].from;}
else {childNode = edges[i].to;}
if (childNode.edges.length > 1 && childNode.hierarchyEnumerated === false) {
this._setLevelDirected(childNode.level, childNode.edges, childNode.id);
}

Loading…
Cancel
Save