Browse Source

hierarchical layout is now recalculated on addition and removal of node or edge and edit of edge

css_transitions
Alex de Mulder 10 years ago
parent
commit
edfa132fce
4 changed files with 76 additions and 4 deletions
  1. +39
    -3
      dist/vis.js
  2. +22
    -0
      src/graph/Graph.js
  3. +3
    -1
      src/graph/Node.js
  4. +12
    -0
      src/graph/graphMixins/HierarchicalLayoutMixin.js

+ 39
- 3
dist/vis.js View File

@ -4,8 +4,8 @@
* *
* A dynamic, browser-based visualization library. * A dynamic, browser-based visualization library.
* *
* @version @@version
* @date @@date
* @version 0.7.2-SNAPSHOT
* @date 2014-04-07
* *
* @license * @license
* Copyright (C) 2011-2014 Almende B.V, http://almende.com * Copyright (C) 2011-2014 Almende B.V, http://almende.com
@ -9465,6 +9465,8 @@ function Node(properties, imagelist, grouplist, constants) {
this.radiusMin = constants.nodes.radiusMin; this.radiusMin = constants.nodes.radiusMin;
this.radiusMax = constants.nodes.radiusMax; this.radiusMax = constants.nodes.radiusMax;
this.level = -1; this.level = -1;
this.preassignedLevel = false;
this.imagelist = imagelist; this.imagelist = imagelist;
this.grouplist = grouplist; this.grouplist = grouplist;
@ -9557,7 +9559,7 @@ Node.prototype.setProperties = function(properties, constants) {
if (properties.x !== undefined) {this.x = properties.x;} if (properties.x !== undefined) {this.x = properties.x;}
if (properties.y !== undefined) {this.y = properties.y;} if (properties.y !== undefined) {this.y = properties.y;}
if (properties.value !== undefined) {this.value = properties.value;} if (properties.value !== undefined) {this.value = properties.value;}
if (properties.level !== undefined) {this.level = properties.level;}
if (properties.level !== undefined) {this.level = properties.level; this.preassignedLevel = true;}
// physics // physics
@ -12599,6 +12601,18 @@ var repulsionMixin = {
var HierarchicalLayoutMixin = { var HierarchicalLayoutMixin = {
_resetLevels : function() {
for (var nodeId in this.nodes) {
if (this.nodes.hasOwnProperty(nodeId)) {
var node = this.nodes[nodeId];
if (node.preassignedLevel == false) {
node.level = -1;
}
}
}
},
/** /**
* This is the main function to layout the nodes in a hierarchical way. * This is the main function to layout the nodes in a hierarchical way.
* It checks if the node details are supplied correctly * It checks if the node details are supplied correctly
@ -16032,6 +16046,7 @@ function Graph (container, data, options) {
this.stabilize = true; // stabilize before displaying the graph this.stabilize = true; // stabilize before displaying the graph
this.selectable = true; this.selectable = true;
this.initializing = true;
// these functions are triggered when the dataset is edited // these functions are triggered when the dataset is edited
this.triggerFunctions = {add:null,edit:null,connect:null,delete:null}; this.triggerFunctions = {add:null,edit:null,connect:null,delete:null};
@ -16250,6 +16265,7 @@ function Graph (container, data, options) {
this.setData(data,this.constants.clustering.enabled || this.constants.hierarchicalLayout.enabled); this.setData(data,this.constants.clustering.enabled || this.constants.hierarchicalLayout.enabled);
// hierarchical layout // hierarchical layout
this.initializing = false;
if (this.constants.hierarchicalLayout.enabled == true) { if (this.constants.hierarchicalLayout.enabled == true) {
this._setupHierarchicalLayout(); this._setupHierarchicalLayout();
} }
@ -17284,6 +17300,10 @@ Graph.prototype._addNodes = function(ids) {
this.moving = true; this.moving = true;
} }
this._updateNodeIndexList(); this._updateNodeIndexList();
if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
this._resetLevels();
this._setupHierarchicalLayout();
}
this._updateCalculationNodes(); this._updateCalculationNodes();
this._reconnectEdges(); this._reconnectEdges();
this._updateValueRange(this.nodes); this._updateValueRange(this.nodes);
@ -17333,6 +17353,10 @@ Graph.prototype._removeNodes = function(ids) {
delete nodes[id]; delete nodes[id];
} }
this._updateNodeIndexList(); this._updateNodeIndexList();
if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
this._resetLevels();
this._setupHierarchicalLayout();
}
this._updateCalculationNodes(); this._updateCalculationNodes();
this._reconnectEdges(); this._reconnectEdges();
this._updateSelection(); this._updateSelection();
@ -17411,6 +17435,10 @@ Graph.prototype._addEdges = function (ids) {
this.moving = true; this.moving = true;
this._updateValueRange(edges); this._updateValueRange(edges);
this._createBezierNodes(); this._createBezierNodes();
if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
this._resetLevels();
this._setupHierarchicalLayout();
}
this._updateCalculationNodes(); this._updateCalculationNodes();
}; };
@ -17441,6 +17469,10 @@ Graph.prototype._updateEdges = function (ids) {
} }
this._createBezierNodes(); this._createBezierNodes();
if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
this._resetLevels();
this._setupHierarchicalLayout();
}
this.moving = true; this.moving = true;
this._updateValueRange(edges); this._updateValueRange(edges);
}; };
@ -17466,6 +17498,10 @@ Graph.prototype._removeEdges = function (ids) {
this.moving = true; this.moving = true;
this._updateValueRange(edges); this._updateValueRange(edges);
if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
this._resetLevels();
this._setupHierarchicalLayout();
}
this._updateCalculationNodes(); this._updateCalculationNodes();
}; };

+ 22
- 0
src/graph/Graph.js View File

@ -27,6 +27,7 @@ function Graph (container, data, options) {
this.stabilize = true; // stabilize before displaying the graph this.stabilize = true; // stabilize before displaying the graph
this.selectable = true; this.selectable = true;
this.initializing = true;
// these functions are triggered when the dataset is edited // these functions are triggered when the dataset is edited
this.triggerFunctions = {add:null,edit:null,connect:null,delete:null}; this.triggerFunctions = {add:null,edit:null,connect:null,delete:null};
@ -245,6 +246,7 @@ function Graph (container, data, options) {
this.setData(data,this.constants.clustering.enabled || this.constants.hierarchicalLayout.enabled); this.setData(data,this.constants.clustering.enabled || this.constants.hierarchicalLayout.enabled);
// hierarchical layout // hierarchical layout
this.initializing = false;
if (this.constants.hierarchicalLayout.enabled == true) { if (this.constants.hierarchicalLayout.enabled == true) {
this._setupHierarchicalLayout(); this._setupHierarchicalLayout();
} }
@ -1279,6 +1281,10 @@ Graph.prototype._addNodes = function(ids) {
this.moving = true; this.moving = true;
} }
this._updateNodeIndexList(); this._updateNodeIndexList();
if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
this._resetLevels();
this._setupHierarchicalLayout();
}
this._updateCalculationNodes(); this._updateCalculationNodes();
this._reconnectEdges(); this._reconnectEdges();
this._updateValueRange(this.nodes); this._updateValueRange(this.nodes);
@ -1328,6 +1334,10 @@ Graph.prototype._removeNodes = function(ids) {
delete nodes[id]; delete nodes[id];
} }
this._updateNodeIndexList(); this._updateNodeIndexList();
if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
this._resetLevels();
this._setupHierarchicalLayout();
}
this._updateCalculationNodes(); this._updateCalculationNodes();
this._reconnectEdges(); this._reconnectEdges();
this._updateSelection(); this._updateSelection();
@ -1406,6 +1416,10 @@ Graph.prototype._addEdges = function (ids) {
this.moving = true; this.moving = true;
this._updateValueRange(edges); this._updateValueRange(edges);
this._createBezierNodes(); this._createBezierNodes();
if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
this._resetLevels();
this._setupHierarchicalLayout();
}
this._updateCalculationNodes(); this._updateCalculationNodes();
}; };
@ -1436,6 +1450,10 @@ Graph.prototype._updateEdges = function (ids) {
} }
this._createBezierNodes(); this._createBezierNodes();
if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
this._resetLevels();
this._setupHierarchicalLayout();
}
this.moving = true; this.moving = true;
this._updateValueRange(edges); this._updateValueRange(edges);
}; };
@ -1461,6 +1479,10 @@ Graph.prototype._removeEdges = function (ids) {
this.moving = true; this.moving = true;
this._updateValueRange(edges); this._updateValueRange(edges);
if (this.constants.hierarchicalLayout.enabled == true && this.initializing == false) {
this._resetLevels();
this._setupHierarchicalLayout();
}
this._updateCalculationNodes(); this._updateCalculationNodes();
}; };

+ 3
- 1
src/graph/Node.js View File

@ -54,6 +54,8 @@ function Node(properties, imagelist, grouplist, constants) {
this.radiusMin = constants.nodes.radiusMin; this.radiusMin = constants.nodes.radiusMin;
this.radiusMax = constants.nodes.radiusMax; this.radiusMax = constants.nodes.radiusMax;
this.level = -1; this.level = -1;
this.preassignedLevel = false;
this.imagelist = imagelist; this.imagelist = imagelist;
this.grouplist = grouplist; this.grouplist = grouplist;
@ -146,7 +148,7 @@ Node.prototype.setProperties = function(properties, constants) {
if (properties.x !== undefined) {this.x = properties.x;} if (properties.x !== undefined) {this.x = properties.x;}
if (properties.y !== undefined) {this.y = properties.y;} if (properties.y !== undefined) {this.y = properties.y;}
if (properties.value !== undefined) {this.value = properties.value;} if (properties.value !== undefined) {this.value = properties.value;}
if (properties.level !== undefined) {this.level = properties.level;}
if (properties.level !== undefined) {this.level = properties.level; this.preassignedLevel = true;}
// physics // physics

+ 12
- 0
src/graph/graphMixins/HierarchicalLayoutMixin.js View File

@ -1,6 +1,18 @@
var HierarchicalLayoutMixin = { var HierarchicalLayoutMixin = {
_resetLevels : function() {
for (var nodeId in this.nodes) {
if (this.nodes.hasOwnProperty(nodeId)) {
var node = this.nodes[nodeId];
if (node.preassignedLevel == false) {
node.level = -1;
}
}
}
},
/** /**
* This is the main function to layout the nodes in a hierarchical way. * This is the main function to layout the nodes in a hierarchical way.
* It checks if the node details are supplied correctly * It checks if the node details are supplied correctly

Loading…
Cancel
Save