I find that it works as I think you are expecting. Here’s a complete sample that uses double-click in the background to create a new (root) node:
<!DOCTYPE html>
<html>
<head>
<!-- Copyright 1998-2019 by Northwoods Software Corporation. -->
<meta charset="UTF-8">
<script src="go.js"></script>
<script>
function init() {
var $ = go.GraphObject.make;
myDiagram =
$(go.Diagram, "myDiagramDiv",
{
"undoManager.isEnabled": true,
layout: $(go.TreeLayout,
{ arrangement: go.TreeLayout.ArrangementFixedRoots }),
"clickCreatingTool.archetypeNodeData": { text: "new node", color: "yellow" }
});
myDiagram.nodeTemplate =
$(go.Node, "Spot",
{ locationSpot: go.Spot.Center, locationObjectName: "BODY", selectionObjectName: "BODY" },
$(go.Panel, "Auto",
{ name: "BODY" },
$(go.Shape,
{ fill: "white", portId: "" },
new go.Binding("fill", "color")),
$(go.TextBlock,
{ margin: 8 },
new go.Binding("text"))
),
$("Button",
$(go.Shape, "PlusLine", { width: 8, height: 8 }),
{
alignment: go.Spot.BottomRight,
click: function(e, button) {
var parentnode = button.part;
e.diagram.model.commit(function(m) {
var childdata = { text: "new child", color: "orange" };
m.addNodeData(childdata);
m.addLinkData({ from: parentnode.key, to: childdata.key })
})
}
}
)
);
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 }
]);
}
</script>
</head>
<body onload="init()">
<div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:600px"></div>
</body>
</html>