@plait/draw 0.28.0 → 0.29.0
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/constants/geometry.d.ts +71 -1
- package/constants/pointer.d.ts +4 -2
- package/engines/{comment.d.ts → basic-shapes/comment.d.ts} +1 -1
- package/engines/{cross.d.ts → basic-shapes/cross.d.ts} +2 -2
- package/engines/{diamond.d.ts → basic-shapes/diamond.d.ts} +1 -1
- package/engines/basic-shapes/ellipse.d.ts +13 -0
- package/engines/{hexagon.d.ts → basic-shapes/hexagon.d.ts} +2 -2
- package/engines/{left-arrow.d.ts → basic-shapes/left-arrow.d.ts} +2 -2
- package/engines/{octagon.d.ts → basic-shapes/octagon.d.ts} +2 -2
- package/engines/basic-shapes/parallelogram.d.ts +4 -0
- package/engines/{pentagon-arrow.d.ts → basic-shapes/pentagon-arrow.d.ts} +2 -2
- package/engines/{pentagon.d.ts → basic-shapes/pentagon.d.ts} +2 -2
- package/engines/basic-shapes/polygon.d.ts +8 -0
- package/engines/{process-arrow.d.ts → basic-shapes/process-arrow.d.ts} +2 -2
- package/engines/{rectangle.d.ts → basic-shapes/rectangle.d.ts} +1 -1
- package/engines/{right-arrow.d.ts → basic-shapes/right-arrow.d.ts} +2 -2
- package/engines/{round-comment.d.ts → basic-shapes/round-comment.d.ts} +1 -1
- package/engines/{round-rectangle.d.ts → basic-shapes/round-rectangle.d.ts} +1 -1
- package/engines/{star.d.ts → basic-shapes/star.d.ts} +2 -2
- package/engines/{trapezoid.d.ts → basic-shapes/trapezoid.d.ts} +2 -2
- package/engines/{triangle.d.ts → basic-shapes/triangle.d.ts} +2 -2
- package/engines/{two-way-arrow.d.ts → basic-shapes/two-way-arrow.d.ts} +2 -2
- package/engines/flowchart/delay.d.ts +2 -0
- package/engines/flowchart/manual-input.d.ts +4 -0
- package/engines/flowchart/manual-loop.d.ts +4 -0
- package/engines/flowchart/merge.d.ts +4 -0
- package/engines/flowchart/preparation.d.ts +4 -0
- package/engines/flowchart/stored-data.d.ts +2 -0
- package/engines/flowchart/terminal.d.ts +5 -0
- package/engines/index.d.ts +3 -3
- package/esm2022/constants/geometry.mjs +40 -2
- package/esm2022/constants/pointer.mjs +9 -3
- package/esm2022/engines/basic-shapes/comment.mjs +57 -0
- package/esm2022/engines/basic-shapes/cross.mjs +33 -0
- package/esm2022/engines/basic-shapes/diamond.mjs +16 -0
- package/esm2022/engines/basic-shapes/ellipse.mjs +100 -0
- package/esm2022/engines/basic-shapes/hexagon.mjs +27 -0
- package/esm2022/engines/basic-shapes/left-arrow.mjs +30 -0
- package/esm2022/engines/basic-shapes/octagon.mjs +29 -0
- package/esm2022/engines/basic-shapes/parallelogram.mjs +25 -0
- package/esm2022/engines/basic-shapes/pentagon-arrow.mjs +24 -0
- package/esm2022/engines/basic-shapes/pentagon.mjs +30 -0
- package/esm2022/engines/basic-shapes/polygon.mjs +40 -0
- package/esm2022/engines/basic-shapes/process-arrow.mjs +26 -0
- package/esm2022/engines/basic-shapes/rectangle.mjs +26 -0
- package/esm2022/engines/basic-shapes/right-arrow.mjs +28 -0
- package/esm2022/engines/basic-shapes/round-comment.mjs +81 -0
- package/esm2022/engines/basic-shapes/round-rectangle.mjs +59 -0
- package/esm2022/engines/basic-shapes/star.mjs +39 -0
- package/esm2022/engines/basic-shapes/trapezoid.mjs +25 -0
- package/esm2022/engines/basic-shapes/triangle.mjs +33 -0
- package/esm2022/engines/basic-shapes/two-way-arrow.mjs +25 -0
- package/esm2022/engines/flowchart/delay.mjs +45 -0
- package/esm2022/engines/flowchart/manual-input.mjs +32 -0
- package/esm2022/engines/flowchart/manual-loop.mjs +25 -0
- package/esm2022/engines/flowchart/merge.mjs +34 -0
- package/esm2022/engines/flowchart/preparation.mjs +27 -0
- package/esm2022/engines/flowchart/stored-data.mjs +74 -0
- package/esm2022/engines/flowchart/terminal.mjs +59 -0
- package/esm2022/engines/index.mjs +59 -41
- package/esm2022/generators/geometry-shape.generator.mjs +3 -3
- package/esm2022/generators/line.generator.mjs +1 -1
- package/esm2022/geometry.component.mjs +9 -5
- package/esm2022/image.component.mjs +4 -4
- package/esm2022/interfaces/geometry.mjs +38 -24
- package/esm2022/interfaces/index.mjs +9 -3
- package/esm2022/interfaces/text.mjs +1 -1
- package/esm2022/line.component.mjs +4 -4
- package/esm2022/plugins/with-geometry-create.mjs +31 -19
- package/esm2022/transforms/geometry.mjs +6 -6
- package/esm2022/utils/geometry.mjs +13 -5
- package/esm2022/utils/line-arrow.mjs +3 -3
- package/esm2022/utils/shape.mjs +3 -3
- package/fesm2022/plait-draw.mjs +750 -536
- package/fesm2022/plait-draw.mjs.map +1 -1
- package/interfaces/geometry.d.ts +19 -5
- package/interfaces/index.d.ts +2 -0
- package/interfaces/text.d.ts +2 -2
- package/package.json +1 -1
- package/plugins/with-geometry-create.d.ts +5 -0
- package/transforms/geometry.d.ts +2 -2
- package/transforms/index.d.ts +1 -1
- package/utils/geometry.d.ts +22 -3
- package/utils/shape.d.ts +2 -2
- package/engines/ellipse.d.ts +0 -4
- package/engines/parallelogram.d.ts +0 -4
- package/esm2022/engines/comment.mjs +0 -57
- package/esm2022/engines/cross.mjs +0 -46
- package/esm2022/engines/diamond.mjs +0 -30
- package/esm2022/engines/ellipse.mjs +0 -92
- package/esm2022/engines/hexagon.mjs +0 -40
- package/esm2022/engines/left-arrow.mjs +0 -45
- package/esm2022/engines/octagon.mjs +0 -42
- package/esm2022/engines/parallelogram.mjs +0 -39
- package/esm2022/engines/pentagon-arrow.mjs +0 -39
- package/esm2022/engines/pentagon.mjs +0 -39
- package/esm2022/engines/process-arrow.mjs +0 -41
- package/esm2022/engines/rectangle.mjs +0 -26
- package/esm2022/engines/right-arrow.mjs +0 -45
- package/esm2022/engines/round-comment.mjs +0 -81
- package/esm2022/engines/round-rectangle.mjs +0 -59
- package/esm2022/engines/star.mjs +0 -45
- package/esm2022/engines/trapezoid.mjs +0 -40
- package/esm2022/engines/triangle.mjs +0 -40
- package/esm2022/engines/two-way-arrow.mjs +0 -48
package/fesm2022/plait-draw.mjs
CHANGED
|
@@ -8,29 +8,43 @@ import { Subject } from 'rxjs';
|
|
|
8
8
|
import { isKeyHotkey } from 'is-hotkey';
|
|
9
9
|
import { Node } from 'slate';
|
|
10
10
|
|
|
11
|
-
var
|
|
12
|
-
(function (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
})(
|
|
11
|
+
var BasicShapes;
|
|
12
|
+
(function (BasicShapes) {
|
|
13
|
+
BasicShapes["rectangle"] = "rectangle";
|
|
14
|
+
BasicShapes["ellipse"] = "ellipse";
|
|
15
|
+
BasicShapes["diamond"] = "diamond";
|
|
16
|
+
BasicShapes["roundRectangle"] = "roundRectangle";
|
|
17
|
+
BasicShapes["parallelogram"] = "parallelogram";
|
|
18
|
+
BasicShapes["text"] = "text";
|
|
19
|
+
BasicShapes["triangle"] = "triangle";
|
|
20
|
+
BasicShapes["leftArrow"] = "leftArrow";
|
|
21
|
+
BasicShapes["trapezoid"] = "trapezoid";
|
|
22
|
+
BasicShapes["rightArrow"] = "rightArrow";
|
|
23
|
+
BasicShapes["cross"] = "cross";
|
|
24
|
+
BasicShapes["star"] = "star";
|
|
25
|
+
BasicShapes["pentagon"] = "pentagon";
|
|
26
|
+
BasicShapes["hexagon"] = "hexagon";
|
|
27
|
+
BasicShapes["octagon"] = "octagon";
|
|
28
|
+
BasicShapes["pentagonArrow"] = "pentagonArrow";
|
|
29
|
+
BasicShapes["processArrow"] = "processArrow";
|
|
30
|
+
BasicShapes["twoWayArrow"] = "twoWayArrow";
|
|
31
|
+
BasicShapes["comment"] = "comment";
|
|
32
|
+
BasicShapes["roundComment"] = "roundComment";
|
|
33
|
+
})(BasicShapes || (BasicShapes = {}));
|
|
34
|
+
var FlowchartSymbols;
|
|
35
|
+
(function (FlowchartSymbols) {
|
|
36
|
+
FlowchartSymbols["process"] = "process";
|
|
37
|
+
FlowchartSymbols["decision"] = "decision";
|
|
38
|
+
FlowchartSymbols["data"] = "data";
|
|
39
|
+
FlowchartSymbols["connector"] = "connector";
|
|
40
|
+
FlowchartSymbols["terminal"] = "terminal";
|
|
41
|
+
FlowchartSymbols["manualInput"] = "manualInput";
|
|
42
|
+
FlowchartSymbols["preparation"] = "preparation";
|
|
43
|
+
FlowchartSymbols["manualLoop"] = "manualLoop";
|
|
44
|
+
FlowchartSymbols["merge"] = "merge";
|
|
45
|
+
FlowchartSymbols["delay"] = "delay";
|
|
46
|
+
FlowchartSymbols["storedData"] = "storedData";
|
|
47
|
+
})(FlowchartSymbols || (FlowchartSymbols = {}));
|
|
34
48
|
const PlaitGeometry = {
|
|
35
49
|
getTextEditor(element) {
|
|
36
50
|
return PlaitGeometry.getTextManage(element).componentRef.instance.editor;
|
|
@@ -57,7 +71,7 @@ const DefaultGeometryActiveStyle = {
|
|
|
57
71
|
strokeWidth: ACTIVE_STROKE_WIDTH,
|
|
58
72
|
selectionStrokeWidth: ACTIVE_STROKE_WIDTH
|
|
59
73
|
};
|
|
60
|
-
const
|
|
74
|
+
const DefaultBasicShapeProperty = {
|
|
61
75
|
width: 100,
|
|
62
76
|
height: 100,
|
|
63
77
|
strokeColor: '#333',
|
|
@@ -71,9 +85,52 @@ const DefaultTextProperty = {
|
|
|
71
85
|
const GeometryThreshold = {
|
|
72
86
|
defaultTextMaxWidth: 34 * 14
|
|
73
87
|
};
|
|
88
|
+
const DefaultConnectorProperty = {
|
|
89
|
+
width: 44,
|
|
90
|
+
height: 44
|
|
91
|
+
};
|
|
92
|
+
const DefaultFlowchartProperty = {
|
|
93
|
+
width: 120,
|
|
94
|
+
height: 60
|
|
95
|
+
};
|
|
96
|
+
const DefaultDecisionProperty = {
|
|
97
|
+
width: 140,
|
|
98
|
+
height: 70
|
|
99
|
+
};
|
|
100
|
+
const DefaultDataProperty = {
|
|
101
|
+
width: 124,
|
|
102
|
+
height: 60
|
|
103
|
+
};
|
|
104
|
+
const DefaultManualInputProperty = {
|
|
105
|
+
width: 117,
|
|
106
|
+
height: 59
|
|
107
|
+
};
|
|
108
|
+
const DefaultMergeProperty = {
|
|
109
|
+
width: 47,
|
|
110
|
+
height: 33
|
|
111
|
+
};
|
|
112
|
+
const DefaultFlowchartPropertyMap = {
|
|
113
|
+
[FlowchartSymbols.connector]: DefaultConnectorProperty,
|
|
114
|
+
[FlowchartSymbols.process]: DefaultFlowchartProperty,
|
|
115
|
+
[FlowchartSymbols.decision]: DefaultDecisionProperty,
|
|
116
|
+
[FlowchartSymbols.data]: DefaultDataProperty,
|
|
117
|
+
[FlowchartSymbols.terminal]: DefaultFlowchartProperty,
|
|
118
|
+
[FlowchartSymbols.manualInput]: DefaultManualInputProperty,
|
|
119
|
+
[FlowchartSymbols.preparation]: DefaultFlowchartProperty,
|
|
120
|
+
[FlowchartSymbols.manualLoop]: DefaultFlowchartProperty,
|
|
121
|
+
[FlowchartSymbols.merge]: DefaultMergeProperty,
|
|
122
|
+
[FlowchartSymbols.delay]: DefaultFlowchartProperty,
|
|
123
|
+
[FlowchartSymbols.storedData]: DefaultFlowchartProperty
|
|
124
|
+
};
|
|
74
125
|
|
|
75
126
|
const getGeometryPointers = () => {
|
|
76
|
-
return Object.keys(
|
|
127
|
+
return [...Object.keys(BasicShapes), ...Object.keys(FlowchartSymbols)];
|
|
128
|
+
};
|
|
129
|
+
const getBasicPointers = () => {
|
|
130
|
+
return Object.keys(BasicShapes);
|
|
131
|
+
};
|
|
132
|
+
const getFlowchartPointers = () => {
|
|
133
|
+
return Object.keys(FlowchartSymbols);
|
|
77
134
|
};
|
|
78
135
|
const getLinePointers = () => {
|
|
79
136
|
return Object.keys(LineShape);
|
|
@@ -155,33 +212,44 @@ const getCommentPoints = (rectangle) => {
|
|
|
155
212
|
];
|
|
156
213
|
};
|
|
157
214
|
|
|
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
|
-
|
|
215
|
+
function createPolygonEngine(options) {
|
|
216
|
+
const getPoints = options.getPolygonPoints;
|
|
217
|
+
const engine = {
|
|
218
|
+
draw(board, rectangle, options) {
|
|
219
|
+
const points = getPoints(rectangle);
|
|
220
|
+
const rs = PlaitBoard.getRoughSVG(board);
|
|
221
|
+
const polygon = rs.polygon(points, { ...options, fillStyle: 'solid' });
|
|
222
|
+
setStrokeLinecap(polygon, 'round');
|
|
223
|
+
return polygon;
|
|
224
|
+
},
|
|
225
|
+
isHit(rectangle, point) {
|
|
226
|
+
const points = getPoints(rectangle);
|
|
227
|
+
return isPointInPolygon(point, points);
|
|
228
|
+
},
|
|
229
|
+
getCornerPoints(rectangle) {
|
|
230
|
+
return getPoints(rectangle);
|
|
231
|
+
},
|
|
232
|
+
getNearestPoint(rectangle, point) {
|
|
233
|
+
return getNearestPointBetweenPointAndSegments(point, getPoints(rectangle));
|
|
234
|
+
},
|
|
235
|
+
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
236
|
+
const corners = getPoints(rectangle);
|
|
237
|
+
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
238
|
+
return getEdgeOnPolygonByPoint(corners, point);
|
|
239
|
+
},
|
|
240
|
+
getConnectorPoints(rectangle) {
|
|
241
|
+
if (options.getConnectorPoints) {
|
|
242
|
+
return options.getConnectorPoints(rectangle);
|
|
243
|
+
}
|
|
244
|
+
return getPoints(rectangle);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
if (options.getTextRectangle) {
|
|
248
|
+
engine.getTextRectangle = options.getTextRectangle;
|
|
183
249
|
}
|
|
184
|
-
|
|
250
|
+
return engine;
|
|
251
|
+
}
|
|
252
|
+
|
|
185
253
|
const getCrossPoints = (rectangle) => {
|
|
186
254
|
return [
|
|
187
255
|
[rectangle.x + rectangle.width / 4, rectangle.y],
|
|
@@ -198,34 +266,32 @@ const getCrossPoints = (rectangle) => {
|
|
|
198
266
|
[rectangle.x + rectangle.width / 4, rectangle.y + rectangle.height / 4]
|
|
199
267
|
];
|
|
200
268
|
};
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const points = RectangleClient.getEdgeCenterPoints(rectangle);
|
|
205
|
-
const rs = PlaitBoard.getRoughSVG(board);
|
|
206
|
-
const polygon = rs.polygon(points, { ...options, fillStyle: 'solid' });
|
|
207
|
-
setStrokeLinecap(polygon, 'round');
|
|
208
|
-
return polygon;
|
|
209
|
-
},
|
|
210
|
-
isHit(rectangle, point) {
|
|
211
|
-
const controlPoints = RectangleClient.getEdgeCenterPoints(rectangle);
|
|
212
|
-
return isPointInPolygon(point, controlPoints);
|
|
213
|
-
},
|
|
214
|
-
getCornerPoints(rectangle) {
|
|
269
|
+
const CrossEngine = createPolygonEngine({
|
|
270
|
+
getPolygonPoints: getCrossPoints,
|
|
271
|
+
getConnectorPoints(rectangle) {
|
|
215
272
|
return RectangleClient.getEdgeCenterPoints(rectangle);
|
|
216
273
|
},
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
274
|
+
getTextRectangle(element) {
|
|
275
|
+
const rectangle = getTextRectangle(element);
|
|
276
|
+
const width = rectangle.width;
|
|
277
|
+
rectangle.width = rectangle.width / 2;
|
|
278
|
+
rectangle.x += width / 4;
|
|
279
|
+
return rectangle;
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
const DiamondEngine = createPolygonEngine({
|
|
284
|
+
getPolygonPoints: RectangleClient.getEdgeCenterPoints,
|
|
225
285
|
getConnectorPoints(rectangle) {
|
|
226
286
|
return RectangleClient.getEdgeCenterPoints(rectangle);
|
|
287
|
+
},
|
|
288
|
+
getTextRectangle(element) {
|
|
289
|
+
const rectangle = getTextRectangle(element);
|
|
290
|
+
rectangle.width = rectangle.width / 2;
|
|
291
|
+
rectangle.x += rectangle.width / 2;
|
|
292
|
+
return rectangle;
|
|
227
293
|
}
|
|
228
|
-
};
|
|
294
|
+
});
|
|
229
295
|
|
|
230
296
|
const EllipseEngine = {
|
|
231
297
|
draw(board, rectangle, options) {
|
|
@@ -255,6 +321,13 @@ const EllipseEngine = {
|
|
|
255
321
|
},
|
|
256
322
|
getConnectorPoints(rectangle) {
|
|
257
323
|
return RectangleClient.getEdgeCenterPoints(rectangle);
|
|
324
|
+
},
|
|
325
|
+
getTextRectangle(element) {
|
|
326
|
+
const rectangle = getTextRectangle(element);
|
|
327
|
+
const width = rectangle.width;
|
|
328
|
+
rectangle.width = (rectangle.width * 3) / 4;
|
|
329
|
+
rectangle.x += width / 8;
|
|
330
|
+
return rectangle;
|
|
258
331
|
}
|
|
259
332
|
};
|
|
260
333
|
function getNearestPointBetweenPointAndEllipse(point, center, rx, ry, rotation = 0) {
|
|
@@ -318,33 +391,6 @@ function getVectorBySlope(x, y, slope) {
|
|
|
318
391
|
return vector;
|
|
319
392
|
}
|
|
320
393
|
|
|
321
|
-
const HexagonEngine = {
|
|
322
|
-
draw(board, rectangle, options) {
|
|
323
|
-
const points = getHexagonPoints(rectangle);
|
|
324
|
-
const rs = PlaitBoard.getRoughSVG(board);
|
|
325
|
-
const polygon = rs.polygon(points, { ...options, fillStyle: 'solid' });
|
|
326
|
-
setStrokeLinecap(polygon, 'round');
|
|
327
|
-
return polygon;
|
|
328
|
-
},
|
|
329
|
-
isHit(rectangle, point) {
|
|
330
|
-
const parallelogramPoints = getHexagonPoints(rectangle);
|
|
331
|
-
return isPointInPolygon(point, parallelogramPoints);
|
|
332
|
-
},
|
|
333
|
-
getCornerPoints(rectangle) {
|
|
334
|
-
return getHexagonPoints(rectangle);
|
|
335
|
-
},
|
|
336
|
-
getNearestPoint(rectangle, point) {
|
|
337
|
-
return getNearestPointBetweenPointAndSegments(point, getHexagonPoints(rectangle));
|
|
338
|
-
},
|
|
339
|
-
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
340
|
-
const corners = getHexagonPoints(rectangle);
|
|
341
|
-
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
342
|
-
return getEdgeOnPolygonByPoint(corners, point);
|
|
343
|
-
},
|
|
344
|
-
getConnectorPoints(rectangle) {
|
|
345
|
-
return RectangleClient.getEdgeCenterPoints(rectangle);
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
394
|
const getHexagonPoints = (rectangle) => {
|
|
349
395
|
return [
|
|
350
396
|
[rectangle.x + rectangle.width / 4, rectangle.y],
|
|
@@ -355,38 +401,20 @@ const getHexagonPoints = (rectangle) => {
|
|
|
355
401
|
[rectangle.x, rectangle.y + rectangle.height / 2]
|
|
356
402
|
];
|
|
357
403
|
};
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
draw(board, rectangle, options) {
|
|
361
|
-
const points = getLeftArrowPoints(rectangle);
|
|
362
|
-
const rs = PlaitBoard.getRoughSVG(board);
|
|
363
|
-
const polygon = rs.polygon(points, { ...options, fillStyle: 'solid' });
|
|
364
|
-
setStrokeLinecap(polygon, 'round');
|
|
365
|
-
return polygon;
|
|
366
|
-
},
|
|
367
|
-
getCornerPoints(rectangle) {
|
|
368
|
-
return getLeftArrowPoints(rectangle);
|
|
369
|
-
},
|
|
370
|
-
isHit(rectangle, point) {
|
|
371
|
-
const points = getLeftArrowPoints(rectangle);
|
|
372
|
-
return isPointInPolygon(point, points);
|
|
373
|
-
},
|
|
374
|
-
getNearestPoint(rectangle, point) {
|
|
375
|
-
const cornerPoints = getLeftArrowPoints(rectangle);
|
|
376
|
-
return getNearestPointBetweenPointAndSegments(point, cornerPoints);
|
|
377
|
-
},
|
|
378
|
-
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
379
|
-
const corners = getLeftArrowPoints(rectangle);
|
|
380
|
-
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
381
|
-
return getEdgeOnPolygonByPoint(corners, point);
|
|
382
|
-
},
|
|
404
|
+
const HexagonEngine = createPolygonEngine({
|
|
405
|
+
getPolygonPoints: getHexagonPoints,
|
|
383
406
|
getConnectorPoints(rectangle) {
|
|
384
|
-
return
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
407
|
+
return RectangleClient.getEdgeCenterPoints(rectangle);
|
|
408
|
+
},
|
|
409
|
+
getTextRectangle(element) {
|
|
410
|
+
const rectangle = getTextRectangle(element);
|
|
411
|
+
const width = rectangle.width;
|
|
412
|
+
rectangle.width = (rectangle.width * 3) / 4;
|
|
413
|
+
rectangle.x += width / 8;
|
|
414
|
+
return rectangle;
|
|
388
415
|
}
|
|
389
|
-
};
|
|
416
|
+
});
|
|
417
|
+
|
|
390
418
|
const getLeftArrowPoints = (rectangle) => {
|
|
391
419
|
return [
|
|
392
420
|
[rectangle.x, rectangle.y + rectangle.height / 2],
|
|
@@ -398,34 +426,23 @@ const getLeftArrowPoints = (rectangle) => {
|
|
|
398
426
|
[rectangle.x + rectangle.width * 0.32, rectangle.y + rectangle.height]
|
|
399
427
|
];
|
|
400
428
|
};
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
return polygon;
|
|
409
|
-
},
|
|
410
|
-
isHit(rectangle, point) {
|
|
411
|
-
const parallelogramPoints = getOctagonPoints(rectangle);
|
|
412
|
-
return isPointInPolygon(point, parallelogramPoints);
|
|
413
|
-
},
|
|
414
|
-
getCornerPoints(rectangle) {
|
|
415
|
-
return getOctagonPoints(rectangle);
|
|
416
|
-
},
|
|
417
|
-
getNearestPoint(rectangle, point) {
|
|
418
|
-
return getNearestPointBetweenPointAndSegments(point, getOctagonPoints(rectangle));
|
|
419
|
-
},
|
|
420
|
-
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
421
|
-
const corners = getOctagonPoints(rectangle);
|
|
422
|
-
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
423
|
-
return getEdgeOnPolygonByPoint(corners, point);
|
|
429
|
+
const LeftArrowEngine = createPolygonEngine({
|
|
430
|
+
getPolygonPoints: getLeftArrowPoints,
|
|
431
|
+
getConnectorPoints: (rectangle) => {
|
|
432
|
+
return [
|
|
433
|
+
[rectangle.x, rectangle.y + rectangle.height / 2],
|
|
434
|
+
[rectangle.x + rectangle.width, rectangle.y + rectangle.height / 2]
|
|
435
|
+
];
|
|
424
436
|
},
|
|
425
|
-
|
|
426
|
-
|
|
437
|
+
getTextRectangle(element) {
|
|
438
|
+
const rectangle = getTextRectangle(element);
|
|
439
|
+
const width = rectangle.width;
|
|
440
|
+
rectangle.width = rectangle.width * (1 - 0.32);
|
|
441
|
+
rectangle.x += width * 0.32;
|
|
442
|
+
return rectangle;
|
|
427
443
|
}
|
|
428
|
-
};
|
|
444
|
+
});
|
|
445
|
+
|
|
429
446
|
const getOctagonPoints = (rectangle) => {
|
|
430
447
|
return [
|
|
431
448
|
[rectangle.x + (rectangle.width * 3) / 10, rectangle.y],
|
|
@@ -438,36 +455,21 @@ const getOctagonPoints = (rectangle) => {
|
|
|
438
455
|
[rectangle.x, rectangle.y + (rectangle.height * 3) / 10]
|
|
439
456
|
];
|
|
440
457
|
};
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
draw(board, rectangle, options) {
|
|
444
|
-
const points = getParallelogramCornerPoints(rectangle);
|
|
445
|
-
const rs = PlaitBoard.getRoughSVG(board);
|
|
446
|
-
const polygon = rs.polygon(points, { ...options, fillStyle: 'solid' });
|
|
447
|
-
setStrokeLinecap(polygon, 'round');
|
|
448
|
-
return polygon;
|
|
449
|
-
},
|
|
450
|
-
isHit(rectangle, point) {
|
|
451
|
-
const parallelogramPoints = getParallelogramCornerPoints(rectangle);
|
|
452
|
-
return isPointInPolygon(point, parallelogramPoints);
|
|
453
|
-
},
|
|
454
|
-
getCornerPoints(rectangle) {
|
|
455
|
-
return getParallelogramCornerPoints(rectangle);
|
|
456
|
-
},
|
|
457
|
-
getNearestPoint(rectangle, point) {
|
|
458
|
-
return getNearestPointBetweenPointAndSegments(point, ParallelogramEngine.getCornerPoints(rectangle));
|
|
459
|
-
},
|
|
460
|
-
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
461
|
-
const corners = getParallelogramCornerPoints(rectangle);
|
|
462
|
-
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
463
|
-
return getEdgeOnPolygonByPoint(corners, point);
|
|
464
|
-
},
|
|
458
|
+
const OctagonEngine = createPolygonEngine({
|
|
459
|
+
getPolygonPoints: getOctagonPoints,
|
|
465
460
|
getConnectorPoints(rectangle) {
|
|
466
|
-
|
|
467
|
-
|
|
461
|
+
return RectangleClient.getEdgeCenterPoints(rectangle);
|
|
462
|
+
},
|
|
463
|
+
getTextRectangle(element) {
|
|
464
|
+
const rectangle = getTextRectangle(element);
|
|
465
|
+
const width = rectangle.width;
|
|
466
|
+
rectangle.width = (rectangle.width * 3) / 4;
|
|
467
|
+
rectangle.x += width / 8;
|
|
468
|
+
return rectangle;
|
|
468
469
|
}
|
|
469
|
-
};
|
|
470
|
-
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
const getParallelogramPoints = (rectangle) => {
|
|
471
473
|
return [
|
|
472
474
|
[rectangle.x + rectangle.width / 4, rectangle.y],
|
|
473
475
|
[rectangle.x + rectangle.width, rectangle.y],
|
|
@@ -475,34 +477,21 @@ const getParallelogramCornerPoints = (rectangle) => {
|
|
|
475
477
|
[rectangle.x, rectangle.y + rectangle.height]
|
|
476
478
|
];
|
|
477
479
|
};
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
const polygon = rs.polygon(points, { ...options, fillStyle: 'solid' });
|
|
484
|
-
setStrokeLinecap(polygon, 'round');
|
|
485
|
-
return polygon;
|
|
486
|
-
},
|
|
487
|
-
isHit(rectangle, point) {
|
|
488
|
-
const parallelogramPoints = getPentagonPoints(rectangle);
|
|
489
|
-
return isPointInPolygon(point, parallelogramPoints);
|
|
490
|
-
},
|
|
491
|
-
getCornerPoints(rectangle) {
|
|
492
|
-
return getPentagonPoints(rectangle);
|
|
493
|
-
},
|
|
494
|
-
getNearestPoint(rectangle, point) {
|
|
495
|
-
return getNearestPointBetweenPointAndSegments(point, getPentagonPoints(rectangle));
|
|
496
|
-
},
|
|
497
|
-
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
498
|
-
const corners = getPentagonPoints(rectangle);
|
|
499
|
-
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
500
|
-
return getEdgeOnPolygonByPoint(corners, point);
|
|
480
|
+
const ParallelogramEngine = createPolygonEngine({
|
|
481
|
+
getPolygonPoints: getParallelogramPoints,
|
|
482
|
+
getConnectorPoints: (rectangle) => {
|
|
483
|
+
const cornerPoints = getParallelogramPoints(rectangle);
|
|
484
|
+
return getCenterPointsOnPolygon(cornerPoints);
|
|
501
485
|
},
|
|
502
|
-
|
|
503
|
-
|
|
486
|
+
getTextRectangle(element) {
|
|
487
|
+
const rectangle = getTextRectangle(element);
|
|
488
|
+
const width = rectangle.width;
|
|
489
|
+
rectangle.width = rectangle.width / 2;
|
|
490
|
+
rectangle.x += width / 4;
|
|
491
|
+
return rectangle;
|
|
504
492
|
}
|
|
505
|
-
};
|
|
493
|
+
});
|
|
494
|
+
|
|
506
495
|
const getPentagonPoints = (rectangle) => {
|
|
507
496
|
return [
|
|
508
497
|
[rectangle.x + rectangle.width / 2, rectangle.y],
|
|
@@ -512,34 +501,23 @@ const getPentagonPoints = (rectangle) => {
|
|
|
512
501
|
[rectangle.x, rectangle.y + (rectangle.height * 2) / 5]
|
|
513
502
|
];
|
|
514
503
|
};
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
const
|
|
519
|
-
const
|
|
520
|
-
const
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
return getPentagonArrowPoints(rectangle);
|
|
530
|
-
},
|
|
531
|
-
getNearestPoint(rectangle, point) {
|
|
532
|
-
return getNearestPointBetweenPointAndSegments(point, getPentagonArrowPoints(rectangle));
|
|
533
|
-
},
|
|
534
|
-
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
535
|
-
const corners = getPentagonArrowPoints(rectangle);
|
|
536
|
-
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
537
|
-
return getEdgeOnPolygonByPoint(corners, point);
|
|
538
|
-
},
|
|
539
|
-
getConnectorPoints(rectangle) {
|
|
540
|
-
return RectangleClient.getEdgeCenterPoints(rectangle);
|
|
504
|
+
const PentagonEngine = createPolygonEngine({
|
|
505
|
+
getPolygonPoints: getPentagonPoints,
|
|
506
|
+
getTextRectangle(element) {
|
|
507
|
+
const elementRectangle = getRectangleByPoints(element.points);
|
|
508
|
+
const strokeWidth = getStrokeWidthByElement(element);
|
|
509
|
+
const height = element.textHeight;
|
|
510
|
+
const originWidth = elementRectangle.width - ShapeDefaultSpace.rectangleAndText * 2 - strokeWidth * 2;
|
|
511
|
+
const width = (originWidth * 3) / 5;
|
|
512
|
+
return {
|
|
513
|
+
height,
|
|
514
|
+
width: width > 0 ? width : 0,
|
|
515
|
+
x: elementRectangle.x + ShapeDefaultSpace.rectangleAndText + strokeWidth + originWidth / 5,
|
|
516
|
+
y: elementRectangle.y + elementRectangle.height / 5 + ((elementRectangle.height * 4) / 5 - height) / 2
|
|
517
|
+
};
|
|
541
518
|
}
|
|
542
|
-
};
|
|
519
|
+
});
|
|
520
|
+
|
|
543
521
|
const getPentagonArrowPoints = (rectangle) => {
|
|
544
522
|
return [
|
|
545
523
|
[rectangle.x, rectangle.y],
|
|
@@ -549,59 +527,103 @@ const getPentagonArrowPoints = (rectangle) => {
|
|
|
549
527
|
[rectangle.x, rectangle.y + rectangle.height]
|
|
550
528
|
];
|
|
551
529
|
};
|
|
530
|
+
const PentagonArrowEngine = createPolygonEngine({
|
|
531
|
+
getPolygonPoints: getPentagonArrowPoints,
|
|
532
|
+
getConnectorPoints(rectangle) {
|
|
533
|
+
return RectangleClient.getEdgeCenterPoints(rectangle);
|
|
534
|
+
},
|
|
535
|
+
getTextRectangle(element) {
|
|
536
|
+
const rectangle = getTextRectangle(element);
|
|
537
|
+
rectangle.width = (rectangle.width * 3) / 5;
|
|
538
|
+
return rectangle;
|
|
539
|
+
}
|
|
540
|
+
});
|
|
552
541
|
|
|
553
|
-
const
|
|
542
|
+
const getProcessArrowPoints = (rectangle) => {
|
|
543
|
+
const wider = rectangle.width > rectangle.height / 2;
|
|
544
|
+
return [
|
|
545
|
+
[rectangle.x, rectangle.y],
|
|
546
|
+
[rectangle.x + (wider ? rectangle.width - rectangle.height / 2 : 0), rectangle.y],
|
|
547
|
+
[rectangle.x + rectangle.width, rectangle.y + rectangle.height / 2],
|
|
548
|
+
[rectangle.x + (wider ? rectangle.width - rectangle.height / 2 : 0), rectangle.y + rectangle.height],
|
|
549
|
+
[rectangle.x, rectangle.y + rectangle.height],
|
|
550
|
+
[rectangle.x + (wider ? rectangle.height / 2 : rectangle.width), rectangle.y + rectangle.height / 2]
|
|
551
|
+
];
|
|
552
|
+
};
|
|
553
|
+
const ProcessArrowEngine = createPolygonEngine({
|
|
554
|
+
getPolygonPoints: getProcessArrowPoints,
|
|
555
|
+
getTextRectangle(element) {
|
|
556
|
+
const rectangle = getTextRectangle(element);
|
|
557
|
+
const elementRectangle = getRectangleByPoints(element.points);
|
|
558
|
+
const width = rectangle.width;
|
|
559
|
+
rectangle.width = elementRectangle.height / 2;
|
|
560
|
+
rectangle.x += elementRectangle.height / 2;
|
|
561
|
+
return rectangle;
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
const RectangleEngine = {
|
|
554
566
|
draw(board, rectangle, options) {
|
|
555
|
-
|
|
556
|
-
const rs = PlaitBoard.getRoughSVG(board);
|
|
557
|
-
const polygon = rs.polygon(points, { ...options, fillStyle: 'solid' });
|
|
558
|
-
setStrokeLinecap(polygon, 'round');
|
|
559
|
-
return polygon;
|
|
567
|
+
return drawRectangle(board, rectangle, { ...options, fillStyle: 'solid' });
|
|
560
568
|
},
|
|
561
569
|
isHit(rectangle, point) {
|
|
562
|
-
const
|
|
563
|
-
return
|
|
570
|
+
const rangeRectangle = RectangleClient.toRectangleClient([point, point]);
|
|
571
|
+
return RectangleClient.isHit(rectangle, rangeRectangle);
|
|
564
572
|
},
|
|
565
573
|
getCornerPoints(rectangle) {
|
|
566
|
-
return
|
|
574
|
+
return RectangleClient.getCornerPoints(rectangle);
|
|
567
575
|
},
|
|
568
576
|
getNearestPoint(rectangle, point) {
|
|
569
|
-
return getNearestPointBetweenPointAndSegments(point,
|
|
577
|
+
return getNearestPointBetweenPointAndSegments(point, RectangleEngine.getCornerPoints(rectangle));
|
|
570
578
|
},
|
|
571
579
|
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
572
|
-
const corners =
|
|
580
|
+
const corners = RectangleEngine.getCornerPoints(rectangle);
|
|
573
581
|
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
574
582
|
return getEdgeOnPolygonByPoint(corners, point);
|
|
575
583
|
},
|
|
576
584
|
getConnectorPoints(rectangle) {
|
|
577
|
-
return
|
|
585
|
+
return RectangleClient.getEdgeCenterPoints(rectangle);
|
|
578
586
|
}
|
|
579
587
|
};
|
|
580
|
-
|
|
581
|
-
|
|
588
|
+
|
|
589
|
+
const getRightArrowPoints = (rectangle) => {
|
|
582
590
|
return [
|
|
583
|
-
[rectangle.x, rectangle.y],
|
|
584
|
-
[rectangle.x +
|
|
591
|
+
[rectangle.x, rectangle.y + rectangle.height * 0.2],
|
|
592
|
+
[rectangle.x + rectangle.width * 0.68, rectangle.y + rectangle.height * 0.2],
|
|
593
|
+
[rectangle.x + rectangle.width * 0.68, rectangle.y],
|
|
585
594
|
[rectangle.x + rectangle.width, rectangle.y + rectangle.height / 2],
|
|
586
|
-
[rectangle.x +
|
|
587
|
-
[rectangle.x, rectangle.y + rectangle.height],
|
|
588
|
-
[rectangle.x
|
|
595
|
+
[rectangle.x + rectangle.width * 0.68, rectangle.y + rectangle.height],
|
|
596
|
+
[rectangle.x + rectangle.width * 0.68, rectangle.y + rectangle.height * 0.8],
|
|
597
|
+
[rectangle.x, rectangle.y + rectangle.height * 0.8]
|
|
589
598
|
];
|
|
590
599
|
};
|
|
600
|
+
const RightArrowEngine = createPolygonEngine({
|
|
601
|
+
getPolygonPoints: getRightArrowPoints,
|
|
602
|
+
getConnectorPoints: (rectangle) => {
|
|
603
|
+
return [
|
|
604
|
+
[rectangle.x, rectangle.y + rectangle.height / 2],
|
|
605
|
+
[rectangle.x + rectangle.width, rectangle.y + rectangle.height / 2]
|
|
606
|
+
];
|
|
607
|
+
},
|
|
608
|
+
getTextRectangle(element) {
|
|
609
|
+
const rectangle = getTextRectangle(element);
|
|
610
|
+
rectangle.width = rectangle.width * 0.68;
|
|
611
|
+
return rectangle;
|
|
612
|
+
}
|
|
613
|
+
});
|
|
591
614
|
|
|
592
|
-
const
|
|
615
|
+
const RoundRectangleEngine = {
|
|
593
616
|
draw(board, rectangle, options) {
|
|
594
|
-
return
|
|
617
|
+
return drawRoundRectangle(PlaitBoard.getRoughSVG(board), rectangle.x, rectangle.y, rectangle.x + rectangle.width, rectangle.y + rectangle.height, { ...options, fillStyle: 'solid' }, false, getRoundRectangleRadius(rectangle));
|
|
595
618
|
},
|
|
596
619
|
isHit(rectangle, point) {
|
|
597
|
-
|
|
598
|
-
return RectangleClient.isHit(rectangle, rangeRectangle);
|
|
620
|
+
return isPointInRoundRectangle(point, rectangle, getRoundRectangleRadius(rectangle));
|
|
599
621
|
},
|
|
600
622
|
getCornerPoints(rectangle) {
|
|
601
623
|
return RectangleClient.getCornerPoints(rectangle);
|
|
602
624
|
},
|
|
603
625
|
getNearestPoint(rectangle, point) {
|
|
604
|
-
return
|
|
626
|
+
return getNearestPointBetweenPointAndRoundRectangle$1(point, rectangle, getRoundRectangleRadius(rectangle));
|
|
605
627
|
},
|
|
606
628
|
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
607
629
|
const corners = RectangleEngine.getCornerPoints(rectangle);
|
|
@@ -612,62 +634,237 @@ const RectangleEngine = {
|
|
|
612
634
|
return RectangleClient.getEdgeCenterPoints(rectangle);
|
|
613
635
|
}
|
|
614
636
|
};
|
|
637
|
+
const getRoundRectangleRadius = (rectangle) => {
|
|
638
|
+
return Math.min(rectangle.width * 0.1, rectangle.height * 0.1);
|
|
639
|
+
};
|
|
640
|
+
function getNearestPointBetweenPointAndRoundRectangle$1(point, rectangle, radius) {
|
|
641
|
+
const { x: rectX, y: rectY, width, height } = rectangle;
|
|
642
|
+
const cornerPoints = RectangleClient.getCornerPoints(rectangle);
|
|
643
|
+
let result = getNearestPointBetweenPointAndSegments(point, cornerPoints);
|
|
644
|
+
let circleCenter = null;
|
|
645
|
+
const inLeftTop = point[0] >= rectX && point[0] <= rectX + radius && point[1] >= rectY && point[1] <= rectY + radius;
|
|
646
|
+
if (inLeftTop) {
|
|
647
|
+
circleCenter = [rectX + radius, rectY + radius];
|
|
648
|
+
}
|
|
649
|
+
const inLeftBottom = point[0] >= rectX && point[0] <= rectX + radius && point[1] >= rectY + height && point[1] <= rectY + height - radius;
|
|
650
|
+
if (inLeftBottom) {
|
|
651
|
+
circleCenter = [rectX + radius, rectY + height - radius];
|
|
652
|
+
}
|
|
653
|
+
const inRightTop = point[0] >= rectX + width - radius && point[0] <= rectX + width && point[1] >= rectY && point[1] <= rectY + radius;
|
|
654
|
+
if (inRightTop) {
|
|
655
|
+
circleCenter = [rectX + width - radius, rectY + radius];
|
|
656
|
+
}
|
|
657
|
+
const inRightBottom = point[0] >= rectX + width - radius &&
|
|
658
|
+
point[0] <= rectX + width &&
|
|
659
|
+
point[1] >= rectY + height - radius &&
|
|
660
|
+
point[1] <= rectY + height;
|
|
661
|
+
if (inRightBottom) {
|
|
662
|
+
circleCenter = [rectX + width - radius, rectY + height - radius];
|
|
663
|
+
}
|
|
664
|
+
if (circleCenter) {
|
|
665
|
+
result = getNearestPointBetweenPointAndEllipse(point, circleCenter, radius, radius);
|
|
666
|
+
}
|
|
667
|
+
return result;
|
|
668
|
+
}
|
|
615
669
|
|
|
616
|
-
const
|
|
670
|
+
const heightRatio = 3 / 4;
|
|
671
|
+
const RoundCommentEngine = {
|
|
617
672
|
draw(board, rectangle, options) {
|
|
618
|
-
const points = getRightArrowPoints(rectangle);
|
|
619
673
|
const rs = PlaitBoard.getRoughSVG(board);
|
|
620
|
-
const
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
674
|
+
const x1 = rectangle.x;
|
|
675
|
+
const y1 = rectangle.y;
|
|
676
|
+
const x2 = rectangle.x + rectangle.width;
|
|
677
|
+
const y2 = rectangle.y + rectangle.height * heightRatio;
|
|
678
|
+
const radius = getRoundRectangleRadius(rectangle);
|
|
679
|
+
const point1 = [x1 + radius, y1];
|
|
680
|
+
const point2 = [x2 - radius, y1];
|
|
681
|
+
const point3 = [x2, y1 + radius];
|
|
682
|
+
const point4 = [x2, y2 - radius];
|
|
683
|
+
const point5 = [x2 - radius, y2];
|
|
684
|
+
const point6 = [x1 + radius, y2];
|
|
685
|
+
const point7 = [x1, y2 - radius];
|
|
686
|
+
const point8 = [x1, y1 + radius];
|
|
687
|
+
const point9 = [x1 + rectangle.width / 4, y2];
|
|
688
|
+
const point10 = [x1 + rectangle.width / 4, rectangle.y + rectangle.height];
|
|
689
|
+
const point11 = [x1 + rectangle.width / 2, y2];
|
|
690
|
+
return rs.path(`M${point2[0]} ${point2[1]} A ${radius} ${radius}, 0, 0, 1, ${point3[0]} ${point3[1]} L ${point4[0]} ${point4[1]} A ${radius} ${radius}, 0, 0, 1, ${point5[0]} ${point5[1]} L ${point11[0]} ${point11[1]} ${point10[0]} ${point10[1]} ${point9[0]} ${point9[1]} ${point6[0]} ${point6[1]} A ${radius} ${radius}, 0, 0, 1, ${point7[0]} ${point7[1]} L ${point8[0]} ${point8[1]} A ${radius} ${radius}, 0, 0, 1, ${point1[0]} ${point1[1]} Z`, { ...options, fillStyle: 'solid' });
|
|
626
691
|
},
|
|
627
692
|
isHit(rectangle, point) {
|
|
628
|
-
const points =
|
|
629
|
-
|
|
693
|
+
const points = [
|
|
694
|
+
[rectangle.x + rectangle.width / 4, rectangle.y + (rectangle.height * 3) / 4],
|
|
695
|
+
[rectangle.x + rectangle.width / 4, rectangle.y + rectangle.height],
|
|
696
|
+
[rectangle.x + rectangle.width / 2, rectangle.y + (rectangle.height * 3) / 4]
|
|
697
|
+
];
|
|
698
|
+
rectangle.height = (rectangle.height * 3) / 4;
|
|
699
|
+
return isPointInPolygon(point, points) || isPointInRoundRectangle(point, rectangle, getRoundRectangleRadius(rectangle));
|
|
700
|
+
},
|
|
701
|
+
getCornerPoints(rectangle) {
|
|
702
|
+
return getRoundCommentPoints(rectangle);
|
|
630
703
|
},
|
|
631
704
|
getNearestPoint(rectangle, point) {
|
|
632
|
-
|
|
633
|
-
return getNearestPointBetweenPointAndSegments(point, cornerPoints);
|
|
705
|
+
return getNearestPointBetweenPointAndSegments(point, getRoundCommentPoints(rectangle));
|
|
634
706
|
},
|
|
635
707
|
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
636
|
-
const corners =
|
|
708
|
+
const corners = getRoundCommentPoints(rectangle);
|
|
637
709
|
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
638
710
|
return getEdgeOnPolygonByPoint(corners, point);
|
|
639
711
|
},
|
|
640
712
|
getConnectorPoints(rectangle) {
|
|
641
713
|
return [
|
|
642
|
-
[rectangle.x
|
|
643
|
-
[rectangle.x + rectangle.width, rectangle.y + rectangle.height / 2]
|
|
714
|
+
[rectangle.x + rectangle.width / 2, rectangle.y],
|
|
715
|
+
[rectangle.x + rectangle.width, rectangle.y + rectangle.height / 2],
|
|
716
|
+
[rectangle.x + rectangle.width / 2, rectangle.y + rectangle.height * heightRatio],
|
|
717
|
+
[rectangle.x, rectangle.y + rectangle.height / 2]
|
|
644
718
|
];
|
|
719
|
+
},
|
|
720
|
+
getTextRectangle(element) {
|
|
721
|
+
const elementRectangle = getRectangleByPoints(element.points);
|
|
722
|
+
const strokeWidth = getStrokeWidthByElement(element);
|
|
723
|
+
const height = element.textHeight;
|
|
724
|
+
const width = elementRectangle.width - ShapeDefaultSpace.rectangleAndText * 2 - strokeWidth * 2;
|
|
725
|
+
return {
|
|
726
|
+
height,
|
|
727
|
+
width: width > 0 ? width : 0,
|
|
728
|
+
x: elementRectangle.x + ShapeDefaultSpace.rectangleAndText + strokeWidth,
|
|
729
|
+
y: elementRectangle.y + (elementRectangle.height * heightRatio - height) / 2
|
|
730
|
+
};
|
|
645
731
|
}
|
|
646
732
|
};
|
|
647
|
-
const
|
|
733
|
+
const getRoundCommentPoints = (rectangle) => {
|
|
648
734
|
return [
|
|
649
|
-
[rectangle.x, rectangle.y
|
|
650
|
-
[rectangle.x + rectangle.width
|
|
651
|
-
[rectangle.x + rectangle.width
|
|
735
|
+
[rectangle.x, rectangle.y],
|
|
736
|
+
[rectangle.x + rectangle.width, rectangle.y],
|
|
737
|
+
[rectangle.x + rectangle.width, rectangle.y + rectangle.height * heightRatio],
|
|
738
|
+
[rectangle.x + rectangle.width / 2, rectangle.y + rectangle.height * heightRatio],
|
|
739
|
+
[rectangle.x + rectangle.width / 4, rectangle.y + rectangle.height],
|
|
740
|
+
[rectangle.x + rectangle.width / 4, rectangle.y + rectangle.height * heightRatio],
|
|
741
|
+
[rectangle.x, rectangle.y + rectangle.height * heightRatio]
|
|
742
|
+
];
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
const getTrapezoidPoints = (rectangle) => {
|
|
746
|
+
return [
|
|
747
|
+
[rectangle.x + rectangle.width * 0.15, rectangle.y],
|
|
748
|
+
[rectangle.x + rectangle.width * 0.85, rectangle.y],
|
|
749
|
+
[rectangle.x + rectangle.width, rectangle.y + rectangle.height],
|
|
750
|
+
[rectangle.x, rectangle.y + rectangle.height]
|
|
751
|
+
];
|
|
752
|
+
};
|
|
753
|
+
const TrapezoidEngine = createPolygonEngine({
|
|
754
|
+
getPolygonPoints: getTrapezoidPoints,
|
|
755
|
+
getConnectorPoints(rectangle) {
|
|
756
|
+
const points = getTrapezoidPoints(rectangle);
|
|
757
|
+
return getCenterPointsOnPolygon(points);
|
|
758
|
+
},
|
|
759
|
+
getTextRectangle(element) {
|
|
760
|
+
const rectangle = getTextRectangle(element);
|
|
761
|
+
const width = rectangle.width;
|
|
762
|
+
rectangle.width = (rectangle.width * 3) / 4;
|
|
763
|
+
rectangle.x += width / 8;
|
|
764
|
+
return rectangle;
|
|
765
|
+
}
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
const getTrianglePoints = (rectangle) => {
|
|
769
|
+
return [
|
|
770
|
+
[rectangle.x + rectangle.width / 2, rectangle.y],
|
|
771
|
+
[rectangle.x + rectangle.width, rectangle.y + rectangle.height],
|
|
772
|
+
[rectangle.x, rectangle.y + rectangle.height]
|
|
773
|
+
];
|
|
774
|
+
};
|
|
775
|
+
const TriangleEngine = createPolygonEngine({
|
|
776
|
+
getPolygonPoints: getTrianglePoints,
|
|
777
|
+
getConnectorPoints(rectangle) {
|
|
778
|
+
const cornerPoints = getTrianglePoints(rectangle);
|
|
779
|
+
const lineCenterPoints = getCenterPointsOnPolygon(cornerPoints);
|
|
780
|
+
return [...lineCenterPoints, ...cornerPoints];
|
|
781
|
+
},
|
|
782
|
+
getTextRectangle(element) {
|
|
783
|
+
const elementRectangle = getRectangleByPoints(element.points);
|
|
784
|
+
const strokeWidth = getStrokeWidthByElement(element);
|
|
785
|
+
const height = element.textHeight;
|
|
786
|
+
const originWidth = elementRectangle.width - ShapeDefaultSpace.rectangleAndText * 2 - strokeWidth * 2;
|
|
787
|
+
const width = (originWidth * 2) / 3;
|
|
788
|
+
return {
|
|
789
|
+
height,
|
|
790
|
+
width: width > 0 ? width : 0,
|
|
791
|
+
x: elementRectangle.x + ShapeDefaultSpace.rectangleAndText + strokeWidth + originWidth / 6,
|
|
792
|
+
y: elementRectangle.y + (elementRectangle.height * 3) / 5 + ((elementRectangle.height * 2) / 5 - height) / 2
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
const getTwoWayArrowPoints = (rectangle) => {
|
|
798
|
+
return [
|
|
799
|
+
[rectangle.x, rectangle.y + rectangle.height / 2],
|
|
800
|
+
[rectangle.x + (rectangle.width * 8) / 25, rectangle.y],
|
|
801
|
+
[rectangle.x + (rectangle.width * 8) / 25, rectangle.y + rectangle.height / 5],
|
|
802
|
+
[rectangle.x + (rectangle.width * 17) / 25, rectangle.y + rectangle.height / 5],
|
|
803
|
+
[rectangle.x + (rectangle.width * 17) / 25, rectangle.y],
|
|
652
804
|
[rectangle.x + rectangle.width, rectangle.y + rectangle.height / 2],
|
|
653
|
-
[rectangle.x + rectangle.width *
|
|
654
|
-
[rectangle.x + rectangle.width *
|
|
655
|
-
[rectangle.x, rectangle.y + rectangle.height *
|
|
805
|
+
[rectangle.x + (rectangle.width * 17) / 25, rectangle.y + rectangle.height],
|
|
806
|
+
[rectangle.x + (rectangle.width * 17) / 25, rectangle.y + (rectangle.height * 4) / 5],
|
|
807
|
+
[rectangle.x + (rectangle.width * 8) / 25, rectangle.y + (rectangle.height * 4) / 5],
|
|
808
|
+
[rectangle.x + (rectangle.width * 8) / 25, rectangle.y + rectangle.height]
|
|
809
|
+
];
|
|
810
|
+
};
|
|
811
|
+
const TwoWayArrowEngine = createPolygonEngine({
|
|
812
|
+
getPolygonPoints: getTwoWayArrowPoints,
|
|
813
|
+
getConnectorPoints: (rectangle) => {
|
|
814
|
+
return [
|
|
815
|
+
[rectangle.x, rectangle.y + rectangle.height / 2],
|
|
816
|
+
[rectangle.x + rectangle.width, rectangle.y + rectangle.height / 2]
|
|
817
|
+
];
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
|
|
821
|
+
const getStarPoints = (rectangle) => {
|
|
822
|
+
return [
|
|
823
|
+
[rectangle.x + rectangle.width / 2, rectangle.y + (rectangle.height * 75) / 91],
|
|
824
|
+
[rectangle.x + (rectangle.width * 18.61) / 96, rectangle.y + rectangle.height],
|
|
825
|
+
[rectangle.x + (rectangle.width * 24.2235871) / 96, rectangle.y + (rectangle.height * 57.7254249) / 91],
|
|
826
|
+
[rectangle.x, rectangle.y + (rectangle.height * 34.5491503) / 91],
|
|
827
|
+
[rectangle.x + (rectangle.width * 33.3053687) / 96, rectangle.y + (rectangle.height * 29.7745751) / 91],
|
|
828
|
+
[rectangle.x + rectangle.width / 2, rectangle.y],
|
|
829
|
+
[rectangle.x + (rectangle.width * 62.6946313) / 96, rectangle.y + (rectangle.height * 29.7745751) / 91],
|
|
830
|
+
[rectangle.x + rectangle.width, rectangle.y + (rectangle.height * 34.5491503) / 91],
|
|
831
|
+
[rectangle.x + (rectangle.width * 71.7764129) / 96, rectangle.y + (rectangle.height * 57.7254249) / 91],
|
|
832
|
+
[rectangle.x + (rectangle.width * 77.3892626) / 96, rectangle.y + rectangle.height]
|
|
656
833
|
];
|
|
657
834
|
};
|
|
835
|
+
const StarEngine = createPolygonEngine({
|
|
836
|
+
getPolygonPoints: getStarPoints,
|
|
837
|
+
getConnectorPoints: (rectangle) => {
|
|
838
|
+
const points = getStarPoints(rectangle);
|
|
839
|
+
return [points[1], points[3], points[5], points[7], points[9]];
|
|
840
|
+
},
|
|
841
|
+
getTextRectangle(element) {
|
|
842
|
+
const elementRectangle = getRectangleByPoints(element.points);
|
|
843
|
+
const strokeWidth = getStrokeWidthByElement(element);
|
|
844
|
+
const height = element.textHeight;
|
|
845
|
+
const originWidth = elementRectangle.width - ShapeDefaultSpace.rectangleAndText * 2 - strokeWidth * 2;
|
|
846
|
+
const width = originWidth / 2;
|
|
847
|
+
return {
|
|
848
|
+
height,
|
|
849
|
+
width: width > 0 ? width : 0,
|
|
850
|
+
x: elementRectangle.x + ShapeDefaultSpace.rectangleAndText + strokeWidth + originWidth / 4,
|
|
851
|
+
y: elementRectangle.y + (elementRectangle.height * 1) / 5 + ((elementRectangle.height * 4) / 5 - height) / 2
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
});
|
|
658
855
|
|
|
659
|
-
const
|
|
856
|
+
const TerminalEngine = {
|
|
660
857
|
draw(board, rectangle, options) {
|
|
661
|
-
return drawRoundRectangle(PlaitBoard.getRoughSVG(board), rectangle.x, rectangle.y, rectangle.x + rectangle.width, rectangle.y + rectangle.height, { ...options, fillStyle: 'solid' }, false,
|
|
858
|
+
return drawRoundRectangle(PlaitBoard.getRoughSVG(board), rectangle.x, rectangle.y, rectangle.x + rectangle.width, rectangle.y + rectangle.height, { ...options, fillStyle: 'solid' }, false, getStartEndRadius(rectangle));
|
|
662
859
|
},
|
|
663
860
|
isHit(rectangle, point) {
|
|
664
|
-
return isPointInRoundRectangle(point, rectangle,
|
|
861
|
+
return isPointInRoundRectangle(point, rectangle, getStartEndRadius(rectangle));
|
|
665
862
|
},
|
|
666
863
|
getCornerPoints(rectangle) {
|
|
667
864
|
return RectangleClient.getCornerPoints(rectangle);
|
|
668
865
|
},
|
|
669
866
|
getNearestPoint(rectangle, point) {
|
|
670
|
-
return getNearestPointBetweenPointAndRoundRectangle(point, rectangle,
|
|
867
|
+
return getNearestPointBetweenPointAndRoundRectangle(point, rectangle, getStartEndRadius(rectangle));
|
|
671
868
|
},
|
|
672
869
|
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
673
870
|
const corners = RectangleEngine.getCornerPoints(rectangle);
|
|
@@ -678,8 +875,8 @@ const RoundRectangleEngine = {
|
|
|
678
875
|
return RectangleClient.getEdgeCenterPoints(rectangle);
|
|
679
876
|
}
|
|
680
877
|
};
|
|
681
|
-
const
|
|
682
|
-
return Math.min(rectangle.width
|
|
878
|
+
const getStartEndRadius = (rectangle) => {
|
|
879
|
+
return Math.min(rectangle.width / 2, rectangle.height / 2);
|
|
683
880
|
};
|
|
684
881
|
function getNearestPointBetweenPointAndRoundRectangle(point, rectangle, radius) {
|
|
685
882
|
const { x: rectX, y: rectY, width, height } = rectangle;
|
|
@@ -711,57 +908,21 @@ function getNearestPointBetweenPointAndRoundRectangle(point, rectangle, radius)
|
|
|
711
908
|
return result;
|
|
712
909
|
}
|
|
713
910
|
|
|
714
|
-
const
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
const
|
|
726
|
-
|
|
727
|
-
const point5 = [x2 - radius, y2];
|
|
728
|
-
const point6 = [x1 + radius, y2];
|
|
729
|
-
const point7 = [x1, y2 - radius];
|
|
730
|
-
const point8 = [x1, y1 + radius];
|
|
731
|
-
const point9 = [x1 + rectangle.width / 4, y2];
|
|
732
|
-
const point10 = [x1 + rectangle.width / 4, rectangle.y + rectangle.height];
|
|
733
|
-
const point11 = [x1 + rectangle.width / 2, y2];
|
|
734
|
-
return rs.path(`M${point2[0]} ${point2[1]} A ${radius} ${radius}, 0, 0, 1, ${point3[0]} ${point3[1]} L ${point4[0]} ${point4[1]} A ${radius} ${radius}, 0, 0, 1, ${point5[0]} ${point5[1]} L ${point11[0]} ${point11[1]} ${point10[0]} ${point10[1]} ${point9[0]} ${point9[1]} ${point6[0]} ${point6[1]} A ${radius} ${radius}, 0, 0, 1, ${point7[0]} ${point7[1]} L ${point8[0]} ${point8[1]} A ${radius} ${radius}, 0, 0, 1, ${point1[0]} ${point1[1]} Z`, options);
|
|
735
|
-
},
|
|
736
|
-
isHit(rectangle, point) {
|
|
737
|
-
const points = [
|
|
738
|
-
[rectangle.x + rectangle.width / 4, rectangle.y + (rectangle.height * 3) / 4],
|
|
739
|
-
[rectangle.x + rectangle.width / 4, rectangle.y + rectangle.height],
|
|
740
|
-
[rectangle.x + rectangle.width / 2, rectangle.y + (rectangle.height * 3) / 4]
|
|
741
|
-
];
|
|
742
|
-
rectangle.height = (rectangle.height * 3) / 4;
|
|
743
|
-
return isPointInPolygon(point, points) || isPointInRoundRectangle(point, rectangle, getRoundRectangleRadius(rectangle));
|
|
744
|
-
},
|
|
745
|
-
getCornerPoints(rectangle) {
|
|
746
|
-
return getRoundCommentPoints(rectangle);
|
|
747
|
-
},
|
|
748
|
-
getNearestPoint(rectangle, point) {
|
|
749
|
-
return getNearestPointBetweenPointAndSegments(point, getRoundCommentPoints(rectangle));
|
|
750
|
-
},
|
|
751
|
-
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
752
|
-
const corners = getRoundCommentPoints(rectangle);
|
|
753
|
-
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
754
|
-
return getEdgeOnPolygonByPoint(corners, point);
|
|
755
|
-
},
|
|
756
|
-
getConnectorPoints(rectangle) {
|
|
757
|
-
return [
|
|
758
|
-
[rectangle.x + rectangle.width / 2, rectangle.y],
|
|
759
|
-
[rectangle.x + rectangle.width, rectangle.y + rectangle.height / 2],
|
|
760
|
-
[rectangle.x + rectangle.width / 2, rectangle.y + rectangle.height * heightRatio],
|
|
761
|
-
[rectangle.x, rectangle.y + rectangle.height / 2]
|
|
762
|
-
];
|
|
911
|
+
const getManualInputPoints = (rectangle) => {
|
|
912
|
+
return [
|
|
913
|
+
[rectangle.x, rectangle.y + rectangle.height / 4],
|
|
914
|
+
[rectangle.x + rectangle.width, rectangle.y],
|
|
915
|
+
[rectangle.x + rectangle.width, rectangle.y + rectangle.height],
|
|
916
|
+
[rectangle.x, rectangle.y + rectangle.height]
|
|
917
|
+
];
|
|
918
|
+
};
|
|
919
|
+
const ManualInputEngine = createPolygonEngine({
|
|
920
|
+
getPolygonPoints: getManualInputPoints,
|
|
921
|
+
getConnectorPoints: (rectangle) => {
|
|
922
|
+
const cornerPoints = getManualInputPoints(rectangle);
|
|
923
|
+
return getCenterPointsOnPolygon(cornerPoints);
|
|
763
924
|
},
|
|
764
|
-
getTextRectangle(element) {
|
|
925
|
+
getTextRectangle: (element) => {
|
|
765
926
|
const elementRectangle = getRectangleByPoints(element.points);
|
|
766
927
|
const strokeWidth = getStrokeWidthByElement(element);
|
|
767
928
|
const height = element.textHeight;
|
|
@@ -770,208 +931,231 @@ const RoundCommentEngine = {
|
|
|
770
931
|
height,
|
|
771
932
|
width: width > 0 ? width : 0,
|
|
772
933
|
x: elementRectangle.x + ShapeDefaultSpace.rectangleAndText + strokeWidth,
|
|
773
|
-
y: elementRectangle.y + (elementRectangle.height *
|
|
934
|
+
y: elementRectangle.y + elementRectangle.height / 4 + ((elementRectangle.height * 3) / 4 - height) / 2
|
|
774
935
|
};
|
|
775
936
|
}
|
|
776
|
-
};
|
|
777
|
-
|
|
937
|
+
});
|
|
938
|
+
|
|
939
|
+
const getPreparationPoints = (rectangle) => {
|
|
778
940
|
return [
|
|
779
|
-
[rectangle.x, rectangle.y],
|
|
780
|
-
[rectangle.x + rectangle.width, rectangle.y],
|
|
781
|
-
[rectangle.x + rectangle.width, rectangle.y
|
|
782
|
-
[rectangle.x + rectangle.width
|
|
783
|
-
[rectangle.x + rectangle.width /
|
|
784
|
-
[rectangle.x + rectangle.width /
|
|
785
|
-
[rectangle.x, rectangle.y + rectangle.height * heightRatio]
|
|
941
|
+
[rectangle.x, rectangle.y + rectangle.height / 2],
|
|
942
|
+
[rectangle.x + rectangle.width / 6, rectangle.y],
|
|
943
|
+
[rectangle.x + (rectangle.width * 5) / 6, rectangle.y],
|
|
944
|
+
[rectangle.x + rectangle.width, rectangle.y + rectangle.height / 2],
|
|
945
|
+
[rectangle.x + (rectangle.width * 5) / 6, rectangle.y + rectangle.height],
|
|
946
|
+
[rectangle.x + rectangle.width / 6, rectangle.y + rectangle.height]
|
|
786
947
|
];
|
|
787
948
|
};
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
const rs = PlaitBoard.getRoughSVG(board);
|
|
793
|
-
const polygon = rs.polygon(points, { ...options, fillStyle: 'solid' });
|
|
794
|
-
setStrokeLinecap(polygon, 'round');
|
|
795
|
-
return polygon;
|
|
796
|
-
},
|
|
797
|
-
isHit(rectangle, point) {
|
|
798
|
-
const parallelogramPoints = getStarPoints(rectangle);
|
|
799
|
-
return isPointInPolygon(point, parallelogramPoints);
|
|
800
|
-
},
|
|
801
|
-
getCornerPoints(rectangle) {
|
|
802
|
-
return getStarPoints(rectangle);
|
|
803
|
-
},
|
|
804
|
-
getNearestPoint(rectangle, point) {
|
|
805
|
-
return getNearestPointBetweenPointAndSegments(point, getStarPoints(rectangle));
|
|
806
|
-
},
|
|
807
|
-
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
808
|
-
const corners = getStarPoints(rectangle);
|
|
809
|
-
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
810
|
-
return getEdgeOnPolygonByPoint(corners, point);
|
|
949
|
+
const PreparationEngine = createPolygonEngine({
|
|
950
|
+
getPolygonPoints: getPreparationPoints,
|
|
951
|
+
getConnectorPoints: (rectangle) => {
|
|
952
|
+
return RectangleClient.getEdgeCenterPoints(rectangle);
|
|
811
953
|
},
|
|
812
|
-
|
|
813
|
-
const
|
|
814
|
-
|
|
954
|
+
getTextRectangle(element) {
|
|
955
|
+
const rectangle = getTextRectangle(element);
|
|
956
|
+
const width = rectangle.width;
|
|
957
|
+
rectangle.width = (rectangle.width * 2) / 3;
|
|
958
|
+
rectangle.x += width / 6;
|
|
959
|
+
return rectangle;
|
|
815
960
|
}
|
|
816
|
-
};
|
|
817
|
-
|
|
961
|
+
});
|
|
962
|
+
|
|
963
|
+
const getManualLoopPoints = (rectangle) => {
|
|
818
964
|
return [
|
|
819
|
-
[rectangle.x
|
|
820
|
-
[rectangle.x +
|
|
821
|
-
[rectangle.x + (rectangle.width *
|
|
822
|
-
[rectangle.x, rectangle.y +
|
|
823
|
-
[rectangle.x + (rectangle.width * 33.3053687) / 96, rectangle.y + (rectangle.height * 29.7745751) / 91],
|
|
824
|
-
[rectangle.x + rectangle.width / 2, rectangle.y],
|
|
825
|
-
[rectangle.x + (rectangle.width * 62.6946313) / 96, rectangle.y + (rectangle.height * 29.7745751) / 91],
|
|
826
|
-
[rectangle.x + rectangle.width, rectangle.y + (rectangle.height * 34.5491503) / 91],
|
|
827
|
-
[rectangle.x + (rectangle.width * 71.7764129) / 96, rectangle.y + (rectangle.height * 57.7254249) / 91],
|
|
828
|
-
[rectangle.x + (rectangle.width * 77.3892626) / 96, rectangle.y + rectangle.height]
|
|
965
|
+
[rectangle.x, rectangle.y],
|
|
966
|
+
[rectangle.x + rectangle.width, rectangle.y],
|
|
967
|
+
[rectangle.x + (rectangle.width * 7) / 8, rectangle.y + rectangle.height],
|
|
968
|
+
[rectangle.x + rectangle.width / 8, rectangle.y + rectangle.height]
|
|
829
969
|
];
|
|
830
970
|
};
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
const
|
|
835
|
-
|
|
836
|
-
const polygon = rs.polygon(points, { ...options, fillStyle: 'solid' });
|
|
837
|
-
setStrokeLinecap(polygon, 'round');
|
|
838
|
-
return polygon;
|
|
839
|
-
},
|
|
840
|
-
isHit(rectangle, point) {
|
|
841
|
-
const points = getTrapezoidPoints(rectangle);
|
|
842
|
-
return isPointInPolygon(point, points);
|
|
843
|
-
},
|
|
844
|
-
getNearestPoint(rectangle, point) {
|
|
845
|
-
const cornerPoints = getTrapezoidPoints(rectangle);
|
|
846
|
-
return getNearestPointBetweenPointAndSegments(point, cornerPoints);
|
|
847
|
-
},
|
|
848
|
-
getConnectorPoints(rectangle) {
|
|
849
|
-
const points = getTrapezoidPoints(rectangle);
|
|
850
|
-
return getCenterPointsOnPolygon(points);
|
|
851
|
-
},
|
|
852
|
-
getEdgeByConnectionPoint(rectangle, pointOfRectangle) {
|
|
853
|
-
const corners = getTrapezoidPoints(rectangle);
|
|
854
|
-
const point = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
855
|
-
return getEdgeOnPolygonByPoint(corners, point);
|
|
971
|
+
const ManualLoopEngine = createPolygonEngine({
|
|
972
|
+
getPolygonPoints: getManualLoopPoints,
|
|
973
|
+
getConnectorPoints: (rectangle) => {
|
|
974
|
+
const cornerPoints = getManualLoopPoints(rectangle);
|
|
975
|
+
return getCenterPointsOnPolygon(cornerPoints);
|
|
856
976
|
},
|
|
857
|
-
|
|
858
|
-
|
|
977
|
+
getTextRectangle(element) {
|
|
978
|
+
const rectangle = getTextRectangle(element);
|
|
979
|
+
const width = rectangle.width;
|
|
980
|
+
rectangle.width = (rectangle.width * 3) / 4;
|
|
981
|
+
rectangle.x += width / 8;
|
|
982
|
+
return rectangle;
|
|
859
983
|
}
|
|
860
|
-
};
|
|
861
|
-
|
|
984
|
+
});
|
|
985
|
+
|
|
986
|
+
const getMergePoints = (rectangle) => {
|
|
862
987
|
return [
|
|
863
|
-
[rectangle.x
|
|
864
|
-
[rectangle.x + rectangle.width
|
|
865
|
-
[rectangle.x + rectangle.width, rectangle.y + rectangle.height]
|
|
866
|
-
[rectangle.x, rectangle.y + rectangle.height]
|
|
988
|
+
[rectangle.x, rectangle.y],
|
|
989
|
+
[rectangle.x + rectangle.width, rectangle.y],
|
|
990
|
+
[rectangle.x + rectangle.width / 2, rectangle.y + rectangle.height]
|
|
867
991
|
];
|
|
868
992
|
};
|
|
993
|
+
const MergeEngine = createPolygonEngine({
|
|
994
|
+
getPolygonPoints: getMergePoints,
|
|
995
|
+
getConnectorPoints: (rectangle) => {
|
|
996
|
+
const cornerPoints = getMergePoints(rectangle);
|
|
997
|
+
const lineCenterPoints = getCenterPointsOnPolygon(cornerPoints);
|
|
998
|
+
return [...lineCenterPoints, ...cornerPoints];
|
|
999
|
+
},
|
|
1000
|
+
getTextRectangle(element) {
|
|
1001
|
+
const elementRectangle = getRectangleByPoints(element.points);
|
|
1002
|
+
const strokeWidth = getStrokeWidthByElement(element);
|
|
1003
|
+
const height = element.textHeight;
|
|
1004
|
+
const originWidth = elementRectangle.width - ShapeDefaultSpace.rectangleAndText * 2 - strokeWidth * 2;
|
|
1005
|
+
const width = (originWidth * 2) / 3;
|
|
1006
|
+
return {
|
|
1007
|
+
height,
|
|
1008
|
+
width: width > 0 ? width : 0,
|
|
1009
|
+
x: elementRectangle.x + ShapeDefaultSpace.rectangleAndText + strokeWidth + originWidth / 6,
|
|
1010
|
+
y: elementRectangle.y + ((elementRectangle.height * 2) / 3 - height) / 2
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
});
|
|
869
1014
|
|
|
870
|
-
const
|
|
1015
|
+
const DelayEngine = {
|
|
871
1016
|
draw(board, rectangle, options) {
|
|
872
|
-
const points = getTrianglePoints(rectangle);
|
|
873
1017
|
const rs = PlaitBoard.getRoughSVG(board);
|
|
874
|
-
const
|
|
875
|
-
|
|
876
|
-
|
|
1018
|
+
const shape = rs.path(`M${rectangle.x} ${rectangle.y} L${rectangle.x + (rectangle.width * 3) / 4} ${rectangle.y} A ${rectangle.width /
|
|
1019
|
+
4} ${rectangle.height / 2}, 0, 0, 1,${rectangle.x + (rectangle.width * 3) / 4} ${rectangle.y + rectangle.height} L${rectangle.x} ${rectangle.y + rectangle.height} Z`, { ...options, fillStyle: 'solid' });
|
|
1020
|
+
setStrokeLinecap(shape, 'round');
|
|
1021
|
+
return shape;
|
|
877
1022
|
},
|
|
878
1023
|
isHit(rectangle, point) {
|
|
879
|
-
|
|
880
|
-
|
|
1024
|
+
//split shape to rectangle and a half ellipse
|
|
1025
|
+
const rangeRectangle = RectangleClient.toRectangleClient([point, point]);
|
|
1026
|
+
const isInRectangle = RectangleClient.isHit({
|
|
1027
|
+
...rectangle,
|
|
1028
|
+
width: (rectangle.width * 3) / 4
|
|
1029
|
+
}, rangeRectangle);
|
|
1030
|
+
const isInEllipse = isPointInEllipse(point, [rectangle.x + (rectangle.width * 3) / 4, rectangle.y + rectangle.height / 2], rectangle.width / 4, rectangle.height / 2);
|
|
1031
|
+
return isInRectangle || isInEllipse;
|
|
881
1032
|
},
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
return getNearestPointBetweenPointAndSegments(point, cornerPoints);
|
|
1033
|
+
getCornerPoints(rectangle) {
|
|
1034
|
+
return RectangleClient.getCornerPoints(rectangle);
|
|
885
1035
|
},
|
|
886
|
-
|
|
887
|
-
const
|
|
888
|
-
|
|
889
|
-
|
|
1036
|
+
getNearestPoint(rectangle, point) {
|
|
1037
|
+
const nearestPoint = getNearestPointBetweenPointAndSegments(point, RectangleEngine.getCornerPoints(rectangle));
|
|
1038
|
+
if (nearestPoint[0] > rectangle.x + (rectangle.width * 3) / 4) {
|
|
1039
|
+
return getNearestPointBetweenPointAndEllipse(point, [rectangle.x + (rectangle.width * 3) / 4, rectangle.y + rectangle.height / 2], rectangle.width / 4, rectangle.height / 2);
|
|
1040
|
+
}
|
|
1041
|
+
return nearestPoint;
|
|
890
1042
|
},
|
|
891
|
-
|
|
892
|
-
const
|
|
893
|
-
const
|
|
894
|
-
|
|
1043
|
+
getTangentVectorByConnectionPoint(rectangle, pointOfRectangle) {
|
|
1044
|
+
const connectionPoint = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
1045
|
+
const centerPoint = [rectangle.x + (rectangle.width * 3) / 4, rectangle.y + rectangle.height / 2];
|
|
1046
|
+
const point = [connectionPoint[0] - centerPoint[0], -(connectionPoint[1] - centerPoint[1])];
|
|
1047
|
+
const a = rectangle.width / 4;
|
|
1048
|
+
const b = rectangle.height / 2;
|
|
1049
|
+
const slope = getTangentSlope(point[0], point[1], a, b);
|
|
1050
|
+
return getVectorBySlope(point[0], point[1], slope);
|
|
895
1051
|
},
|
|
896
|
-
|
|
897
|
-
return
|
|
1052
|
+
getConnectorPoints(rectangle) {
|
|
1053
|
+
return RectangleClient.getEdgeCenterPoints(rectangle);
|
|
898
1054
|
}
|
|
899
1055
|
};
|
|
900
|
-
const getTrianglePoints = (rectangle) => {
|
|
901
|
-
return [
|
|
902
|
-
[rectangle.x + rectangle.width / 2, rectangle.y],
|
|
903
|
-
[rectangle.x + rectangle.width, rectangle.y + rectangle.height],
|
|
904
|
-
[rectangle.x, rectangle.y + rectangle.height]
|
|
905
|
-
];
|
|
906
|
-
};
|
|
907
1056
|
|
|
908
|
-
const
|
|
1057
|
+
const StoredDataEngine = {
|
|
909
1058
|
draw(board, rectangle, options) {
|
|
910
|
-
const points = getTwoWayArrowPoints(rectangle);
|
|
911
1059
|
const rs = PlaitBoard.getRoughSVG(board);
|
|
912
|
-
const
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
return
|
|
1060
|
+
const shape = rs.path(`M${rectangle.x + rectangle.width / 10} ${rectangle.y} L${rectangle.x + rectangle.width} ${rectangle.y} A ${rectangle.width /
|
|
1061
|
+
10} ${rectangle.height / 2}, 1, 0, 0,${rectangle.x + rectangle.width} ${rectangle.y + rectangle.height} L${rectangle.x +
|
|
1062
|
+
rectangle.width / 10} ${rectangle.y + rectangle.height}A ${rectangle.width / 10} ${rectangle.height /
|
|
1063
|
+
2}, 0, 0, 1,${rectangle.x + rectangle.width / 10} ${rectangle.y}`, { ...options, fillStyle: 'solid' });
|
|
1064
|
+
setStrokeLinecap(shape, 'round');
|
|
1065
|
+
return shape;
|
|
918
1066
|
},
|
|
919
1067
|
isHit(rectangle, point) {
|
|
920
|
-
|
|
921
|
-
|
|
1068
|
+
//split shape to rectangle and a half ellipse
|
|
1069
|
+
const rangeRectangle = RectangleClient.toRectangleClient([point, point]);
|
|
1070
|
+
const isInRectangle = RectangleClient.isHit({
|
|
1071
|
+
...rectangle,
|
|
1072
|
+
x: rectangle.x + rectangle.width / 10,
|
|
1073
|
+
width: (rectangle.width * 9) / 10
|
|
1074
|
+
}, rangeRectangle);
|
|
1075
|
+
const isInFrontEllipse = isPointInEllipse(point, [rectangle.x + rectangle.width / 10, rectangle.y + rectangle.height / 2], rectangle.width / 10, rectangle.height / 2);
|
|
1076
|
+
const notInBackEllipse = !isPointInEllipse(point, [rectangle.x + rectangle.width, rectangle.y + rectangle.height / 2], rectangle.width / 10, rectangle.height / 2);
|
|
1077
|
+
return (isInRectangle && notInBackEllipse) || isInFrontEllipse;
|
|
1078
|
+
},
|
|
1079
|
+
getCornerPoints(rectangle) {
|
|
1080
|
+
return RectangleClient.getCornerPoints(rectangle);
|
|
922
1081
|
},
|
|
923
1082
|
getNearestPoint(rectangle, point) {
|
|
924
|
-
const
|
|
925
|
-
|
|
1083
|
+
const nearestPoint = getNearestPointBetweenPointAndSegments(point, RectangleEngine.getCornerPoints(rectangle));
|
|
1084
|
+
if (nearestPoint[0] < rectangle.x + rectangle.width / 10) {
|
|
1085
|
+
const nearestPoint = getNearestPointBetweenPointAndEllipse(point, [rectangle.x + rectangle.width / 10, rectangle.y + rectangle.height / 2], rectangle.width / 10, rectangle.height / 2);
|
|
1086
|
+
if (nearestPoint[0] > rectangle.x + rectangle.width / 10) {
|
|
1087
|
+
nearestPoint[0] = (rectangle.x + rectangle.width / 10) * 2 - nearestPoint[0];
|
|
1088
|
+
}
|
|
1089
|
+
return nearestPoint;
|
|
1090
|
+
}
|
|
1091
|
+
if (nearestPoint[0] > rectangle.x + (rectangle.width * 9) / 10) {
|
|
1092
|
+
return getNearestPointBetweenPointAndEllipse(point, [rectangle.x + rectangle.width, rectangle.y + rectangle.height / 2], rectangle.width / 10, rectangle.height / 2);
|
|
1093
|
+
}
|
|
1094
|
+
return nearestPoint;
|
|
926
1095
|
},
|
|
927
|
-
|
|
928
|
-
const
|
|
929
|
-
|
|
930
|
-
|
|
1096
|
+
getTangentVectorByConnectionPoint(rectangle, pointOfRectangle) {
|
|
1097
|
+
const connectionPoint = RectangleClient.getConnectionPoint(rectangle, pointOfRectangle);
|
|
1098
|
+
let centerPoint = [rectangle.x + rectangle.width / 10, rectangle.y + rectangle.height / 2];
|
|
1099
|
+
let a = rectangle.width / 10;
|
|
1100
|
+
let b = rectangle.height / 2;
|
|
1101
|
+
const isBackEllipse = connectionPoint[0] > rectangle.x + (rectangle.width * 9) / 10 && connectionPoint[1] > rectangle.y;
|
|
1102
|
+
if (isBackEllipse) {
|
|
1103
|
+
centerPoint = [rectangle.x + rectangle.width, rectangle.y + rectangle.height / 2];
|
|
1104
|
+
}
|
|
1105
|
+
const point = [connectionPoint[0] - centerPoint[0], -(connectionPoint[1] - centerPoint[1])];
|
|
1106
|
+
const slope = getTangentSlope(point[0], point[1], a, b);
|
|
1107
|
+
const vector = getVectorBySlope(point[0], point[1], slope);
|
|
1108
|
+
return isBackEllipse ? vector.map(num => -num) : vector;
|
|
931
1109
|
},
|
|
932
1110
|
getConnectorPoints(rectangle) {
|
|
933
1111
|
return [
|
|
934
|
-
[rectangle.x
|
|
935
|
-
[rectangle.x + rectangle.width, rectangle.y + rectangle.height / 2]
|
|
1112
|
+
[rectangle.x + rectangle.width / 2, rectangle.y],
|
|
1113
|
+
[rectangle.x + (rectangle.width * 9) / 10, rectangle.y + rectangle.height / 2],
|
|
1114
|
+
[rectangle.x + rectangle.width / 2, rectangle.y + rectangle.height],
|
|
1115
|
+
[rectangle.x, rectangle.y + rectangle.height / 2]
|
|
936
1116
|
];
|
|
1117
|
+
},
|
|
1118
|
+
getTextRectangle(element) {
|
|
1119
|
+
const rectangle = getTextRectangle(element);
|
|
1120
|
+
const width = rectangle.width;
|
|
1121
|
+
rectangle.width = (rectangle.width * 3) / 4;
|
|
1122
|
+
rectangle.x += width / 8;
|
|
1123
|
+
return rectangle;
|
|
937
1124
|
}
|
|
938
1125
|
};
|
|
939
|
-
const getTwoWayArrowPoints = (rectangle) => {
|
|
940
|
-
return [
|
|
941
|
-
[rectangle.x, rectangle.y + rectangle.height / 2],
|
|
942
|
-
[rectangle.x + (rectangle.width * 8) / 25, rectangle.y],
|
|
943
|
-
[rectangle.x + (rectangle.width * 8) / 25, rectangle.y + rectangle.height / 5],
|
|
944
|
-
[rectangle.x + (rectangle.width * 17) / 25, rectangle.y + rectangle.height / 5],
|
|
945
|
-
[rectangle.x + (rectangle.width * 17) / 25, rectangle.y],
|
|
946
|
-
[rectangle.x + rectangle.width, rectangle.y + rectangle.height / 2],
|
|
947
|
-
[rectangle.x + (rectangle.width * 17) / 25, rectangle.y + rectangle.height],
|
|
948
|
-
[rectangle.x + (rectangle.width * 17) / 25, rectangle.y + (rectangle.height * 4) / 5],
|
|
949
|
-
[rectangle.x + (rectangle.width * 8) / 25, rectangle.y + (rectangle.height * 4) / 5],
|
|
950
|
-
[rectangle.x + (rectangle.width * 8) / 25, rectangle.y + rectangle.height]
|
|
951
|
-
];
|
|
952
|
-
};
|
|
953
1126
|
|
|
954
1127
|
const ShapeEngineMap = {
|
|
955
|
-
[
|
|
956
|
-
[
|
|
957
|
-
[
|
|
958
|
-
[
|
|
959
|
-
[
|
|
960
|
-
[
|
|
961
|
-
[
|
|
962
|
-
[
|
|
963
|
-
[
|
|
964
|
-
[
|
|
965
|
-
[
|
|
966
|
-
[
|
|
967
|
-
[
|
|
968
|
-
[
|
|
969
|
-
[
|
|
970
|
-
[
|
|
971
|
-
[
|
|
972
|
-
[
|
|
973
|
-
[
|
|
974
|
-
[
|
|
1128
|
+
[BasicShapes.rectangle]: RectangleEngine,
|
|
1129
|
+
[BasicShapes.diamond]: DiamondEngine,
|
|
1130
|
+
[BasicShapes.ellipse]: EllipseEngine,
|
|
1131
|
+
[BasicShapes.parallelogram]: ParallelogramEngine,
|
|
1132
|
+
[BasicShapes.roundRectangle]: RoundRectangleEngine,
|
|
1133
|
+
[BasicShapes.text]: RectangleEngine,
|
|
1134
|
+
[BasicShapes.triangle]: TriangleEngine,
|
|
1135
|
+
[BasicShapes.leftArrow]: LeftArrowEngine,
|
|
1136
|
+
[BasicShapes.trapezoid]: TrapezoidEngine,
|
|
1137
|
+
[BasicShapes.rightArrow]: RightArrowEngine,
|
|
1138
|
+
[BasicShapes.cross]: CrossEngine,
|
|
1139
|
+
[BasicShapes.star]: StarEngine,
|
|
1140
|
+
[BasicShapes.pentagon]: PentagonEngine,
|
|
1141
|
+
[BasicShapes.hexagon]: HexagonEngine,
|
|
1142
|
+
[BasicShapes.octagon]: OctagonEngine,
|
|
1143
|
+
[BasicShapes.pentagonArrow]: PentagonArrowEngine,
|
|
1144
|
+
[BasicShapes.processArrow]: ProcessArrowEngine,
|
|
1145
|
+
[BasicShapes.twoWayArrow]: TwoWayArrowEngine,
|
|
1146
|
+
[BasicShapes.comment]: CommentEngine,
|
|
1147
|
+
[BasicShapes.roundComment]: RoundCommentEngine,
|
|
1148
|
+
[FlowchartSymbols.process]: RectangleEngine,
|
|
1149
|
+
[FlowchartSymbols.decision]: DiamondEngine,
|
|
1150
|
+
[FlowchartSymbols.connector]: EllipseEngine,
|
|
1151
|
+
[FlowchartSymbols.data]: ParallelogramEngine,
|
|
1152
|
+
[FlowchartSymbols.terminal]: TerminalEngine,
|
|
1153
|
+
[FlowchartSymbols.manualInput]: ManualInputEngine,
|
|
1154
|
+
[FlowchartSymbols.preparation]: PreparationEngine,
|
|
1155
|
+
[FlowchartSymbols.manualLoop]: ManualLoopEngine,
|
|
1156
|
+
[FlowchartSymbols.merge]: MergeEngine,
|
|
1157
|
+
[FlowchartSymbols.delay]: DelayEngine,
|
|
1158
|
+
[FlowchartSymbols.storedData]: StoredDataEngine
|
|
975
1159
|
};
|
|
976
1160
|
const getEngine = (shape) => {
|
|
977
1161
|
return ShapeEngineMap[shape];
|
|
@@ -979,7 +1163,7 @@ const getEngine = (shape) => {
|
|
|
979
1163
|
|
|
980
1164
|
const getShape = (value) => {
|
|
981
1165
|
if (PlaitDrawElement.isImage(value)) {
|
|
982
|
-
return
|
|
1166
|
+
return BasicShapes.rectangle;
|
|
983
1167
|
}
|
|
984
1168
|
return value.shape;
|
|
985
1169
|
};
|
|
@@ -987,10 +1171,14 @@ const getShape = (value) => {
|
|
|
987
1171
|
const createGeometryElement = (shape, points, text, options) => {
|
|
988
1172
|
let textOptions = {};
|
|
989
1173
|
let alignment = Alignment.center;
|
|
990
|
-
if (shape ===
|
|
1174
|
+
if (shape === BasicShapes.text) {
|
|
991
1175
|
textOptions = { autoSize: true };
|
|
992
1176
|
alignment = undefined;
|
|
993
1177
|
}
|
|
1178
|
+
let flowchartOptions = {};
|
|
1179
|
+
if (getFlowchartPointers().includes(shape)) {
|
|
1180
|
+
flowchartOptions = { fill: '#ffffff' };
|
|
1181
|
+
}
|
|
994
1182
|
return {
|
|
995
1183
|
id: idCreator(),
|
|
996
1184
|
type: 'geometry',
|
|
@@ -1001,7 +1189,8 @@ const createGeometryElement = (shape, points, text, options) => {
|
|
|
1001
1189
|
text: buildText(text, alignment),
|
|
1002
1190
|
points,
|
|
1003
1191
|
...textOptions,
|
|
1004
|
-
...options
|
|
1192
|
+
...options,
|
|
1193
|
+
...flowchartOptions
|
|
1005
1194
|
};
|
|
1006
1195
|
};
|
|
1007
1196
|
const getPointsByCenterPoint = (point, width, height) => {
|
|
@@ -1073,6 +1262,9 @@ const getEdgeOnPolygonByPoint = (corners, point) => {
|
|
|
1073
1262
|
}
|
|
1074
1263
|
return null;
|
|
1075
1264
|
};
|
|
1265
|
+
const getDefaultFlowchartProperty = (symbol) => {
|
|
1266
|
+
return DefaultFlowchartPropertyMap[symbol];
|
|
1267
|
+
};
|
|
1076
1268
|
|
|
1077
1269
|
const drawLineArrow = (element, points, options) => {
|
|
1078
1270
|
const arrowG = createG();
|
|
@@ -1112,11 +1304,11 @@ const getArrow = (element, arrowOptions, options) => {
|
|
|
1112
1304
|
break;
|
|
1113
1305
|
}
|
|
1114
1306
|
case LineMarkerType.oneSideUp: {
|
|
1115
|
-
targetArrow = drawOneSideArrow(source, target, 'up', options);
|
|
1307
|
+
targetArrow = drawOneSideArrow(source, target, isSource ? 'down' : 'up', options);
|
|
1116
1308
|
break;
|
|
1117
1309
|
}
|
|
1118
1310
|
case LineMarkerType.oneSideDown: {
|
|
1119
|
-
targetArrow = drawOneSideArrow(source, target, 'down', options);
|
|
1311
|
+
targetArrow = drawOneSideArrow(source, target, isSource ? 'up' : 'down', options);
|
|
1120
1312
|
break;
|
|
1121
1313
|
}
|
|
1122
1314
|
case LineMarkerType.hollowTriangle: {
|
|
@@ -1593,7 +1785,7 @@ const PlaitDrawElement = {
|
|
|
1593
1785
|
return value.type === 'line';
|
|
1594
1786
|
},
|
|
1595
1787
|
isText: (value) => {
|
|
1596
|
-
return value.type === 'geometry' && value.shape ===
|
|
1788
|
+
return value.type === 'geometry' && value.shape === BasicShapes.text;
|
|
1597
1789
|
},
|
|
1598
1790
|
isImage: (value) => {
|
|
1599
1791
|
return value.type === 'image';
|
|
@@ -1608,6 +1800,12 @@ const PlaitDrawElement = {
|
|
|
1608
1800
|
},
|
|
1609
1801
|
isShape: (value) => {
|
|
1610
1802
|
return PlaitDrawElement.isImage(value) || PlaitDrawElement.isGeometry(value);
|
|
1803
|
+
},
|
|
1804
|
+
isBaseShape: (value) => {
|
|
1805
|
+
return Object.keys(BasicShapes).includes(value.type);
|
|
1806
|
+
},
|
|
1807
|
+
isFlowchart: (value) => {
|
|
1808
|
+
return Object.keys(FlowchartSymbols).includes(value.type);
|
|
1611
1809
|
}
|
|
1612
1810
|
};
|
|
1613
1811
|
|
|
@@ -1618,7 +1816,7 @@ class GeometryShapeGenerator extends Generator {
|
|
|
1618
1816
|
baseDraw(element, data) {
|
|
1619
1817
|
const rectangle = getRectangleByPoints(element.points);
|
|
1620
1818
|
const shape = element.shape;
|
|
1621
|
-
if (shape ===
|
|
1819
|
+
if (shape === BasicShapes.text) {
|
|
1622
1820
|
return;
|
|
1623
1821
|
}
|
|
1624
1822
|
const strokeWidth = getStrokeWidthByElement(element);
|
|
@@ -1636,15 +1834,15 @@ class GeometryShapeGenerator extends Generator {
|
|
|
1636
1834
|
|
|
1637
1835
|
const insertGeometry = (board, points, shape) => {
|
|
1638
1836
|
let newElement = createGeometryElement(shape, points, '', {
|
|
1639
|
-
strokeColor:
|
|
1640
|
-
strokeWidth:
|
|
1837
|
+
strokeColor: DefaultBasicShapeProperty.strokeColor,
|
|
1838
|
+
strokeWidth: DefaultBasicShapeProperty.strokeWidth
|
|
1641
1839
|
});
|
|
1642
1840
|
Transforms.insertNode(board, newElement, [board.children.length]);
|
|
1643
1841
|
clearSelectedElement(board);
|
|
1644
1842
|
addSelectedElement(board, newElement);
|
|
1645
1843
|
};
|
|
1646
1844
|
const insertText = (board, points, text = '文本') => {
|
|
1647
|
-
let newElement = createGeometryElement(
|
|
1845
|
+
let newElement = createGeometryElement(BasicShapes.text, points, text);
|
|
1648
1846
|
Transforms.insertNode(board, newElement, [board.children.length]);
|
|
1649
1847
|
clearSelectedElement(board);
|
|
1650
1848
|
addSelectedElement(board, newElement);
|
|
@@ -1864,7 +2062,11 @@ class GeometryComponent extends CommonPluginElement {
|
|
|
1864
2062
|
}
|
|
1865
2063
|
},
|
|
1866
2064
|
getMaxWidth: () => {
|
|
1867
|
-
|
|
2065
|
+
let width = getTextRectangle(this.element).width;
|
|
2066
|
+
const getRectangle = getEngine(this.element.shape).getTextRectangle;
|
|
2067
|
+
if (getRectangle) {
|
|
2068
|
+
width = getRectangle(this.element).width;
|
|
2069
|
+
}
|
|
1868
2070
|
return this.element?.autoSize ? GeometryThreshold.defaultTextMaxWidth : width;
|
|
1869
2071
|
},
|
|
1870
2072
|
textPlugins: plugins
|
|
@@ -1877,10 +2079,10 @@ class GeometryComponent extends CommonPluginElement {
|
|
|
1877
2079
|
this.destroy$.next();
|
|
1878
2080
|
this.destroy$.complete();
|
|
1879
2081
|
}
|
|
1880
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.
|
|
1881
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.
|
|
2082
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: GeometryComponent, deps: [{ token: i0.ViewContainerRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
2083
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: GeometryComponent, isStandalone: true, selector: "plait-draw-geometry", usesInheritance: true, ngImport: i0, template: ``, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
1882
2084
|
}
|
|
1883
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.
|
|
2085
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: GeometryComponent, decorators: [{
|
|
1884
2086
|
type: Component,
|
|
1885
2087
|
args: [{
|
|
1886
2088
|
selector: 'plait-draw-geometry',
|
|
@@ -2118,10 +2320,10 @@ class LineComponent extends PlaitPluginElementComponent {
|
|
|
2118
2320
|
this.destroy$.next();
|
|
2119
2321
|
this.destroy$.complete();
|
|
2120
2322
|
}
|
|
2121
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.
|
|
2122
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.
|
|
2323
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: LineComponent, deps: [{ token: i0.ViewContainerRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
2324
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: LineComponent, isStandalone: true, selector: "plait-draw-line", usesInheritance: true, ngImport: i0, template: ``, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
2123
2325
|
}
|
|
2124
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.
|
|
2326
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: LineComponent, decorators: [{
|
|
2125
2327
|
type: Component,
|
|
2126
2328
|
args: [{
|
|
2127
2329
|
selector: 'plait-draw-line',
|
|
@@ -2174,15 +2376,15 @@ const withGeometryCreateByDrag = (board) => {
|
|
|
2174
2376
|
const pointer = PlaitBoard.getPointer(board);
|
|
2175
2377
|
if (dragMode) {
|
|
2176
2378
|
const points = getDefaultGeometryPoints(pointer, movingPoint);
|
|
2177
|
-
if (pointer ===
|
|
2379
|
+
if (pointer === BasicShapes.text) {
|
|
2178
2380
|
const textG = getTemporaryTextG(movingPoint);
|
|
2179
2381
|
geometryShapeG.appendChild(textG);
|
|
2180
2382
|
PlaitBoard.getElementActiveHost(board).append(geometryShapeG);
|
|
2181
2383
|
}
|
|
2182
2384
|
else {
|
|
2183
2385
|
const temporaryElement = createGeometryElement(pointer, points, '', {
|
|
2184
|
-
strokeColor:
|
|
2185
|
-
strokeWidth:
|
|
2386
|
+
strokeColor: DefaultBasicShapeProperty.strokeColor,
|
|
2387
|
+
strokeWidth: DefaultBasicShapeProperty.strokeWidth
|
|
2186
2388
|
});
|
|
2187
2389
|
geometryGenerator.draw(temporaryElement, geometryShapeG);
|
|
2188
2390
|
PlaitBoard.getElementActiveHost(board).append(geometryShapeG);
|
|
@@ -2198,7 +2400,7 @@ const withGeometryCreateByDrag = (board) => {
|
|
|
2198
2400
|
if (dragMode) {
|
|
2199
2401
|
const targetPoint = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
|
|
2200
2402
|
const points = getDefaultGeometryPoints(pointer, targetPoint);
|
|
2201
|
-
if (pointer ===
|
|
2403
|
+
if (pointer === BasicShapes.text) {
|
|
2202
2404
|
DrawTransforms.insertText(board, points);
|
|
2203
2405
|
}
|
|
2204
2406
|
else {
|
|
@@ -2235,9 +2437,9 @@ const withGeometryCreateByDrawing = (board) => {
|
|
|
2235
2437
|
start = point;
|
|
2236
2438
|
const pointer = PlaitBoard.getPointer(board);
|
|
2237
2439
|
preventTouchMove(board, event, true);
|
|
2238
|
-
if (pointer ===
|
|
2440
|
+
if (pointer === BasicShapes.text) {
|
|
2239
2441
|
const points = getDefaultGeometryPoints(pointer, point);
|
|
2240
|
-
const textElement = createGeometryElement(
|
|
2442
|
+
const textElement = createGeometryElement(BasicShapes.text, points, DefaultTextProperty.text);
|
|
2241
2443
|
Transforms.insertNode(board, textElement, [board.children.length]);
|
|
2242
2444
|
clearSelectedElement(board);
|
|
2243
2445
|
addSelectedElement(board, textElement);
|
|
@@ -2254,11 +2456,11 @@ const withGeometryCreateByDrawing = (board) => {
|
|
|
2254
2456
|
const drawMode = !!start;
|
|
2255
2457
|
const movingPoint = transformPoint(board, toPoint(event.x, event.y, PlaitBoard.getHost(board)));
|
|
2256
2458
|
const pointer = PlaitBoard.getPointer(board);
|
|
2257
|
-
if (drawMode && pointer !==
|
|
2459
|
+
if (drawMode && pointer !== BasicShapes.text) {
|
|
2258
2460
|
const points = normalizeShapePoints([start, movingPoint], isShift);
|
|
2259
2461
|
temporaryElement = createGeometryElement(pointer, points, '', {
|
|
2260
|
-
strokeColor:
|
|
2261
|
-
strokeWidth:
|
|
2462
|
+
strokeColor: DefaultBasicShapeProperty.strokeColor,
|
|
2463
|
+
strokeWidth: DefaultBasicShapeProperty.strokeWidth
|
|
2262
2464
|
});
|
|
2263
2465
|
geometryGenerator.draw(temporaryElement, geometryShapeG);
|
|
2264
2466
|
PlaitBoard.getElementActiveHost(board).append(geometryShapeG);
|
|
@@ -2273,10 +2475,10 @@ const withGeometryCreateByDrawing = (board) => {
|
|
|
2273
2475
|
if (Math.hypot(width, height) === 0) {
|
|
2274
2476
|
const pointer = PlaitBoard.getPointer(board);
|
|
2275
2477
|
const points = getDefaultGeometryPoints(pointer, targetPoint);
|
|
2276
|
-
if (pointer !==
|
|
2478
|
+
if (pointer !== BasicShapes.text) {
|
|
2277
2479
|
temporaryElement = createGeometryElement(pointer, points, '', {
|
|
2278
|
-
strokeColor:
|
|
2279
|
-
strokeWidth:
|
|
2480
|
+
strokeColor: DefaultBasicShapeProperty.strokeColor,
|
|
2481
|
+
strokeWidth: DefaultBasicShapeProperty.strokeWidth
|
|
2280
2482
|
});
|
|
2281
2483
|
}
|
|
2282
2484
|
}
|
|
@@ -2297,9 +2499,21 @@ const withGeometryCreateByDrawing = (board) => {
|
|
|
2297
2499
|
return board;
|
|
2298
2500
|
};
|
|
2299
2501
|
const getDefaultGeometryPoints = (pointer, targetPoint) => {
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2502
|
+
const defaultProperty = getGeometryDefaultProperty(pointer);
|
|
2503
|
+
return getPointsByCenterPoint(targetPoint, defaultProperty.width, defaultProperty.height);
|
|
2504
|
+
};
|
|
2505
|
+
const getGeometryDefaultProperty = (pointer) => {
|
|
2506
|
+
const isText = pointer === BasicShapes.text;
|
|
2507
|
+
const isFlowChart = getFlowchartPointers().includes(pointer);
|
|
2508
|
+
if (isText) {
|
|
2509
|
+
return DefaultTextProperty;
|
|
2510
|
+
}
|
|
2511
|
+
else if (isFlowChart) {
|
|
2512
|
+
return getDefaultFlowchartProperty(pointer);
|
|
2513
|
+
}
|
|
2514
|
+
else {
|
|
2515
|
+
return DefaultBasicShapeProperty;
|
|
2516
|
+
}
|
|
2303
2517
|
};
|
|
2304
2518
|
const getTemporaryTextG = (movingPoint) => {
|
|
2305
2519
|
const textG = createG();
|
|
@@ -2836,10 +3050,10 @@ class ImageComponent extends CommonPluginElement {
|
|
|
2836
3050
|
this.destroy$.complete();
|
|
2837
3051
|
this.imageGenerator.destroy();
|
|
2838
3052
|
}
|
|
2839
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.
|
|
2840
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.
|
|
3053
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ImageComponent, deps: [{ token: i0.ViewContainerRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
3054
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: ImageComponent, isStandalone: true, selector: "plait-draw-geometry", usesInheritance: true, ngImport: i0, template: ``, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
2841
3055
|
}
|
|
2842
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.
|
|
3056
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ImageComponent, decorators: [{
|
|
2843
3057
|
type: Component,
|
|
2844
3058
|
args: [{
|
|
2845
3059
|
selector: 'plait-draw-geometry',
|
|
@@ -2938,5 +3152,5 @@ const withDraw = (board) => {
|
|
|
2938
3152
|
* Generated bundle index. Do not edit.
|
|
2939
3153
|
*/
|
|
2940
3154
|
|
|
2941
|
-
export { DEFAULT_IMAGE_WIDTH,
|
|
3155
|
+
export { BasicShapes, DEFAULT_IMAGE_WIDTH, DefaultBasicShapeProperty, DefaultConnectorProperty, DefaultDataProperty, DefaultDecisionProperty, DefaultFlowchartProperty, DefaultFlowchartPropertyMap, DefaultGeometryActiveStyle, DefaultGeometryStyle, DefaultManualInputProperty, DefaultMergeProperty, DefaultTextProperty, DrawTransforms, FlowchartSymbols, GeometryComponent, GeometryThreshold, LineComponent, LineHandleKey, LineMarkerType, LineShape, PlaitDrawElement, PlaitGeometry, PlaitLine, Q2C, ShapeDefaultSpace, StrokeStyle, createGeometryElement, createLineElement, drawBoundMask, drawGeometry, drawLine, getBasicPointers, getBoardLines, getCenterPointsOnPolygon, getConnectionPoint, getCurvePoints, getDefaultFlowchartProperty, getEdgeOnPolygonByPoint, getElbowPoints, getExtendPoint, getFillByElement, getFlowchartPointers, getGeometryPointers, getHitConnectorPoint, getHitLineTextIndex, getLineDashByElement, getLineHandleRefPair, getLinePointers, getLinePoints, getLineTextRectangle, getNearestPoint, getPointsByCenterPoint, getSelectedDrawElements, getSelectedGeometryElements, getSelectedImageElements, getSelectedLineElements, getStrokeColorByElement, getStrokeStyleByElement, getStrokeWidthByElement, getTextRectangle, getVectorByConnection, isHitLineText, isHitPolyLine, removeDuplicatePoints, transformOpsToPoints, transformPointToConnection, withDraw };
|
|
2942
3156
|
//# sourceMappingURL=plait-draw.mjs.map
|