| 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 | 1×
1×
1×
1×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
84×
1×
1×
14×
14×
1×
16×
2×
1×
2×
2×
2×
2×
2×
2×
1×
2×
2×
2×
1×
82×
1×
82×
82×
82×
62×
62×
62×
82×
1×
82×
1×
82×
82×
2×
82×
1×
1×
| define(["require", "exports", "../../enum/enum", "../../primitives/size", "../../primitives/rect", "../../utility/base-util"], function (require, exports, enum_1, size_1, rect_1, base_util_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* DiagramElement module defines the basic unit of diagram
*/
var DrawingElement = /** @class */ (function () {
function DrawingElement() {
/**
* Sets/Gets the reference point of the element
* ```html
* <div id='diagram'></div>
* ```
* ```typescript
* let stackPanel: StackPanel = new StackPanel();
* stackPanel.offsetX = 300; stackPanel.offsetY = 200;
* stackPanel.width = 100; stackPanel.height = 100;
* stackPanel.style.fill = 'red';
* stackPanel.pivot = { x: 0.5, y: 0.5 };
* let diagram: Diagram = new Diagram({
* ...
* basicElements: [stackPanel],
* ...
* });
* diagram.appendTo('#diagram');
* ```
*/
this.pivot = { x: 0.5, y: 0.5 };
this.rotateValue = { x: 0, y: 0, angle: 0 };
/**
* Sets or gets whether the content of the element needs to be measured
*/
this.isDirt = true;
/**
* Sets/Gets the x-coordinate of the element
*/
this.offsetX = 0;
/**
* Sets/Gets the y-coordinate of the element
*/
this.offsetY = 0;
/**
* Set the corner of the element
*/
this.cornerRadius = 0;
/**
* Sets/Gets the minimum height of the element
*/
this.minHeight = undefined;
/**
* Sets/Gets the minimum width of the element
*/
this.minWidth = undefined;
/**
* Sets/Gets the maximum width of the element
*/
this.maxWidth = undefined;
/**
* Sets/Gets the maximum height of the element
*/
this.maxHeight = undefined;
/**
* Sets/Gets the width of the element
*/
this.width = undefined;
/**
* Sets/Gets the height of the element
*/
this.height = undefined;
/**
* Sets/Gets how the element has to be horizontally arranged with respect to its immediate parent
* * Stretch - Stretches the diagram element throughout its immediate parent
* * Left - Aligns the diagram element at the left of its immediate parent
* * Right - Aligns the diagram element at the right of its immediate parent
* * Center - Aligns the diagram element at the center of its immediate parent
* * Auto - Aligns the diagram element based on the characteristics of its immediate parent
*/
this.horizontalAlignment = 'Auto';
/**
* Sets/Gets how the element has to be vertically arranged with respect to its immediate parent
* * Stretch - Stretches the diagram element throughout its immediate parent
* * Top - Aligns the diagram element at the top of its immediate parent
* * Bottom - Aligns the diagram element at the bottom of its immediate parent
* * Center - Aligns the diagram element at the center of its immediate parent
* * Auto - Aligns the diagram element based on the characteristics of its immediate parent
*/
this.verticalAlignment = 'Auto';
/**
* Sets or gets whether the content of the element to be visible
*/
this.visible = true;
/**
* Sets/Gets the rotate angle of the element
*/
this.rotateAngle = 0;
/**
* Sets/Gets the margin of the element
*/
this.margin = { left: 0, right: 0, top: 0, bottom: 0 };
/**
* Sets whether the element has to be aligned with respect to a point/with respect to its immediate parent
* * Point - Diagram elements will be aligned with respect to a point
* * Object - Diagram elements will be aligned with respect to its immediate parent
*/
this.relativeMode = 'Point';
/**
* Sets whether the element has to be transformed based on its parent or not
* * Self - Sets the transform type as Self
* * Parent - Sets the transform type as Parent
*/
/** @private */
this.transform = enum_1.RotateTransform.Self | enum_1.RotateTransform.Parent;
/**
* Sets the style of the element
*/
this.style = { fill: 'white', strokeColor: 'black', opacity: 1, strokeWidth: 1 };
/**
* Gets the minimum size that is required by the element
*/
this.desiredSize = new size_1.Size();
/**
* Gets the size that the element will be rendered
*/
this.actualSize = new size_1.Size();
/**
* Gets the rotate angle that is set to the immediate parent of the element
*/
this.parentTransform = 0;
/** @private */
this.preventContainer = false;
/**
* Gets/Sets the boundary of the element
*/
this.bounds = new rect_1.Rect(0, 0, 0, 0);
/**
* Defines whether the element has to be measured or not
*/
this.staticSize = false;
/**
* check whether the element is rect or not
*/
/** @private */
this.isRectElement = false;
/** @private */
this.isCalculateDesiredSize = true;
/**
* Defines whether the element is group or port
*/
/** @private */
this.elementActions = enum_1.ElementAction.None;
//private variables
this.position = undefined;
this.unitMode = undefined;
/** @private */
this.float = false;
this.floatingBounds = undefined;
}
// public constructor() {
// this.id = randomId();
// }
/**
* Sets the offset of the element with respect to its parent
* @param x
* @param y
* @param mode
*/
DrawingElement.prototype.setOffsetWithRespectToBounds = function (x, y, mode) {
this.unitMode = mode;
this.position = { x: x, y: y };
};
/**
* Gets the position of the element with respect to its parent
* @param size
*/
DrawingElement.prototype.getAbsolutePosition = function (size) {
Iif (this.position !== undefined) {
if (this.unitMode === 'Absolute') {
return this.position;
}
else {
return {
x: this.position.x * size.width, y: this.position.y * size.height
};
}
}
return undefined;
};
Object.defineProperty(DrawingElement.prototype, "outerBounds", {
get: function () {
return this.floatingBounds || this.bounds;
},
/**
* used to set the outer bounds value
* @private
*/
set: function (bounds) {
this.floatingBounds = bounds;
},
enumerable: true,
configurable: true
});
/**
* Measures the minimum space that the element requires
* @param availableSize
*/
DrawingElement.prototype.measure = function (availableSize) {
var width = this.width !== undefined ? this.width : (availableSize.width || 0) - this.margin.left - this.margin.right;
var height = this.height !== undefined ? this.height : (availableSize.height || 0) - this.margin.top - this.margin.bottom;
this.desiredSize = new size_1.Size(width, height);
Eif (this.isCalculateDesiredSize) {
this.desiredSize = this.validateDesiredSize(this.desiredSize, availableSize);
}
return this.desiredSize;
};
/**
* Arranges the element
* @param desiredSize
*/
DrawingElement.prototype.arrange = function (desiredSize) {
this.actualSize = desiredSize;
this.updateBounds();
return this.actualSize;
};
/**
* Updates the bounds of the element
*/
DrawingElement.prototype.updateBounds = function () {
this.bounds = base_util_1.getBounds(this);
};
/**
* Validates the size of the element with respect to its minimum and maximum size
* @param desiredSize
* @param availableSize
*/
DrawingElement.prototype.validateDesiredSize = function (desiredSize, availableSize) {
//Empty canvas
Iif (this.isRectElement && !this.width && !this.minWidth && !this.maxWidth) {
desiredSize.width = 50;
}
Iif (this.isRectElement && !this.height && !this.minHeight && !this.maxHeight) {
desiredSize.height = 50;
}
if (desiredSize === undefined || this.width !== undefined &&
this.height !== undefined) {
desiredSize = desiredSize || new size_1.Size();
desiredSize.width = this.width === undefined ? (availableSize.width || 0)
- this.margin.left - this.margin.right : this.width;
desiredSize.height = this.height === undefined ? (availableSize.height || 0)
- this.margin.top - this.margin.bottom : this.height;
}
//Considering min values
if (this.minWidth !== undefined) {
desiredSize.width = Math.max(desiredSize.width, this.minWidth);
}
if (this.minHeight !== undefined) {
desiredSize.height = Math.max(desiredSize.height, this.minHeight);
}
//Considering max values
Iif (this.maxWidth !== undefined) {
desiredSize.width = Math.min(desiredSize.width, this.maxWidth);
}
if (this.maxHeight !== undefined) {
desiredSize.height = Math.min(desiredSize.height, this.maxHeight);
}
return desiredSize;
};
return DrawingElement;
}());
exports.DrawingElement = DrawingElement;
});
|