<!DOCTYPE html>
<html>
<head>
<title>Minimal GoJS Sample</title>
<!-- Copyright 1998-2020 by Northwoods Software Corporation. -->
<meta charset="UTF-8">
<script src="go.js"></script>
<script id="code">
function CircularLayout2() {
go.CircularLayout.call(this);
}
go.Diagram.inherit(CircularLayout2, go.CircularLayout);
CircularLayout2.prototype.commitNodes = function() {
go.CircularLayout.prototype.commitNodes.call(this);
if (this.network.vertexes.count === 1) {
// need to handle just one node specially, but how?
this.group.placeholder.padding = new go.Margin(0, 0, 0, 100);
} else {
var c = this.diagram.computePartsBounds(this.group.memberParts).center;
this.group.placeholder.padding = new go.Margin(0, -c.x*2, 0, 0);
}
}
function init() {
var $ = go.GraphObject.make;
myDiagram =
$(go.Diagram, "myDiagramDiv");
myDiagram.nodeTemplate =
$(go.Node, "Auto",
{ width: 30, height: 30 },
$(go.Shape, "Circle",
{ fill: "lightgray", portId: "" }),
$(go.TextBlock,
new go.Binding("text", "key"))
);
myDiagram.groupTemplate =
$(go.Group, "Auto",
{
layout: $(CircularLayout2, { radius: 50 }),
minSize: new go.Size(180, 180)
},
$(go.Shape, "Circle",
{ fill: "lightgreen" }),
$(go.Placeholder),
$(go.Panel, "Auto",
{ width: 30, height: 30 },
$(go.Shape, "Circle",
{ fill: "lightgray", portId: "" }),
$(go.TextBlock,
new go.Binding("text", "key"))
)
);
myDiagram.model = new go.GraphLinksModel(
[
{ key: 11, group: -1 },
{ key: -1, isGroup: true },
{ key: 21, group: -2 },
{ key: 22, group: -2 },
{ key: -2, isGroup: true },
{ key: 31, group: -3 },
{ key: 32, group: -3 },
{ key: 33, group: -3 },
{ key: -3, isGroup: true },
{ key: 41, group: -4 },
{ key: 42, group: -4 },
{ key: 43, group: -4 },
{ key: 44, group: -4 },
{ key: -4, isGroup: true },
{ key: 51, group: -5 },
{ key: 52, group: -5 },
{ key: 53, group: -5 },
{ key: 54, group: -5 },
{ key: 55, group: -5 },
{ key: -5, isGroup: true },
],
[
{ from: 11, to: -1 },
{ from: 21, to: -2 },
{ from: 22, to: -2 },
{ from: 31, to: -3 },
{ from: 32, to: -3 },
{ from: 33, to: -3 },
{ from: 41, to: -4 },
{ from: 42, to: -4 },
{ from: 43, to: -4 },
{ from: 44, to: -4 },
{ from: 51, to: -5 },
{ from: 52, to: -5 },
{ from: 53, to: -5 },
{ from: 54, to: -5 },
{ from: 55, to: -5 },
]);
}
</script>
</head>
<body onload="init()">
<div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:600px"></div>
</body>
</html>