I made a sample to reproduce the problem, this will only happen when append nodes and links, initialization layout will not have this problem:
In this sample, you need double click node:8 to append nodes and links
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>AvoidsNodes is invaild</title>
<meta charset="UTF-8">
<!--<script type="text/javascript" language="javascript" src="../Test/GoJS.js"></script>-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/gojs/1.7.28/go-debug.js"></script>
<script id="code">
function init() {
if (window.goSamples) goSamples(); // init for these samples -- you don't need to call this
var $ = go.GraphObject.make; // for conciseness in defining templates
myDiagram =
$(go.Diagram, "myDiagramDiv");
// define the Node template
myDiagram.nodeTemplate =
$(go.Node, "Auto",
{ doubleClick: nodeDoubleClick },
$(go.Shape, { fill: "white", stroke:"white" }),
$(go.TextBlock, { margin: 50 },
new go.Binding("text"))
);
// define the Link template
myDiagram.linkTemplate =
//this AvoidsNodes is invaild when I append nodes/links like that
$(go.Link, go.Link.AvoidsNodes,
{ corner: 5 },
$(go.Shape, { strokeWidth: 4, stroke: "#00a4a4" })); // the link shape
myDiagram.model = $(go.GraphLinksModel);
myDiagram.model.nodeDataArray = [
{ key: 8, group: 66 ,text:"8"},
{ key: 66, isGroup: true, group: 88 },
{ key: 88, isGroup: true }];
myDiagram.model.linkDataArray = [];
myDiagram.groupTemplate = $(go.Group, "Auto",
{
layout: go.GraphObject.make(go.TreeLayout,
{ arrangement: go.TreeLayout.ArrangementVertical, layerSpacing: 100 },
),
isSubGraphExpanded: true,
//avoidable for group is false
avoidable: false
},
go.GraphObject.make(go.Shape, "Rectangle",
{ fill: null, stroke: "gray", strokeWidth: 2 }),
go.GraphObject.make(go.Panel, "Vertical",
{ defaultAlignment: go.Spot.Left, margin: 30 },
go.GraphObject.make(go.Panel, "Horizontal",
{ defaultAlignment: go.Spot.Top },
// the SubGraphExpanderButton is a panel that functions as a button to expand or collapse the subGraph
go.GraphObject.make("SubGraphExpanderButton"),
go.GraphObject.make(go.TextBlock,
{ font: "Bold 18px Sans-Serif", margin: 4 }
),
// create a placeholder to represent the area where the contents of the group are
go.GraphObject.make(go.Placeholder,
{ padding: new go.Margin(10, 30) })
)
));
//to append nodes and links
function nodeDoubleClick(e, obj) {
var clicked = obj.part;
if (clicked !== null) {
var thisemp = clicked.data;
myDiagram.startTransaction("add employee");
var newNodeList =
[
{ key: 2, group: 66, text:"2"},
{ key: 3, group: 66, text: "3"},
{ key: 4, group: 66, text: "4"},
{ key: 5, group: 66, text: "5"},
{ key: 6, group: 66, text: "6"},
{ key: 7, group: 66, text: "7"},
{ key: 1, group: 66, text: "1"},
{ key: 9, group: 66, text: "9"},
{ key: 10, group: 66, text: "10" },
{ key: 11, group: 66, text: "11" }
];
var newLinkList =
[
{ from: 2, to: 3 },
{ from: 3, to: 4 },
{ from: 4, to: 5 },
{ from: 5, to: 6 },
{ from: 6, to: 1 },
{ from: 7, to: 1 },
{ from: 7, to: 8 },
{ from: 8, to: 9 },
{ from: 9, to: 10 },
{ from: 10, to: 11 }
];
myDiagram.model.addNodeDataCollection(newNodeList);
myDiagram.model.addLinkDataCollection(newLinkList);
myDiagram.commitTransaction("add employee");
}
}
}
</script>
</head>
<body onload="init()">
<div id="sample">
<div id="myDiagramDiv" style="background-color: #696969; border: solid 1px black; height: 1000px"></div>
</div>
</body>
</html>
Thanks a lot and Merry Christmas.
Peter