Is there an optimized way to order nodes in nodeDataArray based on their order of appearance in the diagram?

Hi,

We have been using GraphLinksModel for our diagram. Whenever we add any node to diagram, I see that it is just appended to model’s nodeDataArray in the order they are added but not in the order they appear in the diagram.

For instance let’s consider below diagram:

I am looking for an API to sort nodeDataArray so that it returns an array of objects in the order : Start->If->For Loop->Unselect All From List->Unselect All From List->Select Radio Button->End.

Currently it returns the order in which nodes are added to diagram, which is something like Start->End->For Loop ->If ->Unselect All From List ->Select Radio Button-> Unselect All From List.

That sounds like a topological sort, which is fairly straight-forward to implement.
https://en.wikipedia.org/wiki/Topological_sorting