forked from NorthwoodsSoftware/GoJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplates.js
More file actions
384 lines (322 loc) · 10.7 KB
/
Copy pathTemplates.js
File metadata and controls
384 lines (322 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
"use strict";
/*
* Copyright (C) 1998-2018 by Northwoods Software Corporation. All Rights Reserved.
*/
// These are the definitions for all of the predefined templates and tool archetypes.
// You do not need to load this file in order to use the default templates and archetypes.
// Although we have tried to provide definitions here that are faithful to how they
// are actually implemented, there may be some differences from what is in the library.
// Caution: these may change in version 2.0.
// Set up the default templates that each Diagram starts off with.
function setupDiagramTemplates(diagram /* : go.Diagram */) {
// Node Templates
var nodeTemplateMap = new go.Map('string', go.Part);
// create the default Node template
var archnode = new go.Node();
var nodet = new go.TextBlock();
nodet.bind(new go.Binding('text', '', go.Binding.toString));
archnode.add(nodet);
nodeTemplateMap.add('', archnode);
// create the default Comment Node template
var archcmnt = new go.Node();
var nodec = new go.TextBlock();
nodec.stroke = 'brown';
nodec.bind(new go.Binding('text', '', go.Binding.toString));
archcmnt.add(nodec);
nodeTemplateMap.add('Comment', archcmnt);
// create the default Link Label Node template
var archllab = new go.Node();
archllab.selectable = false;
archllab.avoidable = false;
var nodel = new go.Shape();
nodel.figure = 'Ellipse';
nodel.fill = 'black';
nodel.stroke = null;
nodel.desiredSize = new go.Size(3, 3);
archllab.add(nodel);
nodeTemplateMap.add('LinkLabel', archllab);
diagram.nodeTemplateMap = nodeTemplateMap;
// Group Templates
var groupTemplateMap = new go.Map('string', go.Group);
// create the default Group template
var archgrp = new go.Group();
archgrp.selectionObjectName = 'GROUPPANEL';
archgrp.type = go.Panel.Vertical;
var grpt = new go.TextBlock();
grpt.font = 'bold 12pt sans-serif';
grpt.bind(new go.Binding('text', '', go.Binding.toString));
archgrp.add(grpt);
var grppan = new go.Panel(go.Panel.Auto);
grppan.name = 'GROUPPANEL';
var grpbord = new go.Shape();
grpbord.figure = 'Rectangle';
grpbord.fill = 'rgba(128,128,128,0.2)';
grpbord.stroke = 'black';
grppan.add(grpbord);
var phold = new go.Placeholder();
phold.padding = new go.Margin(5, 5, 5, 5);
grppan.add(phold);
archgrp.add(grppan);
groupTemplateMap.add('', archgrp);
diagram.groupTemplateMap = groupTemplateMap;
// Link Templates
var linkTemplateMap = new go.Map('string', go.Link);
// create the default Link template
var archlink = new go.Link();
var archpath = new go.Shape();
archpath.isPanelMain = true;
archlink.add(archpath);
var archarrow = new go.Shape();
archarrow.toArrow = 'Standard';
archarrow.fill = 'black';
archarrow.stroke = null;
archarrow.strokeWidth = 0;
archlink.add(archarrow);
linkTemplateMap.add('', archlink);
// create the default Comment Link template
var archcmntlink = new go.Link();
var archcmntpath = new go.Shape();
archcmntpath.isPanelMain = true;
archcmntpath.stroke = 'brown';
archcmntlink.add(archcmntpath);
linkTemplateMap.add('Comment', archcmntlink);
diagram.linkTemplateMap = linkTemplateMap;
}
// Set up the default Panel.itemTemplate.
function setupDefaultItemTemplate(panel /* : go.Panel */) {
var architem = new go.Panel();
var itemtxt = new go.TextBlock();
itemtxt.bind(new go.Binding('text', '', go.Binding.toString));
architem.add(itemtxt);
panel.itemTemplate = architem;
}
// Set up the diagram's selection Adornments
function setupSelectionAdornments(diagram /* : go.Diagram */) {
// create the default Adornment for selection
var selad = new go.Adornment();
selad.type = go.Panel.Auto;
var seladhandle = new go.Shape();
seladhandle.fill = null;
seladhandle.stroke = 'dodgerblue';
seladhandle.strokeWidth = 3;
selad.add(seladhandle);
var selplace = new go.Placeholder();
selplace.margin = new go.Margin(1.5, 1.5, 1.5, 1.5);
selad.add(selplace);
diagram.nodeSelectionAdornmentTemplate = selad;
// reuse the default Node Adornment for selection
diagram.groupSelectionAdornmentTemplate = selad;
// create the default Link Adornment for selection
selad = new go.Adornment();
selad.type = go.Panel.Link;
seladhandle = new go.Shape();
seladhandle.isPanelMain = true;
seladhandle.fill = null;
seladhandle.stroke = 'dodgerblue';
seladhandle.strokeWidth = 3; //?? zero to use selection object's strokeWidth is often not wide enough
selad.add(seladhandle);
diagram.linkSelectionAdornmentTemplate = selad;
}
// Set up the background Grid Panel.
function setupDefaultBackgroundGrid(diagram /* : go.Diagram */) {
var grid = new go.Panel(go.Panel.Grid);
grid.name = 'GRID';
var hlines = new go.Shape();
hlines.figure = 'LineH';
hlines.stroke = 'lightgray';
hlines.strokeWidth = 0.5;
hlines.interval = 1;
grid.add(hlines);
hlines = new go.Shape();
hlines.figure = 'LineH';
hlines.stroke = 'gray';
hlines.strokeWidth = 0.5;
hlines.interval = 5;
grid.add(hlines);
hlines = new go.Shape();
hlines.figure = 'LineH';
hlines.stroke = 'gray';
hlines.strokeWidth = 1;
hlines.interval = 10;
grid.add(hlines);
var vlines = new go.Shape();
vlines.figure = 'LineV';
vlines.stroke = 'lightgray';
vlines.strokeWidth = 0.5;
vlines.interval = 1;
grid.add(vlines);
vlines = new go.Shape();
vlines.figure = 'LineV';
vlines.stroke = 'gray';
vlines.strokeWidth = 0.5;
vlines.interval = 5;
grid.add(vlines);
vlines = new go.Shape();
vlines.figure = 'LineV';
vlines.stroke = 'gray';
vlines.strokeWidth = 1;
vlines.interval = 10;
grid.add(vlines);
grid.visible = false; // by default the grid is not visible
// Create the Part that holds the grid.
//var gridpart = new go.Part();
//gridpart.add(grid);
//gridpart.layerName = 'Grid'; // goes in the "Grid" layer
//gridpart.zOrder = 0; // to make it easier for other background parts to be behind the grid
//gridpart.isInDocumentBounds = false; // never part of the document bounds
//gridpart.isAnimated = false; // not animated
//gridpart.pickable = false; // user cannot pick it with mouse/touch/stylus
//gridpart.locationObjectName = 'GRID';
//diagram.add(gridpart);
// So then: diagram.grid === grid
// BUT, the gridpart is not actually in the Diagram.parts collection,
// and that Part cannot be replaced; so the above code is commented out.
// Instead, this works in an existing GoJS environment:
diagram.grid = grid;
}
// Set up the "viewport" box part that is the initial value of Overview.box.
function setupOverviewBox(overview /* : go.Overview */) {
var box = new go.Part();
var s = new go.Shape();
s.stroke = 'magenta';
s.strokeWidth = 2;
s.fill = 'transparent';
s.name = 'BOXSHAPE';
box.selectable = true;
box.selectionObjectName = 'BOXSHAPE';
box.locationObjectName = 'BOXSHAPE';
//box.resizable = true;
box.resizeObjectName = 'BOXSHAPE';
box.cursor = 'move';
box.add(s);
// only resize the bottom-right corner
var ad = new go.Adornment();
ad.type = go.Panel.Spot;
ad.locationSpot = go.Spot.Center;
var ph = new go.Placeholder();
ph.isPanelMain = true;
ad.add(ph);
var hnd = new go.Shape();
hnd.alignmentFocus = go.Spot.Center;
hnd.figure = 'Rectangle';
hnd.desiredSize = new go.Size(64, 64);
hnd.cursor = 'se-resize';
hnd.alignment = go.Spot.BottomRight;
ad.add(hnd);
box.resizeAdornmentTemplate = ad;
overview.box = box;
}
// Set up LinkingBaseTool's default temporary nodes and link.
function setupLinkingToolTemporaryNodesAndLink(tool /* : go.LinkingBaseTool */) {
// LinkingTool.temporaryLink
var link = new go.Link();
var path = new go.Shape();
path.isPanelMain = true;
path.stroke = 'blue';
link.add(path);
var arrow = new go.Shape();
arrow.toArrow = 'Standard';
arrow.fill = 'blue';
arrow.stroke = 'blue';
link.add(arrow);
link.layerName = 'Tool';
tool.temporaryLink = link;
// LinkingTool.temporaryFromNode and .temporaryFromPort
var fromNode = new go.Node();
var fromPort = new go.Shape();
fromPort.portId = '';
fromPort.figure = 'Rectangle';
fromPort.fill = null;
fromPort.stroke = 'magenta';
fromPort.strokeWidth = 2;
fromPort.desiredSize = new go.Size(1, 1);
fromNode.add(fromPort);
fromNode.selectable = false;
fromNode.layerName = 'Tool';
tool.temporaryFromNode = fromNode;
tool.temporaryFromPort = fromPort;
// LinkingTool.temporaryToNode and .temporaryToPort
var toNode = new go.Node();
var toPort = new go.Shape();
toPort.portId = '';
toPort.figure = 'Rectangle';
toPort.fill = null;
toPort.stroke = 'magenta';
toPort.strokeWidth = 2;
toPort.desiredSize = new go.Size(1, 1);
toNode.add(toPort);
toNode.selectable = false;
toNode.layerName = 'Tool';
tool.temporaryToNode = toNode;
tool.temporaryToPort = toPort;
}
// Set up RelinkingTool's default handle archetypes
function setupRelinkingToolHandles(tool /* : go.RelinkingTool */) {
var h = new go.Shape();
h.figure = 'Diamond';
h.desiredSize = new go.Size(8, 8);
h.fill = 'lightblue';
h.stroke = 'dodgerblue';
h.cursor = 'pointer';
h.segmentIndex = 0;
tool.fromHandleArchetype = h;
h = new go.Shape();
h.figure = 'Diamond';
h.desiredSize = new go.Size(8, 8);
h.fill = 'lightblue';
h.stroke = 'dodgerblue';
h.cursor = 'pointer';
h.segmentIndex = -1;
tool.toHandleArchetype = h;
}
// Set up LinkReshapingTool's default handle archetypes
function setupLinkReshapingToolHandles(tool /* : go.LinkReshapingTool */) {
var h = new go.Shape();
h.figure = 'Rectangle';
h.desiredSize = new go.Size(6, 6);
h.fill = 'lightblue';
h.stroke = 'dodgerblue';
tool.handleArchetype = h;
h = new go.Shape();
h.figure = 'Diamond';
h.desiredSize = new go.Size(6, 6);
h.fill = 'lightblue';
h.stroke = 'dodgerblue';
tool.midHandleArchetype = h;
}
// Set up ResizingTool's default handle archetype
function setupResizingToolHandles(tool /* : go.ResizingTool */) {
var h = new go.Shape();
h.alignmentFocus = go.Spot.Center;
h.figure = 'Rectangle';
h.desiredSize = new go.Size(6, 6);
h.fill = 'lightblue';
h.stroke = 'dodgerblue';
h.strokeWidth = 1;
h.cursor = 'pointer';
tool.handleArchetype = h;
}
// Set up RotatingTool's default handle archetype
function setupRotatingToolHandles(tool /* : go.RotatingTool */) {
var h = new go.Shape();
h.figure = 'Ellipse';
h.desiredSize = new go.Size(8, 8);
h.fill = 'lightblue';
h.stroke = 'dodgerblue';
h.strokeWidth = 1;
h.cursor = 'pointer';
tool.handleArchetype = h;
}
// Set up DragSelectingTool's default box
function setupDragSelectingToolBox(tool /* : go.DragSelectingTool */) {
var b = new go.Part();
b.layerName = 'Tool';
b.selectable = false;
var r = new go.Shape();
r.name = 'SHAPE';
r.figure = 'Rectangle';
r.fill = null;
r.stroke = 'magenta';
b.add(r);
tool.box = b;
}