I don't see why you wouldn't want to set TreeLayout.comparer.
But one simple solution is to set TreeLayout.sorting to go.TreeLayout.SortingReverse. For example:
<!DOCTYPE html>
<html>
<head>
<title>Minimal GoJS Sample</title>
<!-- Copyright 1998-2022 by Northwoods Software Corporation. -->
</head>
<body>
<div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:600px"></div>
<button id="myTestButton">Test</button>
<script src="https://unpkg.com/gojs"></script>
<script id="code">
const $ = go.GraphObject.make;
const myDiagram =
$(go.Diagram, "myDiagramDiv",
{
layout:
$(go.TreeLayout,
{ angle: 90, sorting: go.TreeLayout.SortingReverse })
});
myDiagram.nodeTemplate =
$(go.Node, "Auto",
{ locationSpot: go.Spot.Top },
$(go.Shape, { fill: "white" },
new go.Binding("fill", "color")),
$(go.TextBlock, { margin: 8 },
new go.Binding("text"))
);
myDiagram.model = new go.GraphLinksModel(
[
{ key: 1, text: "Alpha", color: "lightblue" },
{ key: 2, text: "Beta", color: "orange" },
{ key: 3, text: "Gamma", color: "lightgreen" },
{ key: 4, text: "Delta", color: "pink" }
],
[
{ from: 1, to: 2 },
{ from: 1, to: 3 },
{ from: 3, to: 4 },
]);
document.getElementById("myTestButton").addEventListener("click", e => {
let node = myDiagram.selection.first();
if (!node) node = myDiagram.nodes.first();
if (node instanceof go.Node) {
myDiagram.model.commit(m => {
const d = { text: "New Node", color: go.Brush.randomColor() };
m.addNodeData(d);
const n = myDiagram.findNodeForData(d);
if (n) n.location = node.location;
m.addLinkData( { from: node.key, to: n.key });
});
}
});
</script>
</body>
</html>
Click on the "Test" button to add a tree-child node to the selected node.