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 | <meta name="description" content="TypeScript: Let the user draw a new link by clicking consecutive points through which the link's route must pass."/>
|
7 | <link rel="stylesheet" href="../assets/css/style.css"/>
|
8 |
|
9 | <title>Polyline Linking Tool</title>
|
10 | </head>
|
11 |
|
12 | <body>
|
13 |
|
14 | <nav id="navTop" class="w-full z-30 top-0 text-white bg-nwoods-primary">
|
15 | <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">
|
16 | <div class="md:pl-4">
|
17 | <a class="text-white hover:text-white no-underline hover:no-underline
|
18 | font-bold text-2xl lg:text-4xl rounded-lg hover:bg-nwoods-secondary " href="../">
|
19 | <h1 class="mb-0 p-1 ">GoJS</h1>
|
20 | </a>
|
21 | </div>
|
22 | <button id="topnavButton" class="rounded-lg sm:hidden focus:outline-none focus:ring" aria-label="Navigation">
|
23 | <svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6">
|
24 | <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>
|
25 | <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>
|
26 | </svg>
|
27 | </button>
|
28 | <div id="topnavList" class="hidden sm:block items-center w-auto mt-0 text-white p-0 z-20">
|
29 | <ul class="list-reset list-none font-semibold flex justify-end flex-wrap sm:flex-nowrap items-center px-0 pb-0">
|
30 | <li class="p-1 sm:p-0"><a class="topnav-link" href="../learn/">Learn</a></li>
|
31 | <li class="p-1 sm:p-0"><a class="topnav-link" href="../samples/">Samples</a></li>
|
32 | <li class="p-1 sm:p-0"><a class="topnav-link" href="../intro/">Intro</a></li>
|
33 | <li class="p-1 sm:p-0"><a class="topnav-link" href="../api/">API</a></li>
|
34 | <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/products/register.html">Register</a></li>
|
35 | <li class="p-1 sm:p-0"><a class="topnav-link" href="../download.html">Download</a></li>
|
36 | <li class="p-1 sm:p-0"><a class="topnav-link" href="https://forum.nwoods.com/c/gojs/11">Forum</a></li>
|
37 | <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/contact.html"
|
38 | target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a></li>
|
39 | <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/sales/index.html"
|
40 | target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a></li>
|
41 | </ul>
|
42 | </div>
|
43 | </div>
|
44 | <hr class="border-b border-gray-600 opacity-50 my-0 py-0" />
|
45 | </nav>
|
46 | <div class="md:flex flex-col md:flex-row md:min-h-screen w-full max-w-screen-xl mx-auto">
|
47 | <div id="navSide" class="flex flex-col w-full md:w-48 text-gray-700 bg-white flex-shrink-0"></div>
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | <div class="p-4 w-full">
|
53 | <div id="sample">
|
54 | <div id="myDiagramDiv" style="border: solid 1px black; width: 100%; height: 600px"></div>
|
55 | <div id="buttons">
|
56 | <button id="SaveButton">Save</button>
|
57 | <button id="LoadButton">Load</button>
|
58 | </div>
|
59 | <p>
|
60 | This sample demonstrates the PolylineLinkingTool, which replaces the standard LinkingTool. The tool is defined in its own
|
61 | file, as <a href="PolylineLinkingTool.ts">PolylineLinkingTool.ts</a>.
|
62 | </p>
|
63 | <p>
|
64 | The user starts drawing a new link from a node in the normal manner, by dragging from a port, which for feedback purposes
|
65 | has a "pointer" cursor. Normally the user would have to release the mouse near the target port/node. However with the
|
66 | PolylineLinkingTool the user may click at various points to cause the new link to be routed along those points. Clicking
|
67 | on the target port completes the new link. Press <b>Escape</b> to cancel, or <b>Z</b> to remove the last point.
|
68 | </p>
|
69 | <p>
|
70 | Furthermore, because <a>Link.resegmentable</a> is true, the user can easily add or remove segments from the route of
|
71 | a selected link. To insert a segment, the user can start dragging the small diamond resegmenting handle. To remove
|
72 | a segment, the user needs to move a regular reshaping handle to cause the adjacent two segments to be in a straight
|
73 | line.
|
74 | </p>
|
75 | <p>
|
76 | The PolylineLinkingTool also works with orthogonally routed links. To demonstrate this, uncomment the two lines that initialize
|
77 | <a>Link.routing</a> to be <a>Link.Orthogonal</a>.
|
78 | </p>
|
79 | <textarea id="mySavedModel" style="width:100%;height:300px">
|
80 | { "class": "go.GraphLinksModel",
|
81 | "nodeDataArray": [
|
82 | { "key": 1, "text": "Node 1", "fill": "blueviolet", "loc": "100 100" },
|
83 | { "key": 2, "text": "Node 2", "fill": "orange", "loc": "400 100" }
|
84 | ],
|
85 | "linkDataArray": [ ]
|
86 | }
|
87 | </textarea>
|
88 | </div>
|
89 |
|
90 | <script type="module" id="code">
|
91 | import * as go from "../release/go-module.js";
|
92 | import { PolylineLinkingTool } from './PolylineLinkingTool.js';
|
93 |
|
94 | if (window.goSamples) goSamples();
|
95 | const $ = go.GraphObject.make;
|
96 |
|
97 | const myDiagram =
|
98 | $(go.Diagram, 'myDiagramDiv',
|
99 | { "undoManager.isEnabled": true });
|
100 |
|
101 |
|
102 | const tool = new PolylineLinkingTool();
|
103 |
|
104 | myDiagram.toolManager.linkingTool = tool;
|
105 |
|
106 | myDiagram.nodeTemplate =
|
107 | $(go.Node, 'Spot', { locationSpot: go.Spot.Center }, new go.Binding('location', 'loc', go.Point.parse).makeTwoWay(go.Point.stringify), $(go.Shape, {
|
108 | width: 100, height: 100, fill: 'lightgray',
|
109 | portId: '', cursor: 'pointer',
|
110 | fromLinkable: true,
|
111 | fromLinkableSelfNode: true, fromLinkableDuplicates: true,
|
112 | toLinkable: true,
|
113 | toLinkableSelfNode: true, toLinkableDuplicates: true
|
114 | }, new go.Binding('fill')), $(go.Shape, { width: 70, height: 70, fill: 'transparent', stroke: null }), $(go.TextBlock, new go.Binding('text')));
|
115 | myDiagram.linkTemplate =
|
116 | $(go.Link, { reshapable: true, resegmentable: true },
|
117 |
|
118 | { adjusting: go.Link.Stretch },
|
119 | new go.Binding('points', 'points').makeTwoWay(), $(go.Shape, { strokeWidth: 1.5 }), $(go.Shape, { toArrow: 'OpenTriangle' }));
|
120 | load();
|
121 |
|
122 |
|
123 | export function save() {
|
124 | document.getElementById('mySavedModel').value = myDiagram.model.toJson();
|
125 | myDiagram.isModified = false;
|
126 | }
|
127 | export function load() {
|
128 | myDiagram.model = go.Model.fromJson(document.getElementById('mySavedModel').value);
|
129 | }
|
130 |
|
131 | document.getElementById("SaveButton").onclick = save;
|
132 | document.getElementById("LoadButton").onclick = load;
|
133 |
|
134 | window.myDiagram = myDiagram;
|
135 | </script>
|
136 | </div>
|
137 |
|
138 |
|
139 | </div>
|
140 | </body>
|
141 |
|
142 | <script src="../assets/js/goSamples.js"></script>
|
143 | </html>
|