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 | <title> GoJS Selection -- 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 & 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>Selection</h1>
|
134 | <p>
|
135 | Users normally select <a>Part</a>s manually by clicking on them and they deselect them by clicking in the background or pressing the Esc key.
|
136 | You can select parts programmatically by setting <a>Part.isSelected</a>.
|
137 | </p>
|
138 | <p>
|
139 | Users can also drag in the background in order to select the Parts that are within a rectangular area, via the <a>DragSelectingTool</a>.
|
140 | Read more about that in the Introduction to Tools at <a href="tools.html#DragSelectingTool">DragSelectingTool</a>.
|
141 | </p>
|
142 | <p>
|
143 | The <a>Diagram</a> keeps a collection of selected parts, <a>Diagram.selection</a>.
|
144 | That collection is read-only -- the only way to select or deselect a Part is by setting its <a>Part.isSelected</a> property.
|
145 | You can limit how many parts are selected by setting <a>Diagram.maxSelectionCount</a>.
|
146 | Prevent all selection by the user by setting <a>Diagram.allowSelect</a> to false.
|
147 | Or prevent a particular Part from being selected by setting <a>Part.selectable</a> to false.
|
148 | </p>
|
149 | <p>
|
150 | You can show that a part is selected by either or both of two general techniques: adding <a>Adornment</a>s or
|
151 | changing the appearance of some of the elements in the visual tree of the selected Part.
|
152 | </p>
|
153 |
|
154 | <h2 id="SelectionAdornments">Selection Adornments</h2>
|
155 | <p>
|
156 | It is common to display that a Part is selected by having it show a selection <a>Adornment</a> when the Part is selected.
|
157 | For nodes this is normally a blue rectangle surrounding the whole Node.
|
158 | This is the default behavior; if you do not want such an adornment, you can set <a>Part.selectionAdorned</a> to false.
|
159 | </p>
|
160 |
|
161 | <pre class="lang-js" id="adornmentDefault"><code>
|
162 | diagram.nodeTemplate =
|
163 | $(go.Node, "Vertical",
|
164 | // the location is the center of the Shape, not the center of the whole Node
|
165 | { locationSpot: go.Spot.Center, locationObjectName: "ICON" },
|
166 | new go.Binding("location", "loc", go.Point.parse),
|
167 | $(go.Shape,
|
168 | {
|
169 | name: "ICON",
|
170 | width: 40, height: 40,
|
171 | fill: "gray",
|
172 | portId: "" // the port is this Shape, not the whole Node
|
173 | },
|
174 | new go.Binding("figure")),
|
175 | $(go.TextBlock,
|
176 | { margin: new go.Margin(5, 0, 0, 0) },
|
177 | new go.Binding("text", "key"))
|
178 | );
|
179 |
|
180 | var nodeDataArray = [
|
181 | { key: "Alpha", figure: "Club", loc: "0 0" },
|
182 | { key: "Beta", figure: "Spade", loc: "200 50" }
|
183 | ];
|
184 | var linkDataArray = [
|
185 | { from: "Alpha", to: "Beta" }
|
186 | ];
|
187 | diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
|
188 | diagram.commandHandler.selectAll();
|
189 | </code></pre>
|
190 | <script>goCode("adornmentDefault", 600, 150)</script>
|
191 |
|
192 | <p>
|
193 | By default an <a>Adornment</a> will apply to the whole <a>Node</a>.
|
194 | What if you want attention to be drawn only to the main piece of a node?
|
195 | You can accomplish that by naming that object and setting <a>Part.selectionObjectName</a> to that name.
|
196 | </p>
|
197 | <pre class="lang-js" id="adornmentObject"><code>
|
198 | diagram.nodeTemplate =
|
199 | $(go.Node, "Vertical",
|
200 | { selectionObjectName: "ICON" }, // added this property!
|
201 | // the location is the center of the Shape, not the center of the whole Node
|
202 | { locationSpot: go.Spot.Center, locationObjectName: "ICON" },
|
203 | new go.Binding("location", "loc", go.Point.parse),
|
204 | $(go.Shape,
|
205 | {
|
206 | name: "ICON",
|
207 | width: 40, height: 40,
|
208 | fill: "gray",
|
209 | portId: "" // the port is this Shape, not the whole Node
|
210 | },
|
211 | new go.Binding("figure")),
|
212 | $(go.TextBlock,
|
213 | { margin: new go.Margin(5, 0, 0, 0) },
|
214 | new go.Binding("text", "key"))
|
215 | );
|
216 |
|
217 | var nodeDataArray = [
|
218 | { key: "Alpha", figure: "Club", loc: "0 0" },
|
219 | { key: "Beta", figure: "Spade", loc: "200 50" }
|
220 | ];
|
221 | var linkDataArray = [
|
222 | { from: "Alpha", to: "Beta" }
|
223 | ];
|
224 | diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
|
225 | diagram.selectCollection(diagram.nodes);
|
226 | </code></pre>
|
227 | <script>goCode("adornmentObject", 600, 150)</script>
|
228 | <p>
|
229 | Note how the <a>Part.selectionObjectName</a> property is similar to the <a>Part.locationObjectName</a>
|
230 | in helping to treat a node as if only one piece of it really mattered.
|
231 | </p>
|
232 |
|
233 | <h3 id="CustomSelectionAdornments">Custom Selection Adornments</h3>
|
234 | <p>
|
235 | If you do want a selection adornment but want something different than the standard one, you can customize it.
|
236 | Such customization can be done by setting the <a>Part.selectionAdornmentTemplate</a>.
|
237 | In this example, nodes get thick blue rounded rectangles surrounding the selected node,
|
238 | and links get thick blue lines following the selected link's path.
|
239 | </p>
|
240 | <pre class="lang-js" id="custom"><code>
|
241 | diagram.nodeTemplate =
|
242 | $(go.Node, "Auto",
|
243 | new go.Binding("location", "loc", go.Point.parse),
|
244 | $(go.Shape, "RoundedRectangle", { fill: "lightgray" }),
|
245 | $(go.TextBlock,
|
246 | { margin: 5 },
|
247 | new go.Binding("text", "key")),
|
248 | {
|
249 | selectionAdornmentTemplate:
|
250 | $(go.Adornment, "Auto",
|
251 | $(go.Shape, "RoundedRectangle",
|
252 | { fill: null, stroke: "dodgerblue", strokeWidth: 8 }),
|
253 | $(go.Placeholder)
|
254 | ) // end Adornment
|
255 | }
|
256 | );
|
257 |
|
258 | diagram.linkTemplate =
|
259 | $(go.Link,
|
260 | $(go.Shape, { strokeWidth: 2 }),
|
261 | $(go.Shape, { toArrow: "Standard" }),
|
262 | {
|
263 | selectionAdornmentTemplate:
|
264 | $(go.Adornment,
|
265 | $(go.Shape,
|
266 | { isPanelMain: true, stroke: "dodgerblue", strokeWidth: 8 }),
|
267 | $(go.Shape,
|
268 | { toArrow: "Standard", fill: "dodgerblue", stroke: null, scale: 2.5 })
|
269 | ) // end Adornment
|
270 | }
|
271 | );
|
272 |
|
273 | var nodeDataArray = [
|
274 | { key: "Alpha", loc: "0 0" },
|
275 | { key: "Beta", loc: "200 50" }
|
276 | ];
|
277 | var linkDataArray = [
|
278 | { from: "Alpha", to: "Beta" }
|
279 | ];
|
280 | diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
|
281 | diagram.commandHandler.selectAll();
|
282 | </code></pre>
|
283 | <script>goCode("custom", 600, 100)</script>
|
284 | <p>
|
285 | Note that an <a>Adornment</a> is just a <a>Part</a>.
|
286 | Adornments for nodes must contain a <a>Placeholder</a> in their visual tree.
|
287 | The Placeholder gets positioned where the selected object is.
|
288 | </p>
|
289 | <p>
|
290 | Adornments for links are assumed to be panels of <a>Panel.type</a> that is <a>Panel,Link</a>.
|
291 | Hence the main element may be a <a>Shape</a> that gets the geometry of the selected Link's path shape,
|
292 | and the other elements of the adornment may be positioned on or near the segments of the link route just as for a regular <a>Link</a>.
|
293 | </p>
|
294 |
|
295 | <h3 id="MoreComplexAdornments">More Complex Adornments</h3>
|
296 | <p>
|
297 | The custom <a>Adornment</a> for a <a>Node</a> need not be only a simple <a>Shape</a> outlining the selected node.
|
298 | Here is an adornment that adds a button to the adornment which inserts a node and a link to that new node.
|
299 | </p>
|
300 | <pre class="lang-js" id="complex"><code>
|
301 | function addNodeAndLink(e, b) {
|
302 | // take a button panel in an Adornment, get its Adornment, and then get its adorned Node
|
303 | var node = b.part.adornedPart;
|
304 | // we are modifying the model, so conduct a transaction
|
305 | var diagram = node.diagram;
|
306 | diagram.startTransaction("add node and link");
|
307 | // have the Model add the node data
|
308 | var newnode = { key: "N" };
|
309 | diagram.model.addNodeData(newnode);
|
310 | // locate the node initially where the parent node is
|
311 | diagram.findNodeForData(newnode).location = node.location;
|
312 | // and then add a link data connecting the original node with the new one
|
313 | var newlink = { from: node.data.key, to: newnode.key };
|
314 | diagram.model.addLinkData(newlink);
|
315 | // finish the transaction -- will automatically perform a layout
|
316 | diagram.commitTransaction("add node and link");
|
317 | }
|
318 |
|
319 | diagram.nodeTemplate =
|
320 | $(go.Node, "Auto",
|
321 | $(go.Shape, "RoundedRectangle", { fill: "lightgray" }),
|
322 | $(go.TextBlock,
|
323 | { margin: 5 },
|
324 | new go.Binding("text", "key")),
|
325 | {
|
326 | selectionAdornmentTemplate:
|
327 | $(go.Adornment, "Spot",
|
328 | $(go.Panel, "Auto",
|
329 | // this Adornment has a rectangular blue Shape around the selected node
|
330 | $(go.Shape, { fill: null, stroke: "dodgerblue", strokeWidth: 3 }),
|
331 | $(go.Placeholder)
|
332 | ),
|
333 | // and this Adornment has a Button to the right of the selected node
|
334 | $("Button",
|
335 | { alignment: go.Spot.Right, alignmentFocus: go.Spot.Left,
|
336 | click: addNodeAndLink }, // define click behavior for Button in Adornment
|
337 | $(go.TextBlock, "ADD", // the Button content
|
338 | { font: "bold 6pt sans-serif" })
|
339 | )
|
340 | ) // end Adornment
|
341 | }
|
342 | );
|
343 |
|
344 | diagram.layout = $(go.TreeLayout);
|
345 |
|
346 | var nodeDataArray = [
|
347 | { key: "Alpha" },
|
348 | { key: "Beta" }
|
349 | ];
|
350 | var linkDataArray = [
|
351 | { from: "Alpha", to: "Beta" }
|
352 | ];
|
353 | diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
|
354 | diagram.select(diagram.findNodeForKey("Beta"));
|
355 | </code></pre>
|
356 | <script>goCode("complex", 600, 200)</script>
|
357 | <p>
|
358 | Select any node and click the "ADD" button.
|
359 | Note how the diagram is automatically laid out as a tree.
|
360 | </p>
|
361 |
|
362 | <h3 id="DataBinding">Data Binding</h3>
|
363 | <p>
|
364 | Like all <a>Part</a>s, <a>Adornment</a>s support data binding.
|
365 | If the adorned Part has a data binding (i.e. if <a>Part.data</a> is non-null),
|
366 | all adornments for that part will also be bound to the same data object.
|
367 | </p>
|
368 | <pre class="lang-js" id="binding"><code>
|
369 | diagram.nodeTemplate =
|
370 | $(go.Node, "Auto",
|
371 | new go.Binding("location", "loc", go.Point.parse),
|
372 | $(go.Shape, "RoundedRectangle", { fill: "lightgray", strokeWidth: 2 },
|
373 | new go.Binding("stroke", "color")),
|
374 | $(go.TextBlock,
|
375 | { margin: 5 },
|
376 | new go.Binding("text", "key")),
|
377 | {
|
378 | selectionAdornmentTemplate:
|
379 | $(go.Adornment, "Auto",
|
380 | $(go.Shape,
|
381 | { fill: null, stroke: "dodgerblue", strokeWidth: 6 },
|
382 | new go.Binding("stroke", "color")),
|
383 | $(go.Placeholder)
|
384 | ) // end Adornment
|
385 | }
|
386 | );
|
387 |
|
388 | var nodeDataArray = [
|
389 | { key: "Alpha", loc: "0 0", color: "blue" },
|
390 | { key: "Beta", loc: "200 50", color: "red" }
|
391 | ];
|
392 | var linkDataArray = [
|
393 | { from: "Alpha", to: "Beta" }
|
394 | ];
|
395 | diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
|
396 | diagram.selectCollection(diagram.nodes);
|
397 | </code></pre>
|
398 | <script>goCode("binding", 600, 100)</script>
|
399 | <p>
|
400 | Notice how each Adornment has the same color as the selected node's data.color.
|
401 | </p>
|
402 |
|
403 | <h2 id="SelectionAppearanceChanges">Selection Appearance changes</h2>
|
404 | <p>
|
405 | Adding a selection adornment is not the only way to indicate visually that a <a>Part</a> is selected.
|
406 | You can also modify the appearance of one or more objects in your Part.
|
407 | </p>
|
408 | <p>
|
409 | One way to do this is with data binding.
|
410 | Here we data bind the <a>Shape.fill</a> to the <a>Part.isSelected</a> property
|
411 | with a converter function that converts the boolean value to a color string or brush.
|
412 | We also turn off the regular rectangular blue selection adornment.
|
413 | </p>
|
414 | <pre class="lang-js" id="isSelected"><code>
|
415 | diagram.nodeTemplate =
|
416 | $(go.Node, "Auto",
|
417 | { selectionAdorned: false }, // don't bother with any selection adornment
|
418 | new go.Binding("location", "loc", go.Point.parse),
|
419 | $(go.Shape, "RoundedRectangle", { fill: "lightgray", strokeWidth: 2 },
|
420 | // when this Part.isSelected changes value, change this Shape.fill value:
|
421 | new go.Binding("fill", "isSelected", function(sel) {
|
422 | if (sel) return "cyan"; else return "lightgray";
|
423 | }).ofObject("")), // The object named "" is the root visual element, the Node itself
|
424 | $(go.TextBlock,
|
425 | { margin: 5 },
|
426 | new go.Binding("text", "key"))
|
427 | );
|
428 |
|
429 | var nodeDataArray = [
|
430 | { key: "Alpha", loc: "0 0" },
|
431 | { key: "Beta", loc: "200 50" }
|
432 | ];
|
433 | var linkDataArray = [
|
434 | { from: "Alpha", to: "Beta" }
|
435 | ];
|
436 | diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
|
437 | diagram.select(diagram.findNodeForKey("Beta"));
|
438 | </code></pre>
|
439 | <script>goCode("isSelected", 600, 100)</script>
|
440 | <p>
|
441 | Now when you select a node its background color changes to cyan.
|
442 | </p>
|
443 |
|
444 | <p>
|
445 | More generally you can execute code to modify the Part when <a>Part.isSelected</a> has changed value.
|
446 | In this example we will have the same side effects as the previous example.
|
447 | </p>
|
448 | <pre class="lang-js" id="selectionChanged"><code>
|
449 | function onSelectionChanged(node) {
|
450 | var icon = node.findObject("Icon");
|
451 | if (icon !== null) {
|
452 | if (node.isSelected)
|
453 | icon.fill = "cyan";
|
454 | else
|
455 | icon.fill = "lightgray";
|
456 | }
|
457 | }
|
458 |
|
459 | diagram.nodeTemplate =
|
460 | $(go.Node, "Auto",
|
461 | { selectionAdorned: false, // don't bother with any selection adornment
|
462 | selectionChanged: onSelectionChanged }, // executed when Part.isSelected has changed
|
463 | new go.Binding("location", "loc", go.Point.parse),
|
464 | $(go.Shape, "RoundedRectangle",
|
465 | { name: "Icon", fill: "lightgray", strokeWidth: 2 }),
|
466 | $(go.TextBlock,
|
467 | { margin: 5 },
|
468 | new go.Binding("text", "key"))
|
469 | );
|
470 |
|
471 | var nodeDataArray = [
|
472 | { key: "Alpha", loc: "0 0" },
|
473 | { key: "Beta", loc: "200 50" }
|
474 | ];
|
475 | var linkDataArray = [
|
476 | { from: "Alpha", to: "Beta" }
|
477 | ];
|
478 | diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
|
479 | diagram.select(diagram.findNodeForKey("Beta"));
|
480 | </code></pre>
|
481 | <script>goCode("selectionChanged", 600, 100)</script>
|
482 | <p>
|
483 | There are some restrictions on what you can do in such an event handler:
|
484 | you should not select or deselect any parts, and you should not add or remove any parts from the diagram.
|
485 | </p>
|
486 |
|
487 | </div>
|
488 | </div>
|
489 |
|
490 | <div class="bg-nwoods-primary">
|
491 | <section class="max-w-screen-lg text-white container mx-auto py-2 px-12">
|
492 | <p id="version" class="leading-none mb-2 my-4">GoJS</p>
|
493 | </section>
|
494 | </div><footer class="bg-nwoods-primary text-white">
|
495 | <div class="container max-w-screen-lg mx-auto px-8">
|
496 | <div class="w-full py-6">
|
497 |
|
498 | <div class="max-w-screen-lg xl:max-w-screen-xl mx-auto px-4 sm:px-6 md:px-8">
|
499 | <ul class="text-sm font-medium pb-14 sm:pb-20 grid grid-cols-1 sm:grid-cols-3 gap-y-10">
|
500 | <li class="list-none row-span-2">
|
501 | <h2 class="text-base font-semibold tracking-wide">GoJS</h2>
|
502 | <ul class="list-none space-y-4 md:space-y-1 px-0">
|
503 | <li>
|
504 | <a href="../samples/index.html">Samples</a>
|
505 | </li>
|
506 | <li>
|
507 | <a href="../learn/index.html">Learn</a>
|
508 | </li>
|
509 | <li>
|
510 | <a href="../intro/index.html">Intro</a>
|
511 | </li>
|
512 | <li>
|
513 | <a href="../api/index.html">API</a>
|
514 | </li>
|
515 | <li>
|
516 | <a href="../changelog.html">Changelog</a>
|
517 | </li>
|
518 | <li>
|
519 | <a href="https://github.com/NorthwoodsSoftware/GoJS">GitHub</a>
|
520 | </li>
|
521 | </ul>
|
522 | </li>
|
523 | <li class="list-none row-span-2">
|
524 | <h2 class="text-base font-semibold tracking-wide">Support</h2>
|
525 | <ul class="list-none space-y-4 md:space-y-1 px-0">
|
526 | <li>
|
527 | <a href="https://www.nwoods.com/contact.html"
|
528 | target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a>
|
529 | </li>
|
530 | <li>
|
531 | <a href="https://forum.nwoods.com/c/gojs">Forum</a>
|
532 | </li>
|
533 | <li>
|
534 | <a href="https://www.nwoods.com/app/activate.aspx?sku=gojs">Activate</a>
|
535 | </li>
|
536 | <li>
|
537 | <a href="https://www.nwoods.com/sales/index.html"
|
538 | target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a>
|
539 | </li>
|
540 | <li>
|
541 | <a href="https://www.youtube.com/channel/UC9We8EoX596-6XFjJDtZIDg">Videos</a>
|
542 | </li>
|
543 | </ul>
|
544 | </li>
|
545 | <li class="list-none row-span-2">
|
546 | <h2 class="text-base font-semibold tracking-wide">Company</h2>
|
547 | <ul class="list-none space-y-4 md:space-y-1 px-0">
|
548 | <li>
|
549 | <a href="https://www.nwoods.com">Northwoods</a>
|
550 | </li>
|
551 | <li>
|
552 | <a href="https://www.nwoods.com/about.html">About Us</a>
|
553 | </li>
|
554 | <li>
|
555 | <a href="https://www.nwoods.com/contact.html">Contact Us</a>
|
556 | </li>
|
557 | <li>
|
558 | <a href="https://twitter.com/northwoodsgo">Twitter</a>
|
559 | </li>
|
560 |
|
561 | </ul>
|
562 | </li>
|
563 | </ul>
|
564 |
|
565 |
|
566 | <p class="text-sm text-gray-100 md:mb-6">
|
567 | Copyright 1998-2021 <a class="text-white" href="https://www.nwoods.com">Northwoods Software</a>
|
568 | </p>
|
569 | </div>
|
570 | </div>
|
571 | </footer> </body>
|
572 |
|
573 | <script async src="https://www.googletagmanager.com/gtag/js?id=UA-1506307-5"></script>
|
574 | <script>
|
575 | window.dataLayer = window.dataLayer || [];
|
576 | function gtag(){dataLayer.push(arguments);}
|
577 | gtag('js', new Date()); gtag('config', 'UA-1506307-5');
|
578 | var getOutboundLink = function(url, label) {
|
579 | gtag('event', 'click', {
|
580 | 'event_category': 'outbound',
|
581 | 'event_label': label,
|
582 | 'transport_type': 'beacon'
|
583 | });
|
584 | }
|
585 |
|
586 |
|
587 | var topButton = document.getElementById("topnavButton");
|
588 | var topnavList = document.getElementById("topnavList");
|
589 | topButton.addEventListener("click", function() {
|
590 | this.classList.toggle("active");
|
591 | topnavList.classList.toggle("hidden");
|
592 | document.getElementById("topnavOpen").classList.toggle("hidden");
|
593 | document.getElementById("topnavClosed").classList.toggle("hidden");
|
594 | });
|
595 | </script>
|
596 | <script src="../assets/js/prism.js"></script>
|
597 | <script src="../release/go.js"></script>
|
598 | <script src="../extensions/Figures.js"></script> <script src="../assets/js/goDoc.js"></script>
|
599 | <script>
|
600 | document.addEventListener("DOMContentLoaded", function() {
|
601 | if (window.go) document.getElementById('version').textContent = "GoJS version " + go.version;
|
602 | if (window.goDoc) window.goDoc();
|
603 | var d = window.diagrams;
|
604 | for (var i = 0; i < d.length; i++) {
|
605 | var dargs = d[i];
|
606 | goCodeExecute(dargs[0], dargs[1], dargs[2], dargs[3], dargs[4]);
|
607 | }
|
608 | if (window.extra) window.extra();
|
609 | });
|
610 | </script>
|
611 | </html>
|