Hi Walter
I have JSON array object with key and parent. My JSON array is not consistent some childs will come first and some childs will come later. the parents and childs are not in order in the JSON. in Tree layout some of children not mapped to the parent. the tree layout missing the children and listing as orphans. Please advise what is the way to make them order or in gojs any feature.
walter
April 26, 2017, 6:59pm
2
You can affect the behavior of TreeLayout to control the order of the children for any parent, by setting TreeLayout.sorting and TreeLayout.comparer .
Hi Walter any idea how to invoke the sorting or comparer functions in Tree layout… I have below example.
and one more thing based on data i want to put expand and close tree nodes?? any idea how to do that?
Appreciate your help
myTreeDiagram =
$(go.Diagram, “myTreeDiagramDiv”,
{
allowMove: false,
allowCopy: false,
allowDelete: false,
allowHorizontalScroll: false,
layout:
$(go.TreeLayout,
{
alignment: go.TreeLayout.AlignmentStart,
angle: 0,
sorting: go.TreeLayout.SortingForwards,
compaction: go.TreeLayout.CompactionNone,
layerSpacing: 16,
layerSpacingParentOverlap: 1,
nodeIndent: 2,
nodeIndentPastParent: 0.88,
nodeSpacing: 0,
setsPortSpot: false,
setsChildPortSpot: false
})
});
walter
April 26, 2017, 7:46pm
4
Have you read GoJS Trees -- Northwoods Software ?
You probably want to use go.TreeLayout.SortingAscending
or go.TreeLayout.SortingDescending
.
If you search, you should find some examples of TreeLayout.comparer . For example:
Hi,
I am trying to define custom compare function in treeLayout. here is the sample code, i am using:
var treeLayout = new go.TreeLayout();
<span =“Apple-tab-span” style=“white-space:pre”> treeLayout.angle = 90;
<span =“Apple-tab-span” style=“white-space:pre”> treeLayout.comparer = treeNodeComparer;
<span =“Apple-tab-span” style=“white-space:pre”> treeLayout.sorting = go.TreeLayout.SortingAscending;
<span =“Apple-tab-span” style=“white-space:pre”> treeLayout.path = go.TreeLayout.PathSo…
Hi,
Can you please give me an example to get Left Or Right node from clicked node and also shift the position?
I have used same properties which you have suggested. But its changing data only and working when only group in Node i.e. no members are added in group. My scenario is different, I need to swap the position of left node with position of right node with its child node and data also and it will be permanent change, and also we need the location of swapped node.
Please see attac…
Hi Walter
tryed with “sorting: go.TreeLayout.SortingAscending,” no luck
I am using below command to load the data…
myTreeDiagram.model = new go.TreeModel(nodeTreeDataArray);
walter
April 26, 2017, 8:21pm
6
OK. When you have a specific answerable question I’ll be happy to answer.
sorting: go.TreeLayout.SortingAscending,
is worked. thanks for the help. My data is bad that is messed up tree structure…
I had a similar problem and it was because I was using treeStyle: go.TreeLayout.StyleAlternating
but I was only setting sorting
and comparer
but not alternateSorting
and alternateComparer
. Argh!
walter
March 13, 2020, 2:40pm
9
Thanks for pointing that out for future readers of this topic.
But I should clarify that what you say does not apply to this case because in his declaration of the TreeLayout he clearly does not set TreeLayout.treeStyle .
1 Like