microsoft / automatic-graph-layout

A set of tools for graph layout and viewing
Other
1.35k stars 304 forks source link

LayerConstraints are not enforced when Subgraph is present #228

Open Oaz opened 4 years ago

Oaz commented 4 years ago

I think I've found an issue with Graph.LayerConstraints.AddUpDownConstraint / Graph.LayerConstraints.AddLeftRightConstraint. In a simple graph, the feature works fine but, when using subgraphs, constraints are no longer enforced.

I figured out the Dictionary<Node, int> nodeIdToIndex fields in VerticalConstraintsForSugiyama / HorizontalConstraintsForSugiyama might be related to this issue. When using subgraphs, some Layout.Node duplication occur and the Node keys in the dictionary never match. As a consequence, int NodeIndex(Node node) always returns -1.

For example, the following graph has no layout constraints: image

If I add a layout constraint where all nodes must be ordered from top to bottom in lexical order, I should get the following graph: image

The latest image was generated using a hack where I changed Dictionary<Node, int> nodeIdToIndex into Dictionary<string, int> nodeIdToIndex and using node.ToString() as keys. Without this hack, I get the same graph as the one with no constraint.