-1

I use cytoscape.js to organize an flow of nodes that represent an tasks execution. Sometimes an task is not created hierarchicly.

At least in a visual way, edges gives the correct sequence.

I would like to get the hierarchical sequence based on the edges and list their data as an array. Each index will be dispposed as edges says so.

The image above represent a sequence based on the edges arrows. I would like to transform this edges/arrows sequence into a perfect sequence of data (array).

enter image description here

The cytoscape.elements().toArray() method transform visual to array, but it is delivered the same sequence of the original data.

How can it be done? Is there some method in cytoscape core?

calebeaires
  • 1,972
  • 1
  • 22
  • 34
  • I don't understand the sequence of your numbers. How come that node 7 comes before 9 - 11? Hierarcically it would be the other way, right? If you want the nodes to be in a hierarchy, you would have to rethink your layout. An hierarchy in cytoscape can be achieved by "directed acyclic graph" (= dagre in cytoscape). – Stephan T. Jun 08 '18 at 11:23

1 Answers1

0

The easiest way would be to give the nodes id's with the corresponding numbers in your sequence:

-> The first task to execute has the id 1, the second has the id 2...

After initialization you can then do a loop with n iterations (n = number of nodes in cy) and get the nodes one by one. That way you can access their information and enter this data into an array:

for (i = 0; i < cy.nodes().length; i++) {
    var curr = cy.nodes("[id = '" + i + "']");   // This way you get the node with the id == i
    //do stuff
    array[i] = theDataYouNeed;
}

If you want the nodes to be in a hierarchy, you would have to rethink your layout. An hierarchy in cytoscape can be achieved by "directed acyclic graph" (= dagre in cytoscape).

Stephan T.
  • 5,843
  • 3
  • 20
  • 42