....
layout: graph(TreeLayout, {
sorting: TreeLayout.SortingAscending,
arrangement: TreeLayout.ArrangementFixedRoots,
comparer: function (a, b) {
var ay = a.node ? a.node.location.y : 0
var by = b.node ? b.node.location.y : 0
if (isNaN(ay) || isNaN(by)) return 0
if (ay < by) return -1
if (ay > by) return 1
return 0
}
}),
...
myDiagram.model.addNodeData({parent: 1, loc: '0 100', content: 'test'})
I just tried this, and it worked as I think you are expecting.
$(go.Diagram, . . .,
{
layout: $(go.TreeLayout, {
sorting: go.TreeLayout.SortingAscending,
comparer: function(va, vb) {
var da = va.node.data;
var db = vb.node.data;
if (da.text < db.text) return -1;
if (da.text > db.text) return 1;
return 0;
}
}),
myDiagram.model = new go.GraphLinksModel(
[
{ key: 3, text: "Gamma", color: "lightgreen" },
{ key: 4, text: "Delta", color: "pink" },
{ key: 1, text: "Alpha", color: "lightblue" },
{ key: 2, text: "Beta", color: "orange" }
],
[
{ from: 1, to: 2 },
{ from: 3, to: 4 }
]);
myDiagram.model.commit(function(m) {
m.addNodeData({ text: "Ccc" });
}, "added root node");