Reputation: 1545
I've created a hierarchical directed graph in Vis.js. Now, I want to extract the parents from a given node. How do I do this? I couldn't find a method in the documentation that allowed me to do this.
Upvotes: 3
Views: 2269
Reputation: 1183
As TERMIN had said, vis.Network()
objects have a method getConnectedNodes
for this purpose (documentation). You don't need to use the getPosition
method to differentiate children from parent nodes though, as TERMIN had said, because getConnectedNodes
has an optional input for the edge direction that would cover this.
If your vis.Network()
object is named network, then try:
var myNode = 'desired node ID',
arrayOfParents = network.getConnectedNodes(myNode, 'from')
Upvotes: 5
Reputation: 862
Use the getConnectedNodes
method to get the connected nodes (parents and children).
Get the positions of the nodes using getPosition
method.
Run over the connected nodes and see which node has y
position smaller then the current node y
position. This node should be the parent.
Same for all other found parents.
Upvotes: 0