Skip to content

Instantly share code, notes, and snippets.

@lcds90
Last active April 25, 2022 00:13
Show Gist options
  • Save lcds90/c840bbd5bfac5275293f793efbe2fac4 to your computer and use it in GitHub Desktop.
Save lcds90/c840bbd5bfac5275293f793efbe2fac4 to your computer and use it in GitHub Desktop.
GoJS - Concepts
<body>
<div
id="myDiagramDiv"
style="border: solid 1px blue; width:400px; height:150px">
</div>
<script src="https://unpkg.com/gojs/release/go-debug.js"></script>
<script src="./script.js"</script>
</body>
diagram.nodeTemplate =
new go.Node("Auto") // the Shape will go around the TextBlock
.add(new go.Shape("RoundedRectangle")
// Shape.fill is bound to Node.data.color
.bind("fill", "color"))
.add(new go.TextBlock({ margin: 8}) // Specify a margin to add some room around the text
// TextBlock.text is bound to Node.data.key
.bind("text", "key"));
// the Model holds only the essential information describing the diagram
diagram.model = new go.GraphLinksModel(
[ // a JavaScript Array of JavaScript objects, one per node;
// the "color" property is added specifically for this app
{ key: "Alpha", color: "lightblue" },
{ key: "Beta", color: "orange" },
{ key: "Gamma", color: "lightgreen" },
{ key: "Delta", color: "pink" }
],
[ // a JavaScript Array of JavaScript objects, one per link
{ from: "Alpha", to: "Beta" },
{ from: "Alpha", to: "Gamma" },
{ from: "Beta", to: "Beta" },
{ from: "Gamma", to: "Delta" },
{ from: "Delta", to: "Alpha" }
]);
// enable Ctrl-Z to undo and Ctrl-Y to redo
diagram.undoManager.isEnabled = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment