create-gojs-kit
Version:
A CLI for downloading GoJS samples, extensions, and docs
948 lines (874 loc) • 42 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover"/>
<meta name="description" content="GoJS Introduction Documentation" />
<meta itemprop="description" content="GoJS Introduction Documentation" />
<meta property="og:description" content="GoJS Introduction Documentation" />
<meta name="twitter:description" content="GoJS Introduction Documentation" />
<link rel="preconnect" href="https://rsms.me/">
<link rel="stylesheet" href="../assets/css/style.css">
<!-- Copyright 1998-2025 by Northwoods Software Corporation. -->
<meta itemprop="name" content="Introduction" />
<meta property="og:title" content="Introduction" />
<meta name="twitter:title" content="Introduction" />
<meta property="og:image" content="https://gojs.net/latest/assets/images/fp/defaultCard.png" />
<meta itemprop="image" content="https://gojs.net/latest/assets/images/fp/defaultCard.png" />
<meta name="twitter:image" content="https://gojs.net/latest/assets/images/fp/defaultCard.png" />
<meta property="og:url" content="https://gojs.net/latest/intro/" />
<meta property="twitter:url" content="https://gojs.net/latest/intro/" />
<meta name="twitter:card" content="summary_large_image" />
<meta property="og:type" content="website" />
<meta property="twitter:domain" content="gojs.net" />
<title>
Introduction | GoJS
</title>
<link rel="stylesheet" href="../assets/css/prism.css"/>
</head>
<script>
window.diagrams = [];
window.goCode = function (pre, w, h, parentid, animation) {
window
.diagrams
.push([pre, w, h, parentid, animation]);
}
</script>
<body>
<nav id="navTop" class=" w-full h-[var(--topnav-h)] z-30 bg-white border-b border-b-gray-200">
<div class="max-w-screen-xl mx-auto flex flex-wrap items-start justify-between px-4">
<a class="text-white bg-nwoods-primary font-bold !leading-[calc(var(--topnav-h)_-_1px)] my-0 px-2 text-4xl lg:text-5xl logo"
href="../">
GoJS
</a>
<div class="relative">
<button id="topnavButton" class="h-[calc(var(--topnav-h)_-_1px)] px-2 m-0 text-gray-900 bg-inherit shadow-none md:hidden hover:!bg-inherit hover:!text-nwoods-accent hover:!shadow-none" aria-label="Navigation">
<svg class="h-7 w-7 block" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
<path d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
<div id="topnavList" class="hidden md:block">
<div class="absolute right-0 z-30 flex flex-col items-end rounded border border-gray-200 p-4 pl-12 shadow bg-white text-gray-900 font-semibold
md:flex-row md:space-x-4 md:items-start md:border-0 md:p-0 md:shadow-none md:bg-inherit">
<a href="../learn/">Learn</a>
<a href="../samples/">Samples</a>
<a href="../intro/">Intro</a>
<a href="../api/">API</a>
<a href="../download.html">Download</a>
<a href="https://forum.nwoods.com/c/gojs/11" target="_blank" rel="noopener">Forum</a>
<a id="tc" href="https://nwoods.com/contact.html"
target="_blank" rel="noopener" onclick="getOutboundLink('https://nwoods.com/contact.html', 'contact');">Contact</a>
<a id="tb" href="https://nwoods.com/sales/index.html"
target="_blank" rel="noopener" onclick="getOutboundLink('https://nwoods.com/sales/index.html', 'buy');">Buy</a>
</div>
</div>
</div>
</div>
</nav>
<script>
window.addEventListener("DOMContentLoaded", function () {
// topnav
var topButton = document.getElementById("topnavButton");
var topnavList = document.getElementById("topnavList");
if (topButton && topnavList) {
topButton.addEventListener("click", function (e) {
topnavList
.classList
.toggle("hidden");
e.stopPropagation();
});
document.addEventListener("click", function (e) {
// if the clicked element isn't the list, close the list
if (!topnavList.classList.contains("hidden") && !e.target.closest("#topnavList")) {
topButton.click();
}
});
// set active <a> element
var url = window
.location
.href
.toLowerCase();
var aTags = topnavList.getElementsByTagName('a');
for (var i = 0; i < aTags.length; i++) {
var lowerhref = aTags[i]
.href
.toLowerCase();
if (lowerhref.endsWith('.html'))
lowerhref = lowerhref.slice(0, -5);
if (url.startsWith(lowerhref)) {
aTags[i]
.classList
.add('active');
break;
}
}
}
});
</script>
<div class="sticky top-0 left-0 z-10 px-2 w-full bg-white border-b border-b-gray-200 md:hidden">
<button id="sidenavButton" class="flex p-2 text-gray-900 bg-inherit shadow-none items-center text-sm font-semibold hover:!bg-inherit hover:!text-nwoods-accent hover:!shadow-none" aria-label="Navigation">
<svg class="h-7 w-7 block mr-2" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
<path d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<span>Menu</span>
</button>
</div>
<script>
window.addEventListener("DOMContentLoaded", function () {
// sidenav
var sideButton = document.getElementById("sidenavButton");
var sidenav = document.getElementById("sidenav");
if (sideButton && sidenav) {
sideButton.addEventListener("click", function (e) {
sidenav
.classList
.toggle("hidden");
e.stopPropagation();
});
document.addEventListener("click", function (e) {
// if the clicked element isn't the list, close the list
if (!sidenav.classList.contains("hidden") && !e.target.closest("#sidenavList")) {
sideButton.click();
}
});
}
});
</script>
<div class="flex flex-row md:min-h-screen w-full max-w-screen-xl mx-auto">
<aside id="sidenav"
class="hidden fixed top-0 left-0 z-10 w-full bg-black/10 min-h-screen max-h-screen overflow-x-hidden overflow-y-auto shrink-0
md:block md:sticky md:w-52 md:min-h-0 md:bg-inherit md:border-r md:border-r-gray-200 md:overscroll-auto">
<nav id="sidenavList" class="flex flex-col bg-white w-52 min-h-screen pl-2 pt-4 pb-24 md:w-full md:min-h-0">
<a href="index.html">Basics</a>
<a href="buildingObjects.html">Building Parts</a>
<a href="usingModels.html">Using Models</a>
<a href="dataBinding.html">Data Binding</a>
<a href="react.html">GoJS with React</a>
<a href="svelte.html">GoJS with Svelte</a>
<a href="angular.html">GoJS with Angular</a>
<a href="textBlocks.html">TextBlocks</a>
<a href="shapes.html">Shapes</a>
<a href="pictures.html">Pictures</a>
<a href="panels.html">Panels</a>
<a href="tablePanels.html">Table Panels</a>
<a href="brush.html">Brushes</a>
<a href="sizing.html">Sizing Objects</a>
<a href="itemArrays.html">Item Arrays</a>
<a href="changedEvents.html">Changed Events</a>
<a href="transactions.html">Transactions</a>
<a href="viewport.html">Coordinates</a>
<a href="initialView.html">Initial View</a>
<a href="collections.html">Collections</a>
<a href="links.html">Links</a>
<a href="linkLabels.html">Link Labels</a>
<a href="connectionPoints.html">Link Points</a>
<a href="ports.html">Ports</a>
<a href="nodes.html">Nodes</a>
<a href="typings.html">Typings</a>
<a href="debugging.html">Debugging</a>
<a href="layouts.html">Layouts</a>
<a href="routers.html">Routers</a>
<a href="trees.html">Trees</a>
<a href="subtrees.html">SubTrees</a>
<a href="groups.html">Groups</a>
<a href="subgraphs.html">SubGraphs</a>
<a href="sizedGroups.html">Sized Groups</a>
<a href="selection.html">Selection</a>
<a href="highlighting.html">Highlighting</a>
<a href="theming.html">Theming</a>
<a href="tooltips.html">ToolTips</a>
<a href="contextMenus.html">Context Menus</a>
<a href="events.html">Diagram Events</a>
<a href="tools.html">Tools</a>
<a href="commands.html">Commands</a>
<a href="accessibility.html">Accessibility</a>
<a href="buttons.html">Buttons</a>
<a href="permissions.html">Permissions</a>
<a href="validation.html">Validation</a>
<a href="animation.html">Animation</a>
<a href="HTMLInteraction.html">HTML Interaction</a>
<a href="layers.html">Layers & Z-ordering</a>
<a href="palette.html">Palette</a>
<a href="overview.html">Overview</a>
<a href="replacingDeleting.html">Replacing and Deleting</a>
<a href="templateMaps.html">Template Maps</a>
<a href="legends.html">Legends and Titles</a>
<a href="extensions.html">Extensions</a>
<a href="geometry.html">Geometry Strings</a>
<a href="grids.html">Grid Patterns</a>
<a href="graduatedPanels.html">Graduated Panels</a>
<a href="SVGContext.html">Rendering to SVG</a>
<a href="makingSVG.html">Snapshot to SVG</a>
<a href="makingImages.html">Diagram Images</a>
<a href="printing.html">Printing</a>
<a href="serverSideImages.html">Server-side Images</a>
<a href="nodeScript.html">GoJS in Node.js</a>
<a href="testing.html">Testing</a>
<a href="performance.html">Performance</a>
<a href="platforms.html">Platforms</a>
<a href="deployment.html">Deployment</a>
</nav>
</aside>
<script>
var navList = document.getElementById('sidenavList');
if (navList !== null) {
var url = window.location.href;
var lindex = url.lastIndexOf('/');
url = url
.slice(lindex + 1)
.toLowerCase();
var aTags = navList.getElementsByTagName('a');
var currentindex = -1;
for (var i = 0; i < aTags.length; i++) {
var lowerhref = aTags[i]
.href
.toLowerCase();
if (lowerhref.indexOf('/' + url) !== -1) {
currentindex = i;
aTags[i]
.classList
.add('active');
break;
}
}
}
</script>
<div class="px-4 pb-16 w-full overflow-hidden prose">
<h1>Introduction to GoJS Diagramming Components</h1>
<p>
<b>GoJS</b> is a JavaScript library that lets you easily create interactive diagrams in web browsers.
<b>GoJS</b> supports graphical templates and data-binding of graphical object properties to model data.
You only need to save and restore the model, consisting of simple JavaScript objects holding
whatever properties your app needs.
Many predefined tools and commands implement the standard behaviors that most diagrams need.
Customization of appearance and behavior is mostly a matter of setting properties.
</p>
<h2 id="SimpleGoJSDiagram">A Simple GoJS Diagram</h2>
<p>
The following code defines a node template and model data, which produces a small diagram with a handful of nodes and links.
</p>
<pre class="lang-js" id="minimal"><code>
// the node template describes how each Node should be constructed
diagram.nodeTemplate =
new go.Node("Auto")
.add( // the Shape will be sized to go around the TextBlock
new go.Shape("RoundedRectangle")
// Shape.fill is bound to Node.data.color
.bind("fill", "color"),
new go.TextBlock({ margin: 8}) // Specify a margin to add some room around the text
// TextBlock.text is bound to Node.data.text
.bind("text")
);
// 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: 1, text: "Alpha", color: "lightblue" },
{ key: 2, text: "Beta", color: "orange" },
{ key: 3, text: "Gamma", color: "lightgreen" },
{ key: 4, text: "Delta", color: "pink" }
],
[ // a JavaScript Array of JavaScript objects, one per link
{ from: 1, to: 2 },
{ from: 1, to: 3 },
{ from: 2, to: 2 },
{ from: 3, to: 4 },
{ from: 4, to: 1 }
]);
// enable Ctrl-Z to undo and Ctrl-Y to redo
diagram.undoManager.isEnabled = true;
</code></pre>
<script>goCode("minimal", 400, 150)</script>
<p>
You can interact with this diagram in many ways:
</p>
<ul>
<li>You can select a part (a <a>Node</a> or a <a>Link</a>) by clicking on it.
Selected nodes are highlighted with an <a>Adornment</a> that is a blue rectangle surrounding the node.
Selected links are highlighted with a blue line following the path of the link.</li>
<li>Multiple parts may be selected at once.
Hold the Shift key down when clicking to add to the selection.
Hold the Control key down when clicking to toggle whether that part is selected.</li>
<li>Another way to multi-select is to mouse-down at a point in the background (not on a part),
wait a moment, and then drag a box.
Parts that are fully in the box when the mouse-up occurs are selected.
The Shift and Control modifiers work then as well.</li>
<li>Ctrl-A selects all parts in the diagram.</li>
<li>Move one or more nodes by selecting them and dragging.</li>
<li>Copying selected parts works with either copy/paste (Ctrl-C/Ctrl-V) or with Ctrl-mouse-drag.</li>
<li>Delete selected parts with the Delete key.</li>
<li>Ctrl-Z to undo the previous modification and Ctrl-Y to redo it.</li>
<li>If scrollbars are visible or if the whole collection of parts is smaller than the viewable area of the diagram
(the "viewport"),
you can pan the diagram with a mouse-down in the background (not on a part) if you drag without waiting.</li>
<li>Use the mouse wheel to scroll up and down and Shift-mouse-wheel to scroll left and right.
Ctrl-mouse-wheel zooms in and out.</li>
</ul>
<p>
You can also pan, pinch zoom, select, copy, move, delete, undo, and redo with your fingers on a touch device.
Most commands that can be invoked from a keyboard can be invoked from the default context menu that you get by
pressing your finger and holding it motionless for a moment.
</p>
<p>
What is unique about all of the examples in the documentation is that they are all "live" -- there are no screenshots!
They are actual <a>Diagram</a>s implemented by the source code shown.
You can interact with them -- some even display animation.
</p>
<p>
If you'd like to see more examples of what <b>GoJS</b> can do, see the <a href="../samples/index.html"
target="samples">GoJS Samples directory</a>.
To make it easier to search the JavaScript code and documentation or to experiment by modifying the samples,
you can install the <b>GoJS</b> kit in various manners:
<ul>
<li>Download a ZIP file from our <a href="../download.html">Download</a> page.</li>
<li>Clone or download from <a href="https://github.com/NorthwoodsSoftware/GoJS">GoJS on GitHub</a>.</li>
<li>Install GoJS using <code>npm install gojs</code> and <code>npm create gojs-kit@latest</code>.</li>
</ul>
</p>
<h2 id="GoJSConcepts">GoJS Concepts</h2>
<p>
<a>Diagram</a>s consist of <a>Part</a>s: <a>Node</a>s that may be connected by <a>Link</a>s and that may be grouped
together into <a>Group</a>s.
All of these parts are gathered together in <a>Layer</a>s and are arranged by <a>Layout</a>s and <a>Router</a>s.
</p>
<p>
Each diagram has a <a>Model</a> that holds and interprets your application data to determine node-to-node link
relationships and group-member relationships.
Most parts are data-bound to your application data.
The diagram automatically creates a <a>Node</a> or a <a>Group</a> for each data item in the model's
<a>Model.nodeDataArray</a> and a <a>Link</a> for each data item in the model's <a>GraphLinksModel.linkDataArray</a>.
You can add whatever properties you need to each data object,
but there are just a few properties that each kind of model expects.
They are shown in bold in the gray data objects.
</p>
<pre class="lang-js" id="commented" style="display:none"><code>
diagram.nodeTemplate =
$(go.Node, "Auto",
{ scale : 1.6, isShadowed: true },
new go.Binding("location", "pos", go.Point.parse),
{ locationSpot: go.Spot.Center, portId: "NODE" },
$(go.Shape, "RoundedRectangle",
{ fill: "white", portId: "SHAPE" },
new go.Binding("fill", "color")),
$(go.TextBlock,
{ margin: 4, portId: "TEXTBLOCK" },
new go.Binding("text"))
);
diagram.linkTemplate =
$(go.Link,
{ layerName: "Background", isShadowed: true },
$(go.Shape, { strokeWidth: 3 }),
$(go.Shape, { toArrow: "Standard", scale: 1.5 })
);
// Represents the nodeDataArray for the two nodes
diagram.nodeTemplateMap.add("dataNode",
$(go.Node, "Auto",
{
locationSpot: go.Spot.Center,
scale: 1.2,
selectionAdorned: true,
fromSpot: go.Spot.AllSides,
toSpot: go.Spot.AllSides,
shadowColor: "#C5C1AA"
},
new go.Binding("location", "pos", go.Point.parse),
$(go.Shape, "Rectangle",
{ fill: "lightgray" }),
$(go.Panel, "Vertical",
{ defaultStretch: go.Stretch.Horizontal },
$(go.TextBlock, headerStyle(), // Header:
{ portId: "HEADER" },
new go.Binding("text", "head")),
$(go.Shape, "LineH", { height: 1, stretch: go.Stretch.Fill }),
$(go.TextBlock, textStyle(), // Location:
{ portId: "LOCATION" },
new go.Binding("text", "loc")),
$(go.Shape, "LineH", { height: 1, stretch: go.Stretch.Fill }),
$(go.TextBlock, textStyle(), // Fill:
{ portId: "FILL" },
new go.Binding("text", "color")),
$(go.Shape, "LineH", { height: 1, stretch: go.Stretch.Fill }),
$(go.TextBlock, textStyle(), // Text:
{ portId: "TEXT" },
new go.Binding("text", "txt"))
)
)
);
// Represents a linkDataArray object
diagram.nodeTemplateMap.add("dataLink",
$(go.Node, "Auto",
{
locationSpot: go.Spot.Center,
scale: 1.2,
selectionAdorned: true,
fromSpot: go.Spot.AllSides,
toSpot: go.Spot.AllSides,
shadowColor: "#C5C1AA"
},
new go.Binding("location", "pos", go.Point.parse),
$(go.Shape, "Rectangle",
{ fill: "lightgray" }),
$(go.Panel, "Vertical",
{ defaultStretch: go.Stretch.Horizontal },
$(go.TextBlock, textStyle(), // Location:
{ portId: "FROM", font: "bold 12pt sans-serif" },
new go.Binding("text", "from")),
$(go.Shape, "LineH", { height: 1, stretch: go.Stretch.Fill }),
$(go.TextBlock, textStyle(), // Fill:
{ portId: "TO", font: "bold 12pt sans-serif" },
new go.Binding("text", "to"))
)
)
);
diagram.linkTemplateMap.add("dataNode", // Links from dataNode to Nodes
$(go.Link,
{ routing: go.Routing.Orthogonal, corner: 5 },
$(go.Shape, { stroke: "gray", strokeWidth: 2 }),
$(go.Shape, { toArrow: "Standard", stroke: "gray", fill: "gray" })
));
diagram.nodeTemplateMap.add("title",
$(go.Node, "Auto",
new go.Binding("location", "pos", go.Point.parse),
$(go.TextBlock,
{ font: "bold 25pt sans-serif", textAlign: "center"},
new go.Binding("text", "txt"))
));
diagram.nodeTemplateMap.add("nodeDataArray",
$(go.Node, "Auto",
{
locationSpot: go.Spot.Center,
scale: 1.2,
selectionAdorned: true,
fromSpot: go.Spot.AllSides,
toSpot: go.Spot.AllSides,
shadowColor: "#C5C1AA"
},
new go.Binding("location", "pos", go.Point.parse),
$(go.Shape, "Rectangle", { fill: "lightgray" }),
$(go.Panel, "Vertical",
{ defaultStretch: go.Stretch.Horizontal },
$(go.TextBlock, headerStyle(),
{ portId: "HEADER", text: "nodeDataArray" }),
$(go.Shape, "LineH", { height: 1, stretch: go.Stretch.Fill }),
$(go.TextBlock, textStyle(),
{ portId: "dataNode1", desiredSize: new go.Size(NaN,16) }),
$(go.Shape, "LineH", { height: 1, stretch: go.Stretch.Fill }),
$(go.TextBlock, textStyle(),
{ portId: "dataNode2", desiredSize: new go.Size(NaN,16) })
)
));
// Comments
diagram.nodeTemplateMap.add("Comment", // Template for comment node
$(go.Node,
new go.Binding("location", "pos", go.Point.parse),
{ locationSpot: go.Spot.Center},
$(go.TextBlock,
{ stroke: "brown", textAlign: "center" },
new go.Binding("text", "txt"),
new go.Binding("font", "bold", b => b ? "bold 10pt sans-serif" : "10pt sans-serif"))
));
diagram.nodeTemplateMap.add("LinkLabel", // Template for comments on links
$(go.Node,
new go.Binding("segmentIndex"),
new go.Binding("segmentOffset"),
new go.Binding("segmentFraction")
));
diagram.linkTemplateMap.add("Comment", // Template for links from comments
$(go.Link,
{ curve: go.Curve.Bezier },
new go.Binding("curviness"),
$(go.Shape, { stroke: "brown" }),
$(go.Shape, { toArrow: "OpenTriangle", stroke: "brown" })
));
diagram.linkTemplateMap.add("Binding",
$(go.Link,
{ curve: go.Curve.Bezier },
new go.Binding("curviness"),
$(go.Shape, { stroke: "green" , strokeWidth: 2, strokeDashArray: [2, 7] }),
$(go.Shape, { toArrow: "OpenTriangle", stroke: "green", strokeWidth: 2 })
));
diagram.linkTemplateMap.add("Data",
$(go.Link,
{ curve: go.Curve.Bezier },
new go.Binding("curviness"),
$(go.Shape, { stroke: "gray", strokeWidth: 2 }),
$(go.Shape, { toArrow: "Standard", fill: "gray", stroke: "gray", strokeWidth: 2 }),
$(go.TextBlock, ".data", { font: "bold 12pt Courier", segmentOffset: new go.Point(0, -10) })
));
const model = new go.GraphLinksModel();
model.linkFromPortIdProperty = "fPID";
model.linkToPortIdProperty = "tPID"
model.linkLabelKeysProperty = "labels";
model.nodeDataArray = [
{ key: 1, text: "Alpha", color: "lightblue", pos: "50 20"},
{ key: 2, text: "Beta", color: "orange", pos: "50 270"},
{ key: 3, category: "dataNode", pos: "300 66", head: "key: 1", txt: "text: Alpha", color: "color: lightblue", loc: "location: 50 0" },
{ key: 4, category: "dataNode", pos: "300 316", head: "key: 2", txt: "text: Beta", color: "color: orange", loc: "location: 50 250" },
{ key: 5, category: "dataLink", pos: "450 200", from: "from: 1", to: "to: 2" },
{ key: 6, category: "title", pos: "220 -100", txt: "GraphLinksModel:\ndata"},
{ key: 7, category: "title", pos: "-50 -100", txt: "Diagram:\nNodes, Links"},
{ key: -2, category: "Comment", pos: "10 150", txt: "a Link", bold: true},
{ key: -21, category: "LinkLabel", segmentIndex: 0, segmentFraction: 0.5 },
{ key: -22, category: "LinkLabel", segmentIndex: 0, segmentFraction: 0.65 },
{ key: -3, category: "Comment", pos: "-30 130", txt: "two Nodes", bold: true},
{ key: -4, category: "Comment", pos: "120 130", txt: "data Bindings", bold: true},
{ key: -41, category: "LinkLabel", segmentOffset: new go.Point(25, 0)},
{ key: -42, category: "LinkLabel", segmentOffset: new go.Point(10, 0)},
{ key: -43, category: "LinkLabel", segmentOffset: new go.Point(-10, 0)},
{ key: -44, category: "LinkLabel", segmentOffset: new go.Point(25, 0)},
{ key: -45, category: "LinkLabel", segmentOffset: new go.Point(20, 0)},
{ key: -46, category: "LinkLabel", segmentOffset: new go.Point(-10, 0)},
{ key: -5, category: "Comment", pos: "300 0", txt: "in nodeDataArray:" },
{ key: -6, category: "Comment", pos: "300 250", txt: "in nodeDataArray:" },
{ key: -7, category: "Comment", pos: "450 165", txt: "in linkDataArray:" },
];
model.linkDataArray = [
{ from: 1, to: 2, labels: [-21, -22] },
{ from: 1, to: 3, tPID: "HEADER", category: "Data", curviness: 20 },
{ from: 2, to: 4, tPID: "HEADER", category: "Data", curviness: 20 },
{ from: -22, to: 5, tPID: "FROM", category: "Data", curviness: 20 },
{ from: -2, to: -21, category: "Comment", curviness: 0},
{ from: -3, to: 1, category: "Comment", curviness: 10},
{ from: -3, to: 2, category: "Comment", curviness: -10},
{ from: -4, to: -41, category: "Comment", curviness: 5},
{ from: -4, to: -42, category: "Comment", curviness: 5},
{ from: -4, to: -43, category: "Comment", curviness: 5},
{ from: 3, fPID: "LOCATION", to: 1, tPID: "NODE", category: "Binding", curviness: 10, labels: [-41]},
{ from: 3, fPID: "FILL", to: 1, tPID: "SHAPE" , category: "Binding", curviness: 30, labels: [-42]},
{ from: 3, fPID: "TEXT", to: 1, tPID: "TEXTBLOCK", category: "Binding", curviness: 50, labels: [-43]},
{ from: 4, fPID: "LOCATION", to: 2, tPID: "NODE", category: "Binding", curviness: 10, labels: [-44]},
{ from: 4, fPID: "FILL", to: 2, tPID: "SHAPE" , category: "Binding", curviness: 30, labels: [-45]},
{ from: 4, fPID: "TEXT", to: 2, tPID: "TEXTBLOCK", category: "Binding", curviness: 50, labels: [-46]}
];
diagram.model = model;
// Formatting
function headerStyle() {
return {
margin: 3,
font: "bold 12pt sans-serif",
minSize: new go.Size(16, 16),
maxSize: new go.Size(120, NaN),
textAlign: "center"
};
}
function textStyle() {
return {
margin: 2,
font: "10pt sans-serif",
minSize: new go.Size(16, 16),
maxSize: new go.Size(120, NaN),
textAlign: "center"
};
}
</code></pre>
<script>goCode("commented", 650, 550)</script>
<p>
Each <a>Node</a> or <a>Link</a> is normally defined by a template that declares its appearance and behavior.
Each template consists of <a>Panel</a>s of <a>GraphObject</a>s such as <a>TextBlock</a>s or <a>Shape</a>s.
There are default templates for all parts, but almost all applications will specify custom templates
in order to achieve the desired appearance and behavior.
Data bindings of <a>GraphObject</a> properties to model data properties make each Node or Link unique for the data.
</p>
<p>
The nodes may be positioned manually (interactively or programmatically) or
may be arranged automatically by the <a>Diagram.layout</a> and by each <a>Group.layout</a>.
Nodes are positioned either by their top-left corner point (<a>GraphObject.position</a>) or
by a programmer-defined spot in the node (<a>Part.location</a> and <a>Part.locationSpot</a>).
</p>
<p>
<a>Tool</a>s handle mouse and keyboard and touch or stylus events.
Each diagram has a number of tools that perform interactive tasks such as
selecting parts or dragging them or drawing a new link between two nodes.
The <a>ToolManager</a> determines which tool should be running,
depending on the mouse events and current circumstances.
</p>
<p>
Each diagram also has a <a>CommandHandler</a> that implements various commands, such as Delete or Copy.
The CommandHandler interprets keyboard events, such as Ctrl-Z, when the ToolManager is running.
</p>
<p>
The diagram provides the ability to scroll the parts of the diagram and to zoom in or out.
The diagram also contains all of the layers, which in turn contain all of the parts (nodes and links).
The parts in turn are composed of possibly nested panels of text, shapes, and images.
This hierarchy of JavaScript objects in memory forms the "visual tree" of everything that may be drawn by the diagram.
</p>
<p>
Animations are implemented and controlled by the <a>AnimationManager</a>.
Automatic animations happen after automatic layouts and upon the execution of various commands.
You can define your own custom <a>Animation</a>s.
</p>
<p>
The <a>Overview</a> class allows the user to see the whole model and to control what part of it that the diagram
displays.
The <a>Palette</a> class holds parts that the user may drag-and-drop into a diagram.
</p>
<p>
You can select one or more parts in the diagram. The template implementation may change the appearance
of the node or link when it is selected. The diagram may also add <a>Adornment</a>s to indicate selection and to
support tools such as resizing a node or reconnecting a link.
Adornments are also how tooltips and context menus are implemented.
</p>
<p>
All programmatic changes to <a>Diagram</a>, <a>GraphObject</a>, <a>Model</a> or model data state should be performed
within a single transaction per user action, to make sure updating happens correctly and to support undo/redo.
All of the predefined tools and commands perform transactions, so each user action is automatically undoable
if the <a>UndoManager</a> is enabled.
<a>DiagramEvent</a>s on Diagrams, and event handlers on Diagrams and GraphObjects,
are all documented whether they are raised within a transaction or whether you need to conduct a transaction in order
to change the model or the diagram.
</p>
<h2 id="CreatingDiagram">Creating a Diagram</h2>
<b>GoJS</b> does not depend on any JavaScript library or framework, so you should be able to use it in any environment.
However it does require that the environment support modern HTML and JavaScript.
<h3 id="LoadingGoJS">Loading GoJS</h3>
<p>
Before you can execute any JavaScript code to build a Diagram, you will need to load the <b>GoJS</b> library.
When you include the library, the "<code>go</code>" JavaScript object will hold all of the <b>GoJS</b> types.
During development we recommend that you load "go-debug.js" instead of "go.js", for additional run-time error checking
and debugging ability.
</p>
<p>
We recommend that you declare that your web page supports modern HTML:
</p>
<pre class="lang-html"><code>
<!DOCTYPE html> <!-- Declare standards mode. -->
<html>
<head>
. . .
<!-- Include the GoJS library. -->
<script src="go-debug.js"></script></code></pre>
<p>
If depending on your npm environment:
<pre class="lang-ts"><code>import * as go from "gojs";</code></pre>
</p>
<p>
If you want to use ECMAScript modules, use <code>go-module.js</code> or <code>go.mjs</code>
in the <code>release/</code> directory.
However your build environment may automatically make this choice for you.
</p>
<p>
The extension classes are implemented in TypeScript and compiled as ECMAScript modules in the <code>extensionsJSM/</code> directory.
That directory is present in the kit downloaded from our <a href="../download.html">website</a>
or <a href="https://github.com/NorthwoodsSoftware/GoJS">GitHub</a>,
or in the <code>create-gojs-kit</code> npm package that you can install using <code>npm create gojs-kit@latest</code>.
The extension classes are compiled into regular script-loadable JavaScript in the <code>extensions/</code> directory.
</p>
<pre class="lang-bash"><code>
import { DoubleTreeLayout } from "./path/to/gojs-kit/dist/extensionsJSM/DoubleTreeLayout.js";</code></pre>
<p>
If you are using <a href="https://requirejs.org" target="_blank">RequireJS</a>,
the <b>GoJS</b> library supports UMD module definitions.
Copy each extension file into your project, and update its <code>require</code> statement
so that all of your code loads the same GoJS library and only does so once.
</p>
<h3 id="HostingGoJSinaDivElement">Hosting GoJS in a Div Element</h3>
<p>
Every <a>Diagram</a> must be hosted by an HTML Div element.
<b>GoJS</b> will manage the contents of that Div element, but you may position and size and style the Div as you would
any HTML element.
The diagram will add a Canvas element to that Div element that the diagram will draw in -- this is what users actually
see.
The Canvas element is automatically sized to have the same size as the Div element.
</p>
<pre class="lang-html"><code>
<body>
. . .
<!-- The DIV for a Diagram needs an explicit size or else we won't see anything.
In this case we also add a border to help see the edges. -->
<div id="myDiagramDiv" style="border: solid 1px blue; width:400px; height:150px"></div></code></pre>
<p>
Then you can create the <a>Diagram</a> in JavaScript with a reference to that Div element.
Build the diagram by constructing plain JavaScript objects and adding them to the diagram's model.
Note that all references in JavaScript code to <b>GoJS</b> types such as <a>Diagram</a> are prefixed with
"<code>go.</code>".
</p>
<pre class="lang-html"><code>
<!-- Create the Diagram in the DIV element using JavaScript. -->
<!-- The "go" object is the "namespace" that holds all of the GoJS types. -->
<script>
const diagram = new go.Diagram("myDiagramDiv");
diagram.model = new go.GraphLinksModel(
[{ key: 1, text: "Hello" }, // two node data, in an Array
{ key: 2, text: "World!" }],
[{ from: 1, to: 2 }] // one link data, in an Array
);
</script></code></pre>
<pre id="minimal2" style="display:none;">
diagram.model = new go.GraphLinksModel(
[{ key: "Hello" }, // two node data, in an Array
{ key: "World!" }],
[{ from: "Hello", to: "World!" }] // one link data, in an Array
);
</pre>
<script>goCode("minimal2", 400, 150)</script>
<p>
That one HTML DIV element and little bit of JavaScript code are the complete implementation of
the "Hello World!" live diagram that you see above.
</p>
<h3 id="DevelopingYourDiagram">Developing your Diagram</h3>
<p class="box bg-danger">
<b>GoJS</b> outputs error or warning messages when something goes wrong.
When developing with <b>GoJS</b>, be sure to check your browser's developer console for information.
The "go-debug.js" version of the library contains extra type-checking and error-checking code, and should be used
during development.
The "go.js" version has less error checking, but is faster as a result, and should be used in production.
</p>
<p>
Your JavaScript code should only use properties and methods that are documented in the <a href="../api/index.html" target="api">API</a>.
The <b>GoJS</b> libraries are "minified", so if you look at an instance of a <b>GoJS</b> class in the debugger,
you will see many one or two letter property names. All of those are internal names that you should not use.
At the current time the only one letter property names are "x" and "y" on <a>Point</a>, <a>Rect</a>, <a>Spot</a> and
<a>LayoutVertex</a>.
The only two letter property name is <a>InputEvent.up</a>.
Otherwise you should not try to use any one or two letter property names on any <b>GoJS</b>-defined objects.
</p>
<p class="box bg-danger">
Do not modify the prototypes of the <b>GoJS</b> classes.<br />
Only use the properties and methods documented in the <a href="../api/index.html" target="api">API</a>.
</p>
<p>
You can also use <a href="https://www.typescriptlang.org/">TypeScript</a> in order to get better "edit-time" and
"compile-time" type checking and "edit-time" documentation.
The TypeScript definition files for <b>GoJS</b> are named "go.d.ts" and "go-module.d.ts" and are located in the same directory as the libraries.
The extension classes are implemented in TypeScript, available at <code>../extensionsJSM/</code>
and compiled to JavaScript in <code>../extensionsJSM/</code> as modules and <code>../extensions/</code> as scripts.
Copy the extension definitions into your project and make sure they import the same <b>GoJS</b> library as all of your code does.
</p>
<p>
To learn about new features and bug fixes, read the <a href="https://gojs.net/latest/changelog.html" target="_blank">Change Log</a>.
Read about getting the latest releases at <a href="../download.html">Downloads</a>.
</p>
<p>
You can see the variety of kinds of diagrams that you can build at <a href="../samples/index.html" target="samples">GoJS Samples</a>.
</p>
<p>
In the next introduction page we discuss <a href="buildingObjects.html">building <b>GoJS</b> Parts and adding them into Diagrams.</a>
</p>
</div>
</div>
<footer class="bg-white text-gray-900 border-t border-t-gray-200">
<div class="w-full max-w-screen-lg mx-auto px-4 py-6">
<p id="version" class="text-xs text-gray-900 m-0"></p>
<div class="text-sm px-0 mb-4 grid grid-cols-2 sm:grid-cols-3 gap-y-10">
<div>
<h2 class="text-base font-semibold text-nwoods-primary">GoJS</h2>
<ul class="list-none space-y-4 md:space-y-1 px-0">
<li>
<a href="../samples/index.html">Samples</a>
</li>
<li>
<a href="../learn/index.html">Learn</a>
</li>
<li>
<a href="../intro/index.html">Intro</a>
</li>
<li>
<a href="../api/index.html">API</a>
</li>
<li>
<a href="../changelog.html">Changelog</a>
</li>
<li>
<a href="https://github.com/NorthwoodsSoftware/GoJS" target="_blank" rel="noopener">GitHub</a>
</li>
</ul>
</div>
<div>
<h2 class="text-base font-semibold text-nwoods-primary">Support</h2>
<ul class="list-none space-y-4 md:space-y-1 px-0">
<li>
<a href="https://nwoods.com/contact.html"
target="_blank" rel="noopener" onclick="getOutboundLink('https://nwoods.com/contact.html', 'contact');">Contact</a>
</li>
<li>
<a href="https://forum.nwoods.com/c/gojs" target="_blank" rel="noopener">Forum</a>
</li>
<li>
<a href="https://nwoods.com/app/activate.aspx?sku=gojs" target="_blank" rel="noopener">Activate</a>
</li>
<li>
<a href="https://nwoods.com/sales/index.html"
target="_blank" rel="noopener" onclick="getOutboundLink('https://nwoods.com/sales/index.html', 'buy');">Buy</a>
</li>
<li>
<a href="https://nwoods.com/register.html" target="_blank" rel="noopener">Register</a>
</li>
</ul>
</div>
<div>
<h2 class="text-base font-semibold text-nwoods-primary">Company</h2>
<ul class="list-none space-y-4 md:space-y-1 px-0">
<li>
<a target="_blank" href="https://nwoods.com" target="_blank" rel="noopener">Northwoods</a>
</li>
<li>
<a target="_blank" href="https://nwoods.com/about.html" target="_blank" rel="noopener">About Us</a>
</li>
<li>
<a target="_blank" href="https://nwoods.com/contact.html" target="_blank" rel="noopener">Contact Us</a>
</li>
<li>
<a target="_blank" href="https://nwoods.com/consulting.html" target="_blank" rel="noopener">Consulting</a>
</li>
<li>
<a target="_blank" href="https://twitter.com/northwoodsgo" target="_blank" rel="noopener">Twitter</a>
</li>
</ul>
</div>
</div>
<p class="text-sm text-gray-900 md:mb-6">
Copyright 1998-2025 <a href="https://nwoods.com">Northwoods Software</a>
</p>
</div>
</footer>
</body>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-S5QK8VSK84"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-S5QK8VSK84');
var getOutboundLink = function (url, label) {
gtag('event', 'click', {
'event_category': 'outbound',
'event_label': label,
'transport_type': 'beacon'
});
}
const params = new URL(document.location).searchParams
let a = params.get('a');
if (a) localStorage.setItem('a', a);
a = localStorage.getItem('a');
if (a) {
const links = [...document.body.getElementsByTagName("a")].filter((l) => l.href.includes('nwoods.com'));
for (const l of links) {
const url = new URL(l.href);
url.searchParams.set('a', a);
l.href = url;
}
}
</script>
<script src="../assets/js/prism.js"></script>
<script src="https://cdn.jsdelivr.net/npm/gojs@3.1.0"></script>
<script src="../assets/js/goDoc.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
if (window.go)
document
.getElementById('version')
.textContent = "GoJS version " + go.version;
if (window.goDoc)
window.goDoc();
var d = window.diagrams;
for (var i = 0; i < d.length; i++) {
var dargs = d[i];
goCodeExecute(dargs[0], dargs[1], dargs[2], dargs[3], dargs[4]);
}
if (window.extra)
window.extra();
}
);
</script>
</html>