kieler / elkjs

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

Subflows with MRTREE algorithm - incorrect position and width calculation #294

Open belamajoros opened 2 months ago

belamajoros commented 2 months ago

Hi, when using the mrtree algorithm with subflows, the position of the nodes inside of the subflow is incorrectly calculated. Also in case of a subflow inside a subflow, the width of the parent subflow is also incorrectly calculated and part of the child subflow gets placed outside of its parent subflow.

example for elklive: { id: "root", layoutOptions: { 'algorithm': 'mrtree', 'elk.direction': 'DOWN', 'elk.spacing.nodeNode': '50', }, children: [ { id: "n1", width: 30, height: 30, layoutOptions: { 'elk.alignment': 'TOP'} }, { id: "n2", width: 30, height: 30, layoutOptions: { 'elk.alignment': 'TOP'} }, { id: "n3", width: 30, height: 30, layoutOptions: { 'elk.alignment': 'TOP', 'elk.algorithm': 'mrtree', 'elk.direction': 'DOWN'}, children: [ { id: "n7", width: 30, height: 30, layoutOptions: { 'elk.alignment': 'TOP' }}, { id: "n8", width: 30, height: 30, layoutOptions: { 'elk.alignment': 'TOP'}} ]}, { id: "n4", width: 30, height: 30, layoutOptions: { 'elk.alignment': 'TOP'} }, { id: "n6", width: 30, height: 30, layoutOptions: { 'elk.alignment': 'TOP'} } ], edges: [ { id: "e1", sources: [ "n1" ], targets: [ "n2" ] }, { id: "e4", sources: [ "n1" ], targets: [ "n3" ] }, { id: "e3", sources: [ "n2" ], targets: [ "n4" ] }, { id: "e5", sources: [ "n1" ], targets: [ "n6" ] }, ] }

Screenshots image image

This in itself would not be a huge problem as I am able to correctly position the nodes inside the subflow after calling elk.layout().

Regarding the incorrect parent subflow width:

Screenshots If the subflow is on the right side of the branch (incorrect): image If the subflow is on the left side of the branch (correct): image

ELK Version 0.9.3 algorithm: mrtree

Eddykasp commented 2 months ago

This is indeed a bug, minimally reproduced in this example. The problem seems to be in the position and size calculation of the graph after layout.