1

I have a network built with vis.js

{"_id":"Fy6FrNyNBK2NpxNL","projectId":"Fy6FrNyNBK2NpxNL","projectName":"The new project","nodes":[{"id":"2f03d267-d27d-4d7b-a88a-d32cf9d3a678","x":"-291.5","y":"-63","label":"Party","progress":"not-started","color":"#fff","earliestStartDate":"2016-03-29T22:00:00.000Z"},{"id":"5e780971-69e5-4a85-b1d7-130c23b163df","x":"-69.5","y":"-95","label":"Content structure","progress":"in-progress","color":"#5bc0de","earliestStartDate":"2016-04-19T22:00:00.000Z"},{"id":"ed298c12-810a-4b52-95f1-cfb40128d31a","x":"79.5","y":"-74","label":"validation","progress":"not-started","color":"#fff","earliestStartDate":"2016-04-19T22:00:00.000Z"},{"id":"23ec84a8-914a-4623-807d-3bc69455e8e9","x":"91.5","y":"61","label":"lessons learned","progress":"not-started","color":"#fff","earliestStartDate":"2016-03-29T22:00:00.000Z"},{"id":"e3d55089-8869-415b-99df-374b6cfe4a1b","x":"-434.4375","y":"-47.600006103515625","label":"Kick-off","progress":"completed","color":"#5cb85c","earliestStartDate":"2016-01-31T23:00:00.000Z"},{"id":"ed9eaa83-8116-4ba5-a072-30c08fe45556","x":"-92.4375","y":"-99.60000610351562","label":"Data Migration Germany","progress":"not-started","color":"#fff","earliestStartDate":""},{"id":"21297761-f992-4f29-aa41-8db9d331832c","x":"-107.4375","y":"-14.600006103515625","label":"Data Migration Belgium","progress":"not-started","color":"#fff","earliestStartDate":"2016-03-29T22:00:00.000Z"}],"edges":[{"from":"5e780971-69e5-4a85-b1d7-130c23b163df","to":"2f03d267-d27d-4d7b-a88a-d32cf9d3a678","id":"18a976ee-4ffb-42c3-9f46-a31fa3cfa402"},{"from":"5e780971-69e5-4a85-b1d7-130c23b163df","to":"ed298c12-810a-4b52-95f1-cfb40128d31a","id":"97d98095-a926-464b-bf90-f15483d1097e"},{"from":"ed298c12-810a-4b52-95f1-cfb40128d31a","to":"23ec84a8-914a-4623-807d-3bc69455e8e9","id":"9b91c226-ce47-4713-b08e-b22995f33d73"},{"from":"e3d55089-8869-415b-99df-374b6cfe4a1b","to":"5e780971-69e5-4a85-b1d7-130c23b163df","id":"a3ef8f95-ec16-48b3-aeec-eb38a542646e"},{"from":"e3d55089-8869-415b-99df-374b6cfe4a1b","to":"21297761-f992-4f29-aa41-8db9d331832c","id":"df1295f8-d318-49cc-a0c1-2ed8447dd62d"},{"from":"e3d55089-8869-415b-99df-374b6cfe4a1b","to":"ed9eaa83-8116-4ba5-a072-30c08fe45556","id":"71668683-db31-430d-8050-f2fa3f239bcb"}]}

The structure of those networks are:

  • Nodes
    • Node 1
    • Node 2
  • Edges
    • Edge 1
    • Edge 2

Edges contain a from and to parameter referencing the IDs of the nodes they are connecting.

Basically I would like to travers the graph. I would need to first find the root node. Any ideas how to make this happen?

rapsli
  • 749
  • 1
  • 8
  • 23
  • Possible duplicate of [Finding all the roots in a directed graph](http://stackoverflow.com/questions/19950282/finding-all-the-roots-in-a-directed-graph) – stdob-- Apr 01 '16 at 00:43

1 Answers1

0

You can do the following:

  • Start at some node
  • Find all edges connected to this node by filtering the edges having this node's id as from or to.
  • Loop over all nodes of the filtered edges
  • etc...
Jos de Jong
  • 6,602
  • 3
  • 38
  • 58