UNPKG

39.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 Links -- 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>Links</h1>
137<p>
138 Use the <a>Link</a> class to implement a visual relationship between nodes.
139</p>
140<p>
141 See samples that make use of customized Links in the <a href="../samples/index.html#links">samples index</a>.
142</p>
143
144<h2 id="CreatingLinks">Creating Links</h2>
145<p>
146 Links are normally created by the presence of link data objects in the <a>GraphLinksModel.linkDataArray</a>
147 or by a parent key reference as the value of the <a>TreeModel.nodeParentKeyProperty</a> of a node data object
148 in a <a>TreeModel</a>.
149 Users can draw new links by using the <a>LinkingTool</a>: Introduction to the <a href="tools.html#LinkingToolAndRelinkingTool">Linking Tools</a>.
150</p>
151<p>
152 You can create new links programmatically by modifying the model.
153 It is most common to operate directly on the model by either calling <a>GraphLinksModel.addLinkData</a>
154 or by calling <a>TreeModel.setParentKeyForNodeData</a>.
155 Such changes are observed by all diagrams that are displaying the model so that they can automatically
156 create the corresponding <a>Link</a>s.
157 You can find examples of calls to <a>GraphLinksModel.addLinkData</a> in the samples.
158</p>
159<p>
160 It is also possible to create new links without detailed knowledge of the diagram's model by calling
161 <a>LinkingTool.insertLink</a>. That is how the user's actions to draw a new link actually create it.
162 That method knows how to modify the <a>GraphLinksModel</a> or the <a>TreeModel</a> appropriately,
163 while respecting the additional functionality offered by the <a>LinkingTool.archetypeLinkData</a>
164 and other properties of the <a>LinkingTool</a>.
165 You can find examples of calls to <a>LinkingTool.insertLink</a> in the samples.
166</p>
167
168<h2 id="NondirectionalLinks">Non-directional Links</h2>
169<p>
170 The simplest links are those without arrowheads to indicate a visual direction.
171 Either the relationship really is non-directional, or the direction is implicit in the organization of the diagram.
172</p>
173<p>
174 The template contains a <a>Shape</a> as the main element, as the line that is drawn between nodes.
175 After the link's route is computed the main Shape will get a <a>Geometry</a> based on the points in the route.
176</p>
177<pre class="lang-js" id="noArrowheads"><code>
178 diagram.nodeTemplate =
179 $(go.Node, "Auto",
180 new go.Binding("location", "loc", go.Point.parse),
181 $(go.Shape, "RoundedRectangle", { fill: "lightgray" }),
182 $(go.TextBlock, { margin: 5 },
183 new go.Binding("text", "key"))
184 );
185
186 diagram.linkTemplate =
187 $(go.Link, // the whole link panel
188 $(go.Shape) // the link shape, default black stroke
189 );
190
191 var nodeDataArray = [
192 { key: "Alpha", loc: "0 0" },
193 { key: "Beta", loc: "100 50" }
194 ];
195 var linkDataArray = [
196 { from: "Alpha", to: "Beta" }
197 ];
198 diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
199</code></pre>
200<script>goCode("noArrowheads", 600, 100)</script>
201<p>
202 By default the way that the model and diagram know about the node data references of a link data is
203 by looking at its from and to properties.
204 If you want to use a different properties on the link data, set <a>GraphLinksModel.linkFromKeyProperty</a> to be the name
205 of the property that results in the node data's key, and similarly for the <a>GraphLinksModel.linkToKeyProperty</a>.
206</p>
207
208<h2 id="Arrowheads">Arrowheads</h2>
209<p>
210 Many links do want to indicate directionality by using arrowheads.
211 <b>GoJS</b> makes it easy to create common arrowheads: just add a Shape and set its <a>Shape.toArrow</a> property.
212 Setting that property will automatically assign a <a>Geometry</a> to the <a>Shape.geometry</a>
213 and will set other properties so that the arrowhead is positioned at the head of the link and is pointing in the correct direction.
214 Of course you can set the other Shape properties such as <a>Shape.fill</a> in order to customize the appearance of the arrowhead.
215</p>
216<pre class="lang-js" id="arrowheads"><code>
217 diagram.nodeTemplate =
218 $(go.Node, "Auto",
219 new go.Binding("location", "loc", go.Point.parse),
220 $(go.Shape, "RoundedRectangle", { fill: "lightgray" }),
221 $(go.TextBlock, { margin: 5 },
222 new go.Binding("text", "key"))
223 );
224
225 diagram.linkTemplate =
226 $(go.Link,
227 $(go.Shape), // the link shape
228 $(go.Shape, // the arrowhead
229 { toArrow: "OpenTriangle", fill: null })
230 );
231
232 var nodeDataArray = [
233 { key: "Alpha", loc: "0 0" },
234 { key: "Beta", loc: "100 50" }
235 ];
236 var linkDataArray = [
237 { from: "Alpha", to: "Beta" }
238 ];
239 diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
240</code></pre>
241<script>goCode("arrowheads", 600, 100)</script>
242<p>
243 You can see all of the predefined arrowhead types in the <a href="../samples/arrowheads.html" target="samples">Arrowheads Sample</a>.
244</p>
245<p>
246 You can also have an arrowhead at the start of the link: set the <a>Shape.fromArrow</a> property.
247 Note that an arrowhead normally goes along the path of the link regardless of its position on the path,
248 so just as with a real arrow, setting <code>{ fromArrow: "TripleFeathers" }</code> has the "feathers" pointing forward.
249 If the link is meant to be bi-directional, the arrowhead name for the "from" end of a link
250 will probably want to start with the string "Backward...".
251</p>
252
253<h2 id="Routing">Routing</h2>
254<p>
255 If you want to customize the path that each <a>Link</a> takes, you need to set properties on the link.
256 The property that has the most general effect on the points that the link's route follows is <a>Link.routing</a>.
257</p>
258<p>
259 This example shows the two most common routing values: <a>Link,Normal</a> (the default) and <a>Link,Orthogonal</a>.
260</p>
261<pre class="lang-js" id="routing"><code>
262 diagram.nodeTemplate =
263 $(go.Node, "Auto",
264 new go.Binding("location", "loc", go.Point.parse),
265 $(go.Shape, "RoundedRectangle", { fill: "lightgray" }),
266 $(go.TextBlock, { margin: 5 },
267 new go.Binding("text", "key"))
268 );
269
270 diagram.linkTemplate =
271 $(go.Link,
272 new go.Binding("routing", "routing"),
273 $(go.Shape),
274 $(go.Shape, { toArrow: "Standard" })
275 );
276
277 var nodeDataArray = [
278 { key: "Alpha", loc: "0 0" },
279 { key: "Beta", loc: "50 50" },
280 { key: "Gamma", loc: "100 25" }
281 ];
282 var linkDataArray = [
283 { from: "Alpha", to: "Beta", routing: go.Link.Normal },
284 { from: "Alpha", to: "Gamma", routing: go.Link.Orthogonal }
285 ];
286 diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
287</code></pre>
288<script>goCode("routing", 600, 100)</script>
289
290<p>
291 Note that the computed route also depends on the properties of the node, including its shape.
292 There are other properties, including <a>GraphObject.fromSpot</a> and <a>GraphObject.toSpot</a>, that affect the route.
293 For more discussion about spots, please read this Introduction page: <a href="connectionPoints.html">Link Connection Points</a>.
294 Furthermore some <a>Layout</a>s set properties on links to control their routing according to what the layout expects.
295</p>
296
297<p>
298 You can also set <a>Link.routing</a> to <a>Link,AvoidsNodes</a>:
299</p>
300<pre class="lang-js" id="avoidsNodes"><code>
301 diagram.nodeTemplate =
302 $(go.Node, "Auto",
303 new go.Binding("location", "loc", go.Point.parse),
304 $(go.Shape, "RoundedRectangle", { fill: "lightgray" }),
305 $(go.TextBlock, { margin: 5 },
306 new go.Binding("text", "key"))
307 );
308
309 diagram.linkTemplate =
310 $(go.Link,
311 { routing: go.Link.AvoidsNodes }, // link route should avoid nodes
312 $(go.Shape),
313 $(go.Shape, { toArrow: "Standard" })
314 );
315
316 var nodeDataArray = [
317 { key: "Alpha", loc: "0 0" },
318 { key: "Beta", loc: "250 40" },
319 { key: "Gamma", loc: "100 0" },
320 { key: "Delta", loc: "75 50" },
321 { key: "Epsilon", loc: "150 30" }
322 ];
323 var linkDataArray = [
324 { from: "Alpha", to: "Beta" }
325 ];
326 diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
327</code></pre>
328<script>goCode("avoidsNodes", 600, 100)</script>
329<p>
330 If you move the nodes interactively, you can see how the link's route adjusts to avoid crossing over nodes.
331 Notice that a small gap between nodes might not be considered wide enough for links to go through.
332</p>
333<p>
334 If a node is very close to or overlaps with either the link's <a>Link.fromNode</a> or <a>Link.toNode</a>
335 and would block the link's route, it ignores that node, treating it as if it were just an extension of the connected node.
336 Also if no node-avoiding route exists because there is a ring of nodes around one of the connected nodes,
337 the routing algorithm will give up and cross over some nodes anyway.
338</p>
339<p>
340 You can declare that it is OK to route through a node by setting <a>Node.avoidable</a> to false.
341 This is commonly done for <a>Group</a>s to allow links connecting outside of the group to route nicely within the group.
342</p>
343<p>
344 Note the the use of AvoidsNodes routing is distinctly slower than normal Orthogonal routing, especially for large diagrams.
345</p>
346
347<h3 id="EndSegmentLengths">End Segment Lengths</h3>
348<p>
349 Another way to affect the precise route that Orthogonal and AvoidsNodes routing take is to set or bind
350 <a>GraphObject.fromEndSegmentLength</a> and <a>GraphObject.toEndSegmentLength</a>.
351 These properties determine the length of the very first segment or the very last segment, but only for orthogonally routed links.
352 Those properties can be set either on the port element of the node or on the link.
353 On the link the property value takes precedence over the corresponding property's value at the port.
354</p>
355<pre data-language="javascript" id="endseg">
356 diagram.nodeTemplate =
357 $(go.Node, "Auto",
358 new go.Binding("location", "loc", go.Point.parse),
359 $(go.Shape, "RoundedRectangle", { fill: "lightgray" }),
360 $(go.TextBlock, { margin: 5 },
361 new go.Binding("text", "key"))
362 );
363
364 diagram.linkTemplate =
365 $(go.Link,
366 { routing: go.Link.Orthogonal, fromSpot: go.Spot.Left, toSpot: go.Spot.Right },
367 new go.Binding("fromEndSegmentLength"),
368 new go.Binding("toEndSegmentLength"),
369 $(go.Shape),
370 $(go.Shape, { toArrow: "Standard" })
371 );
372
373 var nodeDataArray = [
374 { key: "Alpha", loc: "0 0" },
375 { key: "Beta", loc: "100 50" },
376 { key: "Gamma", loc: "0 100" },
377 { key: "Delta", loc: "100 150" }
378 ];
379 var linkDataArray = [
380 { from: "Alpha", to: "Beta" },
381 { from: "Gamma", to: "Delta", fromEndSegmentLength: 4, toEndSegmentLength: 30 },
382 ];
383 diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
384</code></pre>
385<script>goCode("endseg", 600, 200)</script>
386<p>
387 In this example the values of the <a>Link.fromEndSegmentLength</a> and <a>Link.toEndSegmentLength</a> are bound
388 to the same named properties on the link data.
389 In both cases the link's route is force to come out of the left side of the source node and to the right side of the destination node.
390 In the case from "Alpha" to "Beta", you see the default behavior.
391 In the case from "Gamma" to "Delta", you see the results of a shorter-than-normal <code>fromEndSegmentLength</code>
392 and a longer-than-normal <code>toEndSegmentLength</code>.
393</p>
394
395<h2 id="CurveCurvinessCorner">Curve, Curviness, Corner</h2>
396<p>
397 Once the <a>Link.routing</a> determines the route (i.e., the sequence of points) that the link takes,
398 other properties control the details of how the link shape gets its path geometry.
399 The first such property is <a>Link.curve</a>, which controls whether the link shape has basically straight segments
400 or is a big curve.
401</p>
402<p>
403 The default value for <a>Link.curve</a> is <a>Link,None</a>, which produces link shapes with straight segments
404 as you see above.
405</p>
406<p>
407 A value of <a>Link,Bezier</a> produces a naturally curved path for the link shape.
408</p>
409
410<pre class="lang-js" id="bezier"><code>
411 diagram.nodeTemplate =
412 $(go.Node, "Auto",
413 new go.Binding("location", "loc", go.Point.parse),
414 $(go.Shape, "RoundedRectangle", { fill: "lightgray" }),
415 $(go.TextBlock, { margin: 5 },
416 new go.Binding("text", "key"))
417 );
418
419 diagram.linkTemplate =
420 $(go.Link,
421 { curve: go.Link.Bezier }, // Bezier curve
422 $(go.Shape),
423 $(go.Shape, { toArrow: "Standard" })
424 );
425
426 var nodeDataArray = [
427 { key: "Alpha", loc: "0 0" },
428 { key: "Beta", loc: "100 50" }
429 ];
430 var linkDataArray = [
431 { from: "Alpha", to: "Beta" }
432 ];
433 diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
434</code></pre>
435<script>goCode("bezier", 600, 100)</script>
436<p>
437 You can control how curved it is by setting the <a>Link.curviness</a> property.
438 The default produces a slight curve.
439</p>
440
441<p>
442 If there are multiple links, it will automatically compute reasonable values for the curviness of each link,
443 unless you assign <a>Link.curviness</a> explicitly.
444</p>
445<pre class="lang-js" id="beziers"><code>
446 diagram.nodeTemplate =
447 $(go.Node, "Auto",
448 new go.Binding("location", "loc", go.Point.parse),
449 $(go.Shape, "RoundedRectangle", { fill: "lightgray" }),
450 $(go.TextBlock, { margin: 5 },
451 new go.Binding("text", "key"))
452 );
453
454 diagram.linkTemplate =
455 $(go.Link,
456 { curve: go.Link.Bezier },
457 $(go.Shape),
458 $(go.Shape, { toArrow: "Standard" })
459 );
460
461 var nodeDataArray = [
462 { key: "Alpha", loc: "0 0" },
463 { key: "Beta", loc: "100 50" }
464 ];
465 var linkDataArray = [
466 { from: "Alpha", to: "Beta" }, // multiple links between the same nodes
467 { from: "Alpha", to: "Beta" },
468 { from: "Alpha", to: "Beta" },
469 { from: "Alpha", to: "Beta" }
470 ];
471 diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
472</code></pre>
473<script>goCode("beziers", 600, 100)</script>
474
475<p>
476 Another kind of curviness comes from rounded corners when the <a>Link.routing</a> is Orthogonal or AvoidsNodes.
477</p>
478<pre class="lang-js" id="corners"><code>
479 diagram.nodeTemplate =
480 $(go.Node, "Auto",
481 new go.Binding("location", "loc", go.Point.parse),
482 $(go.Shape, "RoundedRectangle", { fill: "lightgray" }),
483 $(go.TextBlock, { margin: 5 },
484 new go.Binding("text", "key"))
485 );
486
487 diagram.linkTemplate =
488 $(go.Link,
489 { routing: go.Link.AvoidsNodes,
490 corner: 10 }, // rounded corners
491 $(go.Shape),
492 $(go.Shape, { toArrow: "Standard" })
493 );
494
495 var nodeDataArray = [
496 { key: "Alpha", loc: "0 0" },
497 { key: "Beta", loc: "250 40" },
498 { key: "Gamma", loc: "100 0" },
499 { key: "Delta", loc: "75 50" },
500 { key: "Epsilon", loc: "150 30" }
501 ];
502 var linkDataArray = [
503 { from: "Alpha", to: "Beta" }
504 ];
505 diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
506</code></pre>
507<script>goCode("corners", 600, 100)</script>
508
509<p>
510 Another kind of curviness comes from setting <a>Link.curve</a> to <a>Link,JumpOver</a>.
511 This causes little "hops" in the path of an orthogonal link that crosses another orthogonal link
512 that also has a JumpOver curve.
513</p>
514<pre class="lang-js" id="jumpOvers"><code>
515 diagram.nodeTemplate =
516 $(go.Node, "Auto",
517 { locationSpot: go.Spot.Center },
518 new go.Binding("location", "loc", go.Point.parse),
519 $(go.Shape, "RoundedRectangle", { fill: "lightgray" }),
520 $(go.TextBlock, { margin: 5 },
521 new go.Binding("text", "key"))
522 );
523
524 diagram.linkTemplate =
525 $(go.Link,
526 { routing: go.Link.Orthogonal, // may be either Orthogonal or AvoidsNodes
527 curve: go.Link.JumpOver },
528 $(go.Shape),
529 $(go.Shape, { toArrow: "Standard" })
530 );
531
532 var nodeDataArray = [
533 { key: "Alpha", loc: "0 50" },
534 { key: "Beta", loc: "100 50" },
535 { key: "Alpha2", loc: "50 0" },
536 { key: "Beta2", loc: "50 100" }
537 ];
538 var linkDataArray = [
539 { from: "Alpha", to: "Beta" }, // these two links will cross
540 { from: "Alpha2", to: "Beta2" }
541 ];
542 diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
543</code></pre>
544<script>goCode("jumpOvers", 600, 150)</script>
545
546<p>
547 Note that the use of link jumping is distinctly slower than normal links because all of the crossing
548 points must be computed and the geometry of the link shape will be more complex.
549</p>
550
551<p>
552 Another kind of curviness (or actually lack of it) comes from setting <a>Link.curve</a> to <a>Link,JumpGap</a>.
553 This causes little "gaps" in the path of an orthogonal link that crosses another orthogonal link
554 that also has a JumpGap curve.
555</p>
556<pre class="lang-js" id="jumpGaps"><code>
557 diagram.nodeTemplate =
558 $(go.Node, "Auto",
559 { locationSpot: go.Spot.Center },
560 new go.Binding("location", "loc", go.Point.parse),
561 $(go.Shape, "RoundedRectangle", { fill: "lightgray" }),
562 $(go.TextBlock, { margin: 5 },
563 new go.Binding("text", "key"))
564 );
565
566 diagram.linkTemplate =
567 $(go.Link,
568 { routing: go.Link.Orthogonal, // may be either Orthogonal or AvoidsNodes
569 curve: go.Link.JumpGap },
570 $(go.Shape),
571 $(go.Shape, { toArrow: "Standard" })
572 );
573
574 var nodeDataArray = [
575 { key: "Alpha", loc: "0 50" },
576 { key: "Beta", loc: "100 50" },
577 { key: "Alpha2", loc: "50 0" },
578 { key: "Beta2", loc: "50 100" }
579 ];
580 var linkDataArray = [
581 { from: "Alpha", to: "Beta" }, // these two links will cross
582 { from: "Alpha2", to: "Beta2" }
583 ];
584 diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
585</code></pre>
586<script>goCode("jumpGaps", 600, 150)</script>
587
588<h2 id="EasierClickingOnLinks">Easier Clicking on Links</h2>
589<p>
590 A problem that users may notice, especially when using fingers but also with the mouse,
591 is that it can be difficult to click on links that have a thin <a>Link.path</a>.
592 One could set the <a>Shape.strokeWidth</a> to a larger value, such as 8, but you may not want that appearance.
593</p>
594<pre class="lang-js" id="thickPath"><code>
595 diagram.nodeTemplate =
596 $(go.Node, "Auto",
597 new go.Binding("location", "loc", go.Point.parse),
598 $(go.Shape, "RoundedRectangle", { fill: "lightgray" }),
599 $(go.TextBlock, { margin: 5 },
600 new go.Binding("text", "key"))
601 );
602
603 diagram.linkTemplate =
604 $(go.Link,
605 $(go.Shape, { strokeWidth: 8 }), // thick path
606 $(go.Shape, { toArrow: "Standard" })
607 );
608
609 var nodeDataArray = [
610 { key: "Alpha", loc: "0 0" },
611 { key: "Beta", loc: "100 50" }
612 ];
613 var linkDataArray = [
614 { from: "Alpha", to: "Beta" }
615 ];
616 diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
617</code></pre>
618<script>goCode("thickPath", 600, 100)</script>
619
620<p>
621 The solution is to add a thick path Shape but not have it draw anything.
622 This is easily done by setting <code>{ stroke: "transparent", strokeWidth: 8 }</code>.
623 However if you want to keep the original path Shape, <em>both</em> Shapes need to be declared as the "main" element
624 for the Link by setting <a>GraphObject.isPanelMain</a> to true.
625 The Link panel knows that all such Shapes should get the same computed Geometry for the link path.
626</p>
627<pre class="lang-js" id="doublePath"><code>
628 diagram.nodeTemplate =
629 $(go.Node, "Auto",
630 new go.Binding("location", "loc", go.Point.parse),
631 $(go.Shape, "RoundedRectangle", { fill: "lightgray" }),
632 $(go.TextBlock, { margin: 5 },
633 new go.Binding("text", "key"))
634 );
635
636 diagram.linkTemplate =
637 $(go.Link,
638 $(go.Shape, { isPanelMain: true, stroke: "transparent", strokeWidth: 8 }), // thick undrawn path
639 $(go.Shape, { isPanelMain: true }), // default stroke === "black", strokeWidth === 1
640 $(go.Shape, { toArrow: "Standard" })
641 );
642
643 var nodeDataArray = [
644 { key: "Alpha", loc: "0 0" },
645 { key: "Beta", loc: "100 50" }
646 ];
647 var linkDataArray = [
648 { from: "Alpha", to: "Beta" }
649 ];
650 diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
651</code></pre>
652<script>goCode("doublePath", 600, 100)</script>
653<p>
654 In this example you will find it easier to select the link than without the second transparent link path shape.
655</p>
656<p>
657 The transparent shape can also be used for highlighting purposes.
658 For example, to implement the effect of highlighting the link when the mouse passes over it,
659 add <a>GraphObject.mouseEnter</a> and <a>GraphObject.mouseLeave</a> event handlers:
660</p>
661<pre class="lang-js" id="doublePathHighlight"><code>
662 diagram.nodeTemplate =
663 $(go.Node, "Auto",
664 new go.Binding("location", "loc", go.Point.parse),
665 $(go.Shape, "RoundedRectangle", { fill: "lightgray" }),
666 $(go.TextBlock, { margin: 5 },
667 new go.Binding("text", "key"))
668 );
669
670 diagram.linkTemplate =
671 $(go.Link,
672 $(go.Shape, { isPanelMain: true, stroke: "transparent", strokeWidth: 8 }), // thick undrawn path
673 $(go.Shape, { isPanelMain: true }), // default stroke === "black", strokeWidth === 1
674 $(go.Shape, { toArrow: "Standard" }),
675 {
676 // a mouse-over highlights the link by changing the first main path shape's stroke:
677 mouseEnter: function(e, link) { link.elt(0).stroke = "rgba(0,90,156,0.3)"; },
678 mouseLeave: function(e, link) { link.elt(0).stroke = "transparent"; }
679 }
680 );
681
682 var nodeDataArray = [
683 { key: "Alpha", loc: "0 0" },
684 { key: "Beta", loc: "100 50" }
685 ];
686 var linkDataArray = [
687 { from: "Alpha", to: "Beta" }
688 ];
689 diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
690</code></pre>
691<script>goCode("doublePathHighlight", 600, 100)</script>
692<p>
693 Pass the mouse over the link to see the effect.
694 Such feedback also helps the user click or context click on the link.
695</p>
696
697<h2 id="ShortLengths">Short Lengths</h2>
698<p>
699 Note in the example above with the thick black path shape,
700 that the arrowhead seems to have disappeared due to the thickness of the link path.
701 One can avoid the problem by increasing the <a>GraphObject.scale</a> of the arrowhead, perhaps to 2.
702</p>
703<pre class="lang-js" id="thickPath2"><code>
704 diagram.nodeTemplate =
705 $(go.Node, "Auto",
706 new go.Binding("location", "loc", go.Point.parse),
707 $(go.Shape, "RoundedRectangle", { fill: "lightgray" }),
708 $(go.TextBlock, { margin: 5 },
709 new go.Binding("text", "key"))
710 );
711
712 diagram.linkTemplate =
713 $(go.Link,
714 $(go.Shape, { strokeWidth: 8 }), // thick path
715 $(go.Shape, { toArrow: "Standard", scale: 2 }) // bigger arrowhead
716 );
717
718 var nodeDataArray = [
719 { key: "Alpha", loc: "0 0" },
720 { key: "Beta", loc: "100 50" }
721 ];
722 var linkDataArray = [
723 { from: "Alpha", to: "Beta" }
724 ];
725 diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
726</code></pre>
727<script>goCode("thickPath2", 600, 100)</script>
728
729<p>
730 Now the arrowhead is clearly visible.
731 But that in turn shows that the arrowhead is still obscured at the very end of the link path,
732 where it is too wide to show the point of the arrowhead.
733 That problem can be avoided by setting <a>Link.toShortLength</a> to a value such as 8,
734 depending on the kind of arrowhead used.
735 The path geometry will be shortened by that distance so that the link path does not interfere with the arrowhead.
736</p>
737<pre class="lang-js" id="shortLength"><code>
738 diagram.nodeTemplate =
739 $(go.Node, "Auto",
740 new go.Binding("location", "loc", go.Point.parse),
741 $(go.Shape, "RoundedRectangle", { fill: "lightgray" }),
742 $(go.TextBlock, { margin: 5 },
743 new go.Binding("text", "key"))
744 );
745
746 diagram.linkTemplate =
747 $(go.Link,
748 { toShortLength: 8 }, // shortens path to avoid interfering with arrowhead
749 $(go.Shape, { strokeWidth: 8 }), // thick path
750 $(go.Shape, { toArrow: "Standard", scale: 2 }) // bigger arrowhead
751 );
752
753 var nodeDataArray = [
754 { key: "Alpha", loc: "0 0" },
755 { key: "Beta", loc: "100 50" }
756 ];
757 var linkDataArray = [
758 { from: "Alpha", to: "Beta" }
759 ];
760 diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
761</code></pre>
762<script>goCode("shortLength", 600, 100)</script>
763
764<p>
765 There is also a <a>Link.fromShortLength</a> property, to control how far the "from" end of the link path is drawn.
766 If there is an end segment, the distance that it can be shortened is limited to the corresponding
767 <a>Link.toEndSegmentLength</a> or <a>Link.fromEndSegmentLength</a>.
768 Note also that the short length may be negative, which would cause the link path to be drawn longer --
769 into the port at which the link is connected.
770</p>
771
772<h2 id="DisconnectedLinks">Disconnected Links</h2>
773<p>
774 The normal expectation is that one cannot have a link relationship unless it connects two nodes.
775 However <b>GoJS</b> does support the creation and manipulation of links that have either or both of
776 the <a>Link.fromNode</a> and <a>Link.toNode</a> properties with null values.
777 This is demonstrated by the <a href="../samples/draggableLink.html">Draggable Link</a> sample.
778</p>
779<p>
780 Both ends of the link must be connected to nodes in order for the standard link routing to operate.
781 If a link does not know where to start or where to end, it cannot compute a route or a position for the link.
782 However, you can provide a route by setting or binding <a>Link.points</a> to a list of two or more Points.
783 That will automatically give the link a position so that it can be seen in the diagram.
784</p>
785<p>
786 The linking tools, <a>LinkingTool</a> and <a>RelinkingTool</a>, normally do not permit the creation
787 or reconnection of links that connect with "nothing".
788 However, you can set <a>LinkingBaseTool.isUnconnectedLinkValid</a> to true to allow the user to do so,
789 as the Draggable Link sample demonstrates.
790</p>
791<p>
792 Links cannot normally be dragged unless they are part of a collection that includes the connected nodes.
793 However, you can set <a>DraggingTool.dragsLink</a> to true to allow the user to drag a solitary <a>Link</a>.
794 This mode allows the user to disconnect a link by dragging it away from the node(s)/port(s) to which it was attached.
795 It also allows the user to reconnect one or both ends of the link by dropping it so that the end(s) are at valid port(s).
796 This too is demonstrated by the Draggable Link sample.
797</p>
798
799 </div>
800 </div>
801
802 <div class="bg-nwoods-primary">
803 <section class="max-w-screen-lg text-white container mx-auto py-2 px-12">
804 <p id="version" class="leading-none mb-2 my-4">GoJS</p>
805 </section>
806 </div><footer class="bg-nwoods-primary text-white">
807 <div class="container max-w-screen-lg mx-auto px-8">
808 <div class="w-full py-6">
809
810 <div class="max-w-screen-lg xl:max-w-screen-xl mx-auto px-4 sm:px-6 md:px-8">
811 <ul class="text-sm font-medium pb-14 sm:pb-20 grid grid-cols-1 sm:grid-cols-3 gap-y-10">
812 <li class="list-none row-span-2">
813 <h2 class="text-base font-semibold tracking-wide">GoJS</h2>
814 <ul class="list-none space-y-4 md:space-y-1 px-0">
815 <li>
816 <a href="../samples/index.html">Samples</a>
817 </li>
818 <li>
819 <a href="../learn/index.html">Learn</a>
820 </li>
821 <li>
822 <a href="../intro/index.html">Intro</a>
823 </li>
824 <li>
825 <a href="../api/index.html">API</a>
826 </li>
827 <li>
828 <a href="../changelog.html">Changelog</a>
829 </li>
830 <li>
831 <a href="https://github.com/NorthwoodsSoftware/GoJS">GitHub</a>
832 </li>
833 </ul>
834 </li>
835 <li class="list-none row-span-2">
836 <h2 class="text-base font-semibold tracking-wide">Support</h2>
837 <ul class="list-none space-y-4 md:space-y-1 px-0">
838 <li>
839 <a href="https://www.nwoods.com/contact.html"
840 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a>
841 </li>
842 <li>
843 <a href="https://forum.nwoods.com/c/gojs">Forum</a>
844 </li>
845 <li>
846 <a href="https://www.nwoods.com/app/activate.aspx?sku=gojs">Activate</a>
847 </li>
848 <li>
849 <a href="https://www.nwoods.com/sales/index.html"
850 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a>
851 </li>
852 <li>
853 <a href="https://www.youtube.com/channel/UC9We8EoX596-6XFjJDtZIDg">Videos</a>
854 </li>
855 </ul>
856 </li>
857 <li class="list-none row-span-2">
858 <h2 class="text-base font-semibold tracking-wide">Company</h2>
859 <ul class="list-none space-y-4 md:space-y-1 px-0">
860 <li>
861 <a href="https://www.nwoods.com">Northwoods</a>
862 </li>
863 <li>
864 <a href="https://www.nwoods.com/about.html">About Us</a>
865 </li>
866 <li>
867 <a href="https://www.nwoods.com/contact.html">Contact Us</a>
868 </li>
869 <li>
870 <a href="https://twitter.com/northwoodsgo">Twitter</a>
871 </li>
872
873 </ul>
874 </li>
875 </ul>
876
877
878 <p class="text-sm text-gray-100 md:mb-6">
879 Copyright 1998-2021 <a class="text-white" href="https://www.nwoods.com">Northwoods Software</a>
880 </p>
881 </div>
882 </div>
883</footer> </body>
884
885<script async src="https://www.googletagmanager.com/gtag/js?id=UA-1506307-5"></script>
886<script>
887 window.dataLayer = window.dataLayer || [];
888 function gtag(){dataLayer.push(arguments);}
889 gtag('js', new Date()); gtag('config', 'UA-1506307-5');
890 var getOutboundLink = function(url, label) {
891 gtag('event', 'click', {
892 'event_category': 'outbound',
893 'event_label': label,
894 'transport_type': 'beacon'
895 });
896 }
897
898 // topnav
899 var topButton = document.getElementById("topnavButton");
900 var topnavList = document.getElementById("topnavList");
901 topButton.addEventListener("click", function() {
902 this.classList.toggle("active");
903 topnavList.classList.toggle("hidden");
904 document.getElementById("topnavOpen").classList.toggle("hidden");
905 document.getElementById("topnavClosed").classList.toggle("hidden");
906 });
907</script>
908 <script src="../assets/js/prism.js"></script>
909 <script src="../release/go.js"></script>
910 <script src="../assets/js/goDoc.js"></script>
911 <script>
912 document.addEventListener("DOMContentLoaded", function() {
913 if (window.go) document.getElementById('version').textContent = "GoJS version " + go.version;
914 if (window.goDoc) window.goDoc();
915 var d = window.diagrams;
916 for (var i = 0; i < d.length; i++) {
917 var dargs = d[i];
918 goCodeExecute(dargs[0], dargs[1], dargs[2], dargs[3], dargs[4]);
919 }
920 if (window.extra) window.extra();
921 });
922 </script>
923</html>