create-gojs-kit
Version:
A CLI for downloading GoJS samples, extensions, and docs
727 lines (660 loc) • 32.5 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="Nodes with varying lists of ports on each of four sides." />
<meta itemprop="description" content="Nodes with varying lists of ports on each of four sides." />
<meta property="og:description" content="Nodes with varying lists of ports on each of four sides." />
<meta name="twitter:description" content="Nodes with varying lists of ports on each of four sides." />
<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="Add/Remove/Modify Ports Dynamically on Nodes" />
<meta property="og:title" content="Add/Remove/Modify Ports Dynamically on Nodes" />
<meta name="twitter:title" content="Add/Remove/Modify Ports Dynamically on Nodes" />
<meta property="og:image" content="https://gojs.net/latest/assets/images/screenshots/dynamicports.png" />
<meta itemprop="image" content="https://gojs.net/latest/assets/images/screenshots/dynamicports.png" />
<meta name="twitter:image" content="https://gojs.net/latest/assets/images/screenshots/dynamicports.png" />
<meta property="og:url" content="https://gojs.net/latest/samples/dynamicPorts.html" />
<meta property="twitter:url" content="https://gojs.net/latest/samples/dynamicPorts.html" />
<meta name="twitter:card" content="summary_large_image" />
<meta property="og:type" content="website" />
<meta property="twitter:domain" content="gojs.net" />
<title>
Add/Remove/Modify Ports Dynamically on Nodes | GoJS Diagramming Library
</title>
</head>
<body>
<!-- This top nav is not part of the sample code -->
<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="flex flex-col prose">
<div class="w-full max-w-screen-xl mx-auto">
<!-- * * * * * * * * * * * * * -->
<!-- Start of GoJS sample code -->
<script src="https://cdn.jsdelivr.net/npm/gojs@3.1.0"></script>
<div id="allSampleContent" class="p-4 w-full">
<script src="../extensions/AvoidsLinksRouter.js"></script>
<script id="code">
function init() {
myDiagram = new go.Diagram('myDiagramDiv', { //Diagram refers to its DIV HTML element by id
'undoManager.isEnabled': true
});
myDiagram.routers.add(new AvoidsLinksRouter());
// Use some colors for ports
portColors = ['black', 'red', 'green', 'gray'];
myDiagram.themeManager.set('', {
colors: { ports: portColors }
});
// when the document is modified, add a "*" to the title and enable the "Save" button
myDiagram.addDiagramListener('Modified', e => {
const button = document.getElementById('SaveButton');
if (button) button.disabled = !myDiagram.isModified;
const idx = document.title.indexOf('*');
if (myDiagram.isModified) {
if (idx < 0) document.title += '*';
} else {
if (idx >= 0) document.title = document.title.slice(0, idx);
}
});
// To simplify this code we define a function for creating a context menu button:
function makeButton(text, action, visiblePredicate) {
const button =
go.GraphObject.build('ContextMenuButton', { click: action})
.add(new go.TextBlock(text));
if (visiblePredicate) {
button.bindObject('visible', '', (o, e) => o.diagram ? visiblePredicate(o, e) : false);
}
return button;
}
const nodeMenu = // context menu for each Node
go.GraphObject.build('ContextMenu')
.add(
makeButton('Copy', (e, obj) => e.diagram.commandHandler.copySelection()),
makeButton('Delete', (e, obj) => e.diagram.commandHandler.deleteSelection()),
new go.Shape('LineH', { strokeWidth: 2, height: 1, stretch: go.Stretch.Horizontal }),
makeButton('Add top port', (e, obj) => addPort('top')),
makeButton('Add left port', (e, obj) => addPort('left')),
makeButton('Add right port', (e, obj) => addPort('right')),
makeButton('Add bottom port', (e, obj) => addPort('bottom'))
);
const portSize = new go.Size(8, 8);
const portMenu = // context menu for each port
go.GraphObject.build('ContextMenu')
.add(
makeButton('Swap order', (e, obj) => swapOrder(obj.part.adornedObject)),
makeButton('Remove port',
// in the click event handler, the obj.part is the Adornment;
// its adornedObject is the port
(e, obj) => removePort(obj.part.adornedObject)
),
makeButton('Change color', (e, obj) => changeColor(obj.part.adornedObject)),
makeButton('Remove side ports', (e, obj) => removeAll(obj.part.adornedObject))
);
// the node template
// includes a panel on each side with an itemArray of panels containing ports
myDiagram.nodeTemplate =
new go.Node('Table', {
locationObjectName: 'BODY',
locationSpot: go.Spot.Center,
selectionObjectName: 'BODY',
contextMenu: nodeMenu
})
.bindTwoWay('location', 'loc', go.Point.parse, go.Point.stringify)
.add(
// the body
new go.Panel('Auto', {
row: 1,
column: 1,
name: 'BODY',
stretch: go.Stretch.Fill
})
.add(
new go.Shape('Rectangle', {
fill: 'lightgray',
stroke: 'gray',
strokeWidth: 0.5,
minSize: new go.Size(60, 60)
}),
new go.TextBlock({
margin: 10,
textAlign: 'center',
font: 'bold 14px Segoe UI,sans-serif',
stroke: '#484848',
editable: true
})
.bindTwoWay('text', 'name')
), // end Auto Panel body
// the Panel holding the left port elements, which are themselves Panels,
// created for each item in the itemArray, bound to data.leftArray
new go.Panel('Vertical', {
row: 1,
column: 0,
itemTemplate:
new go.Panel({
fromSpot: go.Spot.Left,
toSpot: go.Spot.Left,
fromLinkable: true,
toLinkable: true,
cursor: 'pointer',
contextMenu: portMenu
})
.attach({ _side: 'left' }) // internal property to make it easier to tell which side it's on
.bind('portId', 'portId')
.add(
new go.Shape('Rectangle', {
stroke: null,
strokeWidth: 0,
desiredSize: portSize,
margin: new go.Margin(1, 0)
})
.themeData('fill', 'portColor', 'ports')
)
}) // end Vertical Panel
.bind('itemArray', 'leftArray'),
// the Panel holding the top port elements, which are themselves Panels,
// created for each item in the itemArray, bound to data.topArray
new go.Panel('Horizontal', {
row: 0,
column: 1,
itemTemplate:
new go.Panel({
fromSpot: go.Spot.Top,
toSpot: go.Spot.Top,
fromLinkable: true,
toLinkable: true,
cursor: 'pointer',
contextMenu: portMenu
})
.attach({ _side: 'top' }) // internal property to make it easier to tell which side it's on
.bind('portId', 'portId')
.add(
new go.Shape('Rectangle', {
stroke: null,
strokeWidth: 0,
desiredSize: portSize,
margin: new go.Margin(0, 1)
})
.themeData('fill', 'portColor', 'ports')
)
}) // end Horizontal Panel
.bind('itemArray', 'topArray'),
// the Panel holding the right port elements, which are themselves Panels,
// created for each item in the itemArray, bound to data.rightArray
new go.Panel('Vertical', {
row: 1,
column: 2,
itemTemplate:
new go.Panel({
fromSpot: go.Spot.Right,
toSpot: go.Spot.Right,
fromLinkable: true,
toLinkable: true,
cursor: 'pointer',
contextMenu: portMenu
})
.attach({ _side: 'right' }) // internal property to make it easier to tell which side it's on
.bind('portId', 'portId')
.add(
new go.Shape('Rectangle', {
stroke: null,
strokeWidth: 0,
desiredSize: portSize,
margin: new go.Margin(1, 0)
})
.themeData('fill', 'portColor', 'ports')
)
}) // end Vertical Panel
.bind('itemArray', 'rightArray'),
// the Panel holding the bottom port elements, which are themselves Panels,
// created for each item in the itemArray, bound to data.bottomArray
new go.Panel('Horizontal', {
row: 2,
column: 1,
itemTemplate:
new go.Panel({
fromSpot: go.Spot.Bottom,
toSpot: go.Spot.Bottom,
fromLinkable: true,
toLinkable: true,
cursor: 'pointer',
contextMenu: portMenu
})
.attach({ _side: 'bottom' }) // internal property to make it easier to tell which side it's on
.bind('portId', 'portId')
.add(
new go.Shape('Rectangle', {
stroke: null,
strokeWidth: 0,
desiredSize: portSize,
margin: new go.Margin(0, 1)
})
.themeData('fill', 'portColor', 'ports')
) // end itemTemplate
}) // end Horizontal Panel
.bind('itemArray', 'bottomArray')
); // end Node
// an orthogonal link template, reshapable and relinkable
myDiagram.linkTemplate =
new go.Link({
routing: go.Routing.AvoidsNodes,
corner: 4,
curve: go.Curve.JumpGap,
reshapable: true,
resegmentable: true,
relinkableFrom: true,
relinkableTo: true
})
.bindTwoWay('points')
.add(
new go.Shape({ stroke: '#2F4F4F', strokeWidth: 1.5 })
);
// support double-clicking in the background to add a copy of this data as a node
myDiagram.toolManager.clickCreatingTool.archetypeNodeData = {
name: 'Unit',
leftArray: [],
rightArray: [],
topArray: [],
bottomArray: []
};
myDiagram.contextMenu =
go.GraphObject.build('ContextMenu')
.add(
makeButton('Paste',
(e, obj) => e.diagram.commandHandler.pasteSelection(
e.diagram.toolManager.contextMenuTool.mouseDownPoint
),
o => o.diagram.commandHandler.canPasteSelection(
o.diagram.toolManager.contextMenuTool.mouseDownPoint
)
),
makeButton('Undo',
(e, obj) => e.diagram.commandHandler.undo(),
o => o.diagram.commandHandler.canUndo()
),
makeButton('Redo',
(e, obj) => e.diagram.commandHandler.redo(),
o => o.diagram.commandHandler.canRedo()
)
);
// load the diagram from JSON data
load();
}
// Add a port to the specified side of the selected nodes.
function addPort(side) {
myDiagram.startTransaction('addPort');
myDiagram.selection.each(node => {
// skip any selected Links
if (!(node instanceof go.Node)) return;
// compute the next available index number for the side
let i = 0;
while (node.findPort(side + i.toString()) !== node) i++;
// now this new port name is unique within the whole Node because of the side prefix
const name = side + i.toString();
// get the Array of port data to be modified
const arr = node.data[side + 'Array'];
if (arr) {
// create a new port data object
const newportdata = {
portId: name,
portColor: getPortColor()
};
// and add it to the Array of port data
myDiagram.model.insertArrayItem(arr, -1, newportdata);
}
});
myDiagram.commitTransaction('addPort');
}
// Exchange the position/order of the given port with the next one.
// If it's the last one, swap with the previous one.
function swapOrder(port) {
const arr = port.panel.itemArray;
if (arr.length >= 2) {
// only if there are at least two ports!
for (let i = 0; i < arr.length; i++) {
if (arr[i].portId === port.portId) {
myDiagram.startTransaction('swap ports');
if (i >= arr.length - 1) i--; // now can swap I and I+1, even if it's the last port
const newarr = arr.slice(0); // copy Array
newarr[i] = arr[i + 1]; // swap items
newarr[i + 1] = arr[i];
// remember the new Array in the model
myDiagram.model.setDataProperty(port.part.data, port._side + 'Array', newarr);
port.part.findLinksConnected(newarr[i].portId).each(l => l.invalidateRoute());
port.part.findLinksConnected(newarr[i + 1].portId).each(l => l.invalidateRoute());
myDiagram.commitTransaction('swap ports');
break;
}
}
}
}
// Remove the clicked port from the node.
// Links to the port will be redrawn to the node's shape.
function removePort(port) {
myDiagram.startTransaction('removePort');
const pid = port.portId;
const arr = port.panel.itemArray;
for (let i = 0; i < arr.length; i++) {
if (arr[i].portId === pid) {
myDiagram.model.removeArrayItem(arr, i);
break;
}
}
myDiagram.commitTransaction('removePort');
}
// Remove all ports from the same side of the node as the clicked port.
function removeAll(port) {
myDiagram.startTransaction('removePorts');
const nodedata = port.part.data;
const side = port._side; // there are four property names, all ending in "Array"
myDiagram.model.setDataProperty(nodedata, side + 'Array', []); // an empty Array
myDiagram.commitTransaction('removePorts');
}
// Change the color of the clicked port.
function changeColor(port) {
myDiagram.startTransaction('colorPort');
const data = port.data;
myDiagram.model.setDataProperty(data, 'portColor', getPortColor());
myDiagram.commitTransaction('colorPort');
}
function getPortColor() {
return Math.floor(Math.random() * portColors.length);
}
// Save the model to / load it from JSON text shown on the page itself, not in a database.
function save() {
document.getElementById('mySavedModel').value = myDiagram.model.toJson();
myDiagram.isModified = false;
}
function load() {
myDiagram.model = go.Model.fromJson(document.getElementById('mySavedModel').value);
// When copying a node, we need to copy the data that the node is bound to.
// This JavaScript object includes properties for the node as a whole, and
// four properties that are Arrays holding data for each port.
// Those arrays and port data objects need to be copied too.
// Thus Model.copiesArrays and Model.copiesArrayObjects both need to be true.
// Link data includes the names of the to- and from- ports;
// so the GraphLinksModel needs to set these property names:
// linkFromPortIdProperty and linkToPortIdProperty.
}
window.addEventListener('DOMContentLoaded', init);
</script>
<div id="sample">
<div id="myDiagramDiv" style="width: 600px; height: 500px; border: 1px solid black"></div>
Add port to selected nodes:
<button onclick="addPort('top')">Top</button>
<button onclick="addPort('bottom')">Bottom</button>
<button onclick="addPort('left')">Left</button>
<button onclick="addPort('right')">Right</button>
<p>
Double-click in the diagram background in order to add a new node there. In this sample you can
add ports to a selected node by clicking the above buttons or by using the context menu. Draw
links between ports by dragging between ports. If you select a link you can relink or reshape
it. Right-click or touch-hold on a port to bring up a context menu that allows you to remove it
or change its color.
</p>
<p>
See the <a href="../intro/ports.html">Ports Intro page</a> for an explanation of GoJS ports.
</p>
<div>
<div>
<button id="SaveButton" onclick="save()">Save</button>
<button onclick="load()">Load</button>
Diagram Model saved in JSON format:
</div>
<textarea id="mySavedModel" style="width: 100%; height: 250px">
{ "class": "go.GraphLinksModel",
"copiesArrays": true,
"copiesArrayObjects": true,
"linkFromPortIdProperty": "fromPort",
"linkToPortIdProperty": "toPort",
"pointsDigits": 1,
"nodeDataArray": [
{"key":1, "name":"Unit One", "loc":"101 204",
"leftArray":[ {"portColor":0, "portId":"left0"} ],
"topArray":[ {"portColor":1, "portId":"top0"} ],
"bottomArray":[ {"portColor":2, "portId":"bottom0"} ],
"rightArray":[ {"portColor":3, "portId":"right0"},{"portColor":0, "portId":"right1"} ] },
{"key":2, "name":"Unit Two", "loc":"320 152",
"leftArray":[ {"portColor":0, "portId":"left0"},{"portColor":0, "portId":"left1"},{"portColor":0, "portId":"left2"} ],
"topArray":[ {"portColor":3, "portId":"top0"} ],
"bottomArray":[ {"portColor":2, "portId":"bottom0"},{"portColor":3, "portId":"bottom1"},{"portColor":0, "portId":"bottom2"} ],
"rightArray":[ ] },
{"key":3, "name":"Unit Three", "loc":"384 319",
"leftArray":[ {"portColor":0, "portId":"left0"},{"portColor":0, "portId":"left1"},{"portColor":0, "portId":"left2"} ],
"topArray":[ {"portColor":0, "portId":"top0"} ],
"bottomArray":[ {"portColor":2, "portId":"bottom0"} ],
"rightArray":[ ] },
{"key":4, "name":"Unit Four", "loc":"138 351",
"leftArray":[ {"portColor":0, "portId":"left0"} ],
"topArray":[ {"portColor":0, "portId":"top0"} ],
"bottomArray":[ {"portColor":2, "portId":"bottom0"} ],
"rightArray":[ {"portColor":0, "portId":"right0"},{"portColor":0, "portId":"right1"} ] }
],
"linkDataArray": [
{"from":4, "to":2, "fromPort":"top0", "toPort":"bottom0"},
{"from":4, "to":2, "fromPort":"top0", "toPort":"bottom0"},
{"from":3, "to":2, "fromPort":"top0", "toPort":"bottom1"},
{"from":4, "to":3, "fromPort":"right0", "toPort":"left0"},
{"from":4, "to":3, "fromPort":"right1", "toPort":"left2"},
{"from":1, "to":2, "fromPort":"right0", "toPort":"left1"},
{"from":1, "to":2, "fromPort":"right1", "toPort":"left2"}
]}
</textarea>
</div>
</div>
</div>
<!-- * * * * * * * * * * * * * -->
<!-- End of GoJS sample code -->
</div>
<div id="allTagDescriptions" class="p-4 w-full max-w-screen-xl mx-auto">
<hr/>
<h3 class="text-xl">GoJS Features in this sample</h3>
<!-- blacklist tags that do not correspond to a specific GoJS feature -->
<h4>Table Panels</h4>
<p>
The "Table" Panel, <a href="../api/symbols/Panel.html#static-Table" target="api">Panel.Table</a>, arranges objects in rows and columns.
Each object in a Table Panel is put into the cell indexed by the value of <a href="../api/symbols/GraphObject.html#row" target="api">GraphObject.row</a> and <a href="../api/symbols/GraphObject.html#column" target="api">GraphObject.column</a>.
The panel will look at the rows and columns for all of the objects in the panel to determine how many rows and columns the table should have.
More information can be found in the <a href="../intro/tablePanels.html">GoJS Intro</a>.
</p>
<p>
<a href="../samples/index.html#tables">Related samples</a>
</p>
<hr>
<!-- blacklist tags that do not correspond to a specific GoJS feature -->
<h4>Item Arrays</h4>
<p>
It is sometimes useful to display a variable number of elements in a node by data binding to a JavaScript Array.
In GoJS, this is simply achieved by binding (or setting) <a href="../api/symbols/Panel.html#itemArray" target="api">Panel.itemArray</a>.
The <a href="../api/symbols/Panel.html" target="api">Panel</a> will create an element in the panel for each value in the Array.
More information can be found in the <a href="../intro/itemArrays.html">GoJS Intro</a>.
</p>
<p>
<a href="../samples/index.html#itemarrays">Related samples</a>
</p>
<hr>
<!-- blacklist tags that do not correspond to a specific GoJS feature -->
<h4>Links</h4>
<p>
The <a href="../api/symbols/Link.html" target="api">Link</a> class is used to implement a visual relationship between nodes.
Links are normally created by the presence of link data objects in the <a href="../api/symbols/GraphLinksModel.html#linkDataArray" target="api">GraphLinksModel.linkDataArray</a>
or by a parent key reference as the value of the <a href="../api/symbols/TreeModel.html#nodeParentKeyProperty" target="api">TreeModel.nodeParentKeyProperty</a> of a node data object
in a <a href="../api/symbols/TreeModel.html" target="api">TreeModel</a>.
More information can be found in the <a href="../intro/links.html">GoJS Intro</a>.
</p>
<p>
<a href="../samples/index.html#links">Related samples</a>
</p>
<hr>
<!-- blacklist tags that do not correspond to a specific GoJS feature -->
<h4>Ports in Nodes</h4>
<p>
Specific elements of a Node at which links may connect are called <i>ports</i>.
There may be any number of ports in a node. By default there is just one port, the whole node,
which results in the effect of having the whole node act as the port.
Port-like GraphObjects can only be in <a href="../api/symbols/Node.html" target="api">Node</a>s or <a href="../api/symbols/Group.html" target="api">Group</a>s, not in <a href="../api/symbols/Link.html" target="api">Link</a>s or <a href="../api/symbols/Adornment.html" target="api">Adornment</a>s or simple <a href="../api/symbols/Part.html" target="api">Part</a>s.
</p>
<p>
More information can be found in the <a href="../intro/ports.html">GoJS Intro</a>.
</p>
<p>
<a href="../samples/index.html#ports">Related samples</a>
</p>
<hr>
<!-- blacklist tags that do not correspond to a specific GoJS feature -->
<h4>Context Menus</h4>
<p>
A GoJS context menu is an <a href="../api/symbols/Adornment.html" target="api">Adornment</a> that is shown when the user context-clicks (right mouse click or long touch hold)
an object that has its <a href="../api/symbols/GraphObject.html#contextMenu" target="api">GraphObject.contextMenu</a> set.
The context menu is bound to the same data as the part itself.
</p>
<p>
It is typical to implement a context menu as a "ContextMenu" Panel containing "ContextMenuButton"s,
as you can see in the code below in the assignment of the Node's <a href="../api/symbols/GraphObject.html#contextMenu" target="api">GraphObject.contextMenu</a> and <a href="../api/symbols/Diagram.html#contextMenu" target="api">Diagram.contextMenu</a> properties.
Each "ContextMenu" is just a "Vertical" Panel <a href="../api/symbols/Adornment.html" target="api">Adornment</a> that is shadowed.
Each "ContextMenuButton" is a Panel on which you can set the <a href="../api/symbols/GraphObject.html#click" target="api">GraphObject.click</a> event handler.
In the event handler <code>obj.part</code> will be the whole context menu Adornment.
<code>obj.part.adornedPart</code> will be the adorned Node or Link.
The bound data is <code>obj.part.data</code>, which will be the same as <code>obj.part.adornedPart.data</code>.
</p>
<p>
More information can be found in the <a href="../intro/contextmenus.html">GoJS Intro</a>.
</p>
<p>
<a href="../samples/index.html#contextmenus">Related samples</a>
</p>
<hr>
<!-- blacklist tags that do not correspond to a specific GoJS feature -->
<h4>Buttons</h4>
<p>
GoJS defines several <a href="../api/symbols/Panel.html" target="api">Panel</a>s for common uses.
These include "Button", "TreeExpanderButton", "SubGraphExpanderButton", "PanelExpanderButton", "ContextMenuButton", and "CheckBoxButton".
"ContextMenuButton"s are typically used inside of "ContextMenu" Panels;
"CheckBoxButton"s are used in the implementation of "CheckBox" Panels.
</p>
<p>
These predefined panels can be used as if they were <a href="../api/symbols/Panel.html" target="api">Panel</a>-derived classes in calls to <a href="../api/symbols/GraphObject.html#build" target="api">GraphObject.build</a>.
They are implemented as simple visual trees of <a href="../api/symbols/GraphObject.html" target="api">GraphObject</a>s in <a href="../api/symbols/Panel.html" target="api">Panel</a>s,
with pre-set properties and event handlers.
</p>
<p>
More information can be found in the <a href="../intro/buttons.html">GoJS Intro</a>.
</p>
<p>
<a href="../samples/index.html#buttons">Related samples</a>
</p>
<hr>
<!-- blacklist tags that do not correspond to a specific GoJS feature -->
<h4>Theming</h4>
<p>
<b>GoJS</b> allows diagrams to be themed. This is commonly used to provide a light and dark mode for diagrams.
</p>
<p>
The <a href="../api/symbols/Diagram.html#themeManager" target="api">Diagram.themeManager</a> handles themes within a <a href="../api/symbols/Diagram.html" target="api">Diagram</a>.
The <a href="../api/symbols/ThemeManager.html" target="api">ThemeManager</a> can by shared by multiple diagrams,
and is responsible to managing the current theme and default theme, along with any theme updates.
More information can be found in the <a href="../intro/theming.html">GoJS Intro</a>.
</p>
<p>
<a href="../samples/index.html#theme">Related samples</a>
</p>
<hr>
<!-- blacklist tags that do not correspond to a specific GoJS feature -->
<h4>Commands</h4>
<p>
A <a href="../api/symbols/CommandHandler.html" target="api">CommandHandler</a> handles all default keyboard input events in a Diagram.
There are many predefined methods on <a>CommandHandler</a> that implement common commands to operate on the Diagram or the current <a>Diagram.selection></a>.
</p>
<p>
You can override <a>CommandHandler.doKeyDown</a> to handle additional keyboard shortcuts or to change which commands are invoked via the keyboard.
<p>
Your code can invoke a command by calling the appropriate method on the <a>Diagram.commandHandler</a>.
Each command method has a corresponding <b>can...</b> predicate that your code can use to enable or disable any buttons that invoke the command.
Your code can customize the behavior of a command by overriding the method on <a>CommandHandler</a>,
or by setting properties on the <a>CommandHandler</a> or <a>Diagram</a> or <a>Part</a>s --
see <a href="../intro/permissions.html">GoJS Permissions</a>.
</p>
<p>
There are several CommandHandler extensions that provide additional functionality.
<p>
More information can be found in the <a href="../intro/commands.html">GoJS Intro</a>.
</p>
<p>
<a href="../samples/index.html#commands">Related samples</a>
</p>
<hr>
</div>
</div>
</body>
<!-- This script is part of the gojs.net website, and is not needed to run the sample -->
<script src="../assets/js/goSamples.js"></script>
</html>