kieler / elkjs

ELK's layout algorithms for JavaScript
Other
1.73k stars 94 forks source link

[Question] Mrtree center node with multiple parents #297

Open fima-methodic opened 2 weeks ago

fima-methodic commented 2 weeks ago

Hey, i am using elkjs and i am trying to achieve a result where when a node in the tree has 2 parents (and 2 edges) it will be centered beneath them and not aligned to the left.

Here is a screenshot of the current behavior: Screenshot 2024-08-28 at 15 12 17 link to elklive

I need the bottom node to be aligned to the center - how can i achieve that?

I'll be glad to provide more information if needed

soerendomroes commented 2 weeks ago

mrtree also "works" for graphs that are not trees, as the one you used. However, it handles all edges that are not part of the primary tree differently and does not consider them for node placement. Hence, this algorithm cannot do what you want it to do.

Maybe the layered algorithm works for you.

fima-methodic commented 2 weeks ago

@soerendomroes The layered algorithm works for me pretty well beside 1 issue that i have with sorting some of the nodes. Extending your example the child nodes n2 - a, n3 - b, n4 - c being placed like this (from left to right) -> n4 - n2 - n3. Is there a way to sort the nodes in a different way (n2 - n3 - n4)?

soerendomroes commented 2 weeks ago

Have you tried setting considerModelOrder.strategy to NODES_AND_EDGES?

fima-methodic commented 1 week ago

Thank you very much for your help @soerendomroes it worked :)