kieler / elkjs

ELK's layout algorithms for JavaScript
Other
1.76k stars 97 forks source link

Partitions not aligning by order #218

Closed willedanielsson closed 1 year ago

willedanielsson commented 1 year ago

Describe the bug We use partitioning for having nodes in a certain depth but some the nodes are not partitioned in their give partition order. LINK TO EDITOR

In this example, node n9 would in my understanding be positioned in the same layer as the others with partition: 1 but is now Y-alligned with the nodes with partition: 0. Is this a bugg or is there another way for me to accomplish the desired behaviour?

Expected behavior Nodes are layered by partition

Screenshots

Screenshot 2023-04-27 at 12 38 04

ELK Version 0.8.2 and rest

Additional context

{
  id: "root",
  layoutOptions: { 'algorithm': 'layered', 'partitioning.activate': true,  "elk.direction": "DOWN", },
  children: [
    { id: "n1", width: 30, height: 30, layoutOptions: {'partitioning.partition': 0}},
    { id: "n2", width: 30, height: 30, layoutOptions: {'partitioning.partition': 1}},
    { id: "n3", width: 30, height: 30, layoutOptions: {'partitioning.partition': 2}},
    { id: "n4", width: 30, height: 30, layoutOptions: {'partitioning.partition': 2} },
    { id: "n5", width: 30, height: 30, layoutOptions: {'partitioning.partition': 3} },
    { id: "n6", width: 30, height: 30, layoutOptions: {'partitioning.partition': 3} },
    { id: "n7", width: 30, height: 30, layoutOptions: {'partitioning.partition': 0} },
    { id: "n8", width: 30, height: 30, layoutOptions: {'partitioning.partition': 1} },
    { id: "n9", width: 30, height: 30, layoutOptions: {'partitioning.partition': 1} }
  ],
  edges: [
    { id: "e1", sources: [ "n1" ], targets: [ "n2" ] },
    { id: "e2", sources: [ "n1" ], targets: [ "n3" ] },
    { id: "e3", sources: [ "n1" ], targets: [ "n4" ] },
    { id: "e4", sources: [ "n1" ], targets: [ "n5" ] },
    { id: "e5", sources: [ "n1" ], targets: [ "n6" ] },
    { id: "e6", sources: [ "n7" ], targets: [ "n8" ] }
  ]
}
soerendomroes commented 1 year ago

You need to specify that the three different separate connected components should not be handled separately. Your updated model

willedanielsson commented 1 year ago

Ooh damn that amazing, thank you!

For others with the same future issue, Adding: 'org.eclipse.elk.separateConnectedComponents': 'false', to layoutOptions fixes it

soerendomroes commented 1 year ago

Another option which might be interesting for you is org.eclipse.elk.considerModelOrder.strategy. If you use elk 0.8.2 you might want to set it to PREFER_EDGES to order the nodes and edges by you edge order per default if no additional crossings are introduced, as seen here. (only works if you change the elkjs version so something 0.8.x or above).