Browse Source

Added param 'direction' to Network.getConnectedNodes() (#3108)

* Added param 'direction' to Network.getConnectedNodes()

* Redo commit - Network.js does not need to change
gemini
wimrijnders 7 years ago
committed by yotamberk
parent
commit
0e6b6ecdb8
2 changed files with 14 additions and 6 deletions
  1. +9
    -3
      docs/network/index.html
  2. +5
    -3
      lib/network/modules/NodesHandler.js

+ 9
- 3
docs/network/index.html View File

@ -866,13 +866,19 @@ function releaseFunction (clusterPosition, containedNodesPositions) {
</tr>
<tr class="collapsible toggle" onclick="toggleTable('methodTable','getConnectedNodes', this);">
<td colspan="2"><span parent="getConnectedNodes" class="right-caret" id="method_getConnectedNodes"></span> getConnectedNodes(<code><i>String
nodeId or edgeId</i></code>)
nodeId or edgeId, [String direction]</i></code>)
</td>
</tr>
<tr class="hidden" parent="getConnectedNodes">
<td class="midMethods">Returns: Array</td>
<td>Returns an array of nodeIds of the all the nodes that are directly connected to this node. If you supply an edgeId,
vis will first match the id to nodes. If no match is found, it will search in the edgelist and return an array: <code>[fromId, toId]</code>.</td>
<td>Returns an array of nodeIds of all the nodes that are directly connected to this node or edge.<br><br>
For a node id, returns an array with the id's of the connected nodes.<br>
If optional parameter <code>direction</code> is set to string <i>'from'</i>, only parent nodes are returned.<br>
If <code>direction</code> is set to <i>'to'</i>, only child nodes are returned.<br>
Any other value or <code>undefined</code> returns both parent and child nodes.
<br><br>
For an edge id, returns an array: <code>[fromId, toId]</code>.
Parameter <i>direction</i> is ignored for edges.</td>
</tr>
<tr class="collapsible toggle" onclick="toggleTable('methodTable','getConnectedEdges', this);">
<td colspan="2"><span parent="getConnectedEdges" class="right-caret" id="method_getConnectedEdges"></span> getConnectedEdges(<code><i>String

+ 5
- 3
lib/network/modules/NodesHandler.js View File

@ -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;

Loading…
Cancel
Save