I can't seem to apply a tree layout to my diagram that uses GraphLinksModel.
That looks correct to me, except that setting Conditions=“All” seems excessive. But maybe you were just trying different things to get it to work.
Do links go from the parent node to the child nodes? If it’s the other way around, you should set TreeLayout’s Path=“Source”.
I don’t have an explanation for why it isn’t working. Can you determine if there are any relevant differences between your application and any of the samples that make use of TreeLayout?
Are the nodes actually connected by links in the manner you would expect? In other words, is the only problem that the TreeLayout doesn’t seem to be positioning the nodes? So that if you drag the nodes by hand you can get something like what you want?
The difference is that I use the GraphLinksModel and the GraphLinksModelNodeData and the examples use the TreeModel with the TreeModelNodeData, but according to the documentation it should work the same. Is there any example of a GraphLinksModel with a tree layout?
The DecisionTree and FamilyTree samples use GraphLinksModel, because they need to (due to ports and non-tree-structure, respectively).
I was also amused to see that the Tree Layout sample uses a GraphLinksModel too, even though its graphs are definitely tree structured.
Found the problem!
I think the issue is that by default when a diagram is loaded, if all of the nodes have definite Locations, no layout is performed.
A Node.Location is “definite” when both the X and Y values are not NaN – in other words when the X and Y value are both regular numbers.
By not setting or data-binding the go:Node.Location attached property, it defaults to NaN,NaN, which results in a layout assigning the node locations. That’s why your second solution worked.
If you don’t like this “don’t do an initial layout when all of the nodes have locations” behavior, you can change it by customizing the LayoutManager:
<go:LayoutManager Initial=“InvalidateAll” />
The default value is “InvalidateIfNodesUnlocated”.
It isn’t clear to me why your first solution worked. I would have thought that your data-binding of Node.Location was assigning actual locations to all of the nodes, but redefining the data.Location property wouldn’t change that because the default value of your m_location field is 0,0.
The first solution isn’t clear at all to me too, espacialy when i removed any location assignment from the code.
That’s odd, because when I modified the FlowChart sample, everything behaved the way it’s supposed to.
The existing behavior is to load a diagram from XML; it doesn’t do any layout.
If you define a go:Diagram.Layout, that layout doesn’t happen after the initial diagram is loaded. It only happens when its DiagramLayout.Conditions are met – by default when nodes or links are added or removed, etc.
But if you define a go:Diagram.Layout and a go:Diagram.LayoutManager with Initial=“InvalidateAll”, the layout occurs immediately after loading, thereby discarding all of the node locations that were read from the XML and assigned to the go:Node.Location via data-binding.
Just to be clear: I never re-defined a “Location” property in the data class.