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>
<tr class="collapsible toggle" onclick="toggleTable('methodTable','getConnectedNodes', this);"> <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 <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> </td>
</tr> </tr>
<tr class="hidden" parent="getConnectedNodes"> <tr class="hidden" parent="getConnectedNodes">
<td class="midMethods">Returns: Array</td> <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, <td>Returns an array of nodeIds of all the nodes that are directly connected to this node or edge.<br><br>
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> 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>
<tr class="collapsible toggle" onclick="toggleTable('methodTable','getConnectedEdges', this);"> <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 <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. * Get the Ids of nodes connected to this node.
* @param nodeId * @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} * @returns {Array}
*/ */
getConnectedNodes(nodeId) { getConnectedNodes(nodeId, direction) {
let nodeList = []; let nodeList = [];
if (this.body.nodes[nodeId] !== undefined) { if (this.body.nodes[nodeId] !== undefined) {
let node = this.body.nodes[nodeId]; let node = this.body.nodes[nodeId];
let nodeObj = {}; // used to quickly check if node already exists let nodeObj = {}; // used to quickly check if node already exists
for (let i = 0; i < node.edges.length; i++) { for (let i = 0; i < node.edges.length; i++) {
let edge = node.edges[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) { if (nodeObj[edge.fromId] === undefined) {
nodeList.push(edge.fromId); nodeList.push(edge.fromId);
nodeObj[edge.fromId] = true; 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) { if (nodeObj[edge.toId] === undefined) {
nodeList.push(edge.toId); nodeList.push(edge.toId);
nodeObj[edge.toId] = true; nodeObj[edge.toId] = true;

|||||||
x
 
000:0
Loading…
Cancel
Save