function init() {
var $ = go.GraphObject.make;
myDiagram =
$(go.Diagram, "myDiagramDiv");
myDiagram.nodeTemplate =
$(go.Node, "Auto",
$(go.Shape,
{ fill: "white", strokeWidth: 2, portId: "" },
new go.Binding("stroke", "color")),
$(go.Panel, "Table",
new go.Binding("itemArray", "items", function(arr, table) {
arr.sort(function(a, b) {
if (a.isKey && !b.isKey) return -1;
if (!a.isKey && b.isKey) return 1;
return 0; });
var keys = 0;
arr.forEach(function(item) { if (item.isKey) keys++; });
table.getRowDefinition(keys).separatorStroke = table.part.data.color;
return arr;
}),
$(go.RowColumnDefinition, { column: 1 }, new go.Binding("separatorStroke", "color")),
{
padding: 2,
defaultSeparatorPadding: 2,
defaultAlignment: go.Spot.Left,
itemTemplate:
$(go.Panel, "TableRow",
$(go.TextBlock, new go.Binding("text", "name"), { column: 0 },
new go.Binding("isUnderline", "isKey"),
new go.Binding("font", "secondary", function(i) { return i ? "italic 10pt sans-serif" : "10pt sans-serif"; })),
$(go.TextBlock, new go.Binding("text", "type"), { column: 1 })
)
}
)
);
myDiagram.linkTemplate =
$(go.Link,
$(go.Shape),
$(go.Shape, { toArrow: "OpenTriangle" })
);
myDiagram.model = new go.GraphLinksModel([
{
key: 1, text: "Alpha", color: "blue",
items: [
{ name: "activity_id", type: "INTEGER", isKey: true },
{ name: "section_id", type: "INTEGER", isKey: true, secondary: true },
{ name: "group_id", type: "INTEGER", isKey: true, secondary: true },
{ name: "date_time", type: "DATETIME" },
{ name: "type", type: "VARCHAR" },
{ name: "details", type: "VARCHAR" },
{ name: "position", type: "VARCHAR" },
{ name: "link", type: "VARCHAR" },
{ name: "ip_address", type: "VARCHAR" },
{ name: "viewed", type: "CHAR" }
]
},
{ key: 2, text: "Beta", color: "orange",
items: [
{ name: "group_no", type: "CHAR" },
{ name: "group_name", type: "VARCHAR" },
{ name: "schema_name", type: "VARCHAR" },
{ name: "group_id", type: "INTEGER", isKey: true },
{ name: "diagram", type: "CHAR" },
{ name: "section_id", type: "INTEGER", secondary: true }
]
}
], [
{ from: 1, to: 2 }
]);
}
produces: