LayeredDigraphLayout changes vertical order of nodes

For my group template, I use LayeredDigraphLayout. However, once the layout is applied, the nodes are vertically reversed. How can I prevent this?

What do you mean by “vertically reversed”? A small screenshot would help, along with one that shows what you would prefer.

Hi walter, what happens is that, if the nodes were arranged in the diagram like:


after the group layout is applied, their order is:


Do you need to change the value of LayeredDigraphLayout.direction?

I didn’t notice you answered…
I havn’t tried changing the direction, it is set to default… I want it to grow to the right, these are nodes that are in the same column

Hi, walter, I just wanted to ping regarding this question.

Hello, sorry we missed this one.

I understand what you’re saying now. The problem in this case is that LayeredDigraphLayout doesn’t guarantee which layers a node will be placed into, and doesn’t have an easy way of comparing nodes within a layer since it shuffles things around to reduce link crossings in most cases.

Have you considered using a TreeLayout? That way you could use TreeLayout.comparer to organize your nodes.

I haven’t, I might give it a try… I would then simply compare them by their initial y coordinates?

You would probably want to set the sorting to TreeLayout.SortingAscending and then your comparer function should return however you’d like them sorted, whether that be by key or some other property.

I tried using TreeLayout a few moments ago, but I get the same thing… the links are crossed and the nodes are sorted in reverse… I think this only happens for nodes with no in links… or bottom children in a tree… I don’t know, maybe it has something to do with me using the subGraphExpander button?
The group is not initially expanded…

How is your TreeLayout configured?

I’ve tried configuring the tree layout with like this… I dont use any layout on the diagram:

layout: $(go.TreeLayout, {
                    layerSpacing: 10,
                    nodeSpacing: 10,
                    layerStyle: go.TreeLayout.LayerSiblings,
                    setsPortSpot: false,
                    // sorting: go.TreeLayout.SortingForwards

But you haven’t set sorting and comparer as Jon suggested.

you are right… I tried with different sortings, but didn’t try the comparer… I apologize to the both of you… it seems to be working now… thank you!