Jean Zombie
Jean Zombie

Reputation: 627

How to use eles.components() to filter direct neighbours of one node?

I want to filter all nodes not further away then one edge of a given node. I dont have a compound graph. I tried

var children = cy.$('#1').components()

But this only returns the node #1. I also tried

var allEles = cy.elements()
var myChildren = allEles.componentsOf(cy.$('#1'))

But this seems to return all nodes again. The docs also state a selector syntax "> (child selector) Matches direct children of the parent node (e.g. node > node)." But I cant figure that one out either. I tried

var myChildren = cy.elements('node#1 > node')

getting an empty array.

So, how can filter for direct children (depth=1) of a given node?

Upvotes: 0

Views: 253

Answers (1)

Luck21
Luck21

Reputation: 136

Did you try use:

// outgoers return all elements (edges as well) comming out from $('#1') 
// nodes() > select only nodes
var children = cy.$('#1').outgoers().nodes();

doc: https://js.cytoscape.org/#nodes.outgoers

Upvotes: 2

Related Questions