1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | import * as go from '../release/go-module.js';
|
10 |
|
11 | function setupDiagramTemplates(diagram) {
|
12 |
|
13 | const nodeTemplateMap = new go.Map();
|
14 |
|
15 | const archnode = new go.Node();
|
16 | const nodet = new go.TextBlock();
|
17 | nodet.bind(new go.Binding('text', '', go.Binding.toString));
|
18 | archnode.add(nodet);
|
19 | nodeTemplateMap.add('', archnode);
|
20 |
|
21 | const archcmnt = new go.Node();
|
22 | const nodec = new go.TextBlock();
|
23 | nodec.stroke = 'brown';
|
24 | nodec.bind(new go.Binding('text', '', go.Binding.toString));
|
25 | archcmnt.add(nodec);
|
26 | nodeTemplateMap.add('Comment', archcmnt);
|
27 |
|
28 | const archllab = new go.Node();
|
29 | archllab.selectable = false;
|
30 | archllab.avoidable = false;
|
31 | const nodel = new go.Shape();
|
32 | nodel.figure = 'Ellipse';
|
33 | nodel.fill = 'black';
|
34 | nodel.stroke = null;
|
35 | nodel.desiredSize = new go.Size(3, 3);
|
36 | archllab.add(nodel);
|
37 | nodeTemplateMap.add('LinkLabel', archllab);
|
38 | diagram.nodeTemplateMap = nodeTemplateMap;
|
39 |
|
40 | const groupTemplateMap = new go.Map();
|
41 |
|
42 | const archgrp = new go.Group();
|
43 | archgrp.selectionObjectName = 'GROUPPANEL';
|
44 | archgrp.type = go.Panel.Vertical;
|
45 | const grpt = new go.TextBlock();
|
46 | grpt.font = 'bold 12pt sans-serif';
|
47 | grpt.bind(new go.Binding('text', '', go.Binding.toString));
|
48 | archgrp.add(grpt);
|
49 | const grppan = new go.Panel(go.Panel.Auto);
|
50 | grppan.name = 'GROUPPANEL';
|
51 | const grpbord = new go.Shape();
|
52 | grpbord.figure = 'Rectangle';
|
53 | grpbord.fill = 'rgba(128,128,128,0.2)';
|
54 | grpbord.stroke = 'black';
|
55 | grppan.add(grpbord);
|
56 | const phold = new go.Placeholder();
|
57 | phold.padding = new go.Margin(5, 5, 5, 5);
|
58 | grppan.add(phold);
|
59 | archgrp.add(grppan);
|
60 | groupTemplateMap.add('', archgrp);
|
61 | diagram.groupTemplateMap = groupTemplateMap;
|
62 |
|
63 | const linkTemplateMap = new go.Map();
|
64 |
|
65 | const archlink = new go.Link();
|
66 | const archpath = new go.Shape();
|
67 | archpath.isPanelMain = true;
|
68 | archlink.add(archpath);
|
69 | const archarrow = new go.Shape();
|
70 | archarrow.toArrow = 'Standard';
|
71 | archarrow.fill = 'black';
|
72 | archarrow.stroke = null;
|
73 | archarrow.strokeWidth = 0;
|
74 | archlink.add(archarrow);
|
75 | linkTemplateMap.add('', archlink);
|
76 |
|
77 | const archcmntlink = new go.Link();
|
78 | const archcmntpath = new go.Shape();
|
79 | archcmntpath.isPanelMain = true;
|
80 | archcmntpath.stroke = 'brown';
|
81 | archcmntlink.add(archcmntpath);
|
82 | linkTemplateMap.add('Comment', archcmntlink);
|
83 | diagram.linkTemplateMap = linkTemplateMap;
|
84 | }
|
85 |
|
86 | function setupDefaultItemTemplate(panel) {
|
87 | const architem = new go.Panel();
|
88 | const itemtxt = new go.TextBlock();
|
89 | itemtxt.bind(new go.Binding('text', '', go.Binding.toString));
|
90 | architem.add(itemtxt);
|
91 | panel.itemTemplate = architem;
|
92 | }
|
93 |
|
94 | function setupSelectionAdornments(diagram) {
|
95 |
|
96 | let selad = new go.Adornment();
|
97 | selad.type = go.Panel.Auto;
|
98 | let seladhandle = new go.Shape();
|
99 | seladhandle.fill = null;
|
100 | seladhandle.stroke = 'dodgerblue';
|
101 | seladhandle.strokeWidth = 3;
|
102 | selad.add(seladhandle);
|
103 | const selplace = new go.Placeholder();
|
104 | selplace.margin = new go.Margin(1.5, 1.5, 1.5, 1.5);
|
105 | selad.add(selplace);
|
106 | diagram.nodeSelectionAdornmentTemplate = selad;
|
107 |
|
108 | diagram.groupSelectionAdornmentTemplate = selad;
|
109 |
|
110 | selad = new go.Adornment();
|
111 | selad.type = go.Panel.Link;
|
112 | seladhandle = new go.Shape();
|
113 | seladhandle.isPanelMain = true;
|
114 | seladhandle.fill = null;
|
115 | seladhandle.stroke = 'dodgerblue';
|
116 | seladhandle.strokeWidth = 3;
|
117 | selad.add(seladhandle);
|
118 | diagram.linkSelectionAdornmentTemplate = selad;
|
119 | }
|
120 |
|
121 | function setupDefaultBackgroundGrid(diagram) {
|
122 | const grid = new go.Panel(go.Panel.Grid);
|
123 | grid.name = 'GRID';
|
124 | let hlines = new go.Shape();
|
125 | hlines.figure = 'LineH';
|
126 | hlines.stroke = 'lightgray';
|
127 | hlines.strokeWidth = 0.5;
|
128 | hlines.interval = 1;
|
129 | grid.add(hlines);
|
130 | hlines = new go.Shape();
|
131 | hlines.figure = 'LineH';
|
132 | hlines.stroke = 'gray';
|
133 | hlines.strokeWidth = 0.5;
|
134 | hlines.interval = 5;
|
135 | grid.add(hlines);
|
136 | hlines = new go.Shape();
|
137 | hlines.figure = 'LineH';
|
138 | hlines.stroke = 'gray';
|
139 | hlines.strokeWidth = 1;
|
140 | hlines.interval = 10;
|
141 | grid.add(hlines);
|
142 | let vlines = new go.Shape();
|
143 | vlines.figure = 'LineV';
|
144 | vlines.stroke = 'lightgray';
|
145 | vlines.strokeWidth = 0.5;
|
146 | vlines.interval = 1;
|
147 | grid.add(vlines);
|
148 | vlines = new go.Shape();
|
149 | vlines.figure = 'LineV';
|
150 | vlines.stroke = 'gray';
|
151 | vlines.strokeWidth = 0.5;
|
152 | vlines.interval = 5;
|
153 | grid.add(vlines);
|
154 | vlines = new go.Shape();
|
155 | vlines.figure = 'LineV';
|
156 | vlines.stroke = 'gray';
|
157 | vlines.strokeWidth = 1;
|
158 | vlines.interval = 10;
|
159 | grid.add(vlines);
|
160 | grid.visible = false;
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 | diagram.grid = grid;
|
176 | }
|
177 |
|
178 | function setupOverviewBox(overview) {
|
179 | const box = new go.Part();
|
180 | const s = new go.Shape();
|
181 | s.stroke = 'magenta';
|
182 | s.strokeWidth = 2;
|
183 | s.fill = 'transparent';
|
184 | s.name = 'BOXSHAPE';
|
185 | box.selectable = true;
|
186 | box.selectionObjectName = 'BOXSHAPE';
|
187 | box.locationObjectName = 'BOXSHAPE';
|
188 |
|
189 | box.resizeObjectName = 'BOXSHAPE';
|
190 | box.cursor = 'move';
|
191 | box.add(s);
|
192 |
|
193 | const ad = new go.Adornment();
|
194 | ad.type = go.Panel.Spot;
|
195 | ad.locationSpot = go.Spot.Center;
|
196 | const ph = new go.Placeholder();
|
197 | ph.isPanelMain = true;
|
198 | ad.add(ph);
|
199 | const hnd = new go.Shape();
|
200 | hnd.alignmentFocus = go.Spot.Center;
|
201 | hnd.figure = 'Rectangle';
|
202 | hnd.desiredSize = new go.Size(64, 64);
|
203 | hnd.cursor = 'se-resize';
|
204 | hnd.alignment = go.Spot.BottomRight;
|
205 | ad.add(hnd);
|
206 | box.resizeAdornmentTemplate = ad;
|
207 | overview.box = box;
|
208 | }
|
209 |
|
210 | function setupLinkingToolTemporaryNodesAndLink(tool) {
|
211 |
|
212 | const link = new go.Link();
|
213 | const path = new go.Shape();
|
214 | path.isPanelMain = true;
|
215 | path.stroke = 'blue';
|
216 | link.add(path);
|
217 | const arrow = new go.Shape();
|
218 | arrow.toArrow = 'Standard';
|
219 | arrow.fill = 'blue';
|
220 | arrow.stroke = 'blue';
|
221 | link.add(arrow);
|
222 | link.layerName = 'Tool';
|
223 | tool.temporaryLink = link;
|
224 |
|
225 | const fromNode = new go.Node();
|
226 | const fromPort = new go.Shape();
|
227 | fromPort.portId = '';
|
228 | fromPort.figure = 'Rectangle';
|
229 | fromPort.fill = null;
|
230 | fromPort.stroke = 'magenta';
|
231 | fromPort.strokeWidth = 2;
|
232 | fromPort.desiredSize = new go.Size(1, 1);
|
233 | fromNode.add(fromPort);
|
234 | fromNode.selectable = false;
|
235 | fromNode.layerName = 'Tool';
|
236 | tool.temporaryFromNode = fromNode;
|
237 | tool.temporaryFromPort = fromPort;
|
238 |
|
239 | const toNode = new go.Node();
|
240 | const toPort = new go.Shape();
|
241 | toPort.portId = '';
|
242 | toPort.figure = 'Rectangle';
|
243 | toPort.fill = null;
|
244 | toPort.stroke = 'magenta';
|
245 | toPort.strokeWidth = 2;
|
246 | toPort.desiredSize = new go.Size(1, 1);
|
247 | toNode.add(toPort);
|
248 | toNode.selectable = false;
|
249 | toNode.layerName = 'Tool';
|
250 | tool.temporaryToNode = toNode;
|
251 | tool.temporaryToPort = toPort;
|
252 | }
|
253 |
|
254 | function setupRelinkingToolHandles(tool) {
|
255 | let h = new go.Shape();
|
256 | h.figure = 'Diamond';
|
257 | h.desiredSize = new go.Size(8, 8);
|
258 | h.fill = 'lightblue';
|
259 | h.stroke = 'dodgerblue';
|
260 | h.cursor = 'pointer';
|
261 | h.segmentIndex = 0;
|
262 | tool.fromHandleArchetype = h;
|
263 | h = new go.Shape();
|
264 | h.figure = 'Diamond';
|
265 | h.desiredSize = new go.Size(8, 8);
|
266 | h.fill = 'lightblue';
|
267 | h.stroke = 'dodgerblue';
|
268 | h.cursor = 'pointer';
|
269 | h.segmentIndex = -1;
|
270 | tool.toHandleArchetype = h;
|
271 | }
|
272 |
|
273 | function setupLinkReshapingToolHandles(tool) {
|
274 | let h = new go.Shape();
|
275 | h.figure = 'Rectangle';
|
276 | h.desiredSize = new go.Size(6, 6);
|
277 | h.fill = 'lightblue';
|
278 | h.stroke = 'dodgerblue';
|
279 | tool.handleArchetype = h;
|
280 | h = new go.Shape();
|
281 | h.figure = 'Diamond';
|
282 | h.desiredSize = new go.Size(8, 8);
|
283 | h.fill = 'lightblue';
|
284 | h.stroke = 'dodgerblue';
|
285 | h.cursor = 'move';
|
286 | tool.midHandleArchetype = h;
|
287 | }
|
288 |
|
289 | function setupResizingToolHandles(tool) {
|
290 | const h = new go.Shape();
|
291 | h.alignmentFocus = go.Spot.Center;
|
292 | h.figure = 'Rectangle';
|
293 | h.desiredSize = new go.Size(6, 6);
|
294 | h.fill = 'lightblue';
|
295 | h.stroke = 'dodgerblue';
|
296 | h.strokeWidth = 1;
|
297 | h.cursor = 'pointer';
|
298 | tool.handleArchetype = h;
|
299 | }
|
300 |
|
301 | function setupRotatingToolHandles(tool) {
|
302 | const h = new go.Shape();
|
303 | h.figure = 'Ellipse';
|
304 | h.desiredSize = new go.Size(8, 8);
|
305 | h.fill = 'lightblue';
|
306 | h.stroke = 'dodgerblue';
|
307 | h.strokeWidth = 1;
|
308 | h.cursor = 'pointer';
|
309 | tool.handleArchetype = h;
|
310 | }
|
311 |
|
312 | function setupDragSelectingToolBox(tool) {
|
313 | const b = new go.Part();
|
314 | b.layerName = 'Tool';
|
315 | b.selectable = false;
|
316 | const r = new go.Shape();
|
317 | r.name = 'SHAPE';
|
318 | r.figure = 'Rectangle';
|
319 | r.fill = null;
|
320 | r.stroke = 'magenta';
|
321 | b.add(r);
|
322 | tool.box = b;
|
323 | }
|