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 | 1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-drawings", "./drawing-util", "@syncfusion/ej2-base"], function (require, exports, ej2_drawings_1, drawing_util_1, ej2_base_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function getConnectorPoints(obj, points) {
points = obj.vertexPoints;
var newPoints = points.slice(0);
if (newPoints && newPoints.length > 0) {
obj.sourcePoint = newPoints[0];
obj.targetPoint = newPoints[newPoints.length - 1];
}
return newPoints;
}
exports.getConnectorPoints = getConnectorPoints;
function getSegmentPath(connector, points) {
var path = '';
var getPt;
var pts = [];
var j = 0;
while (j < points.length) {
pts.push({ x: points[parseInt(j.toString(), 10)].x, y: points[parseInt(j.toString(), 10)].y });
j++;
}
pts = clipDecorators(connector, pts);
for (var k = 0; k < pts.length; k++) {
getPt = pts[parseInt(k.toString(), 10)];
if (k === 0) {
path = 'M' + getPt.x + ' ' + getPt.y;
}
if (k > 0) {
path += ' ' + 'L' + getPt.x + ' ' + getPt.y;
}
}
return path;
}
exports.getSegmentPath = getSegmentPath;
function updateSegmentElement(connector, points, element) {
var bounds = new ej2_drawings_1.Rect();
var segmentPath = getSegmentPath(connector, points);
bounds = ej2_drawings_1.Rect.toBounds(points);
element.width = bounds.width;
element.height = bounds.height;
element.offsetX = bounds.x + element.width / 2;
element.offsetY = bounds.y + element.height / 2;
element.data = segmentPath;
if (connector.wrapper) {
connector.wrapper.offsetX = element.offsetX;
connector.wrapper.offsetY = element.offsetY;
var boundsValue = bounds.width;
if (bounds.width < bounds.height) {
boundsValue = bounds.height;
}
else {
boundsValue = bounds.width;
}
connector.wrapper.width = connector.enableShapeLabel ? boundsValue / 2 : boundsValue;
connector.wrapper.height = bounds.height;
}
return element;
}
exports.updateSegmentElement = updateSegmentElement;
function getSegmentElement(connector, segmentElement) {
var points = [];
points = getConnectorPoints(connector);
segmentElement.staticSize = true;
segmentElement = updateSegmentElement(connector, points, segmentElement);
drawing_util_1.setElementStype(connector, segmentElement);
return segmentElement;
}
exports.getSegmentElement = getSegmentElement;
function updateDecoratorElement(obj, element, pt, adjacentPoint, isSource) {
element.offsetX = pt.x;
element.offsetY = pt.y;
var angle = ej2_drawings_1.Point.findAngle(pt, adjacentPoint);
var getPath = getDecoratorShape(isSource ? obj.sourceDecoraterShapes : obj.taregetDecoraterShapes);
var thickness = 0;
var size;
if (obj.shapeAnnotationType === 'LineWidthArrowHead' || obj.shapeAnnotationType === 'Line') {
thickness = obj.thickness;
size = new ej2_drawings_1.Size(thickness * 12, thickness * 12);
}
else {
thickness = obj.thickness <= 5 ? 5 : obj.thickness;
size = new ej2_drawings_1.Size(thickness * 2, thickness * 2);
}
element.transform = ej2_drawings_1.RotateTransform.Self;
drawing_util_1.setElementStype(obj, element);
element.style.fill = (obj.fillColor !== 'tranparent') ? obj.fillColor : 'white';
element.rotateAngle = angle;
element.data = getPath;
element.canMeasurePath = true;
element.width = size.width;
element.height = size.height;
if (obj.sourceDecoraterShapes === 'Butt') {
element.width = size.width - 10;
element.height = size.height + 10;
}
}
exports.updateDecoratorElement = updateDecoratorElement;
function getDecoratorElement(obj, offsetPoint, adjacentPoint, isSource) {
var decEle = new ej2_drawings_1.PathElement();
updateDecoratorElement(obj, decEle, offsetPoint, adjacentPoint, isSource);
return decEle;
}
exports.getDecoratorElement = getDecoratorElement;
function clipDecorators(connector, pts) {
pts[0] = clipDecorator(connector, pts, true);
pts[pts.length - 1] = clipDecorator(connector, pts, false);
return pts;
}
exports.clipDecorators = clipDecorators;
function clipDecorator(connector, points, isSource) {
var point = { x: 0, y: 0 };
var start = { x: 0, y: 0 };
var end = { x: 0, y: 0 };
var length = points.length;
start = !isSource ? points[length - 1] : points[0];
end = !isSource ? points[length - 2] : points[1];
var len = ej2_drawings_1.Point.distancePoints(start, end);
len = (len === 0) ? 1 : len;
var width = connector.thickness;
point.x = (Math.round(start.x + width * (end.x - start.x) / len));
point.y = (Math.round(start.y + width * (end.y - start.y) / len));
var strokeWidth = 1;
point = ej2_drawings_1.Point.adjustPoint(point, end, true, (strokeWidth / 2));
return point;
}
exports.clipDecorator = clipDecorator;
function initDistanceLabel(obj, points, measure, pdfviewer) {
var labels = [];
var angle = ej2_drawings_1.Point.findAngle(points[0], points[1]);
var textele = textElement(obj, angle);
if (!pdfviewer.enableImportAnnotationMeasurement && obj.notes && obj.notes !== '') {
textele.content = obj.notes;
}
else {
textele.content = measure.setConversion(drawing_util_1.findPointsLength([points[0], points[1]]) * measure.pixelToPointFactor, obj);
}
textele.rotateValue = { y: -10, angle: angle };
if (obj.enableShapeLabel === true) {
textele.style.strokeColor = obj.labelBorderColor;
textele.style.fill = obj.labelFillColor;
textele.style.fontSize = obj.fontSize;
textele.style.color = obj.fontColor;
textele.style.fontFamily = obj.fontFamily;
}
labels.push(textele);
return labels;
}
exports.initDistanceLabel = initDistanceLabel;
function updateDistanceLabel(obj, points, measure) {
var distance;
for (var i = 0; i < obj.wrapper.children.length; i++) {
var textElement_1 = obj.wrapper.children[parseInt(i.toString(), 10)];
if (textElement_1 && !ej2_base_1.isNullOrUndefined(textElement_1.content)) {
distance = measure.setConversion(drawing_util_1.findPointsLength([points[0], points[1]]) * measure.pixelToPointFactor, obj);
textElement_1.content = distance;
textElement_1.childNodes[0].text = textElement_1.content;
textElement_1.refreshTextElement();
}
}
return distance;
}
exports.updateDistanceLabel = updateDistanceLabel;
function updateRadiusLabel(obj, measure) {
var radius;
for (var i = 0; i < obj.wrapper.children.length; i++) {
var textElement_2 = obj.wrapper.children[parseInt(i.toString(), 10)];
if (textElement_2 && !ej2_base_1.isNullOrUndefined(textElement_2.content)) {
radius = measure.setConversion((obj.bounds.width / 2) * measure.pixelToPointFactor, obj);
textElement_2.content = radius;
if (textElement_2.childNodes.length === 2) {
textElement_2.childNodes[0].text = radius;
textElement_2.childNodes.splice(textElement_2.childNodes.length - 1, 1);
}
else {
textElement_2.childNodes[0].text = radius;
}
textElement_2.refreshTextElement();
}
}
return radius;
}
exports.updateRadiusLabel = updateRadiusLabel;
function initPerimeterLabel(obj, points, measure, pdfviewer) {
var labels = [];
var angle = ej2_drawings_1.Point.findAngle(points[0], points[1]);
var textele = textElement(obj, angle);
if (!pdfviewer.enableImportAnnotationMeasurement && obj.notes && obj.notes !== '') {
textele.content = obj.notes;
}
else {
textele.content = measure.calculatePerimeter(obj);
}
if (obj.enableShapeLabel === true) {
textele.style.strokeColor = obj.labelBorderColor;
textele.style.fill = obj.labelFillColor;
textele.style.fontSize = obj.fontSize;
textele.style.color = obj.fontColor;
textele.style.fontFamily = obj.fontFamily;
}
textele.rotateValue = { y: -10, angle: angle };
labels.push(textele);
return labels;
}
exports.initPerimeterLabel = initPerimeterLabel;
function updatePerimeterLabel(obj, points, measure) {
var perimeter;
for (var i = 0; i < obj.wrapper.children.length; i++) {
var textElement_3 = obj.wrapper.children[parseInt(i.toString(), 10)];
if (textElement_3 && !ej2_base_1.isNullOrUndefined(textElement_3.content)) {
perimeter = measure.calculatePerimeter(obj);
textElement_3.content = perimeter;
textElement_3.childNodes[0].text = textElement_3.content;
textElement_3.refreshTextElement();
}
}
return perimeter;
}
exports.updatePerimeterLabel = updatePerimeterLabel;
function removePerimeterLabel(obj) {
for (var i = 0; i < obj.wrapper.children.length; i++) {
var textElement_4 = obj.wrapper.children[parseInt(i.toString(), 10)];
if (textElement_4 && !ej2_base_1.isNullOrUndefined(textElement_4.content)) {
obj.wrapper.children.splice(i, 1);
}
}
}
exports.removePerimeterLabel = removePerimeterLabel;
function updateCalibrateLabel(obj) {
if (obj.wrapper && obj.wrapper.children) {
for (var i = 0; i < obj.wrapper.children.length; i++) {
var textElement_5 = obj.wrapper.children[parseInt(i.toString(), 10)];
if (textElement_5 && !ej2_base_1.isNullOrUndefined(textElement_5.content)) {
textElement_5.content = obj.notes;
textElement_5.childNodes[0].text = textElement_5.content;
textElement_5.refreshTextElement();
}
}
}
}
exports.updateCalibrateLabel = updateCalibrateLabel;
function getPolygonPath(collection) {
var path = '';
var seg;
path = 'M' + collection[0].x + ' ' + collection[0].y;
var i;
for (i = 1; i < collection.length; i++) {
seg = collection[parseInt(i.toString(), 10)];
path += 'L' + seg.x + ' ' + seg.y;
}
path += 'Z';
return path;
}
exports.getPolygonPath = getPolygonPath;
function textElement(obj, angle) {
var textele = new ej2_drawings_1.TextElement();
drawing_util_1.setElementStype(obj, textele);
textele.style.fill = 'transparent';
textele.id = ej2_drawings_1.randomId();
textele.horizontalAlignment = 'Center';
textele.rotateValue = { y: 10, angle: angle };
textele.verticalAlignment = 'Top';
textele.relativeMode = 'Object';
textele.setOffsetWithRespectToBounds(.5, .5, 'Absolute');
textele.offsetX;
textele.style.textWrapping = 'NoWrap';
return textele;
}
exports.textElement = textElement;
function initLeaders(obj, points) {
var leaders = [];
var leader = initLeader(obj, points[0], points[1]);
leaders.push(leader);
leader = initLeader(obj, points[1], points[0], true);
leaders.push(leader);
return leaders;
}
exports.initLeaders = initLeaders;
function initLeader(obj, point1, point2, isSecondLeader) {
var element = new ej2_drawings_1.PathElement();
element.offsetX = point1.x;
element.offsetY = point1.y;
var angle = ej2_drawings_1.Point.findAngle(point1, point2);
var center = { x: (point1.x + point2.x) / 2, y: (point1.y + point2.y) / 2 };
var matrix = ej2_drawings_1.identityMatrix();
ej2_drawings_1.rotateMatrix(matrix, 0 - angle, center.x, center.y);
var rotatedPoint = ej2_drawings_1.transformPointByMatrix(matrix, point1);
var newPoint1 = { x: rotatedPoint.x, y: rotatedPoint.y - obj.leaderHeight };
matrix = ej2_drawings_1.identityMatrix();
ej2_drawings_1.rotateMatrix(matrix, angle, element.offsetX, element.offsetY);
rotatedPoint = ej2_drawings_1.transformPointByMatrix(matrix, newPoint1);
var finalPoint = { x: point1.x, y: point1.y };
element.offsetX = finalPoint.x;
element.offsetY = finalPoint.y;
element.transform = ej2_drawings_1.RotateTransform.Self;
var getPath = 'M' + point1.x + ',' + point1.y + ',L' + rotatedPoint.x + ',' + rotatedPoint.y + 'Z';
var size = new ej2_drawings_1.Size(0, obj.leaderHeight);
element.pivot.x = .5;
if (isSecondLeader) {
element.id = 'leader2_' + ej2_drawings_1.randomId();
element.pivot.y = 0;
}
else {
element.id = 'leader1_' + ej2_drawings_1.randomId();
element.pivot.y = 1;
}
drawing_util_1.setElementStype(obj, element);
element.rotateAngle = angle;
element.data = getPath;
element.canMeasurePath = true;
element.width = size.width;
element.height = size.height;
return element;
}
exports.initLeader = initLeader;
function isPointOverConnector(connector, reference) {
var vertexPoints = connector.vertexPoints;
if (!ej2_base_1.isNullOrUndefined(vertexPoints)) {
for (var i = 0; i < vertexPoints.length - 1; i++) {
var start = vertexPoints[parseInt(i.toString(), 10)];
var end = vertexPoints[i + 1];
var rect = ej2_drawings_1.Rect.toBounds([start, end]);
rect.Inflate(10);
if (rect.containsPoint(reference)) {
var intersectinPt = findNearestPoint(reference, start, end);
var segment1 = { x1: start.x, x2: end.x, y1: start.y, y2: end.y };
var segment2 = { x1: reference.x, x2: intersectinPt.x, y1: reference.y, y2: intersectinPt.y };
var intersectDetails = ej2_drawings_1.intersect3(segment1, segment2);
if (intersectDetails.enabled) {
var distance = ej2_drawings_1.Point.findLength(reference, intersectDetails.intersectPt);
if (Math.abs(distance) < 10) {
return true;
}
}
else {
var rect_1 = ej2_drawings_1.Rect.toBounds([reference, reference]);
rect_1.Inflate(3);
if (rect_1.containsPoint(start) || rect_1.containsPoint(end)) {
return true;
}
}
if (ej2_drawings_1.Point.equals(reference, intersectinPt)) {
return true;
}
}
}
}
return false;
}
exports.isPointOverConnector = isPointOverConnector;
function findNearestPoint(reference, start, end) {
var shortestPoint;
var shortest = ej2_drawings_1.Point.findLength(start, reference);
var shortest1 = ej2_drawings_1.Point.findLength(end, reference);
if (shortest > shortest1) {
shortestPoint = end;
}
else {
shortestPoint = start;
}
var angleBWStAndEnd = ej2_drawings_1.Point.findAngle(start, end);
var angleBWStAndRef = ej2_drawings_1.Point.findAngle(shortestPoint, reference);
var r = ej2_drawings_1.Point.findLength(shortestPoint, reference);
var vaAngle = angleBWStAndRef + ((angleBWStAndEnd - angleBWStAndRef) * 2);
return {
x: (shortestPoint.x + r * Math.cos(vaAngle * Math.PI / 180)),
y: (shortestPoint.y + r * Math.sin(vaAngle * Math.PI / 180))
};
}
exports.findNearestPoint = findNearestPoint;
function getDecoratorShape(shape) {
return decoratorShapes["" + shape];
}
exports.getDecoratorShape = getDecoratorShape;
var decoratorShapes = {
'OpenArrow': 'M15.9,23 L5,16 L15.9,9 L17,10.7 L8.7,16 L17,21.3Z',
'Square': 'M0,0 L10,0 L10,10 L0,10 z',
'Fletch': 'M14.8,10c0,0-3.5,6,0.2,12c0,0-2.5-6-10.9-6C4.1,16,11.3,16,14.8,10z',
'OpenFetch': 'M6,17c-0.6,0-1-0.4-1-1s0.4-1,1-1c10.9,0,11-5,11-5' +
'c0-0.6,0.4-1,1-1s1,0.4,1,1C19,10.3,18.9,17,6,17C6,17,6,17,6,17z ' +
'M18,23c-0.5,0-1-0.4-1-1c0-0.2-0.3-5-11-5c-0.6,0-1-0.5-1-1s0.4-1,1-1c0,0,0,0,0,0' +
'c12.9,0,13,6.7,13,7 C19,22.6,18.6,23,18,23z',
'IndentedArrow': 'M17,10c0,0-4.5,5.5,0,12L5,16L17,10z',
'OutdentedArrow': 'M14.6,10c0,0,5.4,6,0,12L5,16L14.6,10z',
'DoubleArrow': 'M19,10 L19,22 L13,16Z M12,10 L12,22 L6,16Z',
'Arrow': 'M15,10 L15,22 L5,16Z',
'Diamond': 'M12,23l-7-7l7-7l6.9,7L12,23z',
'Circle': 'M0,50 A50,50,0 1 1 100,50 A50,50,0 1 1 0,50 Z',
'Butt': 'M0,0 L0,90'
};
});
|