diff --git a/docs/network/index.html b/docs/network/index.html index cc86669f..c98ced3a 100644 --- a/docs/network/index.html +++ b/docs/network/index.html @@ -866,13 +866,19 @@ function releaseFunction (clusterPosition, containedNodesPositions) {
String
- nodeId or edgeId
)
+ nodeId or edgeId, [String direction])
[fromId, toId]
.direction
is set to string 'from', only parent nodes are returned.direction
is set to 'to', only child nodes are returned.undefined
returns both parent and child nodes.
+ [fromId, toId]
.
+ Parameter direction is ignored for edges.String
diff --git a/lib/network/modules/NodesHandler.js b/lib/network/modules/NodesHandler.js
index f9999327..3e363ed5 100644
--- a/lib/network/modules/NodesHandler.js
+++ b/lib/network/modules/NodesHandler.js
@@ -408,22 +408,24 @@ class NodesHandler {
/**
* Get the Ids of nodes connected to this node.
* @param nodeId
+ * @param direction {String|undefined} values 'from' and 'to' select respectively parent and child nodes only.
+ * Any other value returns both parent and child nodes.
* @returns {Array}
*/
- getConnectedNodes(nodeId) {
+ getConnectedNodes(nodeId, direction) {
let nodeList = [];
if (this.body.nodes[nodeId] !== undefined) {
let node = this.body.nodes[nodeId];
let nodeObj = {}; // used to quickly check if node already exists
for (let i = 0; i < node.edges.length; i++) {
let edge = node.edges[i];
- if (edge.toId == node.id) { // these are double equals since ids can be numeric or string
+ if (direction !== 'from' && edge.toId == node.id) { // these are double equals since ids can be numeric or string
if (nodeObj[edge.fromId] === undefined) {
nodeList.push(edge.fromId);
nodeObj[edge.fromId] = true;
}
}
- else if (edge.fromId == node.id) { // these are double equals since ids can be numeric or string
+ else if (direction !== 'to' && edge.fromId == node.id) { // these are double equals since ids can be numeric or string
if (nodeObj[edge.toId] === undefined) {
nodeList.push(edge.toId);
nodeObj[edge.toId] = true;