Try this, either with Group.IsSubGraphExpanded true or false in the group template. Click the “Test” button to center the “SubGraphExpanderButton” that is at the top of each Group.
<!DOCTYPE html>
<html>
<head>
<title>Minimal GoJS Sample</title>
<!-- Copyright 1998-2023 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.GridLayout),
"AnimationFinished": e => {
if (myTarget && myTarget.isVisible()) {
const focus = myTarget.findObject("FOCUS");
if (focus) {
const diag = e.diagram;
const b = focus.getDocumentBounds();
const v = diag.viewportBounds;
new go.Animation()
.add(diag, "position", diag.position,
new go.Point(b.centerX - v.width/2, b.centerY - v.height/2))
.start();
}
myTarget = null;
}
},
"undoManager.isEnabled": true
});
myDiagram.nodeTemplate =
$(go.Node, "Auto",
$(go.Shape, { fill: "white" },
new go.Binding("fill", "color")),
$(go.TextBlock, { margin: 8 },
new go.Binding("text"))
);
myDiagram.groupTemplate =
$(go.Group, "Auto",
//{ isSubGraphExpanded: false },
new go.Binding("isSubGraphExpanded"),
$(go.Shape, { fill: "rgba(0,0,0,0.1)", strokeWidth: 3 },
new go.Binding("stroke", "color")),
$(go.Placeholder, { padding: 100 }),
$(go.TextBlock, { alignment: go.Spot.Bottom },
new go.Binding("text", "", d => `${d.text} ${d.key}`)),
$("SubGraphExpanderButton", { name: "FOCUS", alignment: go.Spot.Top })
)
myDiagram.model = new go.GraphLinksModel(
[
{ key: 1, isGroup: true, text: "Alpha", color: "lightblue" },
{ key: 2, isGroup: true, text: "Beta", color: "orange", group: 1 },
{ key: 3, isGroup: true, text: "Gamma", color: "lightgreen", group: 2 },
{ key: 4, isGroup: true, text: "Delta", color: "pink", group: 3, isSubGraphExpanded: true },
{ key: 11, isGroup: true, text: "Alpha", color: "lightblue" },
{ key: 12, isGroup: true, text: "Beta", color: "orange", group: 11 },
{ key: 13, isGroup: true, text: "Gamma", color: "lightgreen", group: 12 },
{ key: 14, isGroup: true, text: "Delta", color: "pink", group: 13, isSubGraphExpanded: true },
{ key: 21, isGroup: true, text: "Alpha", color: "lightblue" },
{ key: 22, isGroup: true, text: "Beta", color: "orange", group: 21 },
{ key: 23, isGroup: true, text: "Gamma", color: "lightgreen", group: 22 },
{ key: 24, isGroup: true, text: "Delta", color: "pink", group: 23, isSubGraphExpanded: true },
{ key: 31, isGroup: true, text: "Alpha", color: "lightblue" },
{ key: 32, isGroup: true, text: "Beta", color: "orange", group: 31 },
{ key: 33, isGroup: true, text: "Gamma", color: "lightgreen", group: 32 },
{ key: 34, isGroup: true, text: "Delta", color: "pink", group: 33, isSubGraphExpanded: true },
{ key: 41, isGroup: true, text: "Alpha", color: "lightblue" },
{ key: 42, isGroup: true, text: "Beta", color: "orange", group: 41 },
{ key: 43, isGroup: true, text: "Gamma", color: "lightgreen", group: 42 },
{ key: 44, isGroup: true, text: "Delta", color: "pink", group: 43, isSubGraphExpanded: true },
{ key: 51, isGroup: true, text: "Alpha", color: "lightblue" },
{ key: 52, isGroup: true, text: "Beta", color: "orange", group: 51 },
{ key: 53, isGroup: true, text: "Gamma", color: "lightgreen", group: 52 },
{ key: 54, isGroup: true, text: "Delta", color: "pink", group: 53, isSubGraphExpanded: true },
]);
// also try loading with Group.isSubGraphExpanded: false
var myTarget = null;
document.getElementById("myTestButton").addEventListener("click", e => {
const g = myDiagram.findNodeForKey(54);
myTarget = g;
myDiagram.commandHandler.scrollToPart(g);
});
</script>
</body>
</html>