aldehyde 0.2.472 → 0.2.474

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.
Files changed (116) hide show
  1. package/lib/controls/entity-select/entity-select.js +1 -1
  2. package/lib/controls/entity-select/entity-select.js.map +1 -1
  3. package/lib/controls/entry-control.js +2 -2
  4. package/lib/controls/entry-control.js.map +1 -1
  5. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.css +47 -3
  6. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.js +12 -12
  7. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.js.map +1 -1
  8. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.json +77 -0
  9. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.ttf +0 -0
  10. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff +0 -0
  11. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff2 +0 -0
  12. package/lib/draw-canvas/edit/components/asset-bar/index.d.ts +5 -0
  13. package/lib/draw-canvas/edit/components/asset-bar/index.d.ts.map +1 -0
  14. package/lib/draw-canvas/edit/components/asset-bar/index.js +78 -0
  15. package/lib/draw-canvas/edit/components/asset-bar/index.js.map +1 -0
  16. package/lib/draw-canvas/edit/components/asset-bar/index.less +36 -0
  17. package/lib/draw-canvas/edit/components/main-header/index.d.ts +14 -0
  18. package/lib/draw-canvas/edit/components/main-header/index.d.ts.map +1 -0
  19. package/lib/draw-canvas/edit/components/main-header/index.js +163 -0
  20. package/lib/draw-canvas/edit/components/main-header/index.js.map +1 -0
  21. package/lib/draw-canvas/edit/components/main-header/index.less +21 -0
  22. package/lib/draw-canvas/edit/components/render/index.d.ts +86 -0
  23. package/lib/draw-canvas/edit/components/render/index.d.ts.map +1 -0
  24. package/lib/draw-canvas/edit/components/render/index.js +686 -0
  25. package/lib/draw-canvas/edit/components/render/index.js.map +1 -0
  26. package/lib/draw-canvas/edit/components/render/types.d.ts +243 -0
  27. package/lib/draw-canvas/edit/components/render/types.d.ts.map +1 -0
  28. package/lib/draw-canvas/edit/components/render/types.js +66 -0
  29. package/lib/draw-canvas/edit/components/render/types.js.map +1 -0
  30. package/lib/draw-canvas/edit/components/setting-form/index.d.ts +19 -0
  31. package/lib/draw-canvas/edit/components/setting-form/index.d.ts.map +1 -0
  32. package/lib/draw-canvas/edit/components/setting-form/index.js +164 -0
  33. package/lib/draw-canvas/edit/components/setting-form/index.js.map +1 -0
  34. package/lib/draw-canvas/edit/index.d.ts +5 -0
  35. package/lib/draw-canvas/edit/index.d.ts.map +1 -0
  36. package/lib/draw-canvas/edit/index.js +112 -0
  37. package/lib/draw-canvas/edit/index.js.map +1 -0
  38. package/lib/draw-canvas/edit/index.less +34 -0
  39. package/lib/form/form-Item-group.d.ts.map +1 -1
  40. package/lib/form/form-Item-group.js +1 -1
  41. package/lib/form/form-Item-group.js.map +1 -1
  42. package/lib/icon/local-aliIcon/iconfont.js +5 -5
  43. package/lib/icon/local-aliIcon/iconfont.js.map +1 -1
  44. package/lib/table/relation-table.d.ts +4 -0
  45. package/lib/table/relation-table.d.ts.map +1 -1
  46. package/lib/tmpl/hcservice-v3.d.ts +1 -0
  47. package/lib/tmpl/hcservice-v3.d.ts.map +1 -1
  48. package/lib/tmpl/hcservice-v3.js +27 -0
  49. package/lib/tmpl/hcservice-v3.js.map +1 -1
  50. package/lib/tmpl/interface.d.ts +4 -0
  51. package/lib/tmpl/interface.d.ts.map +1 -1
  52. package/lib/tmpl/interface.js.map +1 -1
  53. package/lib/units/index.d.ts +1 -0
  54. package/lib/units/index.d.ts.map +1 -1
  55. package/lib/units/index.js +16 -0
  56. package/lib/units/index.js.map +1 -1
  57. package/package.json +1 -1
  58. package/src/aldehyde/controls/entity-select/entity-select.tsx +1 -1
  59. package/src/aldehyde/controls/entry-control.tsx +2 -2
  60. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.css +47 -3
  61. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.js +1 -1
  62. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.json +77 -0
  63. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.ttf +0 -0
  64. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff +0 -0
  65. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff2 +0 -0
  66. package/src/aldehyde/draw-canvas/edit/components/asset-bar/index.less +36 -0
  67. package/src/aldehyde/draw-canvas/edit/components/asset-bar/index.tsx +93 -0
  68. package/src/aldehyde/draw-canvas/edit/components/main-header/index.less +21 -0
  69. package/src/aldehyde/draw-canvas/edit/components/main-header/index.tsx +187 -0
  70. package/src/aldehyde/draw-canvas/edit/components/render/draws/bg-draw.ts +98 -0
  71. package/src/aldehyde/draw-canvas/edit/components/render/draws/contextmenu-draw.ts +307 -0
  72. package/src/aldehyde/draw-canvas/edit/components/render/draws/graph-draw.ts +251 -0
  73. package/src/aldehyde/draw-canvas/edit/components/render/draws/index.ts +7 -0
  74. package/src/aldehyde/draw-canvas/edit/components/render/draws/link-draw.ts +1416 -0
  75. package/src/aldehyde/draw-canvas/edit/components/render/draws/preview-draw.ts +257 -0
  76. package/src/aldehyde/draw-canvas/edit/components/render/draws/ref-line-draw.ts +72 -0
  77. package/src/aldehyde/draw-canvas/edit/components/render/draws/ruler-draw.ts +167 -0
  78. package/src/aldehyde/draw-canvas/edit/components/render/graphs/base-graph.ts +241 -0
  79. package/src/aldehyde/draw-canvas/edit/components/render/graphs/bezier.ts +542 -0
  80. package/src/aldehyde/draw-canvas/edit/components/render/graphs/circle.ts +700 -0
  81. package/src/aldehyde/draw-canvas/edit/components/render/graphs/curve.ts +501 -0
  82. package/src/aldehyde/draw-canvas/edit/components/render/graphs/index.ts +6 -0
  83. package/src/aldehyde/draw-canvas/edit/components/render/graphs/line.ts +494 -0
  84. package/src/aldehyde/draw-canvas/edit/components/render/graphs/rect.ts +681 -0
  85. package/src/aldehyde/draw-canvas/edit/components/render/handlers/drag-handlers.ts +69 -0
  86. package/src/aldehyde/draw-canvas/edit/components/render/handlers/drag-outside-handlers.ts +162 -0
  87. package/src/aldehyde/draw-canvas/edit/components/render/handlers/graph-handlers.ts +108 -0
  88. package/src/aldehyde/draw-canvas/edit/components/render/handlers/index.ts +9 -0
  89. package/src/aldehyde/draw-canvas/edit/components/render/handlers/key-move-handlers.ts +50 -0
  90. package/src/aldehyde/draw-canvas/edit/components/render/handlers/link-handlers.ts +46 -0
  91. package/src/aldehyde/draw-canvas/edit/components/render/handlers/selection-handlers.ts +385 -0
  92. package/src/aldehyde/draw-canvas/edit/components/render/handlers/shutcut-handlers.ts +46 -0
  93. package/src/aldehyde/draw-canvas/edit/components/render/handlers/text-handlers.ts +82 -0
  94. package/src/aldehyde/draw-canvas/edit/components/render/handlers/zoom-handlers.ts +60 -0
  95. package/src/aldehyde/draw-canvas/edit/components/render/index.ts +768 -0
  96. package/src/aldehyde/draw-canvas/edit/components/render/tools/align-tool.ts +91 -0
  97. package/src/aldehyde/draw-canvas/edit/components/render/tools/asset-tool.ts +142 -0
  98. package/src/aldehyde/draw-canvas/edit/components/render/tools/attract-tool.ts +440 -0
  99. package/src/aldehyde/draw-canvas/edit/components/render/tools/copy-tool.ts +269 -0
  100. package/src/aldehyde/draw-canvas/edit/components/render/tools/import-export-tool.ts +603 -0
  101. package/src/aldehyde/draw-canvas/edit/components/render/tools/index.ts +9 -0
  102. package/src/aldehyde/draw-canvas/edit/components/render/tools/link-tool.ts +225 -0
  103. package/src/aldehyde/draw-canvas/edit/components/render/tools/position-tool.ts +212 -0
  104. package/src/aldehyde/draw-canvas/edit/components/render/tools/selection-tool.ts +132 -0
  105. package/src/aldehyde/draw-canvas/edit/components/render/tools/z-index-tool.ts +227 -0
  106. package/src/aldehyde/draw-canvas/edit/components/render/types.ts +287 -0
  107. package/src/aldehyde/draw-canvas/edit/components/render/utils/a-star.ts +116 -0
  108. package/src/aldehyde/draw-canvas/edit/components/render/utils/bezier-scene-func.ts +73 -0
  109. package/src/aldehyde/draw-canvas/edit/components/setting-form/index.tsx +200 -0
  110. package/src/aldehyde/draw-canvas/edit/index.less +34 -0
  111. package/src/aldehyde/draw-canvas/edit/index.tsx +138 -0
  112. package/src/aldehyde/form/form-Item-group.tsx +1 -0
  113. package/src/aldehyde/icon/local-aliIcon/iconfont.js +1 -1
  114. package/src/aldehyde/tmpl/hcservice-v3.tsx +14 -0
  115. package/src/aldehyde/tmpl/interface.tsx +2 -0
  116. package/src/aldehyde/units/index.tsx +15 -0
@@ -0,0 +1,501 @@
1
+ import Konva from 'konva';
2
+ import { GraphAnchor, Render, AssetInfoPoint, LineManualPoint } from '../types';
3
+ import { GraphDraw, LinkDraw, PreviewDraw } from '../draws';
4
+ import { BaseGraph } from './base-graph';
5
+
6
+ /**
7
+ * 曲线
8
+ */
9
+ export class Curve extends BaseGraph {
10
+ // 实现:更新 图形 的 调整点 的 锚点位置
11
+ static override updateAnchorShadows(graph: Konva.Group, anchorShadows: Konva.Circle[], shape?: Konva.Line): void {
12
+ if (shape) {
13
+ const points = shape.points();
14
+ for (const shadow of anchorShadows) {
15
+ switch (shadow.attrs.adjustType) {
16
+ case 'start':
17
+ shadow.position({ x: points[0], y: points[1] });
18
+ break;
19
+ case 'end':
20
+ shadow.position({ x: points[points.length - 2], y: points[points.length - 1] });
21
+ break;
22
+ }
23
+ }
24
+ }
25
+ }
26
+
27
+ // 实现:更新 图形 的 连接点 的 锚点位置
28
+ static override updateLinkAnchorShadows(graph: Konva.Group, linkAnchorShadows: Konva.Circle[], shape?: Konva.Line): void {
29
+ if (shape) {
30
+ const points = shape.points();
31
+ for (const shadow of linkAnchorShadows) {
32
+ switch (shadow.attrs.alias) {
33
+ case 'start':
34
+ shadow.position({ x: points[0], y: points[1] });
35
+ break;
36
+ case 'end':
37
+ shadow.position({ x: points[points.length - 2], y: points[points.length - 1] });
38
+ break;
39
+ }
40
+ }
41
+ }
42
+ }
43
+
44
+ static calculateAngle(sideA: number, sideB: number) {
45
+ if (!isNaN(sideA) && !isNaN(sideB)) {
46
+ const angleInRadians = Math.atan2(sideA, sideB);
47
+ const angleInDegrees = angleInRadians * (180 / Math.PI);
48
+ return angleInDegrees;
49
+ }
50
+ return 0;
51
+ }
52
+
53
+ // 实现:生成 调整点
54
+ static override createAnchorShapes(
55
+ render: Render,
56
+ graph: Konva.Group,
57
+ anchorAndShadows: {
58
+ anchor: GraphAnchor;
59
+ anchorShadow: Konva.Circle;
60
+ shape?: Konva.Shape;
61
+ }[],
62
+ // eslint-disable-next-line
63
+ adjustAnchor?: GraphAnchor
64
+ ): {
65
+ anchorAndShadows: {
66
+ anchor: GraphAnchor;
67
+ anchorShadow: Konva.Circle;
68
+ shape?: Konva.Shape | undefined;
69
+ }[]
70
+ } {
71
+ const stageState = render.getStageState();
72
+ const graphShape = graph.findOne('.graph') as Konva.Line;
73
+ if (graphShape) {
74
+ const points = graphShape.points();
75
+ for (const anchorAndShadow of anchorAndShadows) {
76
+ let rotate = 0;
77
+ const { anchor, anchorShadow } = anchorAndShadow;
78
+ const x = render.toStageValue(anchorShadow.getAbsolutePosition().x - stageState.x),
79
+ y = render.toStageValue(anchorShadow.getAbsolutePosition().y - stageState.y);
80
+ if (anchor.adjustType === 'manual') {
81
+ const anchorShape = new Konva.Circle({
82
+ name: 'anchor',
83
+ anchor: anchor,
84
+ fill: anchor.adjusted ? `rgba(0,0,0,0.4)` : `rgba(0,0,255,0.4)`,
85
+ radius: render.toStageValue(5),
86
+ strokeWidth: 0,
87
+ x: x,
88
+ y: y,
89
+ rotation: graph.getAbsoluteRotation(),
90
+ visible: graph.attrs.adjusting || graph.attrs.hover === true
91
+ });
92
+ anchorShape.on('mouseenter', () => {
93
+ document.body.style.cursor = 'move';
94
+ graph.setAttr('hover', true);
95
+ graph.setAttr('hoverAnchor', true);
96
+ });
97
+ anchorShape.on('mouseleave', () => {
98
+ document.body.style.cursor = anchorShape.attrs.adjusting ? 'move' : 'default';
99
+ graph.setAttr('hover', false);
100
+ graph.setAttr('hoverAnchor', false);
101
+ render.redraw([GraphDraw.name]);
102
+ });
103
+ anchorAndShadow.shape = anchorShape;
104
+ } else {
105
+ if (anchor.adjustType === 'start') {
106
+ rotate = Curve.calculateAngle(points[2] - points[0], points[3] - points[1]);
107
+ } else if (anchor.adjustType === 'end') {
108
+ rotate = Curve.calculateAngle(points[points.length - 2] - points[points.length - 4], points[points.length - 1] - points[points.length - 3]);
109
+ }
110
+ const cos = Math.cos((rotate * Math.PI) / 180);
111
+ const sin = Math.sin((rotate * Math.PI) / 180);
112
+ const offset = render.toStageValue(render.pointSize - 20);
113
+ const offsetX = offset * sin;
114
+ const offsetY = offset * cos;
115
+ const anchorShape = new Konva.Circle({
116
+ name: 'anchor',
117
+ anchor: anchor,
118
+ fill: `rgba(0,0,255,0.4)`,
119
+ radius: render.toStageValue(5),
120
+ strokeWidth: 0,
121
+ x: x,
122
+ y: y,
123
+ offsetX: anchor.adjustType === 'start' ? offsetX : anchor.adjustType === 'end' ? -offsetX : 0,
124
+ offsetY: anchor.adjustType === 'start' ? offsetY : anchor.adjustType === 'end' ? -offsetY : 0,
125
+ rotation: graph.getAbsoluteRotation(),
126
+ visible: graph.attrs.adjusting || graph.attrs.hover === true
127
+ });
128
+ anchorShape.on('mouseenter', () => {
129
+ document.body.style.cursor = 'move';
130
+ graph.setAttr('hover', true);
131
+ graph.setAttr('hoverAnchor', true);
132
+ });
133
+ anchorShape.on('mouseleave', () => {
134
+ document.body.style.cursor = anchorShape.attrs.adjusting ? 'move' : 'default';
135
+ graph.setAttr('hover', false);
136
+ graph.setAttr('hoverAnchor', false);
137
+ render.redraw([GraphDraw.name]);
138
+ });
139
+ anchorAndShadow.shape = anchorShape;
140
+ }
141
+ }
142
+ }
143
+ return { anchorAndShadows };
144
+ }
145
+
146
+ /**
147
+ * 矩阵变换:坐标系中的一个点,围绕着另外一个点进行旋转
148
+ * - - - - - - - -
149
+ * |x`| |cos -sin| |x-a| |a|
150
+ * | | = | | | | +
151
+ * |y`| |sin cos| |y-b| |b|
152
+ * - - - - - - - -
153
+ * @param x 目标节点坐标 x
154
+ * @param y 目标节点坐标 y
155
+ * @param centerX 围绕的点坐标 x
156
+ * @param centerY 围绕的点坐标 y
157
+ * @param angle 旋转角度
158
+ * @returns
159
+ */
160
+ static rotatePoint(x: number, y: number, centerX: number, centerY: number, angle: number) {
161
+ // 将角度转换为弧度
162
+ const radians = (angle * Math.PI) / 180;
163
+ // 计算旋转后的坐标
164
+ const newX = Math.cos(radians) * (x - centerX) - Math.sin(radians) * (y - centerY) + centerX;
165
+ const newY = Math.sin(radians) * (x - centerX) + Math.cos(radians) * (y - centerY) + centerY;
166
+ return { x: newX, y: newY };
167
+ }
168
+
169
+ // 实现:调整 图形
170
+ static override adjust(
171
+ render: Render,
172
+ graph: Konva.Group,
173
+ graphSnap: Konva.Group,
174
+ adjustShape: Konva.Shape,
175
+ anchorAndShadows: {
176
+ anchor: GraphAnchor;
177
+ anchorShadow: Konva.Circle;
178
+ shape?: Konva.Shape | undefined;
179
+ }[],
180
+ startPoint: Konva.Vector2d,
181
+ endPoint: Konva.Vector2d,
182
+ hoverRect?: Konva.Rect
183
+ ) {
184
+ // 目标 曲线
185
+ const line = graph.findOne('.graph') as Konva.Line;
186
+ const lineSnap = graphSnap.findOne('.graph') as Konva.Line;
187
+ const anchors = (graph.find('.anchor') ?? []) as Konva.Circle[];
188
+ const anchorsSnap = (graphSnap.find('.anchor') ?? []) as Konva.Circle[];
189
+ const linkAnchors = (graph.find('.link-anchor') ?? []) as Konva.Circle[];
190
+ if (line && lineSnap) {
191
+ const stageState = render.getStageState();
192
+ {
193
+ const [graphRotation, adjustType, ex, ey] = [
194
+ Math.round(graph.rotation()),
195
+ adjustShape.attrs.anchor?.adjustType,
196
+ endPoint.x,
197
+ endPoint.y
198
+ ];
199
+ const { x: cx, y: cy, width: cw, height: ch } = graphSnap.getClientRect();
200
+ const { x, y } = graph.position();
201
+ const [centerX, centerY] = [cx + cw / 2, cy + ch / 2];
202
+ const { x: sx, y: sy } = Curve.rotatePoint(ex, ey, centerX, centerY, -graphRotation);
203
+ const { x: rx, y: ry } = Curve.rotatePoint(x, y, centerX, centerY, -graphRotation);
204
+ const points = line.points();
205
+ const manualPoints = (line.attrs.manualPoints ?? []) as LineManualPoint[];
206
+ if (adjustType === 'manual') {
207
+ if (adjustShape.attrs.anchor?.manualIndex !== void 0) {
208
+ const index = adjustShape.attrs.anchor?.adjusted ? adjustShape.attrs.anchor?.manualIndex : adjustShape.attrs.anchor?.manualIndex + 1;
209
+ const manualPointIndex = manualPoints.findIndex((o) => o.index === index);
210
+ if (manualPointIndex > -1) {
211
+ manualPoints[manualPointIndex].x = (sx - rx) / graph.scaleX();
212
+ manualPoints[manualPointIndex].y = (sy - ry) / graph.scaleY();
213
+ }
214
+ const linkPoints = [
215
+ [points[0], points[1]],
216
+ ...manualPoints.sort((a, b) => a.index - b.index).map((o) => [o.x, o.y]),
217
+ [points[points.length - 2], points[points.length - 1]]
218
+ ];
219
+ line.setAttr('manualPoints', manualPoints);
220
+ line.points(linkPoints.flat());
221
+ const adjustAnchorShadow = anchors.find((o) => o.attrs.adjustType === 'manual' && o.attrs.manualIndex === index);
222
+ if (adjustAnchorShadow) {
223
+ adjustAnchorShadow.position({
224
+ x: (sx - rx) / graph.scaleX(),
225
+ y: (sy - ry) / graph.scaleY()
226
+ });
227
+ }
228
+ }
229
+ } else {
230
+ const anchor = anchors.find((o) => o.attrs.adjustType === adjustType);
231
+ const anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === adjustType);
232
+ if (anchor && anchorShadow) {
233
+ const linkPoints = [
234
+ [points[0], points[1]],
235
+ ...manualPoints.sort((a, b) => a.index - b.index).map((o) => [o.x, o.y]),
236
+ [points[points.length - 2], points[points.length - 1]]
237
+ ];
238
+ switch (adjustType) {
239
+ case 'start':
240
+ linkPoints[0] = [(sx - rx) / graph.scaleX(), (sy - ry) / graph.scaleY()];
241
+ line.points(linkPoints.flat());
242
+ break;
243
+ case 'end':
244
+ linkPoints[linkPoints.length - 1] = [(sx - rx) / graph.scaleX(), (sy - ry) / graph.scaleY()];
245
+ line.points(linkPoints.flat());
246
+ break;
247
+ }
248
+ }
249
+ }
250
+ }
251
+ Curve.updateAnchor(render, graph);
252
+ Curve.updateAnchorShadows(graph, anchors, line);
253
+ Curve.updateLinkAnchorShadows(graph, linkAnchors, line);
254
+ for (const anchor of anchors) {
255
+ for (const { shape } of anchorAndShadows) {
256
+ if (shape) {
257
+ if (shape.attrs.anchor?.adjustType === anchor.attrs.adjustType) {
258
+ const anchorShadow = graph.find(`.anchor`).find((o) => o.attrs.adjustType === anchor.attrs.adjustType);
259
+ if (anchorShadow) {
260
+ shape.position({
261
+ x: render.toStageValue(anchorShadow.getAbsolutePosition().x - stageState.x),
262
+ y: render.toStageValue(anchorShadow.getAbsolutePosition().y - stageState.y)
263
+ });
264
+ shape.rotation(graph.getAbsoluteRotation());
265
+ }
266
+ }
267
+ }
268
+ }
269
+ }
270
+ render.redraw([GraphDraw.name, LinkDraw.name, PreviewDraw.name]);
271
+ }
272
+ const allXs = line.points().reduce((arr, item, idx) => {
273
+ if (idx % 2 === 0) arr.push(item);
274
+ return arr;
275
+ }, [] as number[]);
276
+ const allYs = line.points().reduce((arr, item, idx) => {
277
+ if (idx % 2 === 1) arr.push(item);
278
+ return arr;
279
+ }, [] as number[]);
280
+ const minX = Math.min(...allXs);
281
+ const maxX = Math.max(...allXs);
282
+ const minY = Math.min(...allYs);
283
+ const maxY = Math.max(...allYs);
284
+ BaseGraph.adjust(
285
+ render,
286
+ graph,
287
+ graphSnap,
288
+ adjustShape,
289
+ anchorAndShadows,
290
+ startPoint,
291
+ endPoint,
292
+ hoverRect,
293
+ { width: maxX - minX, height: maxY - minY },
294
+ { x: minX, y: minY }
295
+ );
296
+ }
297
+
298
+ /**
299
+ * 提供给 GraphDraw draw 使用
300
+ */
301
+ static override draw(graph: Konva.Group, render: Render, adjustAnchor?: GraphAnchor) {
302
+ const anchors = (graph.attrs.anchors ?? []) as (GraphAnchor & { manualIndex?: number; adjusted?: boolean })[];
303
+ const anchorShapes = graph.find(`.anchor`);
304
+ const anchorAndShadows = anchors
305
+ .map((anchor) => ({
306
+ anchor,
307
+ anchorShadow: anchorShapes.find((shape) => shape.attrs.adjustType === anchor.adjustType && shape.attrs.manualIndex === anchor.manualIndex) as Konva.Circle
308
+ }))
309
+ .filter((o) => o.anchorShadow !== void 0);
310
+ return Curve.createAnchorShapes(render, graph, anchorAndShadows, adjustAnchor);
311
+ }
312
+
313
+ /**
314
+ * 默认图形大小
315
+ */
316
+ static size = 100;
317
+
318
+ /**
319
+ * 曲线 对应的 Konva 实例
320
+ */
321
+ private line: Konva.Line;
322
+
323
+ constructor(render: Render, dropPoint: Konva.Vector2d) {
324
+ super(render, dropPoint, {
325
+ type: "Curve",
326
+ anchors: [{ adjustType: 'start' }, { adjustType: 'end' }].map((o) => ({ adjustType: o.adjustType })),
327
+ linkAnchors: [
328
+ { x: 0, y: 0, alias: 'start' },
329
+ { x: 0, y: 0, alias: 'end' }
330
+ ] as AssetInfoPoint[]
331
+ });
332
+ this.line = new Konva.Arrow({
333
+ name: 'graph',
334
+ x: 0,
335
+ y: 0,
336
+ stroke: this.render.getPageSettings().stroke,
337
+ strokeWidth: this.render.getPageSettings().strokeWidth,
338
+ fill: this.render.getPageSettings().stroke,
339
+ points: [],
340
+ pointerAtBeginning: false,
341
+ pointerAtEnding: false,
342
+ tension: 0
343
+ });
344
+ // 给予 1 像素,防止导出图片 toDataURL 失败
345
+ this.group.size({ width: 1, height: 1 });
346
+ this.group.add(this.line);
347
+ this.group.position(this.dropPoint); // 鼠标按下位置 作为起点
348
+ }
349
+
350
+ // 实现:拖动进行时
351
+ override drawMove(point: Konva.Vector2d): void {
352
+ const offsetX = point.x - this.dropPoint.x,
353
+ offsetY = point.y - this.dropPoint.y;
354
+ // 起点、终点
355
+ const linkPoints = [
356
+ [this.line.x(), this.line.y()],
357
+ [this.line.x() + offsetX, this.line.y() + offsetY]
358
+ ];
359
+ // 曲线 路径
360
+ this.line.points(linkPoints.flat());
361
+ // 更新 图形 的 调整点 的 锚点位置
362
+ Curve.updateAnchorShadows(this.group, this.anchorShadows, this.line);
363
+ // 更新 图形 的 连接点 的 锚点位置
364
+ Curve.updateLinkAnchorShadows(this.group, this.linkAnchorShadows, this.line);
365
+ this.render.redraw([GraphDraw.name, LinkDraw.name, PreviewDraw.name]);
366
+ }
367
+
368
+ // 实现:拖动结束
369
+ override drawEnd(): void {
370
+ if (this.line.width() <= 10 && this.line.height() <= 10) {
371
+ const width = Curve.size, height = width;
372
+ const linkPoints = [
373
+ [this.line.x(), this.line.y()],
374
+ [this.line.x() + width, this.line.y() + height]
375
+ ];
376
+ this.line.points(linkPoints.flat());
377
+ }
378
+ Curve.updateAnchor(this.render, this.group);
379
+ Curve.updateAnchorShadows(this.group, this.anchorShadows, this.line);
380
+ Curve.updateLinkAnchorShadows(this.group, this.linkAnchorShadows, this.line);
381
+ const size = {// 扣除多余的间隙
382
+ width: this.line.size().width - 10,
383
+ height: this.line.size().height - 10
384
+ };
385
+ this.group.size(size); // 更新大小
386
+ this.render.attractTool.alignLinesClear(); // 对齐线清除
387
+ this.render.updateHistory(); // 更新历史
388
+ this.render.redraw([GraphDraw.name, LinkDraw.name, PreviewDraw.name]);
389
+ super.drawEnd(size, {
390
+ x: Math.min(...this.line.points().reduce((arr, item, idx) => {
391
+ if (idx % 2 === 0) arr.push(item);
392
+ return arr;
393
+ }, [] as number[])),
394
+ y: Math.min(...this.line.points().reduce((arr, item, idx) => {
395
+ if (idx % 2 === 1) arr.push(item);
396
+ return arr;
397
+ }, [] as number[]))
398
+ });
399
+ }
400
+
401
+ /**
402
+ * 更新 调整点(拐点)
403
+ * @param render
404
+ * @param graph
405
+ */
406
+ static updateAnchor(render: Render, graph: Konva.Group) {
407
+ const anchors = graph.attrs.anchors ?? [];
408
+ const anchorShadows = graph.find('.anchor') ?? [];
409
+ const shape = graph.findOne('.graph') as Konva.Line;
410
+ if (shape) {
411
+ let manualPoints = (shape.attrs.manualPoints ?? []) as LineManualPoint[];
412
+ const points = shape.points();
413
+ const linkPoints = [
414
+ [points[0], points[1]],
415
+ ...manualPoints.sort((a, b) => a.index - b.index).map((o) => [o.x, o.y]),
416
+ [points[points.length - 2], points[points.length - 1]]
417
+ ];
418
+ // 清空 调整点(拐点),保留 start end
419
+ anchors.splice(2);
420
+ const shadows = anchorShadows.splice(2);
421
+ for (const shadow of shadows) {
422
+ shadow.remove();
423
+ shadow.destroy();
424
+ }
425
+ manualPoints = [];
426
+ for (let i = linkPoints.length - 1; i > 0; i--) {
427
+ linkPoints.splice(i, 0, []);
428
+ }
429
+ for (let i = 1; i < linkPoints.length - 1; i++) {
430
+ const anchor = {
431
+ type: graph.attrs.graphType,
432
+ adjustType: 'manual',
433
+ name: 'anchor',
434
+ groupId: graph.id(),
435
+ manualIndex: i,
436
+ adjusted: false
437
+ };
438
+ if (linkPoints[i].length === 0) {
439
+ anchor.adjusted = false;
440
+ const prev = linkPoints[i - 1];
441
+ const next = linkPoints[i + 1];
442
+ const circle = new Konva.Circle({
443
+ adjustType: anchor.adjustType,
444
+ anchorType: anchor.type,
445
+ name: anchor.name,
446
+ manualIndex: anchor.manualIndex,
447
+ radius: 0,
448
+ x: (prev[0] + next[0]) / 2,
449
+ y: (prev[1] + next[1]) / 2,
450
+ anchor
451
+ });
452
+ graph.add(circle);
453
+ } else {
454
+ anchor.adjusted = true;
455
+ const circle = new Konva.Circle({
456
+ adjustType: anchor.adjustType,
457
+ anchorType: anchor.type,
458
+ name: anchor.name,
459
+ manualIndex: anchor.manualIndex,
460
+ adjusted: true,
461
+ radius: 0,
462
+ x: linkPoints[i][0],
463
+ y: linkPoints[i][1],
464
+ anchor
465
+ });
466
+ graph.add(circle);
467
+ manualPoints.push({ x: linkPoints[i][0], y: linkPoints[i][1], index: anchor.manualIndex });
468
+ }
469
+ anchors.push(anchor);
470
+ }
471
+ shape.setAttr('manualPoints', manualPoints);
472
+ graph.setAttr('anchors', anchors);
473
+ }
474
+ }
475
+
476
+ /**
477
+ * 调整之前
478
+ */
479
+ static adjustStart(
480
+ render: Render,
481
+ graph: Konva.Group,
482
+ adjustAnchor: GraphAnchor & { manualIndex?: number; adjusted?: boolean },
483
+ endPoint: Konva.Vector2d
484
+ ) {
485
+ const { x: gx, y: gy } = graph.position();
486
+ const shape = graph.findOne('.graph') as Konva.Line;
487
+ if (shape && typeof adjustAnchor.manualIndex === 'number') {
488
+ const manualPoints = (shape.attrs.manualPoints ?? []) as LineManualPoint[];
489
+ if (adjustAnchor.adjusted) {
490
+ } else {
491
+ manualPoints.push({
492
+ x: endPoint.x - gx,
493
+ y: endPoint.y - gy,
494
+ index: adjustAnchor.manualIndex
495
+ });
496
+ shape.setAttr('manualPoints', manualPoints);
497
+ }
498
+ Curve.updateAnchor(render, graph);
499
+ }
500
+ }
501
+ }
@@ -0,0 +1,6 @@
1
+ export { BaseGraph } from './base-graph';
2
+ export { Circle } from './circle';
3
+ export { Rect } from './rect';
4
+ export { Line } from './line';
5
+ export { Curve } from './curve';
6
+ export { Bezier } from './bezier';