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 Link Connection Points on 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 & 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 | <h1>Link Connection Points on Nodes</h1>
|
135 | <p>
|
136 | There is flexibility in controlling exactly how and where a link connects to a node.
|
137 | In the previous examples the link has always ended at the edge of the node.
|
138 | But you can specify the <a>Spot</a> on a node at which a link terminates.
|
139 | </p>
|
140 |
|
141 | <h2 id="NonRectangularNodes">Non-rectangular Nodes</h2>
|
142 | <p>
|
143 | When a <a>Node</a> does not have a rectangular shape, by default links will end
|
144 | where the line toward the center of the node intersects with the edge of the node.
|
145 | </p>
|
146 | <p>
|
147 | Here is a demonstration of that -- drag one of the nodes around and watch how the link always
|
148 | connects to the nearest intersection or to the center of the node.
|
149 | This example includes arrowheads at both ends of the link, to make it clear that the link route
|
150 | really ends right at the edge of the node.
|
151 | </p>
|
152 | <pre class="lang-js" id="nonRectangular"><code>
|
153 | diagram.nodeTemplate =
|
154 | $(go.Node, "Auto",
|
155 | { width: 90, height: 90,
|
156 | selectionAdorned: false },
|
157 | new go.Binding("location", "loc", go.Point.parse),
|
158 | $(go.Shape, "FivePointedStar", { fill: "lightgray" }),
|
159 | $(go.TextBlock,
|
160 | new go.Binding("text", "key"))
|
161 | );
|
162 |
|
163 | diagram.linkTemplate =
|
164 | $(go.Link,
|
165 | $(go.Shape),
|
166 | $(go.Shape, // the "from" end arrowhead
|
167 | { fromArrow: "Chevron" }),
|
168 | $(go.Shape, // the "to" end arrowhead
|
169 | { toArrow: "StretchedDiamond", fill: "red" })
|
170 | );
|
171 |
|
172 | var nodeDataArray = [
|
173 | { key: "Alpha", loc: "0 0" },
|
174 | { key: "Beta", loc: "100 50" }
|
175 | ];
|
176 | var linkDataArray = [
|
177 | { from: "Alpha", to: "Beta" }
|
178 | ];
|
179 | diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
|
180 | </code></pre>
|
181 | <script>goCode("nonRectangular", 600, 150)</script>
|
182 |
|
183 | <h2 id="ToSpotAndFromSpot">ToSpot and FromSpot</h2>
|
184 | <p>
|
185 | You can easily require links to end at a particular point within the bounds of the node,
|
186 | rather than at the nearest edge intersection.
|
187 | Set the <a>GraphObject.toSpot</a> to a <a>Spot</a> value other than <a>Spot,None</a>
|
188 | to cause links coming into the node to end at that spot within the node, with a direction
|
189 | that is appropriate for the side that the spot is at.
|
190 | Similarly, set the <a>GraphObject.fromSpot</a> for the ends of links coming out of the node.
|
191 | </p>
|
192 |
|
193 | <p>
|
194 | The following examples all display the same graph but use different templates
|
195 | to demonstrate how links can connect to nodes.
|
196 | They all call this common function to define some nodes and links.
|
197 | </p>
|
198 | <pre class="lang-js" id="makeGraph"><code>
|
199 | function makeGraph(diagram) {
|
200 | var $ = go.GraphObject.make;
|
201 |
|
202 | diagram.layout =
|
203 | $(go.LayeredDigraphLayout, // this will be discussed in a later section
|
204 | { columnSpacing: 5,
|
205 | setsPortSpots: false });
|
206 |
|
207 | var nodeDataArray = [
|
208 | { key: "Alpha" }, { key: "Beta" }, { key: "Gamma" }, { key: "Delta" },
|
209 | { key: "Epsilon" }, { key: "Zeta" }, { key: "Eta" }, { key: "Theta" }
|
210 | ];
|
211 | var linkDataArray = [
|
212 | { from: "Beta", to: "Alpha" },
|
213 | { from: "Gamma", to: "Alpha" },
|
214 | { from: "Delta", to: "Alpha" },
|
215 | { from: "Alpha", to: "Epsilon" },
|
216 | { from: "Alpha", to: "Zeta" },
|
217 | { from: "Alpha", to: "Eta" },
|
218 | { from: "Alpha", to: "Theta" }
|
219 | ];
|
220 | diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
|
221 | }
|
222 | </code></pre>
|
223 | <script>eval(document.getElementById("makeGraph").textContent)</script>
|
224 |
|
225 | <p>
|
226 | Let us specify that links coming into a node connect at the middle of the left side, and that links going out
|
227 | of a node connect at the middle of the right side. Such a convention is appropriate for diagrams that have
|
228 | a general sense of direction to them, such as the following one which goes from left to right.
|
229 | </p>
|
230 | <pre class="lang-js" id="leftright"><code>
|
231 | diagram.nodeTemplate =
|
232 | $(go.Node, "Auto",
|
233 | { fromSpot: go.Spot.Right, // coming out from middle-right
|
234 | toSpot: go.Spot.Left }, // going into at middle-left
|
235 | $(go.Shape, "Rectangle", { fill: "lightgray" }),
|
236 | $(go.TextBlock,
|
237 | { margin: 5},
|
238 | new go.Binding("text", "key"))
|
239 | );
|
240 |
|
241 | diagram.linkTemplate =
|
242 | $(go.Link,
|
243 | $(go.Shape),
|
244 | $(go.Shape, { toArrow: "Standard" })
|
245 | );
|
246 |
|
247 | makeGraph(diagram);
|
248 | </code></pre>
|
249 | <script>goCode("leftright", 600, 150)</script>
|
250 |
|
251 | <p>
|
252 | You can also specify that the links go into a node not at a single spot but spread out along one side.
|
253 | Instead of <a>Spot,Right</a> use <a>Spot,RightSide</a>, and similarly for the left side.
|
254 | </p>
|
255 | <pre class="lang-js" id="leftrightSides"><code>
|
256 | diagram.nodeTemplate =
|
257 | $(go.Node, "Auto",
|
258 | { fromSpot: go.Spot.RightSide, // coming out from right side
|
259 | toSpot: go.Spot.LeftSide }, // going into at left side
|
260 | $(go.Shape, "Rectangle", { fill: "lightgray" }),
|
261 | $(go.TextBlock,
|
262 | { margin: 5},
|
263 | new go.Binding("text", "key"))
|
264 | );
|
265 |
|
266 | diagram.linkTemplate =
|
267 | $(go.Link,
|
268 | $(go.Shape),
|
269 | $(go.Shape, { toArrow: "Standard" })
|
270 | );
|
271 |
|
272 | makeGraph(diagram);
|
273 | </code></pre>
|
274 | <script>goCode("leftrightSides", 600, 150)</script>
|
275 | <p>
|
276 | Of course this only looks good when the nodes are basically rectangular.
|
277 | </p>
|
278 |
|
279 | <p>
|
280 | You can use a different kind of <a>Link.routing</a>:
|
281 | </p>
|
282 | <pre class="lang-js" id="leftrightSidesOrthogonal"><code>
|
283 | diagram.nodeTemplate =
|
284 | $(go.Node, "Auto",
|
285 | { fromSpot: go.Spot.RightSide, // coming out from right side
|
286 | toSpot: go.Spot.LeftSide }, // going into at left side
|
287 | $(go.Shape, "Rectangle", { fill: "lightgray" }),
|
288 | $(go.TextBlock,
|
289 | { margin: 5},
|
290 | new go.Binding("text", "key"))
|
291 | );
|
292 |
|
293 | diagram.linkTemplate =
|
294 | $(go.Link,
|
295 | { routing: go.Link.Orthogonal, // Orthogonal routing
|
296 | corner: 10 }, // with rounded corners
|
297 | $(go.Shape),
|
298 | $(go.Shape, { toArrow: "Standard" })
|
299 | );
|
300 |
|
301 | makeGraph(diagram);
|
302 | </code></pre>
|
303 | <script>goCode("leftrightSidesOrthogonal", 600, 150)</script>
|
304 |
|
305 | <p>
|
306 | Or you can use a different kind of <a>Link.curve</a>:
|
307 | </p>
|
308 | <pre class="lang-js" id="leftrightSidesBezier"><code>
|
309 | diagram.nodeTemplate =
|
310 | $(go.Node, "Auto",
|
311 | { fromSpot: go.Spot.RightSide, // coming out from right side
|
312 | toSpot: go.Spot.LeftSide }, // going into at left side
|
313 | $(go.Shape, "Rectangle", { fill: "lightgray" }),
|
314 | $(go.TextBlock,
|
315 | { margin: 5},
|
316 | new go.Binding("text", "key"))
|
317 | );
|
318 |
|
319 | diagram.linkTemplate =
|
320 | $(go.Link,
|
321 | { curve: go.Link.Bezier }, // Bezier curve
|
322 | $(go.Shape),
|
323 | $(go.Shape, { toArrow: "Standard" })
|
324 | );
|
325 |
|
326 | makeGraph(diagram);
|
327 | </code></pre>
|
328 | <script> goCode("leftrightSidesBezier", 600, 150)</script>
|
329 |
|
330 | <p>
|
331 | But you need to be careful to specify sensible spots for how the graph is arranged.
|
332 | </p>
|
333 | <pre class="lang-js" id="leftrightSidesBad"><code>
|
334 | diagram.nodeTemplate =
|
335 | $(go.Node, "Auto",
|
336 | { fromSpot: go.Spot.TopSide, // coming out from top side -- BAD!
|
337 | toSpot: go.Spot.RightSide }, // going into at right side -- BAD!
|
338 | $(go.Shape, "Rectangle", { fill: "lightgray" }),
|
339 | $(go.TextBlock,
|
340 | { margin: 5},
|
341 | new go.Binding("text", "key"))
|
342 | );
|
343 |
|
344 | diagram.linkTemplate =
|
345 | $(go.Link,
|
346 | $(go.Shape),
|
347 | $(go.Shape, { toArrow: "Standard" })
|
348 | );
|
349 |
|
350 | makeGraph(diagram);
|
351 |
|
352 | diagram.add($(go.Part, // this is just a comment
|
353 | { location: new go.Point(300, 50) },
|
354 | $(go.TextBlock, "Bad Spots",
|
355 | { font: "16pt bold", stroke: "red" })
|
356 | ));
|
357 | </code></pre>
|
358 | <script>goCode("leftrightSidesBad", 600, 150)</script>
|
359 |
|
360 | <h3 id="UndirectedSpots">Undirected Spots</h3>
|
361 | <p>
|
362 | When no spot is specified for the <a>GraphObject.fromSpot</a> or <a>GraphObject.toSpot</a>,
|
363 | the route computation will compute the furthest point on the route of the link from the center of the port to the other port
|
364 | that is an intersection of an edge of the port.
|
365 | This was demonstrated above in <a href="#NonRectangularNodes">Non-rectangular Nodes</a> and is again demonstrated here.
|
366 | </p>
|
367 | <pre class="lang-js" id="noSpotFocus0"><code>
|
368 | diagram.nodeTemplate =
|
369 | $(go.Node, "Vertical",
|
370 | new go.Binding("location", "loc", go.Point.parse),
|
371 | $(go.Shape, "YinYang",
|
372 | {
|
373 | fill: "white", portId: ""
|
374 | },
|
375 | new go.Binding("fill", "color")),
|
376 | $(go.TextBlock,
|
377 | { margin: 8 },
|
378 | new go.Binding("text"))
|
379 | );
|
380 |
|
381 | diagram.model = new go.GraphLinksModel(
|
382 | [
|
383 | { key: 1, text: "Alpha", color: "lightblue", loc: "0 50" },
|
384 | { key: 2, text: "Beta", color: "orange", loc: "150 0" },
|
385 | { key: 3, text: "Gamma", color: "lightgreen", loc: "300 50" }
|
386 | ],
|
387 | [
|
388 | { from: 1, to: 2 },
|
389 | { from: 2, to: 3 }
|
390 | ]);
|
391 | </code></pre>
|
392 | <script>goCode("noSpotFocus0", 600, 250)</script>
|
393 |
|
394 | <p>
|
395 | However it is possible to specify a focus point that is different from the center of the port.
|
396 | Use a <a>Spot</a> value that has <a>Spot.x</a> and <a>Spot.y</a> equal to 0.5 but with <a>Spot.offsetX</a> and <a>Spot.offsetY</a>
|
397 | values that specify where you want links to focus towards, relative to the center of the port.
|
398 | </p>
|
399 | <pre class="lang-js" id="noSpotFocus1"><code>
|
400 | diagram.nodeTemplate =
|
401 | $(go.Node, "Vertical",
|
402 | new go.Binding("location", "loc", go.Point.parse),
|
403 | $(go.Shape, "YinYang",
|
404 | {
|
405 | fill: "white", portId: "",
|
406 | fromSpot: new go.Spot(0.5, 0.5, 0, -25), toSpot: new go.Spot(0.5, 0.5, 0, 25)
|
407 | },
|
408 | new go.Binding("fill", "color")),
|
409 | $(go.TextBlock,
|
410 | { margin: 8 },
|
411 | new go.Binding("text"))
|
412 | );
|
413 |
|
414 | diagram.model = new go.GraphLinksModel(
|
415 | [
|
416 | { key: 1, text: "Alpha", color: "lightblue", loc: "0 50" },
|
417 | { key: 2, text: "Beta", color: "orange", loc: "150 0" },
|
418 | { key: 3, text: "Gamma", color: "lightgreen", loc: "300 50" }
|
419 | ],
|
420 | [
|
421 | { from: 1, to: 2 },
|
422 | { from: 2, to: 3 }
|
423 | ]);
|
424 | </code></pre>
|
425 | <script>goCode("noSpotFocus1", 600, 250)</script>
|
426 | <p>
|
427 | In this example, links always appear to be coming from the hole near the top of the "YinYang" figure
|
428 | towards the dot near the bottom of the figure.
|
429 | Try moving the nodes to see this behavior.
|
430 | Note that the <a>Spot.x</a> and <a>Spot.y</a> values are both 0.5, with fixed offsets from the center of the port.
|
431 | </p>
|
432 |
|
433 | <p>
|
434 | It is also possible to have links go directly to particular spots within a port.
|
435 | Use regular <a>Spot</a> values, but set the Link's end segment length to zero,
|
436 | <a>Link.fromEndSegmentLength</a> or <a>Link.toEndSegmentLength</a>.
|
437 | </p>
|
438 | <pre class="lang-js" id="noSpotFocus2"><code>
|
439 | diagram.nodeTemplate =
|
440 | $(go.Node, "Vertical",
|
441 | new go.Binding("location", "loc", go.Point.parse),
|
442 | $(go.Shape, "YinYang",
|
443 | {
|
444 | fill: "white", portId: "",
|
445 | fromSpot: new go.Spot(0.5, 0.25), toSpot: new go.Spot(0.5, 0.75),
|
446 | fromEndSegmentLength: 0, toEndSegmentLength: 0
|
447 | },
|
448 | new go.Binding("fill", "color")),
|
449 | $(go.TextBlock,
|
450 | { margin: 8 },
|
451 | new go.Binding("text"))
|
452 | );
|
453 |
|
454 | diagram.model = new go.GraphLinksModel(
|
455 | [
|
456 | { key: 1, text: "Alpha", color: "lightblue", loc: "0 50" },
|
457 | { key: 2, text: "Beta", color: "orange", loc: "150 0" },
|
458 | { key: 3, text: "Gamma", color: "lightgreen", loc: "300 50" }
|
459 | ],
|
460 | [
|
461 | { from: 1, to: 2 },
|
462 | { from: 2, to: 3 }
|
463 | ]);
|
464 | </code></pre>
|
465 | <script>goCode("noSpotFocus2", 600, 250)</script>
|
466 | <p>
|
467 | Again, links always appear to be coming from the hole near the top of the "YinYang" figure
|
468 | towards the dot near the bottom of the figure, but now they go all the way rather than stop at the edge.
|
469 | Note that the <a>Spot.x</a> and <a>Spot.y</a> values are <i>not</i> both 0.5,
|
470 | and that the Link end segment lengths are zero.
|
471 | </p>
|
472 |
|
473 | <h2 id="SpotsForIndividualLinks">Spots for Individual Links</h2>
|
474 | <p>
|
475 | Setting the <a>GraphObject.fromSpot</a> and <a>GraphObject.toSpot</a> properties specifies
|
476 | the default link connection point for all links connected to the node.
|
477 | What if you want some links to go to the middle-top spot but some other links to go to the middle-left spot of the same node?
|
478 | You can achieve this by setting the <a>Link.fromSpot</a> and <a>Link.toSpot</a> properties,
|
479 | which take precedence over the correspondingly named properties of what the link connects with.
|
480 | </p>
|
481 | <pre class="lang-js" id="customSpots"><code>
|
482 | diagram.nodeTemplate =
|
483 | $(go.Node, "Auto",
|
484 | $(go.Shape, "Rectangle", { fill: "lightgray" }),
|
485 | $(go.TextBlock,
|
486 | { margin: 5},
|
487 | new go.Binding("text", "key"))
|
488 | );
|
489 |
|
490 | diagram.linkTemplate =
|
491 | $(go.Link,
|
492 | // get the link spots from the link data
|
493 | new go.Binding("fromSpot", "fromSpot", go.Spot.parse),
|
494 | new go.Binding("toSpot", "toSpot", go.Spot.parse),
|
495 | $(go.Shape),
|
496 | $(go.Shape, { toArrow: "Standard" })
|
497 | );
|
498 |
|
499 | var nodeDataArray = [
|
500 | { key: "Alpha" }, { key: "Beta" }, { key: "Gamma" }, { key: "Delta" }
|
501 | ];
|
502 | var linkDataArray = [
|
503 | { from: "Alpha", to: "Beta", fromSpot: "TopRight", toSpot: "Left" },
|
504 | { from: "Alpha", to: "Gamma", fromSpot: "Left", toSpot: "Left" },
|
505 | { from: "Alpha", to: "Delta", fromSpot: "None", toSpot: "Top" }
|
506 | ];
|
507 | diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);
|
508 | </code></pre>
|
509 | <script>goCode("customSpots", 600, 150)</script>
|
510 |
|
511 | <h3 id="SomeLayoutsSetLinkSpots">Some Layouts set Link Spots</h3>
|
512 | <p>
|
513 | Some of the predefined <a>Layout</a>s automatically set <a>Link.fromSpot</a> and <a>Link.toSpot</a>
|
514 | when the nature of the layout implies a natural direction.
|
515 | So, for example, a <a>TreeLayout</a> with a <a>TreeLayout.angle</a> <code>== 90</code> will set each Link's
|
516 | fromSpot to be <a>Spot,Bottom</a> and each Link's toSpot to be <a>Spot,Top</a>.
|
517 | </p>
|
518 | <p>
|
519 | You can disable the setting of Link spots for TreeLayout by setting <a>TreeLayout.setsPortSpot</a> and/or <a>TreeLayout.setsChildPortSpot</a> to false.
|
520 | For LayeredDigraphLayout, set <a>LayeredDigraphLayout.setsPortSpots</a> to false.
|
521 | For ForceDirectedLayout, set <a>ForceDirectedLayout.setsPortSpots</a> to false, although this is rarely needed.
|
522 | </p>
|
523 |
|
524 | </div>
|
525 | </div>
|
526 |
|
527 | <div class="bg-nwoods-primary">
|
528 | <section class="max-w-screen-lg text-white container mx-auto py-2 px-12">
|
529 | <p id="version" class="leading-none mb-2 my-4">GoJS</p>
|
530 | </section>
|
531 | </div><footer class="bg-nwoods-primary text-white">
|
532 | <div class="container max-w-screen-lg mx-auto px-8">
|
533 | <div class="w-full py-6">
|
534 |
|
535 | <div class="max-w-screen-lg xl:max-w-screen-xl mx-auto px-4 sm:px-6 md:px-8">
|
536 | <ul class="text-sm font-medium pb-14 sm:pb-20 grid grid-cols-1 sm:grid-cols-3 gap-y-10">
|
537 | <li class="list-none row-span-2">
|
538 | <h2 class="text-base font-semibold tracking-wide">GoJS</h2>
|
539 | <ul class="list-none space-y-4 md:space-y-1 px-0">
|
540 | <li>
|
541 | <a href="../samples/index.html">Samples</a>
|
542 | </li>
|
543 | <li>
|
544 | <a href="../learn/index.html">Learn</a>
|
545 | </li>
|
546 | <li>
|
547 | <a href="../intro/index.html">Intro</a>
|
548 | </li>
|
549 | <li>
|
550 | <a href="../api/index.html">API</a>
|
551 | </li>
|
552 | <li>
|
553 | <a href="../changelog.html">Changelog</a>
|
554 | </li>
|
555 | <li>
|
556 | <a href="https://github.com/NorthwoodsSoftware/GoJS">GitHub</a>
|
557 | </li>
|
558 | </ul>
|
559 | </li>
|
560 | <li class="list-none row-span-2">
|
561 | <h2 class="text-base font-semibold tracking-wide">Support</h2>
|
562 | <ul class="list-none space-y-4 md:space-y-1 px-0">
|
563 | <li>
|
564 | <a href="https://www.nwoods.com/contact.html"
|
565 | target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a>
|
566 | </li>
|
567 | <li>
|
568 | <a href="https://forum.nwoods.com/c/gojs">Forum</a>
|
569 | </li>
|
570 | <li>
|
571 | <a href="https://www.nwoods.com/app/activate.aspx?sku=gojs">Activate</a>
|
572 | </li>
|
573 | <li>
|
574 | <a href="https://www.nwoods.com/sales/index.html"
|
575 | target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a>
|
576 | </li>
|
577 | <li>
|
578 | <a href="https://www.youtube.com/channel/UC9We8EoX596-6XFjJDtZIDg">Videos</a>
|
579 | </li>
|
580 | </ul>
|
581 | </li>
|
582 | <li class="list-none row-span-2">
|
583 | <h2 class="text-base font-semibold tracking-wide">Company</h2>
|
584 | <ul class="list-none space-y-4 md:space-y-1 px-0">
|
585 | <li>
|
586 | <a href="https://www.nwoods.com">Northwoods</a>
|
587 | </li>
|
588 | <li>
|
589 | <a href="https://www.nwoods.com/about.html">About Us</a>
|
590 | </li>
|
591 | <li>
|
592 | <a href="https://www.nwoods.com/contact.html">Contact Us</a>
|
593 | </li>
|
594 | <li>
|
595 | <a href="https://twitter.com/northwoodsgo">Twitter</a>
|
596 | </li>
|
597 |
|
598 | </ul>
|
599 | </li>
|
600 | </ul>
|
601 |
|
602 |
|
603 | <p class="text-sm text-gray-100 md:mb-6">
|
604 | Copyright 1998-2021 <a class="text-white" href="https://www.nwoods.com">Northwoods Software</a>
|
605 | </p>
|
606 | </div>
|
607 | </div>
|
608 | </footer> </body>
|
609 |
|
610 | <script async src="https://www.googletagmanager.com/gtag/js?id=UA-1506307-5"></script>
|
611 | <script>
|
612 | window.dataLayer = window.dataLayer || [];
|
613 | function gtag(){dataLayer.push(arguments);}
|
614 | gtag('js', new Date()); gtag('config', 'UA-1506307-5');
|
615 | var getOutboundLink = function(url, label) {
|
616 | gtag('event', 'click', {
|
617 | 'event_category': 'outbound',
|
618 | 'event_label': label,
|
619 | 'transport_type': 'beacon'
|
620 | });
|
621 | }
|
622 |
|
623 |
|
624 | var topButton = document.getElementById("topnavButton");
|
625 | var topnavList = document.getElementById("topnavList");
|
626 | topButton.addEventListener("click", function() {
|
627 | this.classList.toggle("active");
|
628 | topnavList.classList.toggle("hidden");
|
629 | document.getElementById("topnavOpen").classList.toggle("hidden");
|
630 | document.getElementById("topnavClosed").classList.toggle("hidden");
|
631 | });
|
632 | </script>
|
633 | <script src="../assets/js/prism.js"></script>
|
634 | <script src="../release/go.js"></script>
|
635 | <script src="../extensions/Figures.js"></script> <script src="../assets/js/goDoc.js"></script>
|
636 | <script>
|
637 | document.addEventListener("DOMContentLoaded", function() {
|
638 | if (window.go) document.getElementById('version').textContent = "GoJS version " + go.version;
|
639 | if (window.goDoc) window.goDoc();
|
640 | var d = window.diagrams;
|
641 | for (var i = 0; i < d.length; i++) {
|
642 | var dargs = d[i];
|
643 | goCodeExecute(dargs[0], dargs[1], dargs[2], dargs[3], dargs[4]);
|
644 | }
|
645 | if (window.extra) window.extra();
|
646 | });
|
647 | </script>
|
648 | </html>
|