Skip to content

Commit 03417c0

Browse files
committed
Merge pull request philogb#91 from pedrofaustino/master
onBeforeRemoveNode method
2 parents 133bde8 + 58b8761 commit 03417c0

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

Source/Graph/Graph.Op.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ Graph.Op = {
6363
var i, that, nodeObj;
6464
switch(options.type) {
6565
case 'nothing':
66-
for(i=0; i<n.length; i++) viz.graph.removeNode(n[i]);
66+
for(i=0; i<n.length; i++) {
67+
options.onBeforeRemoveNode(viz.graph.getNode(n[i]));
68+
viz.graph.removeNode(n[i]);
69+
}
6770
break;
6871

6972
case 'replot':

Source/Graph/Graph.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,7 @@ Graph.Util = {
10731073
var queue = [graph.getNode(id)];
10741074
while(queue.length != 0) {
10751075
var node = queue.pop();
1076+
if (!node) return;
10761077
node._flag = true;
10771078
action(node, node._depth);
10781079
this.eachAdjacency(node, function(adj) {
@@ -1089,6 +1090,7 @@ Graph.Util = {
10891090
Method: eachLevel
10901091
10911092
Iterates over a node's subgraph applying *action* to the nodes of relative depth between *levelBegin* and *levelEnd*.
1093+
In case you need to break the iteration, *action* should return false.
10921094
10931095
Also implemented by:
10941096
@@ -1103,18 +1105,20 @@ Graph.Util = {
11031105
11041106
*/
11051107
eachLevel: function(node, levelBegin, levelEnd, action, flags) {
1106-
var d = node._depth, filter = this.filter(flags), that = this;
1108+
var d = node._depth, filter = this.filter(flags), that = this, shouldContinue = true;
11071109
levelEnd = levelEnd === false? Number.MAX_VALUE -d : levelEnd;
11081110
(function loopLevel(node, levelBegin, levelEnd) {
1109-
var d = node._depth;
1110-
if(d >= levelBegin && d <= levelEnd && filter(node)) action(node, d);
1111-
if(d < levelEnd) {
1111+
if(!shouldContinue) return;
1112+
var d = node._depth, ret;
1113+
if(d >= levelBegin && d <= levelEnd && filter(node)) ret = action(node, d);
1114+
if(typeof ret !== "undefined") shouldContinue = ret;
1115+
if(shouldContinue && d < levelEnd) {
11121116
that.eachAdjacency(node, function(adj) {
11131117
var n = adj.nodeTo;
11141118
if(n._depth > d) loopLevel(n, levelBegin, levelEnd);
11151119
});
11161120
}
1117-
})(node, levelBegin + d, levelEnd + d);
1121+
})(node, levelBegin + d, levelEnd + d);
11181122
},
11191123

11201124
/*

Source/Options/Options.Controller.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@
6666
onAfterPlotNode(node) - This method is triggered right after plotting each <Graph.Node>.
6767
onBeforePlotLine(adj) - This method is triggered right before plotting a <Graph.Adjacence>. This method is useful for adding some styles to a particular edge before being plotted.
6868
onAfterPlotLine(adj) - This method is triggered right after plotting a <Graph.Adjacence>.
69-
69+
onBeforeRemoveNode(node) - This method is triggered right before removing each <Graph.Node>.
70+
7071
*Used in <ST>, <TM.Base> and <Icicle> visualizations*
7172
7273
request(nodeId, level, onComplete) - This method is used for buffering information into the visualization. When clicking on an empty node, the visualization will make a request for this node's subtrees, specifying a given level for this subtree (defined by _levelsToShow_). Once the request is completed, the onComplete callback should be called with the given result. This is useful to provide on-demand information into the visualizations withought having to load the entire information from start. The parameters used by this method are _nodeId_, which is the id of the root of the subtree to request, _level_ which is the depth of the subtree to be requested (0 would mean just the root node). _onComplete_ is an object having the callback method _onComplete.onComplete(json)_ that should be called once the json has been retrieved.
@@ -75,14 +76,15 @@
7576
Options.Controller = {
7677
$extend: true,
7778

78-
onBeforeCompute: $.empty,
79-
onAfterCompute: $.empty,
80-
onCreateLabel: $.empty,
81-
onPlaceLabel: $.empty,
82-
onComplete: $.empty,
83-
onBeforePlotLine:$.empty,
84-
onAfterPlotLine: $.empty,
85-
onBeforePlotNode:$.empty,
86-
onAfterPlotNode: $.empty,
79+
onBeforeCompute: $.empty,
80+
onAfterCompute: $.empty,
81+
onCreateLabel: $.empty,
82+
onPlaceLabel: $.empty,
83+
onComplete: $.empty,
84+
onBeforePlotLine: $.empty,
85+
onAfterPlotLine: $.empty,
86+
onBeforePlotNode: $.empty,
87+
onAfterPlotNode: $.empty,
88+
onBeforeRemoveNode:$.empty,
8789
request: false
8890
};

0 commit comments

Comments
 (0)