UNPKG

33 kBHTMLView Raw
1<!DOCTYPE html>
2<html lang="en">
3 <head>
4<meta charset="utf-8"/>
5<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover"/>
6
7<link rel="stylesheet" href="../assets/css/style.css"/>
8<!-- Copyright 1998-2021 by Northwoods Software Corporation. --> <title> GoJS Buttons -- Northwoods Software </title>
9 <link rel="stylesheet" href="../assets/css/prism.css" />
10 </head>
11 <script>
12
13 window.diagrams = [];
14 window.goCode = function(pre, w, h, parentid, animation) {
15 window.diagrams.push([pre, w, h, parentid, animation]);
16 }
17 </script>
18 <body>
19 <nav id="navTop" class="w-full z-30 top-0 text-white bg-nwoods-primary">
20 <div class="w-full container max-w-screen-lg mx-auto flex flex-wrap sm:flex-nowrap items-center justify-between mt-0 py-2">
21 <div class="md:pl-4">
22 <a class="text-white hover:text-white no-underline hover:no-underline
23 font-bold text-2xl lg:text-4xl rounded-lg hover:bg-nwoods-secondary " href="../">
24 <h1 class="mb-0 p-1 ">GoJS</h1>
25 </a>
26 </div>
27 <button id="topnavButton" class="rounded-lg sm:hidden focus:outline-none focus:ring" aria-label="Navigation">
28 <svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6">
29 <path id="topnavOpen" fill-rule="evenodd" d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM9 15a1 1 0 011-1h6a1 1 0 110 2h-6a1 1 0 01-1-1z" clip-rule="evenodd"></path>
30 <path id="topnavClosed" class="hidden" fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path>
31 </svg>
32 </button>
33 <div id="topnavList" class="hidden sm:block items-center w-auto mt-0 text-white p-0 z-20">
34 <ul class="list-reset list-none font-semibold flex justify-end flex-wrap sm:flex-nowrap items-center px-0 pb-0">
35 <li class="p-1 sm:p-0"><a class="topnav-link" href="../learn/">Learn</a></li>
36 <li class="p-1 sm:p-0"><a class="topnav-link" href="../samples/">Samples</a></li>
37 <li class="p-1 sm:p-0"><a class="topnav-link" href="../intro/">Intro</a></li>
38 <li class="p-1 sm:p-0"><a class="topnav-link" href="../api/">API</a></li>
39 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/products/register.html">Register</a></li>
40 <li class="p-1 sm:p-0"><a class="topnav-link" href="../download.html">Download</a></li>
41 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://forum.nwoods.com/c/gojs/11">Forum</a></li>
42 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/contact.html"
43 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a></li>
44 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/sales/index.html"
45 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a></li>
46 </ul>
47 </div>
48 </div>
49 <hr class="border-b border-gray-600 opacity-50 my-0 py-0" />
50 </nav>
51
52 <div class="md:flex flex-col md:flex-row md:min-h-screen w-full max-w-screen-xl mx-auto">
53
54 <div id="navSide" class="flex flex-col w-full md:w-40 lg:w-48 text-gray-700 bg-white flex-shrink-0">
55 <div class="flex-shrink-0 px-8 py-4">
56 <button id="navButton" class="rounded-lg md:hidden focus:outline-none focus:ring" aria-label="Navigation">
57 <svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6">
58 <path id="navOpen" fill-rule="evenodd" d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM9 15a1 1 0 011-1h6a1 1 0 110 2h-6a1 1 0 01-1-1z" clip-rule="evenodd"></path>
59 <path id="navClosed" class="hidden" fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path>
60 </svg>
61 </button>
62 </div>
63 <nav id="navList" class="min-h-screen hidden md:block sidebar-nav flex-grow px-1 lg:px-4 pb-4 md:pb-0 md:overflow-y-auto break-words">
64 <a href="index.html">Basics</a>
65 <a href="buildingObjects.html">Building Parts</a>
66 <a href="usingModels.html">Using Models</a>
67 <a href="dataBinding.html">Data Binding</a>
68 <a href="react.html">GoJS with React</a>
69 <a href="angular.html">GoJS with Angular</a>
70 <a href="textBlocks.html">TextBlocks</a>
71 <a href="shapes.html">Shapes</a>
72 <a href="pictures.html">Pictures</a>
73 <a href="panels.html">Panels</a>
74 <a href="tablePanels.html">Table Panels</a>
75 <a href="brush.html">Brushes</a>
76 <a href="sizing.html">Sizing Objects</a>
77 <a href="itemArrays.html">Item Arrays</a>
78 <a href="changedEvents.html">Changed Events</a>
79 <a href="transactions.html">Transactions</a>
80 <a href="viewport.html">Coordinates</a>
81 <a href="initialView.html">Initial View</a>
82 <a href="collections.html">Collections</a>
83 <a href="links.html">Links</a>
84 <a href="linkLabels.html">Link Labels</a>
85 <a href="connectionPoints.html">Link Points</a>
86 <a href="ports.html">Ports</a>
87 <a href="nodes.html">Nodes</a>
88 <a href="debugging.html">Debugging</a>
89 <a href="layouts.html">Layouts</a>
90 <a href="trees.html">Trees</a>
91 <a href="subtrees.html">SubTrees</a>
92 <a href="groups.html">Groups</a>
93 <a href="subgraphs.html">SubGraphs</a>
94 <a href="sizedGroups.html">Sized Groups</a>
95 <a href="selection.html">Selection</a>
96 <a href="highlighting.html">Highlighting</a>
97 <a href="animation.html">Animation</a>
98 <a href="toolTips.html">ToolTips</a>
99 <a href="contextmenus.html">Context Menus</a>
100 <a href="events.html">Diagram Events</a>
101 <a href="tools.html">Tools</a>
102 <a href="commands.html">Commands</a>
103 <a href="permissions.html">Permissions</a>
104 <a href="validation.html">Validation</a>
105 <a href="HTMLInteraction.html">HTML Interaction</a>
106 <a href="layers.html">Layers &amp; Z-ordering</a>
107 <a href="palette.html">Palette</a>
108 <a href="overview.html">Overview</a>
109 <a href="resizing.html">Resizing Diagrams</a>
110 <a href="replacingDeleting.html">Replacing and Deleting</a>
111 <a href="buttons.html">Buttons</a>
112 <a href="templateMaps.html">Template Maps</a>
113 <a href="legends.html">Legends and Titles</a>
114 <a href="extensions.html">Extensions</a>
115 <a href="geometry.html">Geometry Strings</a>
116 <a href="grids.html">Grid Patterns</a>
117 <a href="graduatedPanels.html">Graduated Panels</a>
118 <a href="makingImages.html">Diagram Images</a>
119 <a href="makingSVG.html">Diagram SVG</a>
120 <a href="printing.html">Printing</a>
121 <a href="serverSideImages.html">Server-side Images</a>
122 <a href="nodeScript.html">GoJS in Node.js</a>
123 <a href="testing.html">Testing</a>
124 <a href="storage.html">Storage</a>
125 <a href="performance.html">Performance</a>
126 <a href="source.html">Building from Source</a>
127 <a href="platforms.html">Platforms</a>
128 <a href="deployment.html">Deployment</a>
129 </nav>
130 </div>
131 <div class="pt-4 px-2 md:px-0 lg:px-4 pb-16 w-full overflow-hidden">
132
133
134
135
136<h1>Buttons</h1>
137<p>
138For your convenience we have defined several <a>Panel</a>s for common uses.
139These include "Button", "TreeExpanderButton", "SubGraphExpanderButton", "PanelExpanderButton", "ContextMenuButton", and "CheckBoxButton".
140"ContextMenuButton"s are typically used inside of "ContextMenu" Panels;
141"CheckBoxButton"s are used in the implementation of "CheckBox" Panels.
142</p>
143<p>
144These predefined panels can be used as if they were <a>Panel</a>-derived classes in calls to <a>GraphObject,make</a>.
145They are implemented as simple visual trees of <a>GraphObject</a>s in <a>Panel</a>s,
146with pre-set properties and event handlers.
147</p>
148<p>
149You can see a copy of their definitions in this file:
150<a href="../extensions/Buttons.js">Buttons.js</a>.
151</p>
152<p>
153See samples that make use of buttons in the <a href="../samples/index.html#buttons">samples index</a>.
154In addition, see the <a href="../extensions/Checkboxes.html">Checkboxes</a> extension for an example of using "CheckBoxButton".
155</p>
156
157
158<h2 id="GeneralButtons">General Buttons</h2>
159<p>
160The most general kind of predefined <a>Panel</a> is "Button".
161</p>
162<pre class="lang-js" id="button"><code>
163 diagram.nodeTemplate =
164 $(go.Node, "Auto",
165 { locationSpot: go.Spot.Center },
166 $(go.Shape, "Rectangle",
167 { fill: "gold" }),
168 $(go.Panel, "Vertical",
169 { margin: 3 },
170 $("Button",
171 { margin: 2,
172 click: incrementCounter },
173 $(go.TextBlock, "Click me!")),
174 $(go.TextBlock,
175 new go.Binding("text", "clickCount",
176 function(c) { return "Clicked " + c + " times."; }))
177 )
178 );
179
180 function incrementCounter(e, obj) {
181 var node = obj.part;
182 var data = node.data;
183 if (data && typeof(data.clickCount) === "number") {
184 node.diagram.model.commit(function(m) {
185 m.set(data, "clickCount", data.clickCount + 1);
186 }, "clicked");
187 }
188 }
189
190 diagram.model = new go.GraphLinksModel(
191 [ { clickCount: 0 } ]);
192</code></pre>
193<script>goCode("button", 600, 150)</script>
194
195<p>
196Buttons are just Panels holding a Shape that will surround whatever content you give it.
197The border Shape is named "ButtonBorder" so that you can easily set or bind its properties.
198</p>
199<p>
200The event handlers defined by all "Button"s make use of additional properties,
201not defined in the API, but that you can see in the definition of "Button":
202<a href="../extensions/Buttons.js">Buttons.js</a>.
203These properties parameterize the appearance of the button.
204</p>
205<pre class="lang-js" id="button2"><code>
206 diagram.nodeTemplate =
207 $(go.Node, "Auto",
208 { locationSpot: go.Spot.Center },
209 $(go.Shape, "Rectangle",
210 { fill: "gold" }),
211 $(go.Panel, "Vertical",
212 { margin: 3 },
213 $("Button",
214 {
215 margin: 2,
216 // set properties on the border Shape of the "Button"
217 "ButtonBorder.fill": "fuchsia",
218 // set properties on the "Button" itself used by its event handlers
219 "_buttonFillOver": "pink",
220 click: function(e, button) { alert(button.findObject("ButtonBorder").fill); }
221 },
222 $(go.TextBlock, "fuchsia button\nwith pink highlight", { margin: 2, textAlign: "center" })
223 ),
224 $("Button",
225 {
226 margin: 2,
227 // set properties on the border Shape of the "Button"
228 "ButtonBorder.figure": "Circle",
229 "ButtonBorder.fill": "cyan",
230 "ButtonBorder.stroke": "darkcyan",
231 "ButtonBorder.strokeWidth": 3,
232 // set properties on the "Button" itself used by its event handlers
233 "_buttonFillOver": "white",
234 "_buttonStrokeOver": "cyan",
235 "_buttonFillPressed": "lightgray",
236 click: function(e, button) { alert(button.findObject("ButtonBorder").stroke); }
237 },
238 $(go.TextBlock, "Circular\nbutton", { margin: 2, textAlign: "center" })
239 ),
240 $("Button",
241 {
242 margin: 2,
243 click: function(e, button) { alert(button.findObject("PIC").source); }
244 },
245 // the button content can be anything -- it doesn't have to be a TextBlock
246 $(go.Picture, "images/50x40.png", { name: "PIC", width: 50, height: 40 })
247 ),
248 $("Button",
249 {
250 margin: 2,
251 // buttons can be disabled too, by either setting or data binding:
252 isEnabled: false,
253 click: function(e, button) { alert("won't be alerted"); }
254 },
255 $(go.TextBlock, "disabled", { stroke: "gray" })
256 )
257 )
258 );
259
260 diagram.model = new go.GraphLinksModel([ { } ]);
261</code></pre>
262<script>goCode("button2", 600, 250)</script>
263
264
265<h2 id="TreeExpanderButtons">TreeExpanderButtons</h2>
266<p>
267It is common to want to expand and collapse subtrees.
268It is easy to let the user control this by adding an instance of the "TreeExpanderButton" to your node template.
269The button calls <a>CommandHandler.collapseTree</a> or <a>CommandHandler.expandTree</a>
270depending on the value of <a>Node.isTreeExpanded</a>.
271The button's icon's <a>Shape.figure</a> changes as the value of
272<a>Node.isTreeExpanded</a> changes.
273</p>
274<pre class="lang-js" id="treeExpanderButton"><code>
275 diagram.nodeTemplate =
276 $(go.Node, "Spot",
277 $(go.Panel, "Auto",
278 $(go.Shape, "Rectangle",
279 { fill: "gold" }),
280 $(go.TextBlock, "Click small button\nto collapse/expand subtree",
281 { margin: 5 })
282 ),
283 $("TreeExpanderButton",
284 { alignment: go.Spot.Bottom, alignmentFocus: go.Spot.Top },
285 { visible: true })
286 );
287
288 diagram.layout = $(go.TreeLayout, { angle: 90 });
289
290 diagram.model = new go.GraphLinksModel(
291 [ { key: 1 },
292 { key: 2 } ],
293 [ { from: 1, to: 2 } ] );
294</code></pre>
295<script>goCode("treeExpanderButton", 600, 200)</script>
296
297<p>
298A "TreeExpanderButton" is a "Button" that holds a Shape displaying either a "MinusLine" or a "PlusLine"
299figure, depending on the value of the <a>Node.isTreeExpanded</a>.
300That shape is named "ButtonIcon", so that you can easily set or bind its properties,
301in addition to the properties of the "ButtonBorder" and of the "Button" itself.
302</p>
303<pre class="lang-js" id="treeExpanderButton2"><code>
304 diagram.nodeTemplate =
305 $(go.Node, "Spot",
306 $(go.Panel, "Auto",
307 $(go.Shape, "Rectangle",
308 { fill: "gold" }),
309 $(go.TextBlock, "Click small button\nto collapse/expand subtree",
310 { margin: 5 })
311 ),
312 $("TreeExpanderButton",
313 {
314 // set the two additional properties used by "TreeExpanderButton"
315 // that control the shape depending on the value of Node.isTreeExpanded
316 "_treeExpandedFigure": "TriangleUp",
317 "_treeCollapsedFigure": "TriangleDown",
318 // set properties on the icon within the border
319 "ButtonIcon.fill": "darkcyan",
320 "ButtonIcon.strokeWidth": 0,
321 // set general "Button" properties
322 "ButtonBorder.figure": "Circle",
323 "ButtonBorder.stroke": "darkcyan",
324 "_buttonStrokeOver": "darkcyan"
325 },
326 { alignment: go.Spot.Bottom, alignmentFocus: go.Spot.Top },
327 { visible: true })
328 );
329
330 diagram.layout = $(go.TreeLayout, { angle: 90 });
331
332 diagram.model = new go.GraphLinksModel(
333 [ { key: 1 },
334 { key: 2 } ],
335 [ { from: 1, to: 2 } ] );
336</code></pre>
337<script>goCode("treeExpanderButton2", 600, 200)</script>
338
339
340<h2 id="SubGraphExpanderButtons">SubGraphExpanderButtons</h2>
341<p>
342It is also common to want to expand and collapse groups containing subgraphs.
343You can let the user control this by adding an instance of the "SubGraphExpanderButton" to your group template.
344The button calls <a>CommandHandler.collapseSubGraph</a> or <a>CommandHandler.expandSubGraph</a>
345depending on the value of <a>Group.isSubGraphExpanded</a>.
346The button's icon's <a>Shape.figure</a> changes as the value of
347<a>Group.isSubGraphExpanded</a> changes.
348</p>
349<pre class="lang-js" id="subgraphExpanderButton"><code>
350 diagram.groupTemplate =
351 $(go.Group, "Auto",
352 $(go.Shape, "Rectangle",
353 { fill: "gold" }),
354 $(go.Panel, "Vertical",
355 { margin: 5,
356 defaultAlignment: go.Spot.Left },
357 $(go.Panel, "Horizontal",
358 $("SubGraphExpanderButton",
359 { margin: new go.Margin(0, 3, 5, 0) }),
360 $(go.TextBlock, "Group")
361 ),
362 $(go.Placeholder)
363 )
364 );
365
366 diagram.model = new go.GraphLinksModel(
367 [ { key: 0, isGroup: true },
368 { key: 1, group: 0 },
369 { key: 2, group: 0 },
370 { key: 3, group: 0 } ] );
371</code></pre>
372<script>goCode("subgraphExpanderButton", 600, 150)</script>
373
374<p>
375A "SubGraphExpanderButton" is like a "TreeExpanderButton" in its being a "Button"
376with a border Shape surrounding an icon Shape.
377That shape is named "ButtonIcon", so that you can easily set or bind its properties,
378in addition to the properties of the "ButtonBorder" and of the "Button" itself.
379</p>
380<pre class="lang-js" id="subgraphExpanderButton2"><code>
381 diagram.groupTemplate =
382 $(go.Group, "Auto",
383 $(go.Shape, "Rectangle",
384 { fill: "gold" }),
385 $(go.Panel, "Vertical",
386 { margin: 5,
387 defaultAlignment: go.Spot.Left },
388 $(go.Panel, "Horizontal",
389 $("SubGraphExpanderButton",
390 {
391 // set the two additional properties used by "SubGraphExpanderButton"
392 // that control the shape depending on the value of Group.isSubGraphExpanded
393 "_subGraphExpandedFigure": "TriangleUp",
394 "_subGraphCollapsedFigure": "TriangleDown",
395 // set other properties on the button icon
396 "ButtonIcon.angle": -45,
397 // and properties on the button border or the button itself
398 "ButtonBorder.opacity": 0.0
399 }),
400 $(go.TextBlock, "Group")
401 ),
402 $(go.Placeholder)
403 )
404 );
405
406 diagram.model = new go.GraphLinksModel(
407 [ { key: 0, isGroup: true },
408 { key: 1, group: 0 },
409 { key: 2, group: 0 },
410 { key: 3, group: 0 } ] );
411</code></pre>
412<script>goCode("subgraphExpanderButton2", 600, 150)</script>
413
414
415<h2 id="PanelExpanderButtons">PanelExpanderButtons</h2>
416<p>
417It is common to want to expand and collapse a piece of a node,
418thereby showing or hiding details that are sometimes not needed.
419It is easy to let the user control this by adding an instance of the "PanelExpanderButton" to your node template.
420The second argument to <a>GraphObject,make</a> should be a string that names the element in the node whose
421<a>GraphObject.visible</a> property you want the button to toggle.
422</p>
423<pre class="lang-js" id="panelExpanderButton"><code>
424 diagram.nodeTemplate =
425 $(go.Node, "Auto",
426 $(go.Shape,
427 { fill: "gold" }),
428 $(go.Panel, "Table",
429 { defaultAlignment: go.Spot.Top, defaultColumnSeparatorStroke: "black" },
430 $(go.Panel, "Table",
431 { column: 0 },
432 $(go.TextBlock, "List 1",
433 { column: 0, margin: new go.Margin(3, 3, 0, 3),
434 font: "bold 12pt sans-serif" }),
435 $("PanelExpanderButton", "LIST1",
436 { column: 1 }),
437 $(go.Panel, "Vertical",
438 { name: "LIST1", row: 1, column: 0, columnSpan: 2 },
439 new go.Binding("itemArray", "list1"))
440 ),
441 $(go.Panel, "Table",
442 { column: 1 },
443 $(go.TextBlock, "List 2",
444 { column: 0, margin: new go.Margin(3, 3, 0, 3),
445 font: "bold 12pt sans-serif" }),
446 $("PanelExpanderButton", "LIST2",
447 { column: 1 }),
448 $(go.Panel, "Vertical",
449 { name: "LIST2", row: 1, column: 0, columnSpan: 2 },
450 new go.Binding("itemArray", "list2"))
451 )
452 )
453 );
454
455 diagram.model = new go.GraphLinksModel([
456 {
457 key: 1,
458 list1: [ "one", "two", "three", "four", "five" ],
459 list2: [ "first", "second", "third", "fourth" ]
460 }
461 ]);
462</code></pre>
463<script>goCode("panelExpanderButton", 600, 200)</script>
464
465<p>
466A "PanelExpanderButton" is like a "TreeExpanderButton" or "SubGraphExpanderButton"
467in its being a "Button" with a border Shape surrounding an icon Shape.
468However, this panel binds the <a>Shape.geometryString</a> rather than the <a>Shape.figure</a>.
469</p>
470<pre class="lang-js" id="panelExpanderButton2"><code>
471 diagram.nodeTemplate =
472 $(go.Node, "Auto",
473 $(go.Shape,
474 { fill: "gold" }),
475 $(go.Panel, "Table",
476 { defaultAlignment: go.Spot.Top, defaultColumnSeparatorStroke: "black" },
477 $(go.Panel, "Table",
478 { column: 0 },
479 $(go.TextBlock, "List 1",
480 { column: 0, margin: new go.Margin(3, 3, 0, 3),
481 font: "bold 12pt sans-serif" }),
482 $("PanelExpanderButton", "LIST1",
483 { column: 1,
484 // set the two additional properties used by "PanelExpanderButton"
485 // that control the shape depending on the value of GraphObject.visible
486 // of the object named "LIST1"
487 "_buttonExpandedFigure": "M0 0 L10 0",
488 "_buttonCollapsedFigure": "M0 5 L10 5 M5 0 L5 10",
489 "ButtonIcon.stroke": "blue",
490 height: 16
491 }),
492 $(go.Panel, "Vertical",
493 { name: "LIST1", row: 1, column: 0, columnSpan: 2 },
494 new go.Binding("itemArray", "list1"))
495 ),
496 $(go.Panel, "Table",
497 { column: 1 },
498 $(go.TextBlock, "List 2",
499 { column: 0, margin: new go.Margin(3, 3, 0, 3),
500 font: "bold 12pt sans-serif" }),
501 $("PanelExpanderButton", "LIST2",
502 { column: 1,
503 // set the two additional properties used by "PanelExpanderButton"
504 // that control the shape depending on the value of GraphObject.visible
505 // of the object named "LIST1"
506 "_buttonExpandedFigure": "F M0 10 L5 0 10 10z",
507 "_buttonCollapsedFigure": "F M0 0 L10 0 5 10z",
508 "ButtonIcon.strokeWidth": 0,
509 "ButtonIcon.fill": "blue"
510 }),
511 $(go.Panel, "Vertical",
512 { name: "LIST2", row: 1, column: 0, columnSpan: 2 },
513 new go.Binding("itemArray", "list2"))
514 )
515 )
516 );
517
518 diagram.model = new go.GraphLinksModel([
519 {
520 key: 1,
521 list1: [ "one", "two", "three", "four", "five" ],
522 list2: [ "first", "second", "third", "fourth" ]
523 }
524 ]);
525</code></pre>
526<script>goCode("panelExpanderButton2", 600, 200)</script>
527
528
529<h2 id="ContextMenuButtons">ContextMenuButtons and ContextMenus</h2>
530<p>
531Although you can implement context menus in any way you choose, it is common to use the predefined "ContextMenuButton".
532</p>
533<pre class="lang-js" id="contextMenuButtons"><code>
534 diagram.nodeTemplate =
535 $(go.Node, "Auto",
536 $(go.Shape, "Rectangle",
537 { fill: "gold" }),
538 $(go.TextBlock, "Use ContextMenu!",
539 { margin: 5 })
540 );
541
542 diagram.nodeTemplate.contextMenu =
543 $("ContextMenu",
544 $("ContextMenuButton",
545 $(go.TextBlock, "Shift Left"),
546 { click: function(e, obj) { shiftNode(obj, -20); } }),
547 $("ContextMenuButton",
548 $(go.TextBlock, "Shift Right"),
549 { click: function(e, obj) { shiftNode(obj, +20); } })
550 );
551
552 function shiftNode(obj, dist) {
553 var adorn = obj.part;
554 var node = adorn.adornedPart;
555 node.diagram.commit(function(d) {
556 var pos = node.location.copy();
557 pos.x += dist;
558 node.location = pos;
559 }, "Shift");
560 }
561
562 diagram.model = new go.GraphLinksModel(
563 [ { key: 1 } ] );
564</code></pre>
565<script>goCode("contextMenuButtons", 600, 150)</script>
566<p>
567For an example of defining context menus using HTML, see the <a href="../samples/customContextMenu.html">Custom ContextMenu sample</a>.
568</p>
569
570<p>
571A "ContextMenuButton" is just a "Button" with a few properties set.
572One of those properties is <a>GraphObject.stretch</a>, which is set to
573<code>go.GraphObject.Horizontal</code> so that all of the "ContextMenuButton"s
574in a "ContextMenu" will be stretch to the same width.
575But you can set all of the usual properties on both its "ButtonBorder" Shape
576as well as on the button itself.
577</p>
578<pre class="lang-js" id="contextMenuButtons2"><code>
579 diagram.nodeTemplate =
580 $(go.Node, "Auto",
581 $(go.Shape, "Rectangle",
582 { fill: "gold" }),
583 $(go.TextBlock, "Use ContextMenu!",
584 { margin: 5 })
585 );
586
587 diagram.nodeTemplate.contextMenu =
588 $("ContextMenu",
589 $("ContextMenuButton",
590 {
591 "ButtonBorder.fill": "yellow",
592 "_buttonFillOver": "cyan",
593 "_buttonFillPressed": "lime"
594 },
595 $(go.TextBlock, "Shift Left"),
596 { click: function(e, obj) { shiftNode(obj, -20); } }
597 ),
598 $("ContextMenuButton",
599 {
600 "ButtonBorder.fill": "yellow",
601 "_buttonFillOver": "cyan",
602 "_buttonFillPressed": "lime"
603 },
604 $(go.TextBlock, "Shift Right"),
605 { click: function(e, obj) { shiftNode(obj, +20); } }
606 ),
607 $("ContextMenuButton",
608 { isEnabled: false },
609 $(go.TextBlock, "Shift Right", { stroke: "gray" }),
610 { click: function(e, obj) { alert("won't be alerted"); } }
611 )
612 );
613
614 function shiftNode(obj, dist) {
615 var adorn = obj.part;
616 var node = adorn.adornedPart;
617 node.diagram.commit(function(d) {
618 var pos = node.location.copy();
619 pos.x += dist;
620 node.location = pos;
621 }, "Shift");
622 }
623
624 diagram.model = new go.GraphLinksModel(
625 [ { key: 1 } ] );
626</code></pre>
627<script>goCode("contextMenuButtons2", 600, 150)</script>
628
629<p>
630See also the fancier round context menu implemented in
631<a href="../samples/radialAdornment.html">Radial Context Menu</a>.
632</p>
633
634<h2 id="CheckBoxButtons">CheckBoxButtons and CheckBoxes</h2>
635<p>
636A "CheckBoxButton" is a "Button" that is configured to toggle the boolean value of a data property.
637By default the button is clear when the value is false and shows a check mark when the value is true,
638but a great deal of customization is possible.
639</p>
640<p>
641The first argument when defining a "CheckBoxButton" should be a string that names the data property
642holding the checked state of the "CheckBoxButton".
643If you do not want clicking on the button to toggle the value of a data property,
644specify a data property name that is the empty string.
645</p>
646<p>
647A "CheckBoxButton" is used in the definition of the "CheckBox" Panel, which is a convenient way to associate
648any GraphObject as a label for the "CheckBoxButton".
649</p>
650<p>
651Many examples of "CheckBox"es with various customizations are shown in the <a href="../extensions/CheckBoxes.html">CheckBoxes</a> sample.
652</p>
653<p>
654You can find the definition of a "TriStateCheckBoxButton" in the <a href="../samples/triStateCheckBoxTree.html">Tri-State CheckBox Tree</a> sample.
655</p>
656
657<h2 id="ButtonDefinitions">Button Definitions</h2>
658<p>
659The implementation of all predefined buttons is provided in <a href="../extensions/Buttons.js">Buttons.js</a>
660in the Extensions directory.
661You may wish to copy and adapt these definitions when creating your own buttons.
662</p>
663<p>
664Those definitions might not be an up-to-date description
665of the actual standard button implementations that are in <b>GoJS</b> and used by <a>GraphObject,make</a>.
666</p>
667<p>
668Note that the definitions of those buttons makes use of the <a>GraphObject.defineBuilder</a> static function.
669That extends the behavior of <a>GraphObject,make</a> to allow the creation of fairly complex visual trees by name with optional arguments.
670You can find the definitions of various kinds of controls throughout the samples and extensions, such as at:
671<ul>
672 <li><a href="../extensions/Buttons.js">Buttons.js</a></li>
673 <li><a href="../extensions/HyperlinkText.js">HyperlinkText.js</a></li>
674 <li><a href="../extensions/ScrollingTable.js">ScrollingTable.js</a></li>
675 <li><a href="../extensions/ScrollingTable.js">AutoRepeatButton</a></li>
676</ul>
677</p>
678
679 </div>
680 </div>
681
682 <div class="bg-nwoods-primary">
683 <section class="max-w-screen-lg text-white container mx-auto py-2 px-12">
684 <p id="version" class="leading-none mb-2 my-4">GoJS</p>
685 </section>
686 </div><footer class="bg-nwoods-primary text-white">
687 <div class="container max-w-screen-lg mx-auto px-8">
688 <div class="w-full py-6">
689
690 <div class="max-w-screen-lg xl:max-w-screen-xl mx-auto px-4 sm:px-6 md:px-8">
691 <ul class="text-sm font-medium pb-14 sm:pb-20 grid grid-cols-1 sm:grid-cols-3 gap-y-10">
692 <li class="list-none row-span-2">
693 <h2 class="text-base font-semibold tracking-wide">GoJS</h2>
694 <ul class="list-none space-y-4 md:space-y-1 px-0">
695 <li>
696 <a href="../samples/index.html">Samples</a>
697 </li>
698 <li>
699 <a href="../learn/index.html">Learn</a>
700 </li>
701 <li>
702 <a href="../intro/index.html">Intro</a>
703 </li>
704 <li>
705 <a href="../api/index.html">API</a>
706 </li>
707 <li>
708 <a href="../changelog.html">Changelog</a>
709 </li>
710 <li>
711 <a href="https://github.com/NorthwoodsSoftware/GoJS">GitHub</a>
712 </li>
713 </ul>
714 </li>
715 <li class="list-none row-span-2">
716 <h2 class="text-base font-semibold tracking-wide">Support</h2>
717 <ul class="list-none space-y-4 md:space-y-1 px-0">
718 <li>
719 <a href="https://www.nwoods.com/contact.html"
720 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a>
721 </li>
722 <li>
723 <a href="https://forum.nwoods.com/c/gojs">Forum</a>
724 </li>
725 <li>
726 <a href="https://www.nwoods.com/app/activate.aspx?sku=gojs">Activate</a>
727 </li>
728 <li>
729 <a href="https://www.nwoods.com/sales/index.html"
730 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a>
731 </li>
732 <li>
733 <a href="https://www.youtube.com/channel/UC9We8EoX596-6XFjJDtZIDg">Videos</a>
734 </li>
735 </ul>
736 </li>
737 <li class="list-none row-span-2">
738 <h2 class="text-base font-semibold tracking-wide">Company</h2>
739 <ul class="list-none space-y-4 md:space-y-1 px-0">
740 <li>
741 <a href="https://www.nwoods.com">Northwoods</a>
742 </li>
743 <li>
744 <a href="https://www.nwoods.com/about.html">About Us</a>
745 </li>
746 <li>
747 <a href="https://www.nwoods.com/contact.html">Contact Us</a>
748 </li>
749 <li>
750 <a href="https://twitter.com/northwoodsgo">Twitter</a>
751 </li>
752
753 </ul>
754 </li>
755 </ul>
756
757
758 <p class="text-sm text-gray-100 md:mb-6">
759 Copyright 1998-2021 <a class="text-white" href="https://www.nwoods.com">Northwoods Software</a>
760 </p>
761 </div>
762 </div>
763</footer> </body>
764
765<script async src="https://www.googletagmanager.com/gtag/js?id=UA-1506307-5"></script>
766<script>
767 window.dataLayer = window.dataLayer || [];
768 function gtag(){dataLayer.push(arguments);}
769 gtag('js', new Date()); gtag('config', 'UA-1506307-5');
770 var getOutboundLink = function(url, label) {
771 gtag('event', 'click', {
772 'event_category': 'outbound',
773 'event_label': label,
774 'transport_type': 'beacon'
775 });
776 }
777
778 // topnav
779 var topButton = document.getElementById("topnavButton");
780 var topnavList = document.getElementById("topnavList");
781 topButton.addEventListener("click", function() {
782 this.classList.toggle("active");
783 topnavList.classList.toggle("hidden");
784 document.getElementById("topnavOpen").classList.toggle("hidden");
785 document.getElementById("topnavClosed").classList.toggle("hidden");
786 });
787</script>
788 <script src="../assets/js/prism.js"></script>
789 <script src="../release/go.js"></script>
790 <script src="../assets/js/goDoc.js"></script>
791 <script>
792 document.addEventListener("DOMContentLoaded", function() {
793 if (window.go) document.getElementById('version').textContent = "GoJS version " + go.version;
794 if (window.goDoc) window.goDoc();
795 var d = window.diagrams;
796 for (var i = 0; i < d.length; i++) {
797 var dargs = d[i];
798 goCodeExecute(dargs[0], dargs[1], dargs[2], dargs[3], dargs[4]);
799 }
800 if (window.extra) window.extra();
801 });
802 </script>
803</html>