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
385
386
387
388
389
390
391
392
393
394
395
396
397 | 1×
1×
1×
78×
78×
78×
78×
60×
60×
60×
60×
23×
9×
9×
9×
9×
9×
9×
8×
1×
1×
1×
1×
1×
23×
23×
60×
78×
1×
1×
100×
100×
81×
81×
81×
81×
81×
81×
30×
6×
5×
5×
5×
5×
5×
5×
5×
5×
5×
2×
2×
5×
81×
1×
1×
90×
90×
90×
230×
90×
1×
1×
101×
101×
101×
1111×
1111×
101×
101×
101×
101×
101×
101×
1×
1×
2476×
2476×
2476×
2476×
2476×
2476×
481×
1995×
1982×
1501×
1501×
481×
481×
1982×
1982×
101×
101×
101×
2476×
2476×
1×
1×
11064×
11064×
1698×
9366×
1×
1×
35×
35×
35×
28×
28×
35×
35×
11×
11×
1×
1×
34×
18×
18×
14×
14×
14×
14×
14×
14×
40×
40×
14×
24×
14×
14×
18×
1×
38×
37×
37×
37×
37×
37×
32×
32×
32×
32×
5×
2×
2×
2×
2×
37×
37×
6×
37×
29×
29×
23×
29×
29×
29×
29×
22×
22×
22×
22×
22×
64×
22×
12×
22×
29×
29×
29×
7×
22×
20×
29×
22×
22×
37×
1×
1×
34×
34×
34×
34×
34×
1×
30×
30×
30×
30×
30×
30×
30×
30×
9×
9×
9×
9×
9×
5×
5×
5×
9×
5×
5×
5×
9×
9×
6×
6×
9×
9×
9×
9×
9×
9×
9×
7×
9×
9×
9×
9×
30×
30×
30×
1×
1×
40×
40×
1×
1×
56×
56×
56×
56×
1×
1×
1×
1×
56×
2×
2×
2×
2×
2×
2×
2×
2×
1×
| define(["require", "exports", "@syncfusion/ej2-base", "../objects/node", "../diagram", "../objects/node", "../primitives/size", "./../utility/base-util", "./../utility/diagram-util", "../primitives/rect", "../utility/dom-util", "../utility/swim-lane-util", "../utility/swim-lane-util", "../utility/swim-lane-util", "../enum/enum", "../utility/dom-util"], function (require, exports, ej2_base_1, node_1, diagram_1, node_2, size_1, base_util_1, diagram_util_1, rect_1, dom_util_1, swim_lane_util_1, swim_lane_util_2, swim_lane_util_3, enum_1, dom_util_2) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function updateCanvasBounds(diagram, obj, position, isBoundsUpdate) {
var container;
var connectorList = [];
var groupAction = false;
if (checkParentAsContainer(diagram, obj, true)) {
diagram.protectPropertyChange(true);
container = diagram.nameTable[obj.parentId];
var wrapper = container.wrapper;
if (container && container.container.type === 'Canvas') {
if ((isBoundsUpdate || (wrapper.bounds.x <= position.x && wrapper.bounds.right >= position.x &&
(wrapper.bounds.y <= position.y && wrapper.bounds.bottom >= position.y)))) {
var parentWrapper = void 0;
var y = wrapper.bounds.y;
var x = wrapper.bounds.x;
var parent_1 = diagram.nameTable[container.parentId] || container;
var shape = parent_1.shape;
if (shape.type === 'SwimLane') {
groupAction = updateLaneBoundsAfterAddChild(container, parent_1, obj, diagram, true);
}
else {
var parent_2 = diagram.nameTable[container.parentId] || container;
var shape_1 = parent_2.shape;
parentWrapper = parent_2.wrapper;
Iif (wrapper.actualSize.width < wrapper.outerBounds.width &&
(!(wrapper.bounds.x > wrapper.outerBounds.x))) {
if (container.rowIndex !== undefined) {
parentWrapper.updateColumnWidth(container.columnIndex, wrapper.outerBounds.width, true);
if (shape_1.orientation === 'Horizontal' && shape_1.phaseSize) {
swim_lane_util_2.updatePhaseMaxWidth(parent_2, diagram, wrapper, container.columnIndex);
}
swim_lane_util_2.updateHeaderMaxWidth(diagram, parent_2);
diagram.drag(parent_2, x - wrapper.bounds.x, y - wrapper.bounds.y);
}
else {
diagram.scale(container, (1 + ((wrapper.outerBounds.width - wrapper.actualSize.width) / wrapper.actualSize.width)), 1, ((wrapper.outerBounds.x < wrapper.bounds.x) ? { x: 1, y: 0.5 } : { x: 0, y: 0.5 }));
}
}
Iif (wrapper.actualSize.height < wrapper.outerBounds.height &&
(!(wrapper.bounds.y > wrapper.outerBounds.y))) {
if (container.rowIndex !== undefined) {
parentWrapper.updateRowHeight(container.rowIndex, wrapper.outerBounds.height, true);
diagram.drag(parent_2, x - wrapper.bounds.x, y - wrapper.bounds.y);
}
else {
diagram.scale(container, 1, (1 + ((wrapper.outerBounds.height - wrapper.actualSize.height) / wrapper.actualSize.height)), ((wrapper.outerBounds.y < wrapper.bounds.y) ? { x: 0.5, y: 1 } : { x: 0.5, y: 0 }));
}
}
}
}
diagram.select([obj]);
swim_lane_util_2.updateConnectorsProperties(connectorList, diagram);
}
diagram.protectPropertyChange(false);
}
return groupAction;
}
exports.updateCanvasBounds = updateCanvasBounds;
function removeChildInContainer(diagram, obj, position, isBoundsUpdate) {
var container;
if (checkParentAsContainer(diagram, obj, true)) {
var isProtectedOnChange = 'isProtectedOnChange';
var propertyChangeValue = diagram["" + isProtectedOnChange];
diagram.protectPropertyChange(true);
container = diagram.nameTable[obj.parentId];
var wrapper = container.wrapper;
if (container && container.container.type === 'Canvas') {
if ((!isBoundsUpdate && (!(wrapper.bounds.x <= position.x && wrapper.bounds.right >= position.x &&
(wrapper.bounds.y <= position.y && wrapper.bounds.bottom >= position.y))))) {
if (!(obj.constraints & enum_1.NodeConstraints.AllowMovingOutsideLane)) {
var undoObj = base_util_1.cloneObject(obj);
diagram.clearSelection();
removeChildrenInLane(diagram, obj);
obj.parentId = '';
obj.parentObj = diagram;
obj.propName = 'nodes';
var entry = {
type: 'ChildCollectionChanged', category: 'Internal',
undoObject: undoObj, redoObject: base_util_1.cloneObject(obj)
};
diagram.addHistoryEntry(entry);
if (diagram.commandHandler.isContainer) {
diagram.commandHandler.isContainer = false;
diagram.endGroupAction();
}
moveSwinLaneChild(obj, diagram);
}
}
}
diagram.protectPropertyChange(propertyChangeValue);
}
}
exports.removeChildInContainer = removeChildInContainer;
function findBounds(obj, columnIndex, isHeader) {
var rect = new rect_1.Rect();
var rows = (obj.shape.type === 'SwimLane') ?
obj.wrapper.children[0].rows : obj.wrapper.rows;
for (var i = ((isHeader) ? 1 : 0); i < rows.length; i++) {
rect.uniteRect(rows[parseInt(i.toString(), 10)].cells[parseInt(columnIndex.toString(), 10)].bounds);
}
return rect;
}
exports.findBounds = findBounds;
function createHelper(diagram, obj) {
var newObj;
var cloneObject = {};
for (var _i = 0, _a = Object.keys(obj); _i < _a.length; _i++) {
var prop = _a[_i];
cloneObject["" + prop] = obj["" + prop];
}
Eif (diagram_util_1.getObjectType(obj) === node_1.Node) {
newObj = new node_1.Node(diagram, 'nodes', cloneObject, true);
newObj.id = obj.id;
diagram.initObject(newObj);
}
diagram.updateDiagramObject(newObj);
return newObj;
}
exports.createHelper = createHelper;
function renderContainerHelper(diagram, obj) {
diagram.enableServerDataBinding(false);
var object;
var container;
var nodes;
Eif (!ej2_base_1.isBlazor()) {
if (diagram.selectedObject.helperObject) {
nodes = diagram.selectedObject.helperObject;
}
else if (diagram.selectedItems.nodes.length > 0 || diagram.selectedItems.connectors.length > 0) {
if (obj instanceof node_2.Selector && obj.nodes.length + obj.connectors.length === 1) {
object = (obj.nodes.length > 0) ? obj.nodes[0] : obj.connectors[0];
container = diagram.selectedItems.wrapper.children[0];
}
else {
object = obj;
container = diagram.selectedItems.wrapper;
}
diagram.selectedObject.actualObject = object;
if ((!diagram.currentSymbol) && (((object.isLane && swim_lane_util_1.canLaneInterchange(object, diagram) &&
checkParentAsContainer(diagram, object))
|| ((!object.isLane) && checkParentAsContainer(diagram, object))) ||
((diagram.constraints & enum_1.DiagramConstraints.LineRouting) && diagram.selectedItems.nodes.length > 0))) {
var node = {
id: 'helper',
rotateAngle: container.rotateAngle,
offsetX: container.offsetX, offsetY: container.offsetY,
minWidth: container.minWidth, minHeight: container.minHeight,
maxWidth: container.maxWidth, maxHeight: container.maxHeight,
width: container.actualSize.width,
height: container.actualSize.height,
style: { strokeDashArray: '2 2', fill: 'transparent', strokeColor: '#7D7D7D', strokeWidth: 2 }
};
nodes = createHelper(diagram, node);
diagram.selectedObject.helperObject = nodes;
}
}
}
diagram.enableServerDataBinding(true);
return nodes;
}
exports.renderContainerHelper = renderContainerHelper;
function checkParentAsContainer(diagram, obj, isChild) {
var parentNode = (isChild) ? diagram.nameTable[obj.parentId] :
(diagram.nameTable[obj.parentId] || obj);
if (parentNode && parentNode.container) {
return true;
}
return false;
}
exports.checkParentAsContainer = checkParentAsContainer;
function checkChildNodeInContainer(diagram, obj) {
var parentNode = diagram.nameTable[obj.parentId];
obj.laneMargin = { left: obj.margin.left, right: obj.margin.right, top: obj.margin.top, bottom: obj.margin.bottom };
if (parentNode.container.type === 'Canvas') {
obj.margin.left = (obj.offsetX - parentNode.wrapper.bounds.x - (obj.width / 2));
obj.margin.top = (obj.offsetY - parentNode.wrapper.bounds.y - (obj.height / 2));
}
diagram.nodePropertyChange(obj, {}, {
width: obj.width, height: obj.height,
offsetX: obj.offsetX, offsetY: obj.offsetY,
margin: {
left: obj.margin.left,
right: obj.margin.right, top: obj.margin.top,
bottom: obj.margin.bottom
}, rotateAngle: obj.rotateAngle
});
if (!parentNode.isLane) {
parentNode.wrapper.measure(new size_1.Size());
parentNode.wrapper.arrange(parentNode.wrapper.desiredSize);
}
}
exports.checkChildNodeInContainer = checkChildNodeInContainer;
function removeChildrenInLane(diagram, node) {
if (node.parentId && node.parentId !== '') {
var prevParentNode = diagram.nameTable[node.parentId];
if (prevParentNode.isLane && prevParentNode.parentId) {
var swimlane = diagram.nameTable[prevParentNode.parentId];
var canvasId = (prevParentNode.id.slice(swimlane.id.length));
var prevParentId = canvasId.substring(0, canvasId.length - 1);
var lanes = swimlane.shape.lanes;
var lane = void 0;
for (var i = 0; i < lanes.length; i++) {
lane = lanes[parseInt(i.toString(), 10)];
if (prevParentId === lane.id) {
for (var j = 0; j < lane.children.length; j++) {
if (lane.children[parseInt(j.toString(), 10)].id === node.id) {
lane.children.splice(j, 1);
j--;
}
}
}
}
}
diagram.deleteChild(node);
}
}
function addChildToContainer(diagram, parent, node, isUndo, historyAction) {
if (!diagram.currentSymbol) {
diagram.protectPropertyChange(true);
var swimlane = diagram.nameTable[parent.parentId];
node = diagram.getObject(node.id) || node;
var child = (diagram.nodes.indexOf(node) !== -1) ? node.id : node;
if (parent.container.type === 'Canvas' && !historyAction) {
var left = (node.wrapper.offsetX - node.wrapper.actualSize.width / 2) -
(parent.wrapper.offsetX - parent.wrapper.actualSize.width / 2);
var top_1 = (node.wrapper.offsetY - node.wrapper.actualSize.height / 2) -
(parent.wrapper.offsetY - parent.wrapper.actualSize.height / 2);
node.margin.left = left;
node.margin.top = top_1;
}
else if (swimlane) {
var swimLaneBounds = swimlane.wrapper.bounds;
var parentBounds = parent.wrapper.bounds;
Eif (swimlane.shape.orientation === 'Horizontal') {
node.margin.left -= parentBounds.x - swimLaneBounds.x;
}
else {
var laneHeaderId = parent.parentId + swimlane.shape.lanes[0].id + '_0_header';
node.margin.top -= parentBounds.y - swimLaneBounds.y - diagram.nameTable["" + laneHeaderId].wrapper.bounds.height;
}
}
var container = diagram.nameTable[parent.id];
if (!container.children) {
container.children = [];
}
if (container.children.indexOf(node.id) === -1) {
removeChildrenInLane(diagram, node);
if (diagram.getObject(node.id)) {
diagram.removeElements(node);
}
var undoObj = base_util_1.cloneObject(node);
diagram.addChild(container, child);
node = diagram.getObject(node.id);
if (container.isLane && container.parentId) {
swimlane = diagram.nameTable[container.parentId];
var lanes = swimlane.shape.lanes;
var canvasId = (container.id.slice(swimlane.id.length));
var currentParentId = canvasId.substring(0, canvasId.length - 1);
for (var i = 0; i < lanes.length; i++) {
if (container.isLane && currentParentId === lanes[parseInt(i.toString(), 10)].id) {
if (!(node.parentObj instanceof diagram_1.Diagram)) {
node.parentObj = lanes[parseInt(i.toString(), 10)];
}
Iif (!diagram.nameTable.hasOwnProperty(node.id)) {
lanes[parseInt(i.toString(), 10)].children.push(node);
}
}
}
}
diagram.updateDiagramObject(node);
moveSwinLaneChild(node, diagram);
if (!container.parentId) {
diagram.updateDiagramObject(container);
}
else if (!isUndo) {
updateLaneBoundsAfterAddChild(container, swimlane, node, diagram);
}
if (!(diagram.diagramActions & enum_1.DiagramAction.UndoRedo)) {
var entry = {
type: 'ChildCollectionChanged', category: 'Internal',
undoObject: undoObj, redoObject: base_util_1.cloneObject(node), historyAction: historyAction ? 'AddNodeToLane' : undefined
};
diagram.addHistoryEntry(entry);
}
}
diagram.protectPropertyChange(false);
}
}
exports.addChildToContainer = addChildToContainer;
function moveSwinLaneChild(node, diagram) {
var sourceNode = dom_util_2.getDiagramElement(node.id + '_groupElement', diagram.element.id);
var targetId = (node.parentId) ? node.parentId + '_groupElement' : diagram.element.id + '_diagramLayer';
var targetNode = dom_util_2.getDiagramElement(targetId, diagram.element.id);
Eif (sourceNode && targetNode) {
targetNode.appendChild(sourceNode);
}
}
function updateLaneBoundsAfterAddChild(container, swimLane, node, diagram, isBoundsUpdate) {
var undoObject = base_util_1.cloneObject(container);
var isUpdateRow;
var isGroupAction = false;
var padding = swimLane.shape.padding;
var containerBounds = container.wrapper.bounds;
var containerOuterBounds = container.wrapper.outerBounds;
var nodeBounds = node.wrapper.bounds;
if (swimLane && swimLane.shape.type === 'SwimLane' &&
(containerBounds.right < nodeBounds.right + padding ||
containerBounds.bottom < nodeBounds.bottom + padding)) {
var grid = swimLane.wrapper.children[0];
var x = grid.bounds.x;
var y = grid.bounds.y;
var size = void 0;
if (containerBounds.right < nodeBounds.right + padding &&
containerOuterBounds.x <= containerBounds.x) {
size = nodeBounds.right - containerBounds.right;
isUpdateRow = false;
grid.updateColumnWidth(container.columnIndex, containerBounds.width + size, true, padding);
}
if (containerBounds.bottom < nodeBounds.bottom + padding &&
containerOuterBounds.y <= containerBounds.y) {
size = nodeBounds.bottom - containerBounds.bottom;
isUpdateRow = true;
grid.updateRowHeight(container.rowIndex, containerBounds.height + size, true, padding);
}
Eif (!(diagram.diagramActions & enum_1.DiagramAction.UndoRedo)) {
if (isBoundsUpdate) {
diagram.startGroupAction();
isGroupAction = true;
}
Eif (isUpdateRow !== undefined) {
var entry = {
category: 'Internal',
type: (isUpdateRow) ? 'RowHeightChanged' : 'ColumnWidthChanged',
undoObject: undoObject, redoObject: base_util_1.cloneObject(container)
};
diagram.addHistoryEntry(entry);
}
}
swimLane.width = swimLane.wrapper.width = grid.width;
swimLane.height = swimLane.wrapper.height = grid.height;
swim_lane_util_1.swimLaneMeasureAndArrange(swimLane);
if (swimLane.shape.orientation === 'Horizontal') {
swim_lane_util_2.updatePhaseMaxWidth(swimLane, diagram, container.wrapper, container.columnIndex);
}
swim_lane_util_2.updateHeaderMaxWidth(diagram, swimLane);
diagram.drag(swimLane, x - grid.bounds.x, y - grid.bounds.y);
swim_lane_util_1.checkPhaseOffset(swimLane, diagram);
swim_lane_util_1.checkLaneSize(swimLane);
}
swim_lane_util_3.considerSwimLanePadding(diagram, node, padding);
diagram.updateDiagramElementQuad();
return isGroupAction;
}
exports.updateLaneBoundsAfterAddChild = updateLaneBoundsAfterAddChild;
function renderStackHighlighter(element, isVertical, position, diagram, isUml, isSwimlane) {
var adornerSvg = dom_util_1.getAdornerLayerSvg(diagram.element.id);
diagram.diagramRenderer.renderStackHighlighter(element, adornerSvg, diagram.scroller.transform, isVertical, position, isUml, isSwimlane);
}
exports.renderStackHighlighter = renderStackHighlighter;
function moveChildInStack(sourceNode, target, diagram, action) {
var obj = sourceNode;
var parent = diagram.nameTable[obj.parentId];
var sourceParent = diagram.nameTable[obj.parentId];
if (target && sourceParent && sourceParent.container && sourceParent.container.type === 'Stack' &&
target.container && target.container.type === 'Stack' && (sourceParent.id !== target.parentId)) {
var value = sourceParent.wrapper.children.indexOf(obj.wrapper);
Eif (value > -1) {
diagram.nameTable[obj.id].parentId = target.id;
sourceParent.wrapper.children.splice(value, 1);
}
}
if (target && target.parentId && obj.parentId && action === 'Drag' &&
sourceParent.container && sourceParent.container.type === 'Stack') {
var targetIndex = parent.wrapper.children.indexOf(target.wrapper);
var sourceIndex = parent.wrapper.children.indexOf(obj.wrapper);
var undoElement = {
targetIndex: targetIndex, target: target,
sourceIndex: sourceIndex, source: sourceNode
};
parent.wrapper.children.splice(sourceIndex, 1);
parent.wrapper.children.splice(targetIndex, 0, obj.wrapper);
var redoElement = {
targetIndex: sourceIndex, target: target,
sourceIndex: targetIndex, source: sourceNode
};
var entry = {
type: 'StackChildPositionChanged', redoObject: redoElement,
undoObject: undoElement, category: 'Internal'
};
diagram.commandHandler.addHistoryEntry(entry);
}
}
exports.moveChildInStack = moveChildInStack;
});
|