Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions lib/dep_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,41 @@ DepGraph.prototype = {
}
}
},
/**
* Combines all outgoingEdges of list of nodes
*/
getNodesNextLevel: function(nodes) {
var source = this;
var nodesInLevel = []
for (i = 0; i < nodes.length; i++) {
nodesInLevel = nodesInLevel.concat(source.outgoingEdges[nodes[i]])
}
return [...new Set(nodesInLevel)]
},
/**
* Get nodes at each level
* .e.g getNodesEachLevel()
*/
getNodesEachLevel: function(nodes, out, level) {
if(this.circular){
throw new Error("getNodesEachLevel only works for trees")
}
if(out == undefined){
out = []
}
if(nodes == undefined){
nodes = [Object.keys(this.nodes)[0]] //set root
out.push(nodes)
level = 0
}
if(this.getNodesNextLevel(nodes).length == 0){
return out
}else{
out.push(this.getNodesNextLevel(nodes))
}
level++
return this.getNodesEachLevel(out[level], out, level)
},
/**
* Return a clone of the dependency graph. If any custom data is attached
* to the nodes, it will only be shallow copied.
Expand Down