I am doing a project to display an org chart/flow and I want when I press a “Set layout” button to arrange the nodes in a strutured way, like from image 1 where they are scattered to image 2 where they have a form.
I have used dagrejs or cytoscape to do this but there is a problem when 2 nodes are partners(they are on the same level and they are not child to one another). The nodes I am talking about can be seen in 2nd image above the red line. .
The structure of my nodes is like this:
I have used dagrejs or cytoscape to do this but there is a problem when 2 nodes are partners(they are on the same level and they are not child to one another). The nodes I am talking about can be seen in 2nd image above the red line.[![First image, scattered nodes](https://i.sstatic.net/oTnXG9UA.png)](https://i.sstatic.net/oTnXG9UA.png) [![Second image, arranged](https://i.sstatic.net/M6g9AbBp.png)](https://i.sstatic.net/M6g9AbBp.png) .
The structure of my nodes is like this:
{
"id": "9cd4",
"type": "default",
"level": 2,
"children": [],
"position": {
"x": 940,
"y": 560
},
"data": {
"slug": "support",
"name": "Support",
"occupied": 6,
"available": 9,
"id": "9cd4"
}
},
{
"id": "19f0",
"type": "default",
"level": 2,
"children": [],
"position": {
"x": 1220,
"y": 560
},
"data": {
"slug": "administration",
"name": "Administration",
"occupied": 11,
"available": 7,
"id": "19f0"
}
},
Those 2 libraries are putting the Administration node below the Support one even for other types like: klay. Do you know if there is way to configure one of those libraries to achieve this? Maybe I missed something in docs or if there is any algorithm to achieve this or an idea how to do my own layout. I tried to think about something using the levels and based on the level with most nodes go from there bottom and up to make the structure but I get stuck when I try to figure out how to recalculate the positions for the nodes in each level.
Those 2 libraries are putting the Administration node below the Support one even for other types like: klay. Do you know if there is way to configure one of those libraries to achieve this? Maybe I missed something in docs or if there is any algorithm to achieve this or an idea how to do my own layout. I tried to think about something using the levels and based on the level with most nodes go from there bottom and up to make the structure but I get stuck when I try to figure out how to recalculate the positions for the nodes in each level.