Asad Ali Khan
Asad Ali Khan

Reputation: 307

How to get List of Edges for particular node in cytoscape js

I want to trace edges of selected nodes and then display them on a graph using cy.add() exactly on the same position

I try to retrieve edges using .connectedEdges(). but it gives me this

u {length: 0, _private: {…}}

Now I don't know how to trace the ID's of edges to display them again on a graph using cy.add()

Is there something is missing...

Upvotes: 1

Views: 2376

Answers (1)

Stephan T.
Stephan T.

Reputation: 6074

You can access the outgoing edges via the outgoers() function, where you also get the targets of the edges you search for:

var outgoers = collection.outgoers();          // This contains all connected edges and their targets
var targets = collection.outgoers().targets(); // This contains all targets of your selected node
cy.ready(function () {
   for (node in outgoers) { 
      // Do what you like here
   }
});

It is better to use:

cy.nodes("[id = '" + id + "']").connectedEdges();

Upvotes: 2

Related Questions