@inweb/markup 26.4.0 → 26.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/markup.js +561 -126
- package/dist/markup.js.map +1 -1
- package/dist/markup.min.js +1 -1
- package/dist/markup.module.js +672 -138
- package/dist/markup.module.js.map +1 -1
- package/lib/markup/IMarkupArrow.d.ts +8 -8
- package/lib/markup/IMarkupCloud.d.ts +12 -5
- package/lib/markup/IMarkupEllipse.d.ts +4 -4
- package/lib/markup/IMarkupImage.d.ts +3 -3
- package/lib/markup/IMarkupLine.d.ts +2 -2
- package/lib/markup/IMarkupObject.d.ts +4 -0
- package/lib/markup/IMarkupRectangle.d.ts +10 -3
- package/lib/markup/IMarkupText.d.ts +3 -3
- package/lib/markup/Konva/KonvaArrow.d.ts +4 -1
- package/lib/markup/Konva/KonvaCloud.d.ts +4 -1
- package/lib/markup/Konva/KonvaEllipse.d.ts +4 -1
- package/lib/markup/Konva/KonvaImage.d.ts +4 -1
- package/lib/markup/Konva/KonvaLine.d.ts +4 -1
- package/lib/markup/Konva/KonvaMarkup.d.ts +2 -2
- package/lib/markup/Konva/KonvaRectangle.d.ts +4 -1
- package/lib/markup/Konva/KonvaText.d.ts +4 -1
- package/package.json +3 -3
- package/src/markup/IMarkupArrow.ts +8 -8
- package/src/markup/IMarkupCloud.ts +10 -5
- package/src/markup/IMarkupEllipse.ts +4 -4
- package/src/markup/IMarkupImage.ts +3 -3
- package/src/markup/IMarkupLine.ts +2 -2
- package/src/markup/IMarkupObject.ts +5 -0
- package/src/markup/IMarkupRectangle.ts +8 -3
- package/src/markup/IMarkupText.ts +3 -3
- package/src/markup/Konva/KonvaArrow.ts +49 -4
- package/src/markup/Konva/KonvaCloud.ts +110 -11
- package/src/markup/Konva/KonvaEllipse.ts +102 -2
- package/src/markup/Konva/KonvaImage.ts +60 -2
- package/src/markup/Konva/KonvaLine.ts +97 -3
- package/src/markup/Konva/KonvaMarkup.ts +182 -166
- package/src/markup/Konva/KonvaRectangle.ts +103 -4
- package/src/markup/Konva/KonvaText.ts +61 -2
package/dist/markup.module.js
CHANGED
|
@@ -55,10 +55,29 @@ class MarkupColor {
|
|
|
55
55
|
const LineTypeSpecs = new Map([ [ "solid", [] ], [ "dot", [ 30, 30, .001, 30 ] ], [ "dash", [ 30, 30 ] ] ]);
|
|
56
56
|
|
|
57
57
|
class KonvaLine {
|
|
58
|
-
constructor(params, ref = null) {
|
|
58
|
+
constructor(params, ref = null, worldTransformer = new WorldTransform) {
|
|
59
59
|
var _a, _b;
|
|
60
|
+
this._worldTransformer = worldTransformer;
|
|
60
61
|
if (ref) {
|
|
61
62
|
this._ref = ref;
|
|
63
|
+
let wcsPoints = this._ref.getAttr("wcsPoints");
|
|
64
|
+
if (!wcsPoints) {
|
|
65
|
+
wcsPoints = [];
|
|
66
|
+
let points = this._ref.points();
|
|
67
|
+
let wcsPoint;
|
|
68
|
+
for (let i = 0; i < points.length; i += 2) {
|
|
69
|
+
wcsPoint = this._worldTransformer.screenToWorld({
|
|
70
|
+
x: points[i],
|
|
71
|
+
y: points[i + 1]
|
|
72
|
+
});
|
|
73
|
+
wcsPoints.push({
|
|
74
|
+
x: wcsPoint.x,
|
|
75
|
+
y: wcsPoint.y,
|
|
76
|
+
z: wcsPoint.z
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
this._ref.setAttr("wcsPoints", wcsPoints);
|
|
80
|
+
}
|
|
62
81
|
return;
|
|
63
82
|
}
|
|
64
83
|
if (!params) params = {};
|
|
@@ -70,7 +89,19 @@ class KonvaLine {
|
|
|
70
89
|
y: 100
|
|
71
90
|
} ];
|
|
72
91
|
const konvaPoints = [];
|
|
73
|
-
|
|
92
|
+
const wcsPoints = [];
|
|
93
|
+
params.points.forEach((point => {
|
|
94
|
+
konvaPoints.push(point.x, point.y);
|
|
95
|
+
let wcsPoint = this._worldTransformer.screenToWorld({
|
|
96
|
+
x: point.x,
|
|
97
|
+
y: point.y
|
|
98
|
+
});
|
|
99
|
+
wcsPoints.push({
|
|
100
|
+
x: wcsPoint.x,
|
|
101
|
+
y: wcsPoint.y,
|
|
102
|
+
z: wcsPoint.z
|
|
103
|
+
});
|
|
104
|
+
}));
|
|
74
105
|
this._ref = new Konva.Line({
|
|
75
106
|
stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
|
|
76
107
|
strokeWidth: (_b = params.width) !== null && _b !== undefined ? _b : 4,
|
|
@@ -82,10 +113,55 @@ class KonvaLine {
|
|
|
82
113
|
strokeScaleEnabled: false,
|
|
83
114
|
dash: LineTypeSpecs.get(params.type) || []
|
|
84
115
|
});
|
|
116
|
+
this._ref.setAttr("wcsPoints", wcsPoints);
|
|
85
117
|
this._ref.on("transform", (e => {
|
|
86
118
|
const attrs = e.target.attrs;
|
|
87
119
|
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
88
120
|
}));
|
|
121
|
+
this._ref.on("transformend", (e => {
|
|
122
|
+
const absoluteTransform = this._ref.getAbsoluteTransform();
|
|
123
|
+
let wcsPoints = [];
|
|
124
|
+
let points = this._ref.points();
|
|
125
|
+
let wcsPoint;
|
|
126
|
+
for (let i = 0; i < points.length; i += 2) {
|
|
127
|
+
const position = absoluteTransform.point({
|
|
128
|
+
x: points[i],
|
|
129
|
+
y: points[i + 1]
|
|
130
|
+
});
|
|
131
|
+
wcsPoint = this._worldTransformer.screenToWorld({
|
|
132
|
+
x: position.x,
|
|
133
|
+
y: position.y
|
|
134
|
+
});
|
|
135
|
+
wcsPoints.push({
|
|
136
|
+
x: wcsPoint.x,
|
|
137
|
+
y: wcsPoint.y,
|
|
138
|
+
z: wcsPoint.z
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
this._ref.setAttr("wcsPoints", wcsPoints);
|
|
142
|
+
}));
|
|
143
|
+
this._ref.on("dragend", (e => {
|
|
144
|
+
const absoluteTransform = this._ref.getAbsoluteTransform();
|
|
145
|
+
let wcsPoints = [];
|
|
146
|
+
let points = this._ref.points();
|
|
147
|
+
let wcsPoint;
|
|
148
|
+
for (let i = 0; i < points.length; i += 2) {
|
|
149
|
+
const position = absoluteTransform.point({
|
|
150
|
+
x: points[i],
|
|
151
|
+
y: points[i + 1]
|
|
152
|
+
});
|
|
153
|
+
wcsPoint = this._worldTransformer.screenToWorld({
|
|
154
|
+
x: position.x,
|
|
155
|
+
y: position.y
|
|
156
|
+
});
|
|
157
|
+
wcsPoints.push({
|
|
158
|
+
x: wcsPoint.x,
|
|
159
|
+
y: wcsPoint.y,
|
|
160
|
+
z: wcsPoint.z
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
this._ref.setAttr("wcsPoints", wcsPoints);
|
|
164
|
+
}));
|
|
89
165
|
this._ref.id(this._ref._id.toString());
|
|
90
166
|
}
|
|
91
167
|
ref() {
|
|
@@ -155,19 +231,48 @@ class KonvaLine {
|
|
|
155
231
|
}
|
|
156
232
|
addPoints(points) {
|
|
157
233
|
let newPoints = this._ref.points();
|
|
234
|
+
let wcsPoints = this._ref.getAttr("wcsPoints");
|
|
158
235
|
points.forEach((point => {
|
|
159
236
|
newPoints = newPoints.concat([ point.x, point.y ]);
|
|
237
|
+
let wcsPoint = this._worldTransformer.screenToWorld(point);
|
|
238
|
+
wcsPoints.push(wcsPoint);
|
|
160
239
|
}));
|
|
161
240
|
this._ref.points(newPoints);
|
|
162
241
|
}
|
|
242
|
+
updateScreenCoordinates() {
|
|
243
|
+
let wcsPoints = this._ref.getAttr("wcsPoints");
|
|
244
|
+
let points = [];
|
|
245
|
+
let invert = this._ref.getAbsoluteTransform().copy();
|
|
246
|
+
invert = invert.invert();
|
|
247
|
+
wcsPoints.forEach((point => {
|
|
248
|
+
let screenPoint = this._worldTransformer.worldToScreen(point);
|
|
249
|
+
screenPoint = invert.point({
|
|
250
|
+
x: screenPoint.x,
|
|
251
|
+
y: screenPoint.y
|
|
252
|
+
});
|
|
253
|
+
points.push(screenPoint.x);
|
|
254
|
+
points.push(screenPoint.y);
|
|
255
|
+
}));
|
|
256
|
+
this._ref.points([]);
|
|
257
|
+
this._ref.points(points);
|
|
258
|
+
this._ref.clearCache();
|
|
259
|
+
}
|
|
163
260
|
}
|
|
164
261
|
|
|
165
262
|
class KonvaText {
|
|
166
|
-
constructor(params, ref = null) {
|
|
263
|
+
constructor(params, ref = null, worldTransformer = new WorldTransform) {
|
|
167
264
|
var _a, _b, _c;
|
|
168
265
|
this.TEXT_FONT_FAMILY = "Calibri";
|
|
266
|
+
this._worldTransformer = worldTransformer;
|
|
169
267
|
if (ref) {
|
|
170
268
|
this._ref = ref;
|
|
269
|
+
const wcsStart = this._ref.getAttr("wcsStart");
|
|
270
|
+
if (!wcsStart) {
|
|
271
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
|
|
272
|
+
x: ref.x(),
|
|
273
|
+
y: ref.y()
|
|
274
|
+
}));
|
|
275
|
+
}
|
|
171
276
|
return;
|
|
172
277
|
}
|
|
173
278
|
if (!params) params = {};
|
|
@@ -188,6 +293,10 @@ class KonvaText {
|
|
|
188
293
|
rotation: (_c = params.rotation) !== null && _c !== undefined ? _c : 0
|
|
189
294
|
});
|
|
190
295
|
this._ref.width(this._ref.getTextWidth());
|
|
296
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
|
|
297
|
+
x: params.position.x,
|
|
298
|
+
y: params.position.y
|
|
299
|
+
}));
|
|
191
300
|
this._ref.on("transform", (e => {
|
|
192
301
|
const attrs = e.target.attrs;
|
|
193
302
|
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
@@ -211,6 +320,24 @@ class KonvaText {
|
|
|
211
320
|
y: 1
|
|
212
321
|
});
|
|
213
322
|
}));
|
|
323
|
+
this._ref.on("transformend", (e => {
|
|
324
|
+
const attrs = e.target.attrs;
|
|
325
|
+
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
326
|
+
const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
|
|
327
|
+
const position = absoluteTransform.point({
|
|
328
|
+
x: this._ref.x(),
|
|
329
|
+
y: this._ref.y()
|
|
330
|
+
});
|
|
331
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
|
|
332
|
+
}));
|
|
333
|
+
this._ref.on("dragend", (e => {
|
|
334
|
+
const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
|
|
335
|
+
const position = absoluteTransform.point({
|
|
336
|
+
x: this._ref.x(),
|
|
337
|
+
y: this._ref.y()
|
|
338
|
+
});
|
|
339
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
|
|
340
|
+
}));
|
|
214
341
|
this._ref.id(this._ref._id.toString());
|
|
215
342
|
}
|
|
216
343
|
ref() {
|
|
@@ -261,6 +388,10 @@ class KonvaText {
|
|
|
261
388
|
x: x,
|
|
262
389
|
y: y
|
|
263
390
|
});
|
|
391
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
|
|
392
|
+
x: x,
|
|
393
|
+
y: y
|
|
394
|
+
}));
|
|
264
395
|
}
|
|
265
396
|
getFontSize() {
|
|
266
397
|
return this._ref.fontSize();
|
|
@@ -268,13 +399,42 @@ class KonvaText {
|
|
|
268
399
|
setFontSize(size) {
|
|
269
400
|
this._ref.fontSize(size);
|
|
270
401
|
}
|
|
402
|
+
updateScreenCoordinates() {
|
|
403
|
+
let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
|
|
404
|
+
let invert = this._ref.getStage().getAbsoluteTransform().copy();
|
|
405
|
+
invert = invert.invert();
|
|
406
|
+
const positionStart = invert.point(screenPositionStart);
|
|
407
|
+
this._ref.position({
|
|
408
|
+
x: positionStart.x,
|
|
409
|
+
y: positionStart.y
|
|
410
|
+
});
|
|
411
|
+
}
|
|
271
412
|
}
|
|
272
413
|
|
|
273
414
|
class KonvaRectangle {
|
|
274
|
-
constructor(params, ref = null) {
|
|
415
|
+
constructor(params, ref = null, worldTransformer = new WorldTransform) {
|
|
275
416
|
var _a, _b, _c, _d;
|
|
417
|
+
this._worldTransformer = worldTransformer;
|
|
276
418
|
if (ref) {
|
|
277
419
|
this._ref = ref;
|
|
420
|
+
const wcsStart = this._ref.getAttr("wcsStart");
|
|
421
|
+
const wcsEnd = this._ref.getAttr("wcsEnd");
|
|
422
|
+
if (!wcsStart) {
|
|
423
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
|
|
424
|
+
x: ref.x(),
|
|
425
|
+
y: ref.y()
|
|
426
|
+
}));
|
|
427
|
+
}
|
|
428
|
+
if (!wcsEnd) {
|
|
429
|
+
const rightBottomPoint = {
|
|
430
|
+
x: ref.x() + ref.width(),
|
|
431
|
+
y: ref.y() + ref.height()
|
|
432
|
+
};
|
|
433
|
+
this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
|
|
434
|
+
x: rightBottomPoint.x,
|
|
435
|
+
y: rightBottomPoint.y
|
|
436
|
+
}));
|
|
437
|
+
}
|
|
278
438
|
return;
|
|
279
439
|
}
|
|
280
440
|
if (!params) params = {};
|
|
@@ -282,6 +442,24 @@ class KonvaRectangle {
|
|
|
282
442
|
x: 0,
|
|
283
443
|
y: 0
|
|
284
444
|
};
|
|
445
|
+
if (params.position2) {
|
|
446
|
+
params.width = params.position.x - params.position2.x;
|
|
447
|
+
params.height = params.position.y - params.position2.y;
|
|
448
|
+
} else {
|
|
449
|
+
if (!params.width || !params.height) {
|
|
450
|
+
params.position2 = {
|
|
451
|
+
x: 200,
|
|
452
|
+
y: 200
|
|
453
|
+
};
|
|
454
|
+
params.width = 200;
|
|
455
|
+
params.height = 200;
|
|
456
|
+
} else {
|
|
457
|
+
params.position2 = {
|
|
458
|
+
x: params.position.x + params.width,
|
|
459
|
+
y: params.position.y + params.height
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
}
|
|
285
463
|
this._ref = new Konva.Rect({
|
|
286
464
|
stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
|
|
287
465
|
strokeWidth: (_b = params.lineWidth) !== null && _b !== undefined ? _b : 4,
|
|
@@ -295,9 +473,16 @@ class KonvaRectangle {
|
|
|
295
473
|
draggable: true,
|
|
296
474
|
strokeScaleEnabled: false
|
|
297
475
|
});
|
|
476
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
|
|
477
|
+
x: params.position.x,
|
|
478
|
+
y: params.position.y
|
|
479
|
+
}));
|
|
480
|
+
this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
|
|
481
|
+
x: params.position2.x,
|
|
482
|
+
y: params.position2.y
|
|
483
|
+
}));
|
|
298
484
|
this._ref.on("transform", (e => {
|
|
299
485
|
const attrs = e.target.attrs;
|
|
300
|
-
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
301
486
|
const scaleByX = Math.abs(attrs.scaleX - 1) > 1e-5;
|
|
302
487
|
const scaleByY = Math.abs(attrs.scaleY - 1) > 1e-5;
|
|
303
488
|
let newWidth = this._ref.width();
|
|
@@ -319,6 +504,32 @@ class KonvaRectangle {
|
|
|
319
504
|
y: 1
|
|
320
505
|
});
|
|
321
506
|
}));
|
|
507
|
+
this._ref.on("transformend", (e => {
|
|
508
|
+
const attrs = e.target.attrs;
|
|
509
|
+
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
510
|
+
const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
|
|
511
|
+
const position = absoluteTransform.point({
|
|
512
|
+
x: this._ref.x(),
|
|
513
|
+
y: this._ref.y()
|
|
514
|
+
});
|
|
515
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
|
|
516
|
+
this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
|
|
517
|
+
x: position.x + this._ref.width(),
|
|
518
|
+
y: position.y + this._ref.height()
|
|
519
|
+
}));
|
|
520
|
+
}));
|
|
521
|
+
this._ref.on("dragend", (e => {
|
|
522
|
+
const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
|
|
523
|
+
const position = absoluteTransform.point({
|
|
524
|
+
x: this._ref.x(),
|
|
525
|
+
y: this._ref.y()
|
|
526
|
+
});
|
|
527
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
|
|
528
|
+
this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
|
|
529
|
+
x: position.x + this._ref.width(),
|
|
530
|
+
y: position.y + this._ref.height()
|
|
531
|
+
}));
|
|
532
|
+
}));
|
|
322
533
|
this._ref.id(this._ref._id.toString());
|
|
323
534
|
}
|
|
324
535
|
getPosition() {
|
|
@@ -332,15 +543,31 @@ class KonvaRectangle {
|
|
|
332
543
|
}
|
|
333
544
|
setWidth(w) {
|
|
334
545
|
this._ref.width(w);
|
|
546
|
+
const rightLowerPoint = {
|
|
547
|
+
x: this._ref.x() + w,
|
|
548
|
+
y: this._ref.y() + this._ref.height()
|
|
549
|
+
};
|
|
550
|
+
const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
|
|
551
|
+
this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
|
|
335
552
|
}
|
|
336
553
|
setHeight(h) {
|
|
337
554
|
this._ref.height(h);
|
|
555
|
+
const rightLowerPoint = {
|
|
556
|
+
x: this._ref.x() + this._ref.width(),
|
|
557
|
+
y: this._ref.y() + h
|
|
558
|
+
};
|
|
559
|
+
const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
|
|
560
|
+
this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
|
|
338
561
|
}
|
|
339
562
|
setPosition(x, y) {
|
|
340
563
|
this._ref.setPosition({
|
|
341
564
|
x: x,
|
|
342
565
|
y: y
|
|
343
566
|
});
|
|
567
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
|
|
568
|
+
x: x,
|
|
569
|
+
y: y
|
|
570
|
+
}));
|
|
344
571
|
}
|
|
345
572
|
ref() {
|
|
346
573
|
return this._ref;
|
|
@@ -382,13 +609,49 @@ class KonvaRectangle {
|
|
|
382
609
|
getLineWidth() {
|
|
383
610
|
return this._ref.strokeWidth();
|
|
384
611
|
}
|
|
612
|
+
updateScreenCoordinates() {
|
|
613
|
+
let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
|
|
614
|
+
let screenPositionEnd = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));
|
|
615
|
+
let invert = this._ref.getStage().getAbsoluteTransform().copy();
|
|
616
|
+
invert = invert.invert();
|
|
617
|
+
const positionStart = invert.point(screenPositionStart);
|
|
618
|
+
const positionEnd = invert.point(screenPositionEnd);
|
|
619
|
+
this._ref.position({
|
|
620
|
+
x: positionStart.x,
|
|
621
|
+
y: positionStart.y
|
|
622
|
+
});
|
|
623
|
+
this._ref.width(Math.abs(positionEnd.x - positionStart.x));
|
|
624
|
+
this._ref.height(Math.abs(positionEnd.y - positionStart.y));
|
|
625
|
+
}
|
|
385
626
|
}
|
|
386
627
|
|
|
387
628
|
class KonvaEllipse {
|
|
388
|
-
constructor(params, ref = null) {
|
|
629
|
+
constructor(params, ref = null, worldTransformer = new WorldTransform) {
|
|
389
630
|
var _a, _b;
|
|
631
|
+
this._worldTransformer = worldTransformer;
|
|
390
632
|
if (ref) {
|
|
391
633
|
this._ref = ref;
|
|
634
|
+
const wcsPosition = this._ref.getAttr("wcsPosition");
|
|
635
|
+
const radiusX = this._ref.getAttr("wcsRadiusX");
|
|
636
|
+
const radiusY = this._ref.getAttr("wcsRadiusY");
|
|
637
|
+
if (!wcsPosition) {
|
|
638
|
+
this._ref.setAttr("wcsPosition", this._worldTransformer.screenToWorld({
|
|
639
|
+
x: ref.x(),
|
|
640
|
+
y: ref.y()
|
|
641
|
+
}));
|
|
642
|
+
}
|
|
643
|
+
if (!radiusX) {
|
|
644
|
+
this._ref.setAttr("wcsRadiusX", this._worldTransformer.screenToWorld({
|
|
645
|
+
x: ref.x() + ref.radiusX(),
|
|
646
|
+
y: ref.y()
|
|
647
|
+
}));
|
|
648
|
+
}
|
|
649
|
+
if (!radiusY) {
|
|
650
|
+
this._ref.setAttr("wcsRadiusY", this._worldTransformer.screenToWorld({
|
|
651
|
+
x: ref.x(),
|
|
652
|
+
y: ref.y() + ref.radiusY()
|
|
653
|
+
}));
|
|
654
|
+
}
|
|
392
655
|
return;
|
|
393
656
|
}
|
|
394
657
|
if (!params) params = {};
|
|
@@ -413,6 +676,18 @@ class KonvaEllipse {
|
|
|
413
676
|
draggable: true,
|
|
414
677
|
strokeScaleEnabled: false
|
|
415
678
|
});
|
|
679
|
+
this._ref.setAttr("wcsPosition", this._worldTransformer.screenToWorld({
|
|
680
|
+
x: params.position.x,
|
|
681
|
+
y: params.position.y
|
|
682
|
+
}));
|
|
683
|
+
this._ref.setAttr("wcsRadiusX", this._worldTransformer.screenToWorld({
|
|
684
|
+
x: this._ref.x() + params.radius.x,
|
|
685
|
+
y: this._ref.y()
|
|
686
|
+
}));
|
|
687
|
+
this._ref.setAttr("wcsRadiusY", this._worldTransformer.screenToWorld({
|
|
688
|
+
x: this._ref.x(),
|
|
689
|
+
y: this._ref.y() + params.radius.y
|
|
690
|
+
}));
|
|
416
691
|
this._ref.on("transform", (e => {
|
|
417
692
|
const attrs = e.target.attrs;
|
|
418
693
|
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
@@ -449,6 +724,42 @@ class KonvaEllipse {
|
|
|
449
724
|
y: 1
|
|
450
725
|
});
|
|
451
726
|
}));
|
|
727
|
+
this._ref.on("transformend", (e => {
|
|
728
|
+
const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
|
|
729
|
+
const position = absoluteTransform.point({
|
|
730
|
+
x: this._ref.x(),
|
|
731
|
+
y: this._ref.y()
|
|
732
|
+
});
|
|
733
|
+
this._ref.setAttr("wcsPosition", this._worldTransformer.screenToWorld(position));
|
|
734
|
+
const radiusX = absoluteTransform.point({
|
|
735
|
+
x: this._ref.x() + this._ref.radiusX(),
|
|
736
|
+
y: this._ref.y()
|
|
737
|
+
});
|
|
738
|
+
this._ref.setAttr("wcsRadiusX", this._worldTransformer.screenToWorld(radiusX));
|
|
739
|
+
const radiusY = absoluteTransform.point({
|
|
740
|
+
x: this._ref.x(),
|
|
741
|
+
y: this._ref.y() + this._ref.radiusY()
|
|
742
|
+
});
|
|
743
|
+
this._ref.setAttr("wcsRadiusY", this._worldTransformer.screenToWorld(radiusY));
|
|
744
|
+
}));
|
|
745
|
+
this._ref.on("dragend", (e => {
|
|
746
|
+
const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
|
|
747
|
+
const position = absoluteTransform.point({
|
|
748
|
+
x: this._ref.x(),
|
|
749
|
+
y: this._ref.y()
|
|
750
|
+
});
|
|
751
|
+
this._ref.setAttr("wcsPosition", this._worldTransformer.screenToWorld(position));
|
|
752
|
+
const radiusX = absoluteTransform.point({
|
|
753
|
+
x: this._ref.x() + this._ref.radiusX(),
|
|
754
|
+
y: this._ref.y()
|
|
755
|
+
});
|
|
756
|
+
this._ref.setAttr("wcsRadiusX", this._worldTransformer.screenToWorld(radiusX));
|
|
757
|
+
const radiusY = absoluteTransform.point({
|
|
758
|
+
x: this._ref.x(),
|
|
759
|
+
y: this._ref.y() + this._ref.radiusY()
|
|
760
|
+
});
|
|
761
|
+
this._ref.setAttr("wcsRadiusY", this._worldTransformer.screenToWorld(radiusY));
|
|
762
|
+
}));
|
|
452
763
|
this._ref.id(this._ref._id.toString());
|
|
453
764
|
}
|
|
454
765
|
getPosition() {
|
|
@@ -459,18 +770,30 @@ class KonvaEllipse {
|
|
|
459
770
|
x: x,
|
|
460
771
|
y: y
|
|
461
772
|
});
|
|
773
|
+
this._ref.setAttr("wcsPosition", this._worldTransformer.screenToWorld({
|
|
774
|
+
x: x,
|
|
775
|
+
y: y
|
|
776
|
+
}));
|
|
462
777
|
}
|
|
463
778
|
getRadiusX() {
|
|
464
779
|
return this._ref.radiusX();
|
|
465
780
|
}
|
|
466
781
|
setRadiusX(r) {
|
|
467
782
|
this._ref.radiusX(r);
|
|
783
|
+
this._ref.setAttr("wcsRadiusX", this._worldTransformer.screenToWorld({
|
|
784
|
+
x: this._ref.x() + r,
|
|
785
|
+
y: this._ref.y()
|
|
786
|
+
}));
|
|
468
787
|
}
|
|
469
788
|
getRadiusY() {
|
|
470
789
|
return this._ref.radiusY();
|
|
471
790
|
}
|
|
472
791
|
setRadiusY(r) {
|
|
473
792
|
this._ref.radiusY(r);
|
|
793
|
+
this._ref.setAttr("wcsRadiusY", this._worldTransformer.screenToWorld({
|
|
794
|
+
x: this._ref.x(),
|
|
795
|
+
y: this._ref.y() + r
|
|
796
|
+
}));
|
|
474
797
|
}
|
|
475
798
|
getLineWidth() {
|
|
476
799
|
return this._ref.strokeWidth();
|
|
@@ -512,13 +835,43 @@ class KonvaEllipse {
|
|
|
512
835
|
this._ref.destroy();
|
|
513
836
|
this._ref = null;
|
|
514
837
|
}
|
|
838
|
+
updateScreenCoordinates() {
|
|
839
|
+
let screenPosition = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsPosition"));
|
|
840
|
+
let radiusX = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsRadiusX"));
|
|
841
|
+
let radiusY = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsRadiusY"));
|
|
842
|
+
let invert = this._ref.getStage().getAbsoluteTransform().copy();
|
|
843
|
+
invert = invert.invert();
|
|
844
|
+
const position = invert.point({
|
|
845
|
+
x: screenPosition.x,
|
|
846
|
+
y: screenPosition.y
|
|
847
|
+
});
|
|
848
|
+
this._ref.position({
|
|
849
|
+
x: position.x,
|
|
850
|
+
y: position.y
|
|
851
|
+
});
|
|
852
|
+
this._ref.radius({
|
|
853
|
+
x: Math.abs(invert.point(radiusX).x - position.x),
|
|
854
|
+
y: Math.abs(invert.point(radiusY).y - position.y)
|
|
855
|
+
});
|
|
856
|
+
}
|
|
515
857
|
}
|
|
516
858
|
|
|
517
859
|
class KonvaArrow {
|
|
518
|
-
constructor(params, ref = null) {
|
|
860
|
+
constructor(params, ref = null, worldTransformer = new WorldTransform) {
|
|
519
861
|
var _a, _b;
|
|
862
|
+
this._worldTransformer = worldTransformer;
|
|
520
863
|
if (ref) {
|
|
521
864
|
this._ref = ref;
|
|
865
|
+
const wcsStart = this._ref.getAttr("wcsStart");
|
|
866
|
+
const wcsEnd = this._ref.getAttr("wcsEnd");
|
|
867
|
+
if (!wcsStart) this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
|
|
868
|
+
x: ref.points()[0],
|
|
869
|
+
y: ref.points()[1]
|
|
870
|
+
}));
|
|
871
|
+
if (!wcsEnd) this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
|
|
872
|
+
x: ref.points()[2],
|
|
873
|
+
y: ref.points()[3]
|
|
874
|
+
}));
|
|
522
875
|
return;
|
|
523
876
|
}
|
|
524
877
|
if (!params) params = {};
|
|
@@ -541,9 +894,43 @@ class KonvaArrow {
|
|
|
541
894
|
draggable: true,
|
|
542
895
|
strokeScaleEnabled: false
|
|
543
896
|
});
|
|
544
|
-
this._ref.
|
|
897
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
|
|
898
|
+
x: params.start.x,
|
|
899
|
+
y: params.start.y
|
|
900
|
+
}));
|
|
901
|
+
this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
|
|
902
|
+
x: params.end.x,
|
|
903
|
+
y: params.end.y
|
|
904
|
+
}));
|
|
905
|
+
this._ref.on("transformend", (e => {
|
|
545
906
|
const attrs = e.target.attrs;
|
|
546
907
|
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
908
|
+
const points = this._ref.points();
|
|
909
|
+
const absoluteTransform = this._ref.getAbsoluteTransform();
|
|
910
|
+
const transformStart = absoluteTransform.point({
|
|
911
|
+
x: points[0],
|
|
912
|
+
y: points[1]
|
|
913
|
+
});
|
|
914
|
+
const transformEnd = absoluteTransform.point({
|
|
915
|
+
x: points[2],
|
|
916
|
+
y: points[3]
|
|
917
|
+
});
|
|
918
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(transformStart));
|
|
919
|
+
this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld(transformEnd));
|
|
920
|
+
}));
|
|
921
|
+
this._ref.on("dragend", (e => {
|
|
922
|
+
const points = this._ref.points();
|
|
923
|
+
const absoluteTransform = e.target.getAbsoluteTransform();
|
|
924
|
+
const transformStart = absoluteTransform.point({
|
|
925
|
+
x: points[0],
|
|
926
|
+
y: points[1]
|
|
927
|
+
});
|
|
928
|
+
const transformEnd = absoluteTransform.point({
|
|
929
|
+
x: points[2],
|
|
930
|
+
y: points[3]
|
|
931
|
+
});
|
|
932
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(transformStart));
|
|
933
|
+
this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld(transformEnd));
|
|
547
934
|
}));
|
|
548
935
|
this._ref.id(this._ref._id.toString());
|
|
549
936
|
}
|
|
@@ -594,6 +981,14 @@ class KonvaArrow {
|
|
|
594
981
|
}
|
|
595
982
|
setPoints(points) {
|
|
596
983
|
if (points.length === 2) {
|
|
984
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
|
|
985
|
+
x: points[0].x,
|
|
986
|
+
y: points[0].y
|
|
987
|
+
}));
|
|
988
|
+
this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
|
|
989
|
+
x: points[1].x,
|
|
990
|
+
y: points[1].y
|
|
991
|
+
}));
|
|
597
992
|
this._ref.points([ points[0].x, points[0].y, points[1].x, points[1].y ]);
|
|
598
993
|
}
|
|
599
994
|
}
|
|
@@ -607,6 +1002,10 @@ class KonvaArrow {
|
|
|
607
1002
|
setStartPoint(x, y) {
|
|
608
1003
|
const points = this._ref.points();
|
|
609
1004
|
this._ref.points([ x, y, points[2], points[3] ]);
|
|
1005
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
|
|
1006
|
+
x: x,
|
|
1007
|
+
y: y
|
|
1008
|
+
}));
|
|
610
1009
|
}
|
|
611
1010
|
getEndPoint() {
|
|
612
1011
|
const points = this._ref.points();
|
|
@@ -618,16 +1017,36 @@ class KonvaArrow {
|
|
|
618
1017
|
setEndPoint(x, y) {
|
|
619
1018
|
const points = this._ref.points();
|
|
620
1019
|
this._ref.points([ points[0], points[1], x, y ]);
|
|
1020
|
+
this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
|
|
1021
|
+
x: x,
|
|
1022
|
+
y: y
|
|
1023
|
+
}));
|
|
1024
|
+
}
|
|
1025
|
+
updateScreenCoordinates() {
|
|
1026
|
+
let screenStartPoint = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
|
|
1027
|
+
let screenEndPoint = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));
|
|
1028
|
+
let invert = this._ref.getAbsoluteTransform().copy();
|
|
1029
|
+
invert = invert.invert();
|
|
1030
|
+
const startPoint = invert.point({
|
|
1031
|
+
x: screenStartPoint.x,
|
|
1032
|
+
y: screenStartPoint.y
|
|
1033
|
+
});
|
|
1034
|
+
const endPoint = invert.point({
|
|
1035
|
+
x: screenEndPoint.x,
|
|
1036
|
+
y: screenEndPoint.y
|
|
1037
|
+
});
|
|
1038
|
+
this._ref.points([ startPoint.x, startPoint.y, endPoint.x, endPoint.y ]);
|
|
621
1039
|
}
|
|
622
1040
|
}
|
|
623
1041
|
|
|
624
1042
|
class KonvaImage {
|
|
625
|
-
constructor(params, ref = null) {
|
|
1043
|
+
constructor(params, ref = null, worldTransformer = new WorldTransform) {
|
|
626
1044
|
var _a, _b;
|
|
627
1045
|
this._ratio = 1;
|
|
628
1046
|
this.EPSILON = 1e-5;
|
|
629
1047
|
this.BASE64_HEADER_START = "data:image/";
|
|
630
1048
|
this.BASE64_NOT_FOUND = "data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAADsAAAA7AF5KHG9AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAmhJREFUWIXtlr9rVEEQxz+H8RQUJIdeIopYm0vkCg0GBBtbG1NF7Kxt7dR/IGIw/uhTaBNLERURg2kCEUyCYCPi70b0InjGS57FzOZN3r19d+9HJIVfWO52dma/s7Mz8xa2KAaBCWAR+AkECWOmSOIdwC1gtQOpHc+NfQ8wClQ8+1d0vcdH/lQ3bSIRGAZ2pTjAqNovANXIWlXlAXA2zvi2Ln4AjqYgtagYEutENSLvjRoOImFv5iB32Ae8UrLXwFBk3h9ndF0VJnKSO9gTu3yKu5Z1LKnS8YIcABgw5Ks692JZFXcXRJ46Aq6kikCnHNi/mQ50WwVtfaIoBzL3gRk2drSscJ2wrc4VvUoe2wn/41/iBfoVLRnBGnDSY3AAKacy8AmYR+o7K1zCl6wgrgpOAc/MuhvfgMuk+1JGHQgSBcAloKXy78AjYBppJk5/noTulseBMZ23iD/piHFkEdgTQzKk+5wHjmHC3cmBg0BD5xcSTrFXyQPgIWFtDwMvab+2N8DpbhyY1v/3E8gdDgNfVX9SCVZ0/gW4B0wB71S2BpxLcuCM/jaQSHSDEeAX4VMuAG4gTzyHbcAVXXO6GxxwIX+vvxe7JHcYQ07nHqklj96UIW/YhSWzMKcep8VVtf8B1Dw6h4DfhB+sdbgn2R+gnoEc5NR3dZ+3QJ9H74HqXLPCGlJyTfI9y3YCs0owq3OLOpKkLeBI1HhSDT/mdKIPiUCARMTlQx34TMLjtww8IczmO8AJ/N/2JNSQXAiQ671JePePge0+wzJSQq4FFzlaenIvucUAkiQLhC/mLGNZ9xgn5s63BP4CCk0QDtm4BhoAAAAASUVORK5CYII=";
|
|
1049
|
+
this._worldTransformer = worldTransformer;
|
|
631
1050
|
if (ref) {
|
|
632
1051
|
if (!ref.src || !ref.src.startsWith(this.BASE64_HEADER_START)) ref.src = this.BASE64_NOT_FOUND;
|
|
633
1052
|
if (ref.height() <= this.EPSILON) ref.height(32);
|
|
@@ -635,6 +1054,13 @@ class KonvaImage {
|
|
|
635
1054
|
this._ref = ref;
|
|
636
1055
|
this._canvasImage = ref.image();
|
|
637
1056
|
this._ratio = this._ref.height() <= this.EPSILON || this._ref.width() <= this.EPSILON ? 1 : this._ref.height() / this._ref.width();
|
|
1057
|
+
const wcsStart = this._ref.getAttr("wcsStart");
|
|
1058
|
+
if (!wcsStart) {
|
|
1059
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
|
|
1060
|
+
x: ref.x(),
|
|
1061
|
+
y: ref.y()
|
|
1062
|
+
}));
|
|
1063
|
+
}
|
|
638
1064
|
return;
|
|
639
1065
|
}
|
|
640
1066
|
if (!params) params = {};
|
|
@@ -676,6 +1102,10 @@ class KonvaImage {
|
|
|
676
1102
|
height: (_b = params.height) !== null && _b !== undefined ? _b : 0,
|
|
677
1103
|
draggable: true
|
|
678
1104
|
});
|
|
1105
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
|
|
1106
|
+
x: params.position.x,
|
|
1107
|
+
y: params.position.y
|
|
1108
|
+
}));
|
|
679
1109
|
this._ref.on("transform", (e => {
|
|
680
1110
|
const attrs = e.target.attrs;
|
|
681
1111
|
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
@@ -706,6 +1136,22 @@ class KonvaImage {
|
|
|
706
1136
|
y: 1
|
|
707
1137
|
});
|
|
708
1138
|
}));
|
|
1139
|
+
this._ref.on("transformend", (e => {
|
|
1140
|
+
const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
|
|
1141
|
+
const position = absoluteTransform.point({
|
|
1142
|
+
x: this._ref.x(),
|
|
1143
|
+
y: this._ref.y()
|
|
1144
|
+
});
|
|
1145
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
|
|
1146
|
+
}));
|
|
1147
|
+
this._ref.on("dragend", (e => {
|
|
1148
|
+
const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
|
|
1149
|
+
const position = absoluteTransform.point({
|
|
1150
|
+
x: this._ref.x(),
|
|
1151
|
+
y: this._ref.y()
|
|
1152
|
+
});
|
|
1153
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
|
|
1154
|
+
}));
|
|
709
1155
|
this._ref.id(this._ref._id.toString());
|
|
710
1156
|
}
|
|
711
1157
|
getSrc() {
|
|
@@ -764,14 +1210,47 @@ class KonvaImage {
|
|
|
764
1210
|
x: x,
|
|
765
1211
|
y: y
|
|
766
1212
|
});
|
|
1213
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
|
|
1214
|
+
x: x,
|
|
1215
|
+
y: y
|
|
1216
|
+
}));
|
|
1217
|
+
}
|
|
1218
|
+
updateScreenCoordinates() {
|
|
1219
|
+
let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
|
|
1220
|
+
let invert = this._ref.getStage().getAbsoluteTransform().copy();
|
|
1221
|
+
invert = invert.invert();
|
|
1222
|
+
const positionStart = invert.point(screenPositionStart);
|
|
1223
|
+
this._ref.position({
|
|
1224
|
+
x: positionStart.x,
|
|
1225
|
+
y: positionStart.y
|
|
1226
|
+
});
|
|
767
1227
|
}
|
|
768
1228
|
}
|
|
769
1229
|
|
|
770
1230
|
class KonvaCloud {
|
|
771
|
-
constructor(params, ref = null) {
|
|
1231
|
+
constructor(params, ref = null, worldTransformer = new WorldTransform) {
|
|
772
1232
|
var _a, _b, _c, _d;
|
|
1233
|
+
this._worldTransformer = worldTransformer;
|
|
773
1234
|
if (ref) {
|
|
774
1235
|
this._ref = ref;
|
|
1236
|
+
const wcsStart = this._ref.getAttr("wcsStart");
|
|
1237
|
+
const wcsEnd = this._ref.getAttr("wcsEnd");
|
|
1238
|
+
if (!wcsStart) {
|
|
1239
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
|
|
1240
|
+
x: ref.x(),
|
|
1241
|
+
y: ref.y()
|
|
1242
|
+
}));
|
|
1243
|
+
}
|
|
1244
|
+
if (!wcsEnd) {
|
|
1245
|
+
const rightBottomPoint = {
|
|
1246
|
+
x: ref.x() + ref.width(),
|
|
1247
|
+
y: ref.y() + ref.height()
|
|
1248
|
+
};
|
|
1249
|
+
this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
|
|
1250
|
+
x: rightBottomPoint.x,
|
|
1251
|
+
y: rightBottomPoint.y
|
|
1252
|
+
}));
|
|
1253
|
+
}
|
|
775
1254
|
return;
|
|
776
1255
|
}
|
|
777
1256
|
if (!params) params = {};
|
|
@@ -779,7 +1258,25 @@ class KonvaCloud {
|
|
|
779
1258
|
x: 0,
|
|
780
1259
|
y: 0
|
|
781
1260
|
};
|
|
782
|
-
|
|
1261
|
+
if (params.position2) {
|
|
1262
|
+
params.width = params.position.x - params.position2.x;
|
|
1263
|
+
params.height = params.position.y - params.position2.y;
|
|
1264
|
+
} else {
|
|
1265
|
+
if (!params.width || !params.height) {
|
|
1266
|
+
params.position2 = {
|
|
1267
|
+
x: 200,
|
|
1268
|
+
y: 200
|
|
1269
|
+
};
|
|
1270
|
+
params.width = 200;
|
|
1271
|
+
params.height = 200;
|
|
1272
|
+
} else {
|
|
1273
|
+
params.position2 = {
|
|
1274
|
+
x: params.position.x + params.width,
|
|
1275
|
+
y: params.position.y + params.height
|
|
1276
|
+
};
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
const ARC_RADIUS = 16;
|
|
783
1280
|
this._ref = new Konva.Shape({
|
|
784
1281
|
x: params.position.x,
|
|
785
1282
|
y: params.position.y,
|
|
@@ -838,9 +1335,9 @@ class KonvaCloud {
|
|
|
838
1335
|
const counterClockwise = pX > midPoint.x && pY > midPoint.y;
|
|
839
1336
|
for (let iArc = 0; iArc < arcCount; iArc++) {
|
|
840
1337
|
if (counterClockwise) {
|
|
841
|
-
context.arc(pX, pY,
|
|
1338
|
+
context.arc(pX, pY, ARC_RADIUS, endAngle, startAngle);
|
|
842
1339
|
} else {
|
|
843
|
-
context.arc(pX, pY,
|
|
1340
|
+
context.arc(pX, pY, ARC_RADIUS, startAngle, endAngle);
|
|
844
1341
|
}
|
|
845
1342
|
pX += dx / arcCount;
|
|
846
1343
|
pY += dy / arcCount;
|
|
@@ -851,9 +1348,16 @@ class KonvaCloud {
|
|
|
851
1348
|
}
|
|
852
1349
|
});
|
|
853
1350
|
this._ref.className = "Cloud";
|
|
1351
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
|
|
1352
|
+
x: params.position.x,
|
|
1353
|
+
y: params.position.y
|
|
1354
|
+
}));
|
|
1355
|
+
this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
|
|
1356
|
+
x: params.position2.x,
|
|
1357
|
+
y: params.position2.y
|
|
1358
|
+
}));
|
|
854
1359
|
this._ref.on("transform", (e => {
|
|
855
1360
|
const attrs = e.target.attrs;
|
|
856
|
-
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
857
1361
|
const scaleByX = Math.abs(attrs.scaleX - 1) > 1e-5;
|
|
858
1362
|
const scaleByY = Math.abs(attrs.scaleY - 1) > 1e-5;
|
|
859
1363
|
let newWidth = this._ref.width();
|
|
@@ -875,11 +1379,37 @@ class KonvaCloud {
|
|
|
875
1379
|
y: 1
|
|
876
1380
|
});
|
|
877
1381
|
}));
|
|
1382
|
+
this._ref.on("transformend", (e => {
|
|
1383
|
+
const attrs = e.target.attrs;
|
|
1384
|
+
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
1385
|
+
const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
|
|
1386
|
+
const position = absoluteTransform.point({
|
|
1387
|
+
x: this._ref.x(),
|
|
1388
|
+
y: this._ref.y()
|
|
1389
|
+
});
|
|
1390
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
|
|
1391
|
+
this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
|
|
1392
|
+
x: position.x + this._ref.width(),
|
|
1393
|
+
y: position.y + this._ref.height()
|
|
1394
|
+
}));
|
|
1395
|
+
}));
|
|
1396
|
+
this._ref.on("dragend", (e => {
|
|
1397
|
+
const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
|
|
1398
|
+
const position = absoluteTransform.point({
|
|
1399
|
+
x: this._ref.x(),
|
|
1400
|
+
y: this._ref.y()
|
|
1401
|
+
});
|
|
1402
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
|
|
1403
|
+
this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
|
|
1404
|
+
x: position.x + this._ref.width(),
|
|
1405
|
+
y: position.y + this._ref.height()
|
|
1406
|
+
}));
|
|
1407
|
+
}));
|
|
878
1408
|
this._ref.getSelfRect = () => ({
|
|
879
|
-
x: 0 -
|
|
880
|
-
y: 0 -
|
|
881
|
-
width: this._ref.width() + 2 *
|
|
882
|
-
height: this._ref.height() + 2 *
|
|
1409
|
+
x: 0 - ARC_RADIUS,
|
|
1410
|
+
y: 0 - ARC_RADIUS,
|
|
1411
|
+
width: this._ref.width() + 2 * ARC_RADIUS,
|
|
1412
|
+
height: this._ref.height() + 2 * ARC_RADIUS
|
|
883
1413
|
});
|
|
884
1414
|
this._ref.id(this._ref._id.toString());
|
|
885
1415
|
}
|
|
@@ -925,18 +1455,34 @@ class KonvaCloud {
|
|
|
925
1455
|
x: x,
|
|
926
1456
|
y: y
|
|
927
1457
|
});
|
|
1458
|
+
this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
|
|
1459
|
+
x: x,
|
|
1460
|
+
y: y
|
|
1461
|
+
}));
|
|
928
1462
|
}
|
|
929
1463
|
getWidth() {
|
|
930
1464
|
return this._ref.width();
|
|
931
1465
|
}
|
|
932
1466
|
setWidth(w) {
|
|
933
1467
|
this._ref.width(w);
|
|
1468
|
+
const rightLowerPoint = {
|
|
1469
|
+
x: this._ref.x() + w,
|
|
1470
|
+
y: this._ref.y() + this._ref.height()
|
|
1471
|
+
};
|
|
1472
|
+
const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
|
|
1473
|
+
this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
|
|
934
1474
|
}
|
|
935
1475
|
getHeigth() {
|
|
936
1476
|
return this._ref.height();
|
|
937
1477
|
}
|
|
938
1478
|
setHeight(h) {
|
|
939
1479
|
this._ref.height(h);
|
|
1480
|
+
const rightLowerPoint = {
|
|
1481
|
+
x: this._ref.x() + this._ref.width(),
|
|
1482
|
+
y: this._ref.y() + h
|
|
1483
|
+
};
|
|
1484
|
+
const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
|
|
1485
|
+
this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
|
|
940
1486
|
}
|
|
941
1487
|
getLineWidth() {
|
|
942
1488
|
return this._ref.strokeWidth();
|
|
@@ -944,6 +1490,20 @@ class KonvaCloud {
|
|
|
944
1490
|
setLineWidth(size) {
|
|
945
1491
|
this._ref.strokeWidth(size);
|
|
946
1492
|
}
|
|
1493
|
+
updateScreenCoordinates() {
|
|
1494
|
+
let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
|
|
1495
|
+
let screenPositionEnd = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));
|
|
1496
|
+
let invert = this._ref.getStage().getAbsoluteTransform().copy();
|
|
1497
|
+
invert = invert.invert();
|
|
1498
|
+
const positionStart = invert.point(screenPositionStart);
|
|
1499
|
+
const positionEnd = invert.point(screenPositionEnd);
|
|
1500
|
+
this._ref.position({
|
|
1501
|
+
x: positionStart.x,
|
|
1502
|
+
y: positionStart.y
|
|
1503
|
+
});
|
|
1504
|
+
this._ref.width(Math.abs(positionEnd.x - positionStart.x));
|
|
1505
|
+
this._ref.height(Math.abs(positionEnd.y - positionStart.y));
|
|
1506
|
+
}
|
|
947
1507
|
}
|
|
948
1508
|
|
|
949
1509
|
const MarkupMode2Konva = {
|
|
@@ -953,37 +1513,49 @@ const MarkupMode2Konva = {
|
|
|
953
1513
|
},
|
|
954
1514
|
Line: {
|
|
955
1515
|
name: "Line",
|
|
956
|
-
initializer: (ref, params = null) => new KonvaLine(params, ref)
|
|
1516
|
+
initializer: (ref, params = null, ...attr) => new KonvaLine(params, ref, ...attr)
|
|
957
1517
|
},
|
|
958
1518
|
Text: {
|
|
959
1519
|
name: "Text",
|
|
960
|
-
initializer: (ref, params = null) => new KonvaText(params, ref)
|
|
1520
|
+
initializer: (ref, params = null, ...attr) => new KonvaText(params, ref, ...attr)
|
|
961
1521
|
},
|
|
962
1522
|
Rectangle: {
|
|
963
1523
|
name: "Rect",
|
|
964
|
-
initializer: (ref, params = null) => new KonvaRectangle(params, ref)
|
|
1524
|
+
initializer: (ref, params = null, ...attr) => new KonvaRectangle(params, ref, ...attr)
|
|
965
1525
|
},
|
|
966
1526
|
Ellipse: {
|
|
967
1527
|
name: "Ellipse",
|
|
968
|
-
initializer: (ref, params = null) => new KonvaEllipse(params, ref)
|
|
1528
|
+
initializer: (ref, params = null, ...attr) => new KonvaEllipse(params, ref, ...attr)
|
|
969
1529
|
},
|
|
970
1530
|
Arrow: {
|
|
971
1531
|
name: "Arrow",
|
|
972
|
-
initializer: (ref, params = null) => new KonvaArrow(params, ref)
|
|
1532
|
+
initializer: (ref, params = null, ...attr) => new KonvaArrow(params, ref, ...attr)
|
|
973
1533
|
},
|
|
974
1534
|
Image: {
|
|
975
1535
|
name: "Image",
|
|
976
|
-
initializer: (ref, params = null) => new KonvaImage(params, ref)
|
|
1536
|
+
initializer: (ref, params = null, ...attr) => new KonvaImage(params, ref, ...attr)
|
|
977
1537
|
},
|
|
978
1538
|
Cloud: {
|
|
979
1539
|
name: "Cloud",
|
|
980
|
-
initializer: (ref, params = null) => new KonvaCloud(params, ref)
|
|
1540
|
+
initializer: (ref, params = null, ...attr) => new KonvaCloud(params, ref, ...attr)
|
|
981
1541
|
}
|
|
982
1542
|
};
|
|
983
1543
|
|
|
1544
|
+
function debounce(func, wait) {
|
|
1545
|
+
let timeout = null;
|
|
1546
|
+
return (...args) => {
|
|
1547
|
+
if (timeout) {
|
|
1548
|
+
clearTimeout(timeout);
|
|
1549
|
+
}
|
|
1550
|
+
timeout = setTimeout((() => {
|
|
1551
|
+
timeout = null;
|
|
1552
|
+
func(...args);
|
|
1553
|
+
}), wait);
|
|
1554
|
+
};
|
|
1555
|
+
}
|
|
1556
|
+
|
|
984
1557
|
class KonvaMarkup {
|
|
985
1558
|
constructor() {
|
|
986
|
-
this._containerEvents = [];
|
|
987
1559
|
this._markupIsActive = false;
|
|
988
1560
|
this._markupColor = new MarkupColor(255, 0, 0);
|
|
989
1561
|
this.lineWidth = 4;
|
|
@@ -1002,25 +1574,29 @@ class KonvaMarkup {
|
|
|
1002
1574
|
if (!this._konvaStage) return;
|
|
1003
1575
|
this._konvaStage.width(width);
|
|
1004
1576
|
this._konvaStage.height(height);
|
|
1577
|
+
this.getObjects().forEach((markupObject => {
|
|
1578
|
+
markupObject.updateScreenCoordinates();
|
|
1579
|
+
}));
|
|
1580
|
+
};
|
|
1581
|
+
this.resizeViewer = event => {
|
|
1582
|
+
const {width: width, height: height} = event;
|
|
1583
|
+
if (!width || !height) return;
|
|
1584
|
+
if (!this._konvaStage) return;
|
|
1585
|
+
this._konvaStage.width(width);
|
|
1586
|
+
this._konvaStage.height(height);
|
|
1587
|
+
this.getObjects().forEach((markupObject => {
|
|
1588
|
+
markupObject.updateScreenCoordinates();
|
|
1589
|
+
}));
|
|
1005
1590
|
};
|
|
1006
1591
|
this.pan = event => {
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
};
|
|
1011
|
-
this._konvaStage.position(newPos);
|
|
1592
|
+
this.getObjects().forEach((markupObject => {
|
|
1593
|
+
markupObject.updateScreenCoordinates();
|
|
1594
|
+
}));
|
|
1012
1595
|
};
|
|
1013
1596
|
this.zoomAt = event => {
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
y: newScale
|
|
1018
|
-
});
|
|
1019
|
-
const newPos = {
|
|
1020
|
-
x: event.x - (event.x - this._konvaStage.x()) * event.data,
|
|
1021
|
-
y: event.y - (event.y - this._konvaStage.y()) * event.data
|
|
1022
|
-
};
|
|
1023
|
-
this._konvaStage.position(newPos);
|
|
1597
|
+
this.getObjects().forEach((markupObject => {
|
|
1598
|
+
markupObject.updateScreenCoordinates();
|
|
1599
|
+
}));
|
|
1024
1600
|
};
|
|
1025
1601
|
this.redirectToViewer = event => {
|
|
1026
1602
|
if (this._viewer) this._viewer.emit(event);
|
|
@@ -1037,7 +1613,6 @@ class KonvaMarkup {
|
|
|
1037
1613
|
this._viewer = viewer;
|
|
1038
1614
|
this._worldTransformer = worldTransformer !== null && worldTransformer !== undefined ? worldTransformer : new WorldTransform;
|
|
1039
1615
|
this._container = container;
|
|
1040
|
-
this._containerEvents = containerEvents !== null && containerEvents !== undefined ? containerEvents : [];
|
|
1041
1616
|
this._markupContainer = document.createElement("div");
|
|
1042
1617
|
this._markupContainer.id = "markup-container";
|
|
1043
1618
|
this._markupContainer.style.position = "absolute";
|
|
@@ -1047,8 +1622,7 @@ class KonvaMarkup {
|
|
|
1047
1622
|
this._markupContainer.style.pointerEvents = "none";
|
|
1048
1623
|
const parentDiv = this._container.parentElement;
|
|
1049
1624
|
parentDiv.appendChild(this._markupContainer);
|
|
1050
|
-
this._resizeObserver = new ResizeObserver(this.resizeContainer);
|
|
1051
|
-
this._resizeObserver.observe(parentDiv);
|
|
1625
|
+
if (viewer) this._viewer.addEventListener("resize", this.resizeViewer); else this._resizeObserver = new ResizeObserver(debounce(this.resizeContainer, 100));
|
|
1052
1626
|
this._markupColor.setColor(255, 0, 0);
|
|
1053
1627
|
this.initializeKonva();
|
|
1054
1628
|
if (this._viewer) {
|
|
@@ -1143,7 +1717,7 @@ class KonvaMarkup {
|
|
|
1143
1717
|
}));
|
|
1144
1718
|
(_d = viewpoint.rectangles) === null || _d === undefined ? undefined : _d.forEach((rect => {
|
|
1145
1719
|
const screenPoint = this._worldTransformer.worldToScreen(rect.position);
|
|
1146
|
-
this.addRectangle(screenPoint, rect.width, rect.height, rect.line_width, rect.color, rect.id);
|
|
1720
|
+
this.addRectangle(screenPoint, null, rect.width, rect.height, rect.line_width, rect.color, rect.id);
|
|
1147
1721
|
}));
|
|
1148
1722
|
(_e = viewpoint.ellipses) === null || _e === undefined ? undefined : _e.forEach((ellipse => {
|
|
1149
1723
|
const screenPoint = this._worldTransformer.worldToScreen(ellipse.position);
|
|
@@ -1156,7 +1730,7 @@ class KonvaMarkup {
|
|
|
1156
1730
|
}));
|
|
1157
1731
|
(_g = viewpoint.clouds) === null || _g === undefined ? undefined : _g.forEach((cloud => {
|
|
1158
1732
|
const screenPoint = this._worldTransformer.worldToScreen(cloud.position);
|
|
1159
|
-
this.addCloud(screenPoint, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
|
|
1733
|
+
this.addCloud(screenPoint, null, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
|
|
1160
1734
|
}));
|
|
1161
1735
|
(_h = viewpoint.images) === null || _h === undefined ? undefined : _h.forEach((image => {
|
|
1162
1736
|
const screenPoint = this._worldTransformer.worldToScreen(image.position);
|
|
@@ -1197,7 +1771,7 @@ class KonvaMarkup {
|
|
|
1197
1771
|
createObject(type, params) {
|
|
1198
1772
|
const konvaShape = MarkupMode2Konva[type];
|
|
1199
1773
|
if (!konvaShape || !konvaShape.initializer) throw new Error(`Markup CreateObject - unsupported markup type ${type}`);
|
|
1200
|
-
const object = konvaShape.initializer(null, params);
|
|
1774
|
+
const object = konvaShape.initializer(null, params, this._worldTransformer);
|
|
1201
1775
|
this.addObject(object);
|
|
1202
1776
|
return object;
|
|
1203
1777
|
}
|
|
@@ -1205,7 +1779,7 @@ class KonvaMarkup {
|
|
|
1205
1779
|
const objects = [];
|
|
1206
1780
|
Object.keys(MarkupMode2Konva).forEach((type => {
|
|
1207
1781
|
const konvaShape = MarkupMode2Konva[type];
|
|
1208
|
-
this.konvaLayerFind(type).forEach((ref => objects.push(konvaShape.initializer(ref))));
|
|
1782
|
+
this.konvaLayerFind(type).forEach((ref => objects.push(konvaShape.initializer(ref, null, this._worldTransformer))));
|
|
1209
1783
|
}));
|
|
1210
1784
|
return objects;
|
|
1211
1785
|
}
|
|
@@ -1214,7 +1788,7 @@ class KonvaMarkup {
|
|
|
1214
1788
|
return this._konvaTransformer.nodes().map((ref => {
|
|
1215
1789
|
const name = ref.className;
|
|
1216
1790
|
const konvaShape = Object.values(MarkupMode2Konva).find((shape => shape.name === name));
|
|
1217
|
-
return konvaShape ? konvaShape.initializer(ref) : null;
|
|
1791
|
+
return konvaShape ? konvaShape.initializer(ref, null, this._worldTransformer) : null;
|
|
1218
1792
|
})).filter((x => x));
|
|
1219
1793
|
}
|
|
1220
1794
|
selectObjects(objects) {
|
|
@@ -1290,7 +1864,7 @@ class KonvaMarkup {
|
|
|
1290
1864
|
this.addRectangle({
|
|
1291
1865
|
x: startX,
|
|
1292
1866
|
y: startY
|
|
1293
|
-
}, dX, dY);
|
|
1867
|
+
}, null, dX, dY);
|
|
1294
1868
|
} else if (this._markupMode === "Ellipse") {
|
|
1295
1869
|
this.addEllipse({
|
|
1296
1870
|
x: startX,
|
|
@@ -1311,7 +1885,7 @@ class KonvaMarkup {
|
|
|
1311
1885
|
this.addCloud({
|
|
1312
1886
|
x: startX,
|
|
1313
1887
|
y: startY
|
|
1314
|
-
}, Math.max(100, dX), Math.max(100, dY));
|
|
1888
|
+
}, null, Math.max(100, dX), Math.max(100, dY));
|
|
1315
1889
|
}
|
|
1316
1890
|
}
|
|
1317
1891
|
}
|
|
@@ -1350,7 +1924,7 @@ class KonvaMarkup {
|
|
|
1350
1924
|
} else lastObj = this.addRectangle({
|
|
1351
1925
|
x: startX,
|
|
1352
1926
|
y: startY
|
|
1353
|
-
}, dX, dY);
|
|
1927
|
+
}, null, dX, dY);
|
|
1354
1928
|
} else if (this._markupMode === "Ellipse") {
|
|
1355
1929
|
if (lastObj) {
|
|
1356
1930
|
lastObj.setPosition(startX, startY);
|
|
@@ -1371,7 +1945,7 @@ class KonvaMarkup {
|
|
|
1371
1945
|
} else lastObj = this.addCloud({
|
|
1372
1946
|
x: startX,
|
|
1373
1947
|
y: startY
|
|
1374
|
-
}, dX, dY);
|
|
1948
|
+
}, null, dX, dY);
|
|
1375
1949
|
}
|
|
1376
1950
|
}));
|
|
1377
1951
|
stage.on("click tap", (e => {
|
|
@@ -1463,22 +2037,12 @@ class KonvaMarkup {
|
|
|
1463
2037
|
getMarkupLines() {
|
|
1464
2038
|
const lines = [];
|
|
1465
2039
|
this.konvaLayerFind("Line").forEach((ref => {
|
|
1466
|
-
const
|
|
1467
|
-
if (!
|
|
1468
|
-
const
|
|
1469
|
-
const absoluteTransform = ref.getAbsoluteTransform();
|
|
1470
|
-
for (let i = 0; i < linePoints.length; i += 2) {
|
|
1471
|
-
const atPoint = absoluteTransform.point({
|
|
1472
|
-
x: linePoints[i],
|
|
1473
|
-
y: linePoints[i + 1]
|
|
1474
|
-
});
|
|
1475
|
-
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
1476
|
-
worldPoints.push(worldPoint);
|
|
1477
|
-
}
|
|
1478
|
-
const konvaLine = new KonvaLine(null, ref);
|
|
2040
|
+
const wcsPoints = ref.getAttr("wcsPoints");
|
|
2041
|
+
if (!wcsPoints) return;
|
|
2042
|
+
const konvaLine = new KonvaLine(null, ref, this._worldTransformer);
|
|
1479
2043
|
const line = {
|
|
1480
2044
|
id: konvaLine.id(),
|
|
1481
|
-
points:
|
|
2045
|
+
points: wcsPoints,
|
|
1482
2046
|
color: konvaLine.getColor() || "#ff0000",
|
|
1483
2047
|
type: konvaLine.getLineType() || this.lineType,
|
|
1484
2048
|
width: konvaLine.getLineWidth() || this.lineWidth
|
|
@@ -1492,17 +2056,12 @@ class KonvaMarkup {
|
|
|
1492
2056
|
this.konvaLayerFind("Text").forEach((ref => {
|
|
1493
2057
|
const textSize = .02;
|
|
1494
2058
|
const textScale = this._worldTransformer.getScale();
|
|
1495
|
-
const
|
|
2059
|
+
const wcsPosition = ref.getAttr("wcsStart");
|
|
1496
2060
|
const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
|
|
1497
|
-
const
|
|
1498
|
-
x: position.x,
|
|
1499
|
-
y: position.y
|
|
1500
|
-
});
|
|
1501
|
-
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
1502
|
-
const shape = new KonvaText(null, ref);
|
|
2061
|
+
const shape = new KonvaText(null, ref, this._worldTransformer);
|
|
1503
2062
|
const text = {
|
|
1504
2063
|
id: shape.id(),
|
|
1505
|
-
position:
|
|
2064
|
+
position: wcsPosition,
|
|
1506
2065
|
text: shape.getText(),
|
|
1507
2066
|
text_size: textSize * textScale.y,
|
|
1508
2067
|
angle: shape.getRotation(),
|
|
@@ -1516,20 +2075,16 @@ class KonvaMarkup {
|
|
|
1516
2075
|
getMarkupRectangles() {
|
|
1517
2076
|
const rectangles = [];
|
|
1518
2077
|
this.konvaLayerFind("Rectangle").forEach((ref => {
|
|
1519
|
-
const
|
|
1520
|
-
const
|
|
1521
|
-
const
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
});
|
|
1525
|
-
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
1526
|
-
const scale = stageAbsoluteTransform.getMatrix()[0];
|
|
1527
|
-
const shape = new KonvaRectangle(null, ref);
|
|
2078
|
+
const wcsStart = ref.getAttr("wcsStart");
|
|
2079
|
+
const wcsEnd = ref.getAttr("wcsEnd");
|
|
2080
|
+
const screenStart = this._worldTransformer.worldToScreen(wcsStart);
|
|
2081
|
+
const screenEnd = this._worldTransformer.worldToScreen(wcsEnd);
|
|
2082
|
+
const shape = new KonvaRectangle(null, ref, this._worldTransformer);
|
|
1528
2083
|
const rectangle = {
|
|
1529
2084
|
id: shape.id(),
|
|
1530
|
-
position:
|
|
1531
|
-
width:
|
|
1532
|
-
height:
|
|
2085
|
+
position: wcsStart,
|
|
2086
|
+
width: Math.abs(screenStart.x - screenEnd.x),
|
|
2087
|
+
height: Math.abs(screenStart.y - screenEnd.y),
|
|
1533
2088
|
line_width: shape.getLineWidth(),
|
|
1534
2089
|
color: shape.getColor()
|
|
1535
2090
|
};
|
|
@@ -1540,18 +2095,13 @@ class KonvaMarkup {
|
|
|
1540
2095
|
getMarkupEllipses() {
|
|
1541
2096
|
const ellipses = [];
|
|
1542
2097
|
this.konvaLayerFind("Ellipse").forEach((ref => {
|
|
1543
|
-
const
|
|
2098
|
+
const wcsPosition = ref.getAttr("wcsPosition");
|
|
1544
2099
|
const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
|
|
1545
|
-
const atPoint = stageAbsoluteTransform.point({
|
|
1546
|
-
x: position.x,
|
|
1547
|
-
y: position.y
|
|
1548
|
-
});
|
|
1549
|
-
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
1550
2100
|
const scale = stageAbsoluteTransform.getMatrix()[0];
|
|
1551
|
-
const shape = new KonvaEllipse(null, ref);
|
|
2101
|
+
const shape = new KonvaEllipse(null, ref, this._worldTransformer);
|
|
1552
2102
|
const ellipse = {
|
|
1553
2103
|
id: shape.id(),
|
|
1554
|
-
position:
|
|
2104
|
+
position: wcsPosition,
|
|
1555
2105
|
radius: {
|
|
1556
2106
|
x: ref.getRadiusX() * scale,
|
|
1557
2107
|
y: ref.getRadiusY() * scale
|
|
@@ -1566,22 +2116,13 @@ class KonvaMarkup {
|
|
|
1566
2116
|
getMarkupArrows() {
|
|
1567
2117
|
const arrows = [];
|
|
1568
2118
|
this.konvaLayerFind("Arrow").forEach((ref => {
|
|
1569
|
-
const
|
|
1570
|
-
const
|
|
1571
|
-
|
|
1572
|
-
y: ref.points()[1]
|
|
1573
|
-
});
|
|
1574
|
-
const worldStartPoint = this._worldTransformer.screenToWorld(atStartPoint);
|
|
1575
|
-
const atEndPoint = absoluteTransform.point({
|
|
1576
|
-
x: ref.points()[2],
|
|
1577
|
-
y: ref.points()[3]
|
|
1578
|
-
});
|
|
1579
|
-
const worldEndPoint = this._worldTransformer.screenToWorld(atEndPoint);
|
|
1580
|
-
const shape = new KonvaArrow(null, ref);
|
|
2119
|
+
const wcsStart = ref.getAttr("wcsStart");
|
|
2120
|
+
const wcsEnd = ref.getAttr("wcsEnd");
|
|
2121
|
+
const shape = new KonvaArrow(null, ref, this._worldTransformer);
|
|
1581
2122
|
const arrow = {
|
|
1582
2123
|
id: shape.id(),
|
|
1583
|
-
start:
|
|
1584
|
-
end:
|
|
2124
|
+
start: wcsStart,
|
|
2125
|
+
end: wcsEnd,
|
|
1585
2126
|
color: shape.getColor()
|
|
1586
2127
|
};
|
|
1587
2128
|
arrows.push(arrow);
|
|
@@ -1591,18 +2132,13 @@ class KonvaMarkup {
|
|
|
1591
2132
|
getMarkupImages() {
|
|
1592
2133
|
const images = [];
|
|
1593
2134
|
this.konvaLayerFind("Image").forEach((ref => {
|
|
1594
|
-
const
|
|
2135
|
+
const wcsStart = ref.getAttr("wcsStart");
|
|
1595
2136
|
const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
|
|
1596
|
-
const atPoint = stageAbsoluteTransform.point({
|
|
1597
|
-
x: position.x,
|
|
1598
|
-
y: position.y
|
|
1599
|
-
});
|
|
1600
|
-
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
1601
2137
|
const scale = stageAbsoluteTransform.getMatrix()[0];
|
|
1602
|
-
const shape = new KonvaImage(null, ref);
|
|
2138
|
+
const shape = new KonvaImage(null, ref, this._worldTransformer);
|
|
1603
2139
|
const image = {
|
|
1604
2140
|
id: shape.id(),
|
|
1605
|
-
position:
|
|
2141
|
+
position: wcsStart,
|
|
1606
2142
|
src: shape.getSrc(),
|
|
1607
2143
|
width: shape.getWidth() * scale,
|
|
1608
2144
|
height: shape.getHeight() * scale
|
|
@@ -1614,20 +2150,16 @@ class KonvaMarkup {
|
|
|
1614
2150
|
getMarkupClouds() {
|
|
1615
2151
|
const clouds = [];
|
|
1616
2152
|
this.konvaLayerFind("Cloud").forEach((ref => {
|
|
1617
|
-
const
|
|
1618
|
-
const
|
|
1619
|
-
const
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
});
|
|
1623
|
-
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
1624
|
-
const scale = stageAbsoluteTransform.getMatrix()[0];
|
|
1625
|
-
const shape = new KonvaCloud(null, ref);
|
|
2153
|
+
const wcsStart = ref.getAttr("wcsStart");
|
|
2154
|
+
const wcsEnd = ref.getAttr("wcsEnd");
|
|
2155
|
+
const screenStart = this._worldTransformer.worldToScreen(wcsStart);
|
|
2156
|
+
const screenEnd = this._worldTransformer.worldToScreen(wcsEnd);
|
|
2157
|
+
const shape = new KonvaCloud(null, ref, this._worldTransformer);
|
|
1626
2158
|
const cloud = {
|
|
1627
2159
|
id: shape.id(),
|
|
1628
|
-
position:
|
|
1629
|
-
width:
|
|
1630
|
-
height:
|
|
2160
|
+
position: wcsStart,
|
|
2161
|
+
width: Math.abs(screenStart.x - screenEnd.x),
|
|
2162
|
+
height: Math.abs(screenStart.y - screenEnd.y),
|
|
1631
2163
|
line_width: shape.getLineWidth(),
|
|
1632
2164
|
color: shape.getColor()
|
|
1633
2165
|
};
|
|
@@ -1664,7 +2196,7 @@ class KonvaMarkup {
|
|
|
1664
2196
|
width: width || this.lineWidth,
|
|
1665
2197
|
color: color || this._markupColor.asHex(),
|
|
1666
2198
|
id: id
|
|
1667
|
-
});
|
|
2199
|
+
}, null, this._worldTransformer);
|
|
1668
2200
|
this.addObject(konvaLine);
|
|
1669
2201
|
return konvaLine;
|
|
1670
2202
|
}
|
|
@@ -1771,20 +2303,21 @@ class KonvaMarkup {
|
|
|
1771
2303
|
fontSize: fontSize || this.fontSize,
|
|
1772
2304
|
color: color || this._markupColor.asHex(),
|
|
1773
2305
|
id: id
|
|
1774
|
-
});
|
|
2306
|
+
}, null, this._worldTransformer);
|
|
1775
2307
|
this.addObject(konvaText);
|
|
1776
2308
|
return konvaText;
|
|
1777
2309
|
}
|
|
1778
|
-
addRectangle(position, width, height, lineWidth, color, id) {
|
|
2310
|
+
addRectangle(position, position2, width, height, lineWidth, color, id) {
|
|
1779
2311
|
if (!position) return;
|
|
1780
2312
|
const konvaRectangle = new KonvaRectangle({
|
|
1781
2313
|
position: position,
|
|
2314
|
+
position2: position2,
|
|
1782
2315
|
width: width,
|
|
1783
2316
|
height: height,
|
|
1784
2317
|
lineWidth: lineWidth || this.lineWidth,
|
|
1785
2318
|
color: color || this._markupColor.asHex(),
|
|
1786
2319
|
id: id
|
|
1787
|
-
});
|
|
2320
|
+
}, null, this._worldTransformer);
|
|
1788
2321
|
this.addObject(konvaRectangle);
|
|
1789
2322
|
return konvaRectangle;
|
|
1790
2323
|
}
|
|
@@ -1796,7 +2329,7 @@ class KonvaMarkup {
|
|
|
1796
2329
|
lineWidth: lineWidth,
|
|
1797
2330
|
color: color || this._markupColor.asHex(),
|
|
1798
2331
|
id: id
|
|
1799
|
-
});
|
|
2332
|
+
}, null, this._worldTransformer);
|
|
1800
2333
|
this.addObject(konvaEllipse);
|
|
1801
2334
|
return konvaEllipse;
|
|
1802
2335
|
}
|
|
@@ -1807,20 +2340,21 @@ class KonvaMarkup {
|
|
|
1807
2340
|
end: end,
|
|
1808
2341
|
color: color || this._markupColor.asHex(),
|
|
1809
2342
|
id: id
|
|
1810
|
-
});
|
|
2343
|
+
}, null, this._worldTransformer);
|
|
1811
2344
|
this.addObject(konvaArrow);
|
|
1812
2345
|
return konvaArrow;
|
|
1813
2346
|
}
|
|
1814
|
-
addCloud(position, width, height, lineWidth, color, id) {
|
|
2347
|
+
addCloud(position, position2, width, height, lineWidth, color, id) {
|
|
1815
2348
|
if (!position || !width || !height) return;
|
|
1816
2349
|
const konvaCloud = new KonvaCloud({
|
|
1817
2350
|
position: position,
|
|
2351
|
+
position2: position2,
|
|
1818
2352
|
width: width,
|
|
1819
2353
|
height: height,
|
|
1820
2354
|
color: color || this._markupColor.asHex(),
|
|
1821
2355
|
lineWidth: lineWidth || this.lineWidth,
|
|
1822
2356
|
id: id
|
|
1823
|
-
});
|
|
2357
|
+
}, null, this._worldTransformer);
|
|
1824
2358
|
this.addObject(konvaCloud);
|
|
1825
2359
|
return konvaCloud;
|
|
1826
2360
|
}
|
|
@@ -1838,7 +2372,7 @@ class KonvaMarkup {
|
|
|
1838
2372
|
maxWidth: this._konvaStage.width() - position.x,
|
|
1839
2373
|
maxHeight: this._konvaStage.height() - position.y,
|
|
1840
2374
|
id: id
|
|
1841
|
-
});
|
|
2375
|
+
}, null, this._worldTransformer);
|
|
1842
2376
|
this.addObject(konvaImage);
|
|
1843
2377
|
return konvaImage;
|
|
1844
2378
|
}
|