UNPKG

33.2 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 Nodes -- 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<h1>Nodes</h1>
134<p>
135You can customize your nodes to have exactly the appearance and behavior that you want.
136So far you have only seen very simple nodes.
137But if you have seen the <a href="../samples/index.html">Sample Applications</a>,
138you have seen many other kinds of nodes.
139</p>
140<p>
141In this page we demonstrate some of the choices you can make when designing your nodes.
142</p>
143
144<h2 id="SurroundingContent">Surrounding Content</h2>
145<p>
146It is common to surround interesting information with a border or other background.
147</p>
148<h3 id="SimpleBorders">Simple borders</h3>
149<p>
150Many of the simplest nodes just consist of a <a>Panel</a> of type <a>Panel,Auto</a> with a <a>Shape</a>
151surrounding a <a>TextBlock</a>.
152</p>
153<pre class="lang-js" id="border"><code>
154 diagram.nodeTemplate =
155 $(go.Node, "Auto",
156 $(go.Shape, "Rectangle",
157 new go.Binding("fill", "color")),
158 $(go.TextBlock,
159 { margin: 5 },
160 new go.Binding("text", "key"))
161 );
162
163 diagram.model.nodeDataArray = [
164 { key: "Alpha", color: "lightblue" }
165 ];
166</code></pre>
167<script>goCode("border", 300, 150)</script>
168
169<h3 id="ShapedNodes">Shaped nodes</h3>
170<p>
171The Shape surrounding the content need not be rectangular.
172This example demonstrates a number of shapes.
173</p>
174<pre class="lang-js" id="shapes"><code>
175 diagram.nodeTemplate =
176 $(go.Node, "Auto",
177 $(go.Shape,
178 new go.Binding("figure", "fig"),
179 new go.Binding("fill", "color")),
180 $(go.TextBlock,
181 { margin: 5 },
182 new go.Binding("text", "key"))
183 );
184
185 diagram.model.nodeDataArray = [
186 { key: "Alpha", color: "lightblue", fig: "RoundedRectangle" },
187 { key: "Beta", color: "lightblue", fig: "Ellipse" },
188 { key: "Gamma", color: "lightblue", fig: "Hexagon" },
189 { key: "Delta", color: "lightblue", fig: "FramedRectangle" },
190 { key: "Epsilon", color: "lightblue", fig: "Cloud" },
191 { key: "Zeta", color: "lightblue", fig: "Procedure" }
192 ];
193</code></pre>
194<script>goCode("shapes", 300, 150)</script>
195<p>
196The surrounding/background object need not be a <a>Shape</a>.
197You could use a <a>Picture</a> or even a more complex object such as a <a>Panel</a>.
198</p>
199
200<h3 id="ComplexContents">Complex contents</h3>
201<p>
202The content of an Auto <a>Panel</a> need not be limited to a single <a>TextBlock</a> --
203you can have arbitrarily complex panels of objects.
204In this example the content is a Table Panel with three rows of TextBlocks.
205</p>
206<pre class="lang-js" id="borderedtable"><code>
207 diagram.nodeTemplate =
208 $(go.Node, "Auto",
209 $(go.Shape,
210 { fill: $(go.Brush, "Linear", { 0: "white", 1: "lightblue" }),
211 stroke: "darkblue", strokeWidth: 2 }),
212 $(go.Panel, "Table",
213 { defaultAlignment: go.Spot.Left, margin: 4 },
214 $(go.RowColumnDefinition, { column: 1, width: 4 }),
215 $(go.TextBlock,
216 { row: 0, column: 0, columnSpan: 3, alignment: go.Spot.Center },
217 { font: "bold 12pt sans-serif" },
218 new go.Binding("text", "key")),
219 $(go.TextBlock, "First: ",
220 { row: 1, column: 0 }),
221 $(go.TextBlock,
222 { row: 1, column: 2 },
223 new go.Binding("text", "prop1")),
224 $(go.TextBlock, "Second: ",
225 { row: 2, column: 0 }),
226 $(go.TextBlock,
227 { row: 2, column: 2 },
228 new go.Binding("text", "prop2"))
229 )
230 );
231
232 diagram.model.nodeDataArray = [
233 { key: "Alpha", prop1: "value of 'prop1'", prop2: "the other property" }
234 ];
235</code></pre>
236<script>goCode("borderedtable", 300, 150)</script>
237
238<h3 id="FixedSizeNodes">Fixed-size nodes</h3>
239 <p>
240 The above examples have the "Auto" Panel surround some content, where the content might be of different sizes.
241 That results in the Nodes having different sizes.
242 </p>
243 <p>
244 If you want a <a>Panel</a> (and thus a Node, because <a>Node</a> inherits from <a>Part</a> which inherits from <a>Panel</a>)
245 to be of fixed size, set <a>GraphObject.desiredSize</a> on that panel.
246 (Equivalently, you can set <a>GraphObject.width</a> and <a>GraphObject.height</a>.)
247 That may result in the clipping of content that is too large,
248 or it may result in extra space if the content is smaller than the available area provided by the "Auto" Panel.
249 </p>
250<pre class="lang-js" id="fixedsize"><code>
251 diagram.nodeTemplate =
252 $(go.Node, "Auto",
253 { desiredSize: new go.Size(100, 50) }, // on Panel
254 $(go.Shape,
255 new go.Binding("figure", "fig"),
256 new go.Binding("fill", "color")),
257 $(go.TextBlock,
258 { margin: 5 },
259 new go.Binding("text", "key"))
260 );
261 diagram.model.nodeDataArray = [
262 { key: "Alpha", color: "lightblue", fig: "RoundedRectangle" },
263 { key: "Beta", color: "lightblue", fig: "Ellipse" },
264 { key: "Gamma", color: "lightblue", fig: "Hexagon" },
265 { key: "Delta", color: "lightblue", fig: "FramedRectangle" },
266 { key: "Epsilon,Epsilon,Epsilon", color: "lightblue", fig: "Cloud" },
267 { key: "Z", color: "lightblue", fig: "Procedure" }
268 ];
269</code></pre>
270<script>goCode("fixedsize", 500, 200)</script>
271 <p>
272 Note how the "Epsilon..." TextBlock is measured with the constraint of having a limited width,
273 as imposed by the Panel's width. That results in the text being wrapped before (maybe) being clipped.
274 </p>
275 <p>
276 You probably do not want to set the desiredSize of the main element, the Shape in this case above.
277 If you did, that would not constrain how the content elements are sized within the Panel.
278 </p>
279<pre class="lang-js" id="fixedsize2"><code>
280 diagram.nodeTemplate =
281 $(go.Node, "Auto",
282 $(go.Shape,
283 { desiredSize: new go.Size(100, 50) }, // on main element, not on Panel
284 new go.Binding("figure", "fig"),
285 new go.Binding("fill", "color")),
286 $(go.TextBlock,
287 { margin: 5 },
288 new go.Binding("text", "key"))
289 );
290 diagram.model.nodeDataArray = [
291 { key: "Alpha", color: "lightblue", fig: "RoundedRectangle" },
292 { key: "Beta", color: "lightblue", fig: "Ellipse" },
293 { key: "Gamma", color: "lightblue", fig: "Hexagon" },
294 { key: "Delta", color: "lightblue", fig: "FramedRectangle" },
295 { key: "Epsilon,Epsilon,Epsilon", color: "lightblue", fig: "Cloud" },
296 { key: "Z", color: "lightblue", fig: "Procedure" }
297 ];
298</code></pre>
299<script>goCode("fixedsize2", 500, 200)</script>
300 <p>
301 Note how the TextBlock is measured without the constraint of having a limited width from the Panel.
302 That results in the text being treated as a single long line, which is then clipped by the Panel.
303 </p>
304
305<h2 id="StackedContent">Stacked Content</h2>
306<p>
307Many simple nodes consist of a few objects positioned above each other or next to each other.
308</p>
309
310<h3 id="Icons">Icons</h3>
311<p>
312Perhaps the most commonly seen kind of node can be implemented using a Vertical <a>Panel</a>.
313</p>
314<pre class="lang-js" id="icons"><code>
315 diagram.nodeTemplate =
316 $(go.Node, "Vertical",
317 $(go.Picture,
318 { maxSize: new go.Size(50, 50) },
319 new go.Binding("source", "img")),
320 $(go.TextBlock,
321 { margin: new go.Margin(3, 0, 0, 0),
322 maxSize: new go.Size(100, 30),
323 isMultiline: false },
324 new go.Binding("text", "text"))
325 );
326
327 diagram.model.nodeDataArray = [
328 { text: "Jellylorum", img: "images/50x40.png" }
329 ];
330</code></pre>
331<script>goCode("icons", 300, 150)</script>
332<p>
333 Of course you are not limited to just two objects in a panel.
334 In fact you can have as many GraphObjects in a "Vertical" or a "Horizontal" Panel as you like.
335</p>
336<pre class="lang-js" id="icons2"><code>
337 diagram.nodeTemplate =
338 $(go.Node, "Vertical",
339 $(go.TextBlock,
340 { margin: new go.Margin(3, 0, 0, 0),
341 maxSize: new go.Size(100, 30),
342 isMultiline: false,
343 font: "bold 10pt sans-serif" },
344 new go.Binding("text", "head")),
345 $(go.Picture,
346 { maxSize: new go.Size(50, 50) },
347 new go.Binding("source", "img")),
348 $(go.TextBlock,
349 { margin: new go.Margin(3, 0, 0, 0),
350 maxSize: new go.Size(100, 30),
351 isMultiline: false },
352 new go.Binding("text", "foot"))
353 );
354 diagram.model.nodeDataArray = [
355 { head: "Kitten", foot: "Tantomile", img: "images/50x40.png" }
356 ];
357</code></pre>
358<script>goCode("icons2", 300, 150)</script>
359
360<h3 id="SmallIcons">Small icons</h3>
361<p>
362Another commonly seen kind of node can be implemented using a Horizontal <a>Panel</a>.
363</p>
364<pre class="lang-js" id="smallicons"><code>
365 diagram.nodeTemplate =
366 $(go.Node, "Horizontal",
367 $(go.Picture,
368 { maxSize: new go.Size(16, 16) },
369 new go.Binding("source", "img")),
370 $(go.TextBlock,
371 { margin: new go.Margin(0, 0, 0, 2) },
372 new go.Binding("text", "text"))
373 );
374
375 diagram.model.nodeDataArray = [
376 { text: "Alonzo", img: "images/50x40.png" }
377 ];
378</code></pre>
379<script>goCode("smallicons", 300, 150)</script>
380
381<h2 id="NestedPanels">Nested Panels</h2>
382<p>
383Panels can be nested.
384For example, here is a node consisting of an "Vertical" Panel consisting of an "Auto" Panel surrounding a "Vertical" Panel including a "Horizontal" Panel.
385The outer "Vertical" Panel arranges the main stuff on top and a TextBlock on the bottom.
386The "Auto" Panel supplies a border around everything but the bottom text.
387The inner "Vertical" Panel places three objects vertically in a stack.
388The "Horizontal" Panel which is the first element of the "Vertical" Panel places three objects horizontally in a row.
389</p>
390<pre class="lang-js" id="nestedpanel1"><code>
391 // common styling for each indicator
392 function makeIndicator(propName) { // the data property name
393 return $(go.Shape,
394 "Circle",
395 { width: 8, height: 8, fill: "white", strokeWidth: 0, margin: 5 },
396 new go.Binding("fill", propName));
397 }
398
399 function makeImagePath(icon) { return "../samples/images/" + icon; }
400
401 diagram.nodeTemplate =
402 $(go.Node, "Vertical",
403 $(go.Panel, "Auto",
404 { background: "white" },
405 { portId: "" }, // this whole panel acts as the only port for the node
406 $(go.Shape, // the border
407 { fill: "transparent", stroke: "lightgray" }),
408 $(go.Panel, "Vertical", // everything within the border
409 $(go.Panel, "Horizontal", // the row of status indicators
410 makeIndicator("ind0"),
411 makeIndicator("ind1"),
412 makeIndicator("ind2")
413 ), // end Horizontal Panel
414 $(go.Picture,
415 { width: 32, height: 32, margin: 4 },
416 new go.Binding("source", "icon", makeImagePath)),
417 $(go.TextBlock,
418 { stretch: go.GraphObject.Horizontal, textAlign: "center" },
419 new go.Binding("text", "number"),
420 new go.Binding("background", "color"))
421 ) // end Vertical Panel
422 ), // end Auto Panel
423 $(go.TextBlock,
424 { margin: 4 },
425 new go.Binding("text"))
426 );
427
428 diagram.model.nodeDataArray = [
429 { key: 1, text: "Device Type A", number: 17, icon: "server switch.jpg", color: "moccasin",
430 ind0: "red", ind1: "orange", ind2: "mediumspringgreen" },
431 { key: 2, text: "Device Type B", number: 97, icon: "voice atm switch.jpg", color: "mistyrose",
432 ind0: "lightgray", ind1: "orange", ind2: "green" }
433 ];
434 diagram.model.linkDataArray = [
435 { from: 1, to: 2 }
436 ];
437</code></pre>
438<script>goCode("nestedpanel1", 300, 150)</script>
439
440<h2 id="DecoratedContent">Decorated Content</h2>
441<p>
442Sometimes you want to have a simple node that may display additional visuals
443to indicate what state it is in.
444</p>
445
446<p>
447One way to implement this is to use a Spot <a>Panel</a>, where the main element is itself a Panel
448containing the elements that you always want to display, and there are additional objects located at spots around the main element.
449The basic outline would be:
450</p>
451<pre class="lang-js"><code>
452Node, "Spot"
453 Panel, "Auto" // the contents with border
454 Shape // the border
455 Panel, ... // the contents
456 . . .
457 Shape // the decoration
458</code></pre>
459<p>
460So the basic body of the node is in a "Vertical" or any kind of Panel,
461which is surrounded by a border using an "Auto" Panel,
462which gets decorations using the "Spot" Panel that is also the Node.
463</p>
464<p>
465The same design of having the Node be a "Spot" Panel can also used for placing ports relative to the body of a node.
466</p>
467<pre class="lang-js" id="spotdecorations"><code>
468 diagram.nodeTemplate =
469 $(go.Node, "Spot",
470 // the main content:
471 $(go.Panel, "Vertical",
472 $(go.Picture,
473 { maxSize: new go.Size(50, 50) },
474 new go.Binding("source", "img")),
475 $(go.TextBlock,
476 { margin: new go.Margin(3, 0, 0, 0) },
477 new go.Binding("text", "text"),
478 new go.Binding("stroke", "error", function(err) { return err ? "red" : "black" }))
479 ),
480 // decorations:
481 $(go.Shape, "TriangleUp",
482 { alignment: go.Spot.TopLeft,
483 fill: "yellow", width: 14, height: 14,
484 visible: false },
485 new go.Binding("visible", "info", function(i) { return i ? true : false; })),
486 $(go.Shape, "StopSign",
487 { alignment: go.Spot.TopRight,
488 fill: "red", width: 14, height: 14,
489 visible: false },
490 new go.Binding("visible", "error")),
491 {
492 toolTip:
493 $(go.Adornment, "Auto",
494 $(go.Shape, { fill: "#FFFFCC" },
495 new go.Binding("visible", "info", function(i) { return i ? true : false; })),
496 $(go.TextBlock, { margin: 4 },
497 new go.Binding("text", "info"))
498 )
499 }
500 );
501
502 diagram.model.nodeDataArray = [
503 { text: "Demeter", img: "images/50x40.png", info: "" },
504 { text: "Copricat", img: "images/50x40.png", error: true, info: "shredded curtains" }
505 ];
506</code></pre>
507<script>goCode("spotdecorations", 300, 150)</script>
508
509<p>
510As another example of a node decoration, this implements a "ribbon" at the top right corner of the node.
511The ribbon is implemented by a <a>Panel</a> that contains both a <a>Shape</a> and a <a>TextBlock</a>,
512and the panel is positioned by its <a>GraphObject.alignment</a> and <a>GraphObject.alignmentFocus</a> in
513the Spot Panel that also is the <a>Node</a>.
514The appearance of the ribbon is achieved by using a custom <a>Geometry</a> and binding <a>GraphObject.opacity</a>.
515</p>
516<pre class="lang-js" id="ribbondecorations"><code>
517 diagram.nodeTemplate =
518 $(go.Node, "Spot",
519 { locationSpot: go.Spot.Center, locationObjectName: "BODY" },
520 { selectionObjectName: "BODY" },
521 $(go.Panel, "Auto",
522 { name: "BODY", width: 150, height: 100 },
523 { portId: "" },
524 $(go.Shape,
525 { fill: "lightgray", stroke: null, strokeWidth: 0 }),
526 $(go.TextBlock,
527 new go.Binding("text"))
528 ),
529 $(go.Panel, "Spot",
530 new go.Binding("opacity", "ribbon", function(t) { return t ? 1 : 0; }),
531 // note that the opacity defaults to zero (not visible),
532 // in case there is no "ribbon" property
533 { opacity: 0,
534 alignment: new go.Spot(1, 0, 5, -5),
535 alignmentFocus: go.Spot.TopRight },
536 $(go.Shape, // the ribbon itself
537 { geometryString: "F1 M0 0 L30 0 70 40 70 70z",
538 fill: "red", stroke: null, strokeWidth: 0 }),
539 $(go.TextBlock,
540 new go.Binding("text", "ribbon"),
541 { alignment: new go.Spot(1, 0, -29, 29),
542 angle: 45, maxSize: new go.Size(100, NaN),
543 stroke: "white", font: "bold 13px sans-serif", textAlign: "center" })
544 )
545 );
546
547 diagram.model = new go.GraphLinksModel([
548 { key: 1, text: "Alpha" },
549 { key: 2, text: "Beta", ribbon: "NEWEST" }
550 ],[
551 ]);
552</code></pre>
553<script>goCode("ribbondecorations", 500, 150)</script>
554
555<h2 id="PositionAndLocation">Position and Location</h2>
556<p>
557Nodes are positioned in document coordinates.
558(For more information, read <a href="viewport.html">Coordinate Systems</a>.)
559The point at which a Node resides, in document coordinates, is normally the top-left corner of the Node's <a>GraphObject.actualBounds</a>.
560If you set the <a>GraphObject.position</a> of a Node, you will be modifying the <code>x</code> and <code>y</code> values of the node's <a>GraphObject.actualBounds</a>.
561</p>
562<p>
563However there are times when it is more natural to think that the "point" of a Node is not at the top-left corner but at some other spot within.
564This is especially true when you want any variably-sized text labels or occasional decorations to be ignored regarding the node's location.
565That is why Nodes also have a "location" which refers to a point inside the Node.
566If you set the <a>Part.location</a> of a Node, you will be lining up the location point of the node to be at that point in document coordinates.
567When you move a Node you are actually changing its <a>Part.location</a>.
568</p>
569<p>
570By default the location of a Node is the same as its position.
571However you can set the <a>Part.locationSpot</a> to cause the location point to be at some spot in the node's actualBounds.
572Furthermore you can set the <a>Part.locationObjectName</a> to cause the location point to be at some spot in some element within the node.
573The position will always be at the top-left corner of the whole node,
574but the location may be some point at some spot in some object within the node.
575</p>
576<pre class="lang-js" id="positionlocation"><code>
577 diagram.grid.visible = true;
578
579 diagram.add(
580 $(go.Node, "Vertical",
581 { position: new go.Point(0, 0) }, // set the Node.position
582 $(go.TextBlock, "position", { editable: true }),
583 $(go.Shape, { name: "SHAPE", width: 30, height: 30, fill: "lightgreen" })
584 ));
585
586 diagram.add(
587 $(go.Node, "Vertical",
588 {
589 location: new go.Point(100, 0), // set the Node.location
590 locationObjectName: "SHAPE" // the location point is on the element named "SHAPE"
591 },
592 $(go.TextBlock, "location", { editable: true }),
593 $(go.Shape, { name: "SHAPE", width: 30, height: 30, fill: "lightgreen" })
594 ));
595</code></pre>
596<script>goCode("positionlocation", 500, 200)</script>
597<p>
598In this example both nodes have the same Y-coordinate value of zero.
599Note how in the above example the "position" Node has the top-left corner of the node at the grid point.
600Yet the "location" Node has the top-left corner of the green square at the grid point.
601If you edit the text of each node after double-clicking on the text,
602note how the green square moves relative to the diagram grid for the "position" node,
603but that it does not move for the "location" node.
604</p>
605<p>
606It is common to specify the <a>Part.locationSpot</a> to be <code>go.Spot.Center</code> so that the location point
607is at the center of some element in the node, rather than at the top-left corner of that element.
608</p>
609<pre class="lang-js" id="positionlocation2"><code>
610diagram.grid.visible = true;
611
612diagram.add(
613 $(go.Node, "Vertical",
614 { position: new go.Point(0, 0) }, // set the Node.position
615 $(go.TextBlock, "position", { editable: true }),
616 $(go.Panel, "Auto",
617 $(go.Shape, "Circle", { name: "SHAPE", width: 16, height: 16, fill: "lightgreen" }),
618 $(go.Shape, "Circle", { width: 6, height: 6, strokeWidth: 0 })
619 )
620 ));
621
622diagram.add(
623 $(go.Node, "Vertical",
624 {
625 location: new go.Point(100, 0), // set the Node.location
626 locationObjectName: "SHAPE", // the location point is at the center of "SHAPE"
627 locationSpot: go.Spot.Center
628 },
629 $(go.TextBlock, "location", { editable: true }),
630 $(go.Panel, "Auto",
631 $(go.Shape, "Circle", { name: "SHAPE", width: 16, height: 16, fill: "lightgreen" }),
632 $(go.Shape, "Circle", { width: 6, height: 6, strokeWidth: 0 })
633 )
634 ));
635</code></pre>
636<script>goCode("positionlocation2", 500, 200)</script>
637<p>
638If the position or location of a Node is not <a>Point.isReal</a>, it will not be seen, because GoJS will not know where to draw the node.
639In fact the default value for a node's position or location is <code>NaN, NaN</code> and it is the responsibility of either the <a>Diagram.layout</a>
640or data bindings to assign real point values for each node.
641</p>
642</div>
643 </div>
644 </div>
645
646 <div class="bg-nwoods-primary">
647 <section class="max-w-screen-lg text-white container mx-auto py-2 px-12">
648 <p id="version" class="leading-none mb-2 my-4">GoJS</p>
649 </section>
650 </div><footer class="bg-nwoods-primary text-white">
651 <div class="container max-w-screen-lg mx-auto px-8">
652 <div class="w-full py-6">
653
654 <div class="max-w-screen-lg xl:max-w-screen-xl mx-auto px-4 sm:px-6 md:px-8">
655 <ul class="text-sm font-medium pb-14 sm:pb-20 grid grid-cols-1 sm:grid-cols-3 gap-y-10">
656 <li class="list-none row-span-2">
657 <h2 class="text-base font-semibold tracking-wide">GoJS</h2>
658 <ul class="list-none space-y-4 md:space-y-1 px-0">
659 <li>
660 <a href="../samples/index.html">Samples</a>
661 </li>
662 <li>
663 <a href="../learn/index.html">Learn</a>
664 </li>
665 <li>
666 <a href="../intro/index.html">Intro</a>
667 </li>
668 <li>
669 <a href="../api/index.html">API</a>
670 </li>
671 <li>
672 <a href="../changelog.html">Changelog</a>
673 </li>
674 <li>
675 <a href="https://github.com/NorthwoodsSoftware/GoJS">GitHub</a>
676 </li>
677 </ul>
678 </li>
679 <li class="list-none row-span-2">
680 <h2 class="text-base font-semibold tracking-wide">Support</h2>
681 <ul class="list-none space-y-4 md:space-y-1 px-0">
682 <li>
683 <a href="https://www.nwoods.com/contact.html"
684 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a>
685 </li>
686 <li>
687 <a href="https://forum.nwoods.com/c/gojs">Forum</a>
688 </li>
689 <li>
690 <a href="https://www.nwoods.com/app/activate.aspx?sku=gojs">Activate</a>
691 </li>
692 <li>
693 <a href="https://www.nwoods.com/sales/index.html"
694 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a>
695 </li>
696 <li>
697 <a href="https://www.youtube.com/channel/UC9We8EoX596-6XFjJDtZIDg">Videos</a>
698 </li>
699 </ul>
700 </li>
701 <li class="list-none row-span-2">
702 <h2 class="text-base font-semibold tracking-wide">Company</h2>
703 <ul class="list-none space-y-4 md:space-y-1 px-0">
704 <li>
705 <a href="https://www.nwoods.com">Northwoods</a>
706 </li>
707 <li>
708 <a href="https://www.nwoods.com/about.html">About Us</a>
709 </li>
710 <li>
711 <a href="https://www.nwoods.com/contact.html">Contact Us</a>
712 </li>
713 <li>
714 <a href="https://twitter.com/northwoodsgo">Twitter</a>
715 </li>
716
717 </ul>
718 </li>
719 </ul>
720
721
722 <p class="text-sm text-gray-100 md:mb-6">
723 Copyright 1998-2021 <a class="text-white" href="https://www.nwoods.com">Northwoods Software</a>
724 </p>
725 </div>
726 </div>
727</footer> </body>
728
729<script async src="https://www.googletagmanager.com/gtag/js?id=UA-1506307-5"></script>
730<script>
731 window.dataLayer = window.dataLayer || [];
732 function gtag(){dataLayer.push(arguments);}
733 gtag('js', new Date()); gtag('config', 'UA-1506307-5');
734 var getOutboundLink = function(url, label) {
735 gtag('event', 'click', {
736 'event_category': 'outbound',
737 'event_label': label,
738 'transport_type': 'beacon'
739 });
740 }
741
742 // topnav
743 var topButton = document.getElementById("topnavButton");
744 var topnavList = document.getElementById("topnavList");
745 topButton.addEventListener("click", function() {
746 this.classList.toggle("active");
747 topnavList.classList.toggle("hidden");
748 document.getElementById("topnavOpen").classList.toggle("hidden");
749 document.getElementById("topnavClosed").classList.toggle("hidden");
750 });
751</script>
752 <script src="../assets/js/prism.js"></script>
753 <script src="../release/go.js"></script>
754<script src="../extensions/Figures.js"></script> <script src="../assets/js/goDoc.js"></script>
755 <script>
756 document.addEventListener("DOMContentLoaded", function() {
757 if (window.go) document.getElementById('version').textContent = "GoJS version " + go.version;
758 if (window.goDoc) window.goDoc();
759 var d = window.diagrams;
760 for (var i = 0; i < d.length; i++) {
761 var dargs = d[i];
762 goCodeExecute(dargs[0], dargs[1], dargs[2], dargs[3], dargs[4]);
763 }
764 if (window.extra) window.extra();
765 });
766 </script>
767</html>