UNPKG

21.7 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 SubGraphs -- 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>Groups as SubGraphs</h1>
137<p>
138There are some common ways of treating the nodes and links that are the members of a group as if it were its own graph.
139One way to declutter a diagram is to "collapse" a <a>Group</a> to hide the subgraph that it holds.
140</p>
141<p>
142A <a>Group</a> has its own <a>Group.layout</a> that is responsible for the positioning of member <a>Node</a>s
143and the routing of member <a>Link</a>s.
144This is exactly like a <a>Diagram</a> having its own <a>Diagram.layout</a> that positions top-level Nodes and routes top-level Links.
145</p>
146<p>
147Keep in mind that subgraphs are not separate Diagrams and that Groups are just one way of organizing Parts.
148Because subgraphs are collections of Nodes and Links in the same Diagram as the Group itself,
149it is possible to have Links that connect Nodes that are inside a Group with Nodes that are outside of the group.
150It is also possible to have links that connect nodes with the group of which they are a member.
151</p>
152
153<h2 id="LayoutsOfSubgraphs">Layouts of SubGraphs</h2>
154<p>
155You can specify a <a>Layout</a> that applies to a group's subgraph by setting the <a>Group.layout</a> property.
156This operates on the group's member nodes and links as if it were its own diagram.
157A diagram layout of nodes that include groups with their own layout will treat those groups
158as if they were simple nodes, albeit probably larger than normal nodes.
159</p>
160<p>
161In this example the group has a different layout than the layout for the whole diagram.
162In this case the only difference is the direction in which the layout works,
163but you could use a completely different layout algorithm.
164</p>
165<p>
166For simplicity these examples use the default templates for nodes and links.
167</p>
168
169<pre class="lang-js" id="layouts"><code>
170 diagram.groupTemplate =
171 $(go.Group, "Auto",
172 // declare the Group.layout:
173 { layout: $(go.LayeredDigraphLayout,
174 { direction: 0, columnSpacing: 10 }) },
175 $(go.Shape, "RoundedRectangle", // surrounds everything
176 { parameter1: 10, fill: "rgba(128,128,128,0.33)" }),
177 $(go.Panel, "Vertical", // position header above the subgraph
178 $(go.TextBlock, // group title near top, next to button
179 { font: "Bold 12pt Sans-Serif" },
180 new go.Binding("text", "key")),
181 $(go.Placeholder, // represents area for all member parts
182 { padding: 5, background: "white" })
183 )
184 );
185
186 // declare the Diagram.layout:
187 diagram.layout = $(go.LayeredDigraphLayout,
188 { direction: 90, layerSpacing: 10, isRealtime: false });
189
190 var nodeDataArray = [
191 { key: "Alpha" },
192 { key: "Omega", isGroup: true },
193 { key: "Beta", group: "Omega" },
194 { key: "Gamma", group: "Omega" },
195 { key: "Epsilon", group: "Omega" },
196 { key: "Zeta", group: "Omega" },
197 { key: "Delta" }
198 ];
199 var linkDataArray = [
200 { from: "Alpha", to: "Omega" }, // from a Node to the Group
201 { from: "Beta", to: "Gamma" }, // this link is a member of the Group
202 { from: "Beta", to: "Epsilon" }, // this link is a member of the Group
203 { from: "Gamma", to: "Zeta" }, // this link is a member of the Group
204 { from: "Epsilon", to: "Zeta" }, // this link is a member of the Group
205 { from: "Omega", to: "Delta" } // from the Group to a Node
206 ];
207 diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
208</code></pre>
209<script>goCode("layouts", 600, 250)</script>
210
211<p>
212The default layout for a Group is an instance of <a>Layout</a>, just as it is for <a>Diagram</a>.
213So if you do not specify a value for <a>Group.layout</a>, the default layout for the group will position
214all member nodes that do not have a real <a>Part.location</a>.
215</p>
216
217<p>
218If you explicitly set <a>Group.layout</a> to null, the Diagram will be responsible for laying out all of
219Nodes and Links as if the Group did not exist.
220This is possible because a subgraph is not another <a>Diagram</a>.
221</p>
222
223<h2 id="CollapsingAndExpandingGroups">Collapsing and Expanding Groups</h2>
224<p>
225One common technique to visually simplify a diagram is to hide parts of them by "collapsing" them.
226In the case of <a>Group</a>s, it may make sense to be able to hide the subgraph.
227</p>
228<p>
229To collapse a group, set <a>Group.isSubGraphExpanded</a> to false; to make sure it is expanded,
230set that property to true.
231</p>
232<p>
233It is commonplace to provide a button on a group to allow users to collapse and expand groups as they wish.
234<b>GoJS</b> makes this easy to implement by providing a predefined kind of <a>Panel</a>, named "SubGraphExpanderButton",
235that acts as a button to collapse and expand <a>Group</a>s.
236This button changes the visibility of the member nodes and links but does not change
237the visibility of the group itself.
238When the group's visual tree includes a <a>Placeholder</a>, the placeholder will automatically
239shrink when the member parts become invisible and will inflate when the member parts become visible again.
240</p>
241<p>
242Click on the expander button to collapse or expand the group.
243Changing the size of the group also invalidates the layout that is responsible for positioning the group as a single node.
244Often the size of the group changes greatly, so a layout usually needs to be performed again.
245</p>
246<pre class="lang-js" id="collapseExpand"><code>
247 diagram.groupTemplate =
248 $(go.Group, "Auto",
249 { layout: $(go.LayeredDigraphLayout,
250 { direction: 0, columnSpacing: 10 }) },
251 $(go.Shape, "RoundedRectangle", // surrounds everything
252 { parameter1: 10, fill: "rgba(128,128,128,0.33)" }),
253 $(go.Panel, "Vertical", // position header above the subgraph
254 { defaultAlignment: go.Spot.Left },
255 $(go.Panel, "Horizontal", // the header
256 { defaultAlignment: go.Spot.Top },
257 $("SubGraphExpanderButton"), // this Panel acts as a Button
258 $(go.TextBlock, // group title near top, next to button
259 { font: "Bold 12pt Sans-Serif" },
260 new go.Binding("text", "key"))
261 ),
262 $(go.Placeholder, // represents area for all member parts
263 { padding: new go.Margin(0, 10), background: "white" })
264 )
265 );
266
267 diagram.layout = $(go.LayeredDigraphLayout,
268 { direction: 90, layerSpacing: 10, isRealtime: false });
269
270 var nodeDataArray = [
271 { key: "Alpha" },
272 { key: "Omega", isGroup: true },
273 { key: "Beta", group: "Omega" },
274 { key: "Gamma", group: "Omega" },
275 { key: "Epsilon", group: "Omega" },
276 { key: "Zeta", group: "Omega" },
277 { key: "Delta" }
278 ];
279 var linkDataArray = [
280 { from: "Alpha", to: "Omega" }, // from a Node to the Group
281 { from: "Beta", to: "Gamma" }, // this link is a member of the Group
282 { from: "Beta", to: "Epsilon" }, // this link is a member of the Group
283 { from: "Gamma", to: "Zeta" }, // this link is a member of the Group
284 { from: "Epsilon", to: "Zeta" }, // this link is a member of the Group
285 { from: "Omega", to: "Delta" } // from the Group to a Node
286 ];
287 diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
288</code></pre>
289<script>goCode("collapseExpand", 600, 250)</script>
290
291<p>
292If you do not want a layout to be performed again when the group changes size,
293you can set the <a>Part.layoutConditions</a> property to control the circumstances under which
294the layout will be invalidated.
295</p>
296
297<p>
298 <a>Placeholder</a>s can be part of complex panels.
299 The following example demonstrates a different way to have each Group have a header holding a button and some text.
300</p>
301<pre class="lang-js" id="collapseExpand2"><code>
302 diagram.groupTemplate =
303 $(go.Group, "Auto",
304 { layout: $(go.TreeLayout) },
305 $(go.Shape, "Rectangle", { fill: "orange", stroke: "darkorange" }),
306 $(go.Panel, "Table",
307 { margin: 0.5 }, // avoid overlapping border with table contents
308 $(go.RowColumnDefinition, { row: 0, background: "white" }), // header is white
309 $("SubGraphExpanderButton", { row: 0, column: 0, margin: 3 }),
310 $(go.TextBlock, // title is centered in header
311 { row: 0, column: 1, font: "bold 14px Sans-Serif", stroke: "darkorange",
312 textAlign: "center", stretch: go.GraphObject.Horizontal },
313 new go.Binding("text")),
314 $(go.Placeholder, // becomes zero-sized when Group.isSubGraphExpanded is false
315 { row: 1, columnSpan: 2, padding: 10, alignment: go.Spot.TopLeft },
316 new go.Binding("padding", "isSubGraphExpanded",
317 function(exp) { return exp ? 10 : 0; } ).ofObject())
318 )
319 );
320
321 diagram.layout = $(go.TreeLayout, { isRealtime: false });
322
323 diagram.model = new go.GraphLinksModel([
324 { key: 1, text: "Alpha" },
325 { key: 2, text: "GROUP", isGroup: true },
326 { key: 3, text: "Beta", group: 2 },
327 { key: 4, text: "Gamma", group: 2 },
328 { key: 5, text: "Delta" }
329 ], [
330 { from: 1, to: 3 },
331 { from: 3, to: 4 },
332 { from: 1, to: 5 }
333 ]);
334</code></pre>
335<script>goCode("collapseExpand2", 600, 200)</script>
336
337 </div>
338 </div>
339
340 <div class="bg-nwoods-primary">
341 <section class="max-w-screen-lg text-white container mx-auto py-2 px-12">
342 <p id="version" class="leading-none mb-2 my-4">GoJS</p>
343 </section>
344 </div><footer class="bg-nwoods-primary text-white">
345 <div class="container max-w-screen-lg mx-auto px-8">
346 <div class="w-full py-6">
347
348 <div class="max-w-screen-lg xl:max-w-screen-xl mx-auto px-4 sm:px-6 md:px-8">
349 <ul class="text-sm font-medium pb-14 sm:pb-20 grid grid-cols-1 sm:grid-cols-3 gap-y-10">
350 <li class="list-none row-span-2">
351 <h2 class="text-base font-semibold tracking-wide">GoJS</h2>
352 <ul class="list-none space-y-4 md:space-y-1 px-0">
353 <li>
354 <a href="../samples/index.html">Samples</a>
355 </li>
356 <li>
357 <a href="../learn/index.html">Learn</a>
358 </li>
359 <li>
360 <a href="../intro/index.html">Intro</a>
361 </li>
362 <li>
363 <a href="../api/index.html">API</a>
364 </li>
365 <li>
366 <a href="../changelog.html">Changelog</a>
367 </li>
368 <li>
369 <a href="https://github.com/NorthwoodsSoftware/GoJS">GitHub</a>
370 </li>
371 </ul>
372 </li>
373 <li class="list-none row-span-2">
374 <h2 class="text-base font-semibold tracking-wide">Support</h2>
375 <ul class="list-none space-y-4 md:space-y-1 px-0">
376 <li>
377 <a href="https://www.nwoods.com/contact.html"
378 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a>
379 </li>
380 <li>
381 <a href="https://forum.nwoods.com/c/gojs">Forum</a>
382 </li>
383 <li>
384 <a href="https://www.nwoods.com/app/activate.aspx?sku=gojs">Activate</a>
385 </li>
386 <li>
387 <a href="https://www.nwoods.com/sales/index.html"
388 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a>
389 </li>
390 <li>
391 <a href="https://www.youtube.com/channel/UC9We8EoX596-6XFjJDtZIDg">Videos</a>
392 </li>
393 </ul>
394 </li>
395 <li class="list-none row-span-2">
396 <h2 class="text-base font-semibold tracking-wide">Company</h2>
397 <ul class="list-none space-y-4 md:space-y-1 px-0">
398 <li>
399 <a href="https://www.nwoods.com">Northwoods</a>
400 </li>
401 <li>
402 <a href="https://www.nwoods.com/about.html">About Us</a>
403 </li>
404 <li>
405 <a href="https://www.nwoods.com/contact.html">Contact Us</a>
406 </li>
407 <li>
408 <a href="https://twitter.com/northwoodsgo">Twitter</a>
409 </li>
410
411 </ul>
412 </li>
413 </ul>
414
415
416 <p class="text-sm text-gray-100 md:mb-6">
417 Copyright 1998-2021 <a class="text-white" href="https://www.nwoods.com">Northwoods Software</a>
418 </p>
419 </div>
420 </div>
421</footer> </body>
422
423<script async src="https://www.googletagmanager.com/gtag/js?id=UA-1506307-5"></script>
424<script>
425 window.dataLayer = window.dataLayer || [];
426 function gtag(){dataLayer.push(arguments);}
427 gtag('js', new Date()); gtag('config', 'UA-1506307-5');
428 var getOutboundLink = function(url, label) {
429 gtag('event', 'click', {
430 'event_category': 'outbound',
431 'event_label': label,
432 'transport_type': 'beacon'
433 });
434 }
435
436 // topnav
437 var topButton = document.getElementById("topnavButton");
438 var topnavList = document.getElementById("topnavList");
439 topButton.addEventListener("click", function() {
440 this.classList.toggle("active");
441 topnavList.classList.toggle("hidden");
442 document.getElementById("topnavOpen").classList.toggle("hidden");
443 document.getElementById("topnavClosed").classList.toggle("hidden");
444 });
445</script>
446 <script src="../assets/js/prism.js"></script>
447 <script src="../release/go.js"></script>
448 <script src="../assets/js/goDoc.js"></script>
449 <script>
450 document.addEventListener("DOMContentLoaded", function() {
451 if (window.go) document.getElementById('version').textContent = "GoJS version " + go.version;
452 if (window.goDoc) window.goDoc();
453 var d = window.diagrams;
454 for (var i = 0; i < d.length; i++) {
455 var dargs = d[i];
456 goCodeExecute(dargs[0], dargs[1], dargs[2], dargs[3], dargs[4]);
457 }
458 if (window.extra) window.extra();
459 });
460 </script>
461</html>