aldehyde 0.2.494 → 0.2.495

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 (127) hide show
  1. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.css +63 -63
  2. package/lib/draw-canvas-edit/components/asset-bar/index.less +35 -35
  3. package/lib/draw-canvas-edit/components/main-header/index.less +23 -23
  4. package/lib/layout2/page.d.ts +2 -1
  5. package/lib/layout2/page.d.ts.map +1 -1
  6. package/lib/layout2/page.js +19 -8
  7. package/lib/layout2/page.js.map +1 -1
  8. package/lib/layout2/type/layout-type.d.ts +1 -0
  9. package/lib/layout2/type/layout-type.d.ts.map +1 -1
  10. package/lib/lowcode-components/base-table/index.less +61 -61
  11. package/lib/lowcode-components/base-text/index.less +19 -19
  12. package/lib/lowcode-components/data-number/index.less +10 -10
  13. package/lib/lowcode-components/date-time/index.less +4 -4
  14. package/lib/lowcode-components/four-angle-glow-border/index.less +49 -49
  15. package/lib/lowcode-components/lowcode-view/component/font/FontGlobal.css +26 -26
  16. package/lib/lowcode-components/lowcode-view/component/screen-fit/index.less +13 -13
  17. package/lib/lowcode-components/text-scroller/index.less +28 -28
  18. package/lib/module/ltmpl-table.d.ts +7 -0
  19. package/lib/module/ltmpl-table.d.ts.map +1 -1
  20. package/lib/module/ltmpl-table.js +12 -16
  21. package/lib/module/ltmpl-table.js.map +1 -1
  22. package/lib/routable/dtmpl-route.d.ts.map +1 -1
  23. package/lib/routable/dtmpl-route.js +8 -2
  24. package/lib/routable/dtmpl-route.js.map +1 -1
  25. package/lib/routable/import-route.d.ts.map +1 -1
  26. package/lib/routable/import-route.js +9 -1
  27. package/lib/routable/import-route.js.map +1 -1
  28. package/lib/routable/ltmpl-route.d.ts.map +1 -1
  29. package/lib/routable/ltmpl-route.js +13 -6
  30. package/lib/routable/ltmpl-route.js.map +1 -1
  31. package/lib/routable/splitview-ltmpl-route.d.ts.map +1 -1
  32. package/lib/routable/splitview-ltmpl-route.js +11 -10
  33. package/lib/routable/splitview-ltmpl-route.js.map +1 -1
  34. package/lib/routable/ttmpl-route.d.ts.map +1 -1
  35. package/lib/routable/ttmpl-route.js +9 -2
  36. package/lib/routable/ttmpl-route.js.map +1 -1
  37. package/lib/table/act-table.d.ts +1 -0
  38. package/lib/table/act-table.d.ts.map +1 -1
  39. package/lib/table/act-table.js +31 -9
  40. package/lib/table/act-table.js.map +1 -1
  41. package/lib/table/page-chart.js +1 -1
  42. package/lib/table/page-chart.js.map +1 -1
  43. package/lib/table/row-table.d.ts +6 -0
  44. package/lib/table/row-table.d.ts.map +1 -1
  45. package/lib/table/row-table.js +21 -6
  46. package/lib/table/row-table.js.map +1 -1
  47. package/lib/tmpl/interface.d.ts +1 -0
  48. package/lib/tmpl/interface.d.ts.map +1 -1
  49. package/lib/tree/act-tree.d.ts +1 -0
  50. package/lib/tree/act-tree.d.ts.map +1 -1
  51. package/lib/tree/act-tree.js +6 -7
  52. package/lib/tree/act-tree.js.map +1 -1
  53. package/lib/tree/tree-utils.d.ts +1 -1
  54. package/lib/tree/tree-utils.d.ts.map +1 -1
  55. package/lib/tree/tree-utils.js +4 -4
  56. package/lib/tree/tree-utils.js.map +1 -1
  57. package/lib/units/index.d.ts +4 -0
  58. package/lib/units/index.d.ts.map +1 -1
  59. package/lib/units/index.js +10 -3
  60. package/lib/units/index.js.map +1 -1
  61. package/package.json +1 -1
  62. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.css +63 -63
  63. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.json +93 -93
  64. package/src/aldehyde/draw-canvas-edit/components/asset-bar/index.less +35 -35
  65. package/src/aldehyde/draw-canvas-edit/components/asset-bar/index.tsx +110 -110
  66. package/src/aldehyde/draw-canvas-edit/components/main-header/index.less +23 -23
  67. package/src/aldehyde/draw-canvas-edit/components/main-header/index.tsx +263 -263
  68. package/src/aldehyde/draw-canvas-edit/components/render/draws/index.ts +7 -7
  69. package/src/aldehyde/draw-canvas-edit/components/render/graphs/base-graph.ts +241 -241
  70. package/src/aldehyde/draw-canvas-edit/components/render/graphs/circle.ts +699 -699
  71. package/src/aldehyde/draw-canvas-edit/components/render/graphs/curve.ts +500 -500
  72. package/src/aldehyde/draw-canvas-edit/components/render/graphs/index.ts +5 -5
  73. package/src/aldehyde/draw-canvas-edit/components/render/graphs/line.ts +493 -493
  74. package/src/aldehyde/draw-canvas-edit/components/render/graphs/rect.ts +680 -680
  75. package/src/aldehyde/draw-canvas-edit/components/render/handlers/drag-handlers.ts +68 -68
  76. package/src/aldehyde/draw-canvas-edit/components/render/handlers/graph-handlers.ts +113 -113
  77. package/src/aldehyde/draw-canvas-edit/components/render/handlers/index.ts +9 -9
  78. package/src/aldehyde/draw-canvas-edit/components/render/handlers/key-move-handlers.ts +49 -49
  79. package/src/aldehyde/draw-canvas-edit/components/render/handlers/link-handlers.ts +45 -45
  80. package/src/aldehyde/draw-canvas-edit/components/render/handlers/shutcut-handlers.ts +45 -45
  81. package/src/aldehyde/draw-canvas-edit/components/render/handlers/text-handlers.ts +81 -81
  82. package/src/aldehyde/draw-canvas-edit/components/render/handlers/zoom-handlers.ts +59 -59
  83. package/src/aldehyde/draw-canvas-edit/components/render/tools/align-tool.ts +89 -89
  84. package/src/aldehyde/draw-canvas-edit/components/render/tools/asset-tool.ts +154 -154
  85. package/src/aldehyde/draw-canvas-edit/components/render/tools/link-tool.ts +222 -222
  86. package/src/aldehyde/draw-canvas-edit/components/render/tools/z-index-tool.ts +224 -224
  87. package/src/aldehyde/draw-canvas-edit/components/render/utils/a-star.ts +116 -116
  88. package/src/aldehyde/draw-canvas-edit/components/render/utils/bezier-scene-func.ts +72 -72
  89. package/src/aldehyde/draw-canvas-edit/components/setting-form/imag-upload.tsx +119 -119
  90. package/src/aldehyde/layout2/page.tsx +17 -9
  91. package/src/aldehyde/layout2/type/layout-type.ts +1 -0
  92. package/src/aldehyde/layout4/imgs/user.svg +26 -26
  93. package/src/aldehyde/lowcode-components/base-color-block/index.tsx +31 -31
  94. package/src/aldehyde/lowcode-components/base-table/index.less +61 -61
  95. package/src/aldehyde/lowcode-components/base-text/index.less +19 -19
  96. package/src/aldehyde/lowcode-components/data-number/index.less +10 -10
  97. package/src/aldehyde/lowcode-components/date-time/index.less +4 -4
  98. package/src/aldehyde/lowcode-components/date-time/index.tsx +64 -64
  99. package/src/aldehyde/lowcode-components/four-angle-glow-border/index.less +49 -49
  100. package/src/aldehyde/lowcode-components/four-angle-glow-border/index.tsx +53 -53
  101. package/src/aldehyde/lowcode-components/lowcode-view/component/abstract-controller.ts +64 -64
  102. package/src/aldehyde/lowcode-components/lowcode-view/component/abstract-definition.ts +77 -77
  103. package/src/aldehyde/lowcode-components/lowcode-view/component/abstract-designer-loader.ts +36 -36
  104. package/src/aldehyde/lowcode-components/lowcode-view/component/component-container.tsx +91 -91
  105. package/src/aldehyde/lowcode-components/lowcode-view/component/font/FontGlobal.css +26 -26
  106. package/src/aldehyde/lowcode-components/lowcode-view/component/group-layer/controller.ts +36 -36
  107. package/src/aldehyde/lowcode-components/lowcode-view/component/group-layer/definition.ts +53 -53
  108. package/src/aldehyde/lowcode-components/lowcode-view/component/group-layer/index.tsx +15 -15
  109. package/src/aldehyde/lowcode-components/lowcode-view/component/layer-builder.tsx +98 -98
  110. package/src/aldehyde/lowcode-components/lowcode-view/component/screen-fit/index.less +13 -13
  111. package/src/aldehyde/lowcode-components/lowcode-view/component/screen-fit/index.tsx +121 -121
  112. package/src/aldehyde/lowcode-components/placeholder-component/index.tsx +81 -81
  113. package/src/aldehyde/lowcode-components/text-scroller/index.less +28 -28
  114. package/src/aldehyde/lowcode-components/text-scroller/index.tsx +173 -173
  115. package/src/aldehyde/module/ltmpl-table.tsx +14 -15
  116. package/src/aldehyde/routable/dtmpl-route.tsx +14 -8
  117. package/src/aldehyde/routable/import-route.tsx +12 -5
  118. package/src/aldehyde/routable/ltmpl-route.tsx +14 -9
  119. package/src/aldehyde/routable/splitview-ltmpl-route.tsx +11 -8
  120. package/src/aldehyde/routable/ttmpl-route.tsx +13 -8
  121. package/src/aldehyde/table/act-table.tsx +28 -9
  122. package/src/aldehyde/table/page-chart.tsx +1 -1
  123. package/src/aldehyde/table/row-table.tsx +29 -6
  124. package/src/aldehyde/tmpl/interface.tsx +1 -0
  125. package/src/aldehyde/tree/act-tree.tsx +8 -6
  126. package/src/aldehyde/tree/tree-utils.tsx +4 -4
  127. package/src/aldehyde/units/index.tsx +11 -3
@@ -1,700 +1,700 @@
1
- import Konva from 'konva';
2
- import { GraphAnchor, Render, AssetInfoPoint } from '../types';
3
- import { GraphDraw, LinkDraw, PreviewDraw } from '../draws';
4
- import { BaseGraph } from './base-graph';
5
-
6
- /**
7
- * 图形 圆/椭圆
8
- */
9
- export class Circle extends BaseGraph {
10
- // 实现:更新 图形 的 调整点 的 锚点位置
11
- static override updateAnchorShadows(graph: Konva.Group, anchorShadows: Konva.Circle[]): void {
12
- const { width, height } = graph.size();
13
- for (const shadow of anchorShadows) {
14
- switch (shadow.attrs.adjustType) {
15
- case 'top':
16
- shadow.position({ x: width / 2, y: 0 });
17
- break;
18
- case 'bottom':
19
- shadow.position({ x: width / 2, y: height });
20
- break;
21
- case 'left':
22
- shadow.position({ x: 0, y: height / 2 });
23
- break;
24
- case 'right':
25
- shadow.position({ x: width, y: height / 2 });
26
- break;
27
- case 'top-left':
28
- shadow.position({ x: 0, y: 0 });
29
- break;
30
- case 'top-right':
31
- shadow.position({ x: width, y: 0 });
32
- break;
33
- case 'bottom-left':
34
- shadow.position({ x: 0, y: height });
35
- break;
36
- case 'bottom-right':
37
- shadow.position({ x: width, y: height });
38
- break;
39
- }
40
- }
41
- }
42
-
43
- // 实现:更新 图形 的 连接点 的 锚点位置
44
- static override updateLinkAnchorShadows(graph: Konva.Group, linkAnchorShadows: Konva.Circle[]): void {
45
- const { width, height } = graph.size();
46
- for (const shadow of linkAnchorShadows) {
47
- switch (shadow.attrs.alias) {
48
- case 'top':
49
- shadow.position({ x: width / 2, y: 0 });
50
- break;
51
- case 'bottom':
52
- shadow.position({ x: width / 2, y: height });
53
- break;
54
- case 'left':
55
- shadow.position({ x: 0, y: height / 2 });
56
- break;
57
- case 'right':
58
- shadow.position({ x: width, y: height / 2 });
59
- break;
60
- case 'center':
61
- shadow.position({ x: width / 2, y: height / 2 });
62
- break;
63
- }
64
- }
65
- }
66
-
67
- // 实现:生成 调整点
68
- static override createAnchorShapes(
69
- render: Render,
70
- graph: Konva.Group,
71
- anchorAndShadows: {
72
- anchor: GraphAnchor,
73
- anchorShadow: Konva.Circle,
74
- shape?: Konva.Shape
75
- }[],
76
- // eslint-disable-next-line
77
- adjustAnchor?: GraphAnchor
78
- ): {
79
- anchorAndShadows: {
80
- anchor: GraphAnchor;
81
- anchorShadow: Konva.Circle;
82
- shape?: Konva.Shape | undefined;
83
- }[]
84
- } {
85
- const stageState = render.getStageState();
86
- for (const anchorAndShadow of anchorAndShadows) {
87
- const { anchor, anchorShadow } = anchorAndShadow;
88
- const x = render.toStageValue(anchorShadow.getAbsolutePosition().x - stageState.x),
89
- y = render.toStageValue(anchorShadow.getAbsolutePosition().y - stageState.y);
90
- const offset = render.toStageValue(render.pointSize + 5);
91
- const anchorShape = new Konva.Line({
92
- name: 'anchor',
93
- anchor: anchor,
94
- stroke: `rgba(0,0,255,0.4)`,
95
- strokeWidth: render.toStageValue(2),
96
- hitStrokeWidth: render.toStageValue(3),
97
- x,
98
- y,
99
- points: {
100
- 'top-left': [[-offset, offset / 2], [-offset, -offset], [offset / 2, -offset]].flat(),
101
- top: [[-offset, -offset], [offset, -offset]].flat(),
102
- 'top-right': [[-offset / 2, -offset], [offset, -offset], [offset, offset / 2]].flat(),
103
- right: [[offset, -offset], [offset, offset]].flat(),
104
- 'bottom-right': [[-offset / 2, offset], [offset, offset], [offset, -offset / 2]].flat(),
105
- bottom: [[-offset, offset], [offset, offset]].flat(),
106
- 'bottom-left': [[-offset, -offset / 2], [-offset, offset], [offset / 2, offset]].flat(),
107
- left: [[-offset, -offset], [-offset, offset]].flat()
108
- }[anchor.adjustType] ?? [],
109
- rotation: graph.getAbsoluteRotation(), // 旋转角度
110
- visible: graph.attrs.adjusting || graph.attrs.hover === true
111
- });
112
- anchorShape.on('mouseenter', () => {
113
- document.body.style.cursor = 'move';
114
- graph.setAttr('hover', true);
115
- graph.setAttr('hoverAnchor', true);
116
- });
117
- anchorShape.on('mouseleave', () => {
118
- document.body.style.cursor = anchorShape.attrs.adjusting ? 'move' : 'default';
119
- graph.setAttr('hover', false);
120
- graph.setAttr('hoverAnchor', false);
121
- // 进入其他元素区域时离开需要靠它 redraw
122
- render.redraw([GraphDraw.NAME]);
123
- });
124
- anchorAndShadow.shape = anchorShape;
125
- }
126
- return { anchorAndShadows };
127
- }
128
-
129
- // 实现:调整 图形
130
- static override adjust(
131
- render: Render,
132
- graph: Konva.Group,
133
- graphSnap: Konva.Group,
134
- adjustShape: Konva.Shape,
135
- anchorAndShadows: {
136
- anchor: GraphAnchor,
137
- anchorShadow: Konva.Circle,
138
- shape?: Konva.Shape | undefined,
139
- }[],
140
- startPoint: Konva.Vector2d,
141
- endPoint: Konva.Vector2d,
142
- hoverRect?: Konva.Rect
143
- ) {
144
- // 目标 圆/椭圆
145
- const circle = graph.findOne('.graph') as Konva.Ellipse;
146
- // 镜像
147
- const circleSnap = graphSnap.findOne('.graph') as Konva.Ellipse;
148
- // 调整点 锚点
149
- const anchors = (graph.find('.anchor') ?? []) as Konva.Circle[];
150
- // 镜像
151
- const anchorsSnap = (graphSnap.find('.anchor') ?? []) as Konva.Circle[];
152
- // 连接点 锚点
153
- const linkAnchors = (graph.find('.link-anchor') ?? []) as Konva.Circle[];
154
- if (circle && circleSnap) {
155
- const [graphRotation, adjustType, ex, ey] = [
156
- Math.round(graph.rotation()),
157
- adjustShape.attrs.anchor?.adjustType,
158
- endPoint.x,
159
- endPoint.y
160
- ];
161
- let anchorShadow: Konva.Circle | undefined, anchorShadowAcross: Konva.Circle | undefined;
162
- switch (adjustType) {
163
- case 'top':
164
- anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'top');
165
- anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'bottom');
166
- break;
167
- case 'bottom':
168
- anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'bottom');
169
- anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'top');
170
- break;
171
- case 'left':
172
- anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'left');
173
- anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'right');
174
- break;
175
- case 'right':
176
- anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'right');
177
- anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'left');
178
- break;
179
- case 'top-left':
180
- anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'top-left');
181
- anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'bottom-right');
182
- break;
183
- case 'top-right':
184
- anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'top-right');
185
- anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'bottom-left');
186
- break;
187
- case 'bottom-left':
188
- anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'bottom-left');
189
- anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'top-right');
190
- break;
191
- case 'bottom-right':
192
- anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'bottom-right');
193
- anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'top-left');
194
- break;
195
- }
196
- if (anchorShadow && anchorShadowAcross) {
197
- const { x: sx, y: sy } = anchorShadow.getAbsolutePosition();
198
- const { x: ax, y: ay } = anchorShadowAcross.getAbsolutePosition();
199
- {
200
- const d1 = Math.sqrt(Math.pow(sx - ax, 2) + Math.pow(sy - ay, 2));
201
- const d2 = Math.sqrt(Math.pow(ex - ax, 2) + Math.pow(ey - ay, 2));
202
- const r1 = d2 / d1;
203
- let zeroWidth = 1, zeroHeight = 1;
204
- switch (adjustType) {
205
- case 'top':
206
- if (graphRotation >= 45 && graphRotation < 135) {
207
- zeroHeight = ex <= ax ? 0 : 1;
208
- } else if (graphRotation >= -135 && graphRotation < -45) {
209
- zeroHeight = ex >= ax ? 0 : 1;
210
- } else if (graphRotation >= -45 && graphRotation < 45) {
211
- zeroHeight = ey >= ay ? 0 : 1;
212
- } else {
213
- zeroHeight = ey <= ay ? 0 : 1;
214
- }
215
- break;
216
- case 'bottom':
217
- if (graphRotation >= 45 && graphRotation < 135) {
218
- zeroHeight = ex <= ax ? 1 : 0;
219
- } else if (graphRotation >= -135 && graphRotation < -45) {
220
- zeroHeight = ex >= ax ? 1 : 0;
221
- } else if (graphRotation >= -45 && graphRotation < 45) {
222
- zeroHeight = ey >= ay ? 1 : 0;
223
- } else {
224
- zeroHeight = ey <= ay ? 1 : 0;
225
- }
226
- break;
227
- case 'left':
228
- if (graphRotation >= 45 && graphRotation < 135) {
229
- zeroWidth = ey >= ay ? 0 : 1;
230
- } else if (graphRotation >= -135 && graphRotation < -45) {
231
- zeroWidth = ex <= ax ? 0 : 1;
232
- } else if (graphRotation >= -45 && graphRotation < 45) {
233
- zeroWidth = ex >= ax ? 0 : 1;
234
- } else {
235
- zeroWidth = ey <= ay ? 0 : 1;
236
- }
237
- break;
238
- case 'right':
239
- if (graphRotation >= 45 && graphRotation < 135) {
240
- zeroWidth = ey >= ay ? 1 : 0;
241
- } else if (graphRotation >= -135 && graphRotation < -45) {
242
- zeroWidth = ex <= ax ? 1 : 0;
243
- } else if (graphRotation >= -45 && graphRotation < 45) {
244
- zeroWidth = ex >= ax ? 1 : 0;
245
- } else {
246
- zeroWidth = ey <= ay ? 1 : 0;
247
- }
248
- break;
249
- case 'top-left':
250
- if (graphRotation > -45 && graphRotation < 45) {
251
- if (ex >= ax && ey >= ay) {
252
- zeroWidth = 0;
253
- zeroHeight = 0;
254
- } else {
255
- zeroWidth = 1;
256
- zeroHeight = 1;
257
- }
258
- } else if (graphRotation === 45) {
259
- if (ey >= ay) {
260
- zeroWidth = 0;
261
- zeroHeight = 0;
262
- } else {
263
- zeroWidth = 1;
264
- zeroHeight = 1;
265
- }
266
- } else if (graphRotation > 45 && graphRotation < 135) {
267
- if (ex <= ax && ey >= ay) {
268
- zeroWidth = 0;
269
- zeroHeight = 0;
270
- } else {
271
- zeroWidth = 1;
272
- zeroHeight = 1;
273
- }
274
- } else if (graphRotation === 135) {
275
- if (ex <= ax) {
276
- zeroWidth = 0;
277
- zeroHeight = 0;
278
- } else {
279
- zeroWidth = 1;
280
- zeroHeight = 1;
281
- }
282
- } else if ((graphRotation > 135 && graphRotation <= 180) || (graphRotation >= -180 && graphRotation < -135)) {
283
- if (ex <= ax && ey <= ay) {
284
- zeroWidth = 0;
285
- zeroHeight = 0;
286
- } else {
287
- zeroWidth = 1;
288
- zeroHeight = 1;
289
- }
290
- } else if (graphRotation === -135) {
291
- if (ey <= ay) {
292
- zeroWidth = 0;
293
- zeroHeight = 0;
294
- } else {
295
- zeroWidth = 1;
296
- zeroHeight = 1;
297
- }
298
- } else if (graphRotation > -135 && graphRotation < -45) {
299
- if (ex >= ax && ey <= ay) {
300
- zeroWidth = 0;
301
- zeroHeight = 0;
302
- } else {
303
- zeroWidth = 1;
304
- zeroHeight = 1;
305
- }
306
- } else if (graphRotation === -45) {
307
- if (ex >= ax) {
308
- zeroWidth = 0;
309
- zeroHeight = 0;
310
- } else {
311
- zeroWidth = 1;
312
- zeroHeight = 1;
313
- }
314
- }
315
- break;
316
- case 'top-right':
317
- if (graphRotation > -45 && graphRotation < 45) {
318
- if (ex <= ax && ey >= ay) {
319
- zeroWidth = 0;
320
- zeroHeight = 0;
321
- } else {
322
- zeroWidth = 1;
323
- zeroHeight = 1;
324
- }
325
- } else if (graphRotation === 45) {
326
- if (ex <= ax) {
327
- zeroWidth = 0;
328
- zeroHeight = 0;
329
- } else {
330
- zeroWidth = 1;
331
- zeroHeight = 1;
332
- }
333
- } else if (graphRotation > 45 && graphRotation < 135) {
334
- if (ex <= ax && ey <= ay) {
335
- zeroWidth = 0;
336
- zeroHeight = 0;
337
- } else {
338
- zeroWidth = 1;
339
- zeroHeight = 1;
340
- }
341
- } else if (graphRotation === 135) {
342
- if (ey <= ay) {
343
- zeroWidth = 0;
344
- zeroHeight = 0;
345
- } else {
346
- zeroWidth = 1;
347
- zeroHeight = 1;
348
- }
349
- } else if ((graphRotation > 135 && graphRotation <= 180) || (graphRotation >= -180 && graphRotation < -135)) {
350
- if (ex >= ax && ey <= ay) {
351
- zeroWidth = 0;
352
- zeroHeight = 0;
353
- } else {
354
- zeroWidth = 1;
355
- zeroHeight = 1;
356
- }
357
- } else if (graphRotation === -135) {
358
- if (ex >= ax) {
359
- zeroWidth = 0;
360
- zeroHeight = 0;
361
- } else {
362
- zeroWidth = 1;
363
- zeroHeight = 1;
364
- }
365
- } else if (graphRotation > -135 && graphRotation < -45) {
366
- if (ex >= ax && ey >= ay) {
367
- zeroWidth = 0;
368
- zeroHeight = 0;
369
- } else {
370
- zeroWidth = 1;
371
- zeroHeight = 1;
372
- }
373
- } else if (graphRotation === -45) {
374
- if (ey >= ay) {
375
- zeroWidth = 0;
376
- zeroHeight = 0;
377
- } else {
378
- zeroWidth = 1;
379
- zeroHeight = 1;
380
- }
381
- }
382
- break;
383
- case 'bottom-left':
384
- if (graphRotation > -45 && graphRotation < 45) {
385
- if (ex >= ax && ey <= ay) {
386
- zeroWidth = 0;
387
- zeroHeight = 0;
388
- } else {
389
- zeroWidth = 1;
390
- zeroHeight = 1;
391
- }
392
- } else if (graphRotation === 45) {
393
- if (ex >= ax) {
394
- zeroWidth = 0;
395
- zeroHeight = 0;
396
- } else {
397
- zeroWidth = 1;
398
- zeroHeight = 1;
399
- }
400
- } else if (graphRotation > 45 && graphRotation < 135) {
401
- if (ex >= ax && ey >= ay) {
402
- zeroWidth = 0;
403
- zeroHeight = 0;
404
- } else {
405
- zeroWidth = 1;
406
- zeroHeight = 1;
407
- }
408
- } else if (graphRotation === 135) {
409
- if (ey >= ay) {
410
- zeroWidth = 0;
411
- zeroHeight = 0;
412
- } else {
413
- zeroWidth = 1;
414
- zeroHeight = 1;
415
- }
416
- } else if ((graphRotation > 135 && graphRotation <= 180) || (graphRotation >= -180 && graphRotation < -135)) {
417
- if (ex <= ax && ey >= ay) {
418
- zeroWidth = 0;
419
- zeroHeight = 0;
420
- } else {
421
- zeroWidth = 1;
422
- zeroHeight = 1;
423
- }
424
- } else if (graphRotation === -135) {
425
- if (ex <= ax) {
426
- zeroWidth = 0;
427
- zeroHeight = 0;
428
- } else {
429
- zeroWidth = 1;
430
- zeroHeight = 1;
431
- }
432
- } else if (graphRotation > -135 && graphRotation < -45) {
433
- if (ex <= ax && ey <= ay) {
434
- zeroWidth = 0;
435
- zeroHeight = 0;
436
- } else {
437
- zeroWidth = 1;
438
- zeroHeight = 1;
439
- }
440
- } else if (graphRotation === -45) {
441
- if (ey <= ay) {
442
- zeroWidth = 0;
443
- zeroHeight = 0;
444
- } else {
445
- zeroWidth = 1;
446
- zeroHeight = 1;
447
- }
448
- }
449
- break;
450
- case 'bottom-right':
451
- if (graphRotation > -45 && graphRotation < 45) {
452
- if (ex <= ax && ey <= ay) {
453
- zeroWidth = 0;
454
- zeroHeight = 0;
455
- } else {
456
- zeroWidth = 1;
457
- zeroHeight = 1;
458
- }
459
- } else if (graphRotation === 45) {
460
- if (ey <= ay) {
461
- zeroWidth = 0;
462
- zeroHeight = 0;
463
- } else {
464
- zeroWidth = 1;
465
- zeroHeight = 1;
466
- }
467
- } else if (graphRotation > 45 && graphRotation < 135) {
468
- if (ex >= ax && ey <= ay) {
469
- zeroWidth = 0;
470
- zeroHeight = 0;
471
- } else {
472
- zeroWidth = 1;
473
- zeroHeight = 1;
474
- }
475
- } else if (graphRotation === 135) {
476
- if (ex >= ax) {
477
- zeroWidth = 0;
478
- zeroHeight = 0;
479
- } else {
480
- zeroWidth = 1;
481
- zeroHeight = 1;
482
- }
483
- } else if ((graphRotation > 135 && graphRotation <= 180) || (graphRotation >= -180 && graphRotation < -135)) {
484
- if (ex >= ax && ey >= ay) {
485
- zeroWidth = 0;
486
- zeroHeight = 0;
487
- } else {
488
- zeroWidth = 1;
489
- zeroHeight = 1;
490
- }
491
- } else if (graphRotation === -135) {
492
- if (ey >= ay) {
493
- zeroWidth = 0;
494
- zeroHeight = 0;
495
- } else {
496
- zeroWidth = 1;
497
- zeroHeight = 1;
498
- }
499
- } else if (graphRotation > -135 && graphRotation < -45) {
500
- if (ex <= ax && ey >= ay) {
501
- zeroWidth = 0;
502
- zeroHeight = 0;
503
- } else {
504
- zeroWidth = 1;
505
- zeroHeight = 1;
506
- }
507
- } else if (graphRotation === -45) {
508
- if (ex <= ax) {
509
- zeroWidth = 0;
510
- zeroHeight = 0;
511
- } else {
512
- zeroWidth = 1;
513
- zeroHeight = 1;
514
- }
515
- }
516
- break;
517
- }
518
- if (/-?(left|right)$/.test(adjustType)) {
519
- graph.width(Math.max(2, graphSnap.width() * r1 * zeroWidth));
520
- }
521
- if (/^(top|bottom)-?/.test(adjustType)) {
522
- graph.height(Math.max(2, graphSnap.height() * r1 * zeroHeight));
523
- }
524
- }
525
- {
526
- const [graphWidth, graphHeight] = [graph.width() * graph.scaleX(), graph.height() * graph.scaleY()];
527
- const cos = Math.cos((graphRotation * Math.PI) / 180);
528
- const sin = Math.sin((graphRotation * Math.PI) / 180);
529
- const tan = Math.tan((graphRotation * Math.PI) / 180);
530
- switch (adjustType) {
531
- case 'top':
532
- graph.x(ax - (graphWidth / 2 - graphHeight * tan) * cos);
533
- if (graphRotation !== 90 && graphRotation !== -90) {
534
- graph.y(ay - (graphHeight / cos + (graphWidth / 2 - graphHeight * tan) * sin));
535
- }
536
- break;
537
- case 'bottom': // 无需处理
538
- break;
539
- case 'left':
540
- if ([90, -90].includes(graphRotation)) {
541
- graph.y(ay - graphWidth);
542
- } else if (Math.abs(graphRotation) === 180) {
543
- graph.x(ax + graphWidth);
544
- } else {
545
- const v1 = graphHeight / 2 / cos;
546
- const v2 = v1 * sin;
547
- const v3 = graphWidth - v2;
548
- const v4 = v3 * sin;
549
- graph.x(ax - v3 * cos);
550
- graph.y(ay - (v1 + v4));
551
- }
552
- break;
553
- case 'right': // 无需处理
554
- break;
555
- case 'top-left':
556
- graph.x(ax - (graphWidth - graphHeight * tan) * cos);
557
- graph.y(ay - (graphWidth * sin + graphHeight * cos));
558
- break;
559
- case 'top-right':
560
- graph.x(ax + graphHeight * sin);
561
- graph.y(ay - graphHeight * cos);
562
- break;
563
- case 'bottom-left':
564
- graph.x(ax - graphWidth * cos);
565
- graph.y(ay - graphWidth * sin);
566
- break;
567
- case 'bottom-right': // 无需处理
568
- break;
569
- }
570
- }
571
- }
572
- const [graphWidth, graphHeight] = [graph.width(), graph.height()];
573
- // 更新 圆/椭圆 大小
574
- circle.x(graphWidth / 2);
575
- circle.radiusX(graphWidth / 2);
576
- circle.y(graphHeight / 2);
577
- circle.radiusY(graphHeight / 2);
578
- // 更新 调整点 的 锚点 位置
579
- Circle.updateAnchorShadows(graph, anchors);
580
- // 更新 图形 的 连接点 的 锚点位置
581
- Circle.updateLinkAnchorShadows(graph, linkAnchors);
582
- const stageState = render.getStageState();
583
- // 更新 调整点 位置
584
- for (const anchor of anchors) {
585
- for (const { shape } of anchorAndShadows) {
586
- if (shape) {
587
- if (shape.attrs.anchor?.adjustType === anchor.attrs.adjustType) {
588
- const anchorShadow = graph.find(`.anchor`).find((o) => o.attrs.adjustType === anchor.attrs.adjustType);
589
- if (anchorShadow) {
590
- shape.position({
591
- x: render.toStageValue(anchorShadow.getAbsolutePosition().x - stageState.x),
592
- y: render.toStageValue(anchorShadow.getAbsolutePosition().y - stageState.y)
593
- });
594
- shape.rotation(graph.getAbsoluteRotation());
595
- }
596
- }
597
- }
598
- }
599
- }
600
- render.redraw([GraphDraw.NAME, LinkDraw.NAME, PreviewDraw.NAME]); // 重绘
601
- }
602
- BaseGraph.adjust(render, graph, graphSnap, adjustShape, anchorAndShadows, startPoint, endPoint, hoverRect);
603
- }
604
-
605
- /**
606
- * 提供给 GraphDraw draw 使用
607
- */
608
- static override draw(graph: Konva.Group, render: Render, adjustAnchor?: GraphAnchor) {
609
- const { anchorAndShadows } = super.draw(graph, render, adjustAnchor);
610
- return Circle.createAnchorShapes(render, graph, anchorAndShadows, adjustAnchor);
611
- }
612
-
613
- /**
614
- * 默认图形大小
615
- */
616
- static size = 100;
617
-
618
- /**
619
- * 圆/椭圆 对应的 Konva 实例
620
- */
621
- private circle: Konva.Ellipse;
622
-
623
- constructor(render: Render, dropPoint: Konva.Vector2d) {
624
- super(render, dropPoint, {
625
- type: "Circle",
626
- anchors: [
627
- { adjustType: 'top' },
628
- { adjustType: 'bottom' },
629
- { adjustType: 'left' },
630
- { adjustType: 'right' },
631
- { adjustType: 'top-left' },
632
- { adjustType: 'top-right' },
633
- { adjustType: 'bottom-left' },
634
- { adjustType: 'bottom-right' }
635
- ].map((o) => ({ adjustType: o.adjustType })),
636
- linkAnchors: [
637
- { x: 0, y: 0, alias: 'top', direction: 'top' },
638
- { x: 0, y: 0, alias: 'bottom', direction: 'bottom' },
639
- { x: 0, y: 0, alias: 'left', direction: 'left' },
640
- { x: 0, y: 0, alias: 'right', direction: 'right' },
641
- { x: 0, y: 0, alias: 'center' }
642
- ] as AssetInfoPoint[]
643
- });
644
- this.circle = new Konva.Ellipse({
645
- name: 'graph',
646
- x: 0,
647
- y: 0,
648
- radiusX: 0,
649
- radiusY: 0,
650
- stroke: "#000000",
651
- strokeWidth: 1,
652
- });
653
- this.group.add(this.circle);
654
- this.group.position(this.dropPoint); // 鼠标按下位置 作为起点
655
- }
656
-
657
- // 实现:拖动进行时
658
- override drawMove(point: Konva.Vector2d): void {
659
- // 鼠标拖动偏移量
660
- let offsetX = point.x - this.dropPoint.x,
661
- offsetY = point.y - this.dropPoint.y;
662
- if (offsetX < 1) offsetX = 1;
663
- if (offsetY < 1) offsetY = 1;
664
- // 半径
665
- const radiusX = offsetX / 2, radiusY = offsetY / 2;
666
- // 圆/椭圆 位置大小
667
- this.circle.x(radiusX);
668
- this.circle.y(radiusY);
669
- this.circle.radiusX(radiusX);
670
- this.circle.radiusY(radiusY);
671
- this.group.size({ width: offsetX, height: offsetY });
672
- Circle.updateAnchorShadows(this.group, this.anchorShadows);
673
- Circle.updateLinkAnchorShadows(this.group, this.linkAnchorShadows);
674
- this.render.redraw([GraphDraw.NAME, LinkDraw.NAME, PreviewDraw.NAME]);
675
- }
676
-
677
- // 实现:拖动结束
678
- override drawEnd(): void {
679
- if (this.circle.radiusX() <= 1 && this.circle.radiusY() <= 1) {
680
- const width = Circle.size, height = width;
681
- const radiusX = Circle.size / 2, radiusY = radiusX;
682
- this.circle.x(radiusX);
683
- this.circle.y(radiusY);
684
- this.circle.radiusX(radiusX - this.circle.strokeWidth());
685
- this.circle.radiusY(radiusY - this.circle.strokeWidth());
686
- this.group.size({ width, height });
687
- // 更新 图形 的 调整点 的 锚点位置
688
- Circle.updateAnchorShadows(this.group, this.anchorShadows);
689
- // 更新 图形 的 连接点 的 锚点位置
690
- Circle.updateLinkAnchorShadows(this.group, this.linkAnchorShadows);
691
- // 对齐线清除
692
- this.render.attractTool.alignLinesClear();
693
- // 更新历史
694
- this.render.updateHistory();
695
- // 重绘
696
- this.render.redraw([GraphDraw.NAME, LinkDraw.NAME, PreviewDraw.NAME]);
697
- }
698
- super.drawEnd();
699
- }
1
+ import Konva from 'konva';
2
+ import { GraphAnchor, Render, AssetInfoPoint } from '../types';
3
+ import { GraphDraw, LinkDraw, PreviewDraw } from '../draws';
4
+ import { BaseGraph } from './base-graph';
5
+
6
+ /**
7
+ * 图形 圆/椭圆
8
+ */
9
+ export class Circle extends BaseGraph {
10
+ // 实现:更新 图形 的 调整点 的 锚点位置
11
+ static override updateAnchorShadows(graph: Konva.Group, anchorShadows: Konva.Circle[]): void {
12
+ const { width, height } = graph.size();
13
+ for (const shadow of anchorShadows) {
14
+ switch (shadow.attrs.adjustType) {
15
+ case 'top':
16
+ shadow.position({ x: width / 2, y: 0 });
17
+ break;
18
+ case 'bottom':
19
+ shadow.position({ x: width / 2, y: height });
20
+ break;
21
+ case 'left':
22
+ shadow.position({ x: 0, y: height / 2 });
23
+ break;
24
+ case 'right':
25
+ shadow.position({ x: width, y: height / 2 });
26
+ break;
27
+ case 'top-left':
28
+ shadow.position({ x: 0, y: 0 });
29
+ break;
30
+ case 'top-right':
31
+ shadow.position({ x: width, y: 0 });
32
+ break;
33
+ case 'bottom-left':
34
+ shadow.position({ x: 0, y: height });
35
+ break;
36
+ case 'bottom-right':
37
+ shadow.position({ x: width, y: height });
38
+ break;
39
+ }
40
+ }
41
+ }
42
+
43
+ // 实现:更新 图形 的 连接点 的 锚点位置
44
+ static override updateLinkAnchorShadows(graph: Konva.Group, linkAnchorShadows: Konva.Circle[]): void {
45
+ const { width, height } = graph.size();
46
+ for (const shadow of linkAnchorShadows) {
47
+ switch (shadow.attrs.alias) {
48
+ case 'top':
49
+ shadow.position({ x: width / 2, y: 0 });
50
+ break;
51
+ case 'bottom':
52
+ shadow.position({ x: width / 2, y: height });
53
+ break;
54
+ case 'left':
55
+ shadow.position({ x: 0, y: height / 2 });
56
+ break;
57
+ case 'right':
58
+ shadow.position({ x: width, y: height / 2 });
59
+ break;
60
+ case 'center':
61
+ shadow.position({ x: width / 2, y: height / 2 });
62
+ break;
63
+ }
64
+ }
65
+ }
66
+
67
+ // 实现:生成 调整点
68
+ static override createAnchorShapes(
69
+ render: Render,
70
+ graph: Konva.Group,
71
+ anchorAndShadows: {
72
+ anchor: GraphAnchor,
73
+ anchorShadow: Konva.Circle,
74
+ shape?: Konva.Shape
75
+ }[],
76
+ // eslint-disable-next-line
77
+ adjustAnchor?: GraphAnchor
78
+ ): {
79
+ anchorAndShadows: {
80
+ anchor: GraphAnchor;
81
+ anchorShadow: Konva.Circle;
82
+ shape?: Konva.Shape | undefined;
83
+ }[]
84
+ } {
85
+ const stageState = render.getStageState();
86
+ for (const anchorAndShadow of anchorAndShadows) {
87
+ const { anchor, anchorShadow } = anchorAndShadow;
88
+ const x = render.toStageValue(anchorShadow.getAbsolutePosition().x - stageState.x),
89
+ y = render.toStageValue(anchorShadow.getAbsolutePosition().y - stageState.y);
90
+ const offset = render.toStageValue(render.pointSize + 5);
91
+ const anchorShape = new Konva.Line({
92
+ name: 'anchor',
93
+ anchor: anchor,
94
+ stroke: `rgba(0,0,255,0.4)`,
95
+ strokeWidth: render.toStageValue(2),
96
+ hitStrokeWidth: render.toStageValue(3),
97
+ x,
98
+ y,
99
+ points: {
100
+ 'top-left': [[-offset, offset / 2], [-offset, -offset], [offset / 2, -offset]].flat(),
101
+ top: [[-offset, -offset], [offset, -offset]].flat(),
102
+ 'top-right': [[-offset / 2, -offset], [offset, -offset], [offset, offset / 2]].flat(),
103
+ right: [[offset, -offset], [offset, offset]].flat(),
104
+ 'bottom-right': [[-offset / 2, offset], [offset, offset], [offset, -offset / 2]].flat(),
105
+ bottom: [[-offset, offset], [offset, offset]].flat(),
106
+ 'bottom-left': [[-offset, -offset / 2], [-offset, offset], [offset / 2, offset]].flat(),
107
+ left: [[-offset, -offset], [-offset, offset]].flat()
108
+ }[anchor.adjustType] ?? [],
109
+ rotation: graph.getAbsoluteRotation(), // 旋转角度
110
+ visible: graph.attrs.adjusting || graph.attrs.hover === true
111
+ });
112
+ anchorShape.on('mouseenter', () => {
113
+ document.body.style.cursor = 'move';
114
+ graph.setAttr('hover', true);
115
+ graph.setAttr('hoverAnchor', true);
116
+ });
117
+ anchorShape.on('mouseleave', () => {
118
+ document.body.style.cursor = anchorShape.attrs.adjusting ? 'move' : 'default';
119
+ graph.setAttr('hover', false);
120
+ graph.setAttr('hoverAnchor', false);
121
+ // 进入其他元素区域时离开需要靠它 redraw
122
+ render.redraw([GraphDraw.NAME]);
123
+ });
124
+ anchorAndShadow.shape = anchorShape;
125
+ }
126
+ return { anchorAndShadows };
127
+ }
128
+
129
+ // 实现:调整 图形
130
+ static override adjust(
131
+ render: Render,
132
+ graph: Konva.Group,
133
+ graphSnap: Konva.Group,
134
+ adjustShape: Konva.Shape,
135
+ anchorAndShadows: {
136
+ anchor: GraphAnchor,
137
+ anchorShadow: Konva.Circle,
138
+ shape?: Konva.Shape | undefined,
139
+ }[],
140
+ startPoint: Konva.Vector2d,
141
+ endPoint: Konva.Vector2d,
142
+ hoverRect?: Konva.Rect
143
+ ) {
144
+ // 目标 圆/椭圆
145
+ const circle = graph.findOne('.graph') as Konva.Ellipse;
146
+ // 镜像
147
+ const circleSnap = graphSnap.findOne('.graph') as Konva.Ellipse;
148
+ // 调整点 锚点
149
+ const anchors = (graph.find('.anchor') ?? []) as Konva.Circle[];
150
+ // 镜像
151
+ const anchorsSnap = (graphSnap.find('.anchor') ?? []) as Konva.Circle[];
152
+ // 连接点 锚点
153
+ const linkAnchors = (graph.find('.link-anchor') ?? []) as Konva.Circle[];
154
+ if (circle && circleSnap) {
155
+ const [graphRotation, adjustType, ex, ey] = [
156
+ Math.round(graph.rotation()),
157
+ adjustShape.attrs.anchor?.adjustType,
158
+ endPoint.x,
159
+ endPoint.y
160
+ ];
161
+ let anchorShadow: Konva.Circle | undefined, anchorShadowAcross: Konva.Circle | undefined;
162
+ switch (adjustType) {
163
+ case 'top':
164
+ anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'top');
165
+ anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'bottom');
166
+ break;
167
+ case 'bottom':
168
+ anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'bottom');
169
+ anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'top');
170
+ break;
171
+ case 'left':
172
+ anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'left');
173
+ anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'right');
174
+ break;
175
+ case 'right':
176
+ anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'right');
177
+ anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'left');
178
+ break;
179
+ case 'top-left':
180
+ anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'top-left');
181
+ anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'bottom-right');
182
+ break;
183
+ case 'top-right':
184
+ anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'top-right');
185
+ anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'bottom-left');
186
+ break;
187
+ case 'bottom-left':
188
+ anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'bottom-left');
189
+ anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'top-right');
190
+ break;
191
+ case 'bottom-right':
192
+ anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'bottom-right');
193
+ anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'top-left');
194
+ break;
195
+ }
196
+ if (anchorShadow && anchorShadowAcross) {
197
+ const { x: sx, y: sy } = anchorShadow.getAbsolutePosition();
198
+ const { x: ax, y: ay } = anchorShadowAcross.getAbsolutePosition();
199
+ {
200
+ const d1 = Math.sqrt(Math.pow(sx - ax, 2) + Math.pow(sy - ay, 2));
201
+ const d2 = Math.sqrt(Math.pow(ex - ax, 2) + Math.pow(ey - ay, 2));
202
+ const r1 = d2 / d1;
203
+ let zeroWidth = 1, zeroHeight = 1;
204
+ switch (adjustType) {
205
+ case 'top':
206
+ if (graphRotation >= 45 && graphRotation < 135) {
207
+ zeroHeight = ex <= ax ? 0 : 1;
208
+ } else if (graphRotation >= -135 && graphRotation < -45) {
209
+ zeroHeight = ex >= ax ? 0 : 1;
210
+ } else if (graphRotation >= -45 && graphRotation < 45) {
211
+ zeroHeight = ey >= ay ? 0 : 1;
212
+ } else {
213
+ zeroHeight = ey <= ay ? 0 : 1;
214
+ }
215
+ break;
216
+ case 'bottom':
217
+ if (graphRotation >= 45 && graphRotation < 135) {
218
+ zeroHeight = ex <= ax ? 1 : 0;
219
+ } else if (graphRotation >= -135 && graphRotation < -45) {
220
+ zeroHeight = ex >= ax ? 1 : 0;
221
+ } else if (graphRotation >= -45 && graphRotation < 45) {
222
+ zeroHeight = ey >= ay ? 1 : 0;
223
+ } else {
224
+ zeroHeight = ey <= ay ? 1 : 0;
225
+ }
226
+ break;
227
+ case 'left':
228
+ if (graphRotation >= 45 && graphRotation < 135) {
229
+ zeroWidth = ey >= ay ? 0 : 1;
230
+ } else if (graphRotation >= -135 && graphRotation < -45) {
231
+ zeroWidth = ex <= ax ? 0 : 1;
232
+ } else if (graphRotation >= -45 && graphRotation < 45) {
233
+ zeroWidth = ex >= ax ? 0 : 1;
234
+ } else {
235
+ zeroWidth = ey <= ay ? 0 : 1;
236
+ }
237
+ break;
238
+ case 'right':
239
+ if (graphRotation >= 45 && graphRotation < 135) {
240
+ zeroWidth = ey >= ay ? 1 : 0;
241
+ } else if (graphRotation >= -135 && graphRotation < -45) {
242
+ zeroWidth = ex <= ax ? 1 : 0;
243
+ } else if (graphRotation >= -45 && graphRotation < 45) {
244
+ zeroWidth = ex >= ax ? 1 : 0;
245
+ } else {
246
+ zeroWidth = ey <= ay ? 1 : 0;
247
+ }
248
+ break;
249
+ case 'top-left':
250
+ if (graphRotation > -45 && graphRotation < 45) {
251
+ if (ex >= ax && ey >= ay) {
252
+ zeroWidth = 0;
253
+ zeroHeight = 0;
254
+ } else {
255
+ zeroWidth = 1;
256
+ zeroHeight = 1;
257
+ }
258
+ } else if (graphRotation === 45) {
259
+ if (ey >= ay) {
260
+ zeroWidth = 0;
261
+ zeroHeight = 0;
262
+ } else {
263
+ zeroWidth = 1;
264
+ zeroHeight = 1;
265
+ }
266
+ } else if (graphRotation > 45 && graphRotation < 135) {
267
+ if (ex <= ax && ey >= ay) {
268
+ zeroWidth = 0;
269
+ zeroHeight = 0;
270
+ } else {
271
+ zeroWidth = 1;
272
+ zeroHeight = 1;
273
+ }
274
+ } else if (graphRotation === 135) {
275
+ if (ex <= ax) {
276
+ zeroWidth = 0;
277
+ zeroHeight = 0;
278
+ } else {
279
+ zeroWidth = 1;
280
+ zeroHeight = 1;
281
+ }
282
+ } else if ((graphRotation > 135 && graphRotation <= 180) || (graphRotation >= -180 && graphRotation < -135)) {
283
+ if (ex <= ax && ey <= ay) {
284
+ zeroWidth = 0;
285
+ zeroHeight = 0;
286
+ } else {
287
+ zeroWidth = 1;
288
+ zeroHeight = 1;
289
+ }
290
+ } else if (graphRotation === -135) {
291
+ if (ey <= ay) {
292
+ zeroWidth = 0;
293
+ zeroHeight = 0;
294
+ } else {
295
+ zeroWidth = 1;
296
+ zeroHeight = 1;
297
+ }
298
+ } else if (graphRotation > -135 && graphRotation < -45) {
299
+ if (ex >= ax && ey <= ay) {
300
+ zeroWidth = 0;
301
+ zeroHeight = 0;
302
+ } else {
303
+ zeroWidth = 1;
304
+ zeroHeight = 1;
305
+ }
306
+ } else if (graphRotation === -45) {
307
+ if (ex >= ax) {
308
+ zeroWidth = 0;
309
+ zeroHeight = 0;
310
+ } else {
311
+ zeroWidth = 1;
312
+ zeroHeight = 1;
313
+ }
314
+ }
315
+ break;
316
+ case 'top-right':
317
+ if (graphRotation > -45 && graphRotation < 45) {
318
+ if (ex <= ax && ey >= ay) {
319
+ zeroWidth = 0;
320
+ zeroHeight = 0;
321
+ } else {
322
+ zeroWidth = 1;
323
+ zeroHeight = 1;
324
+ }
325
+ } else if (graphRotation === 45) {
326
+ if (ex <= ax) {
327
+ zeroWidth = 0;
328
+ zeroHeight = 0;
329
+ } else {
330
+ zeroWidth = 1;
331
+ zeroHeight = 1;
332
+ }
333
+ } else if (graphRotation > 45 && graphRotation < 135) {
334
+ if (ex <= ax && ey <= ay) {
335
+ zeroWidth = 0;
336
+ zeroHeight = 0;
337
+ } else {
338
+ zeroWidth = 1;
339
+ zeroHeight = 1;
340
+ }
341
+ } else if (graphRotation === 135) {
342
+ if (ey <= ay) {
343
+ zeroWidth = 0;
344
+ zeroHeight = 0;
345
+ } else {
346
+ zeroWidth = 1;
347
+ zeroHeight = 1;
348
+ }
349
+ } else if ((graphRotation > 135 && graphRotation <= 180) || (graphRotation >= -180 && graphRotation < -135)) {
350
+ if (ex >= ax && ey <= ay) {
351
+ zeroWidth = 0;
352
+ zeroHeight = 0;
353
+ } else {
354
+ zeroWidth = 1;
355
+ zeroHeight = 1;
356
+ }
357
+ } else if (graphRotation === -135) {
358
+ if (ex >= ax) {
359
+ zeroWidth = 0;
360
+ zeroHeight = 0;
361
+ } else {
362
+ zeroWidth = 1;
363
+ zeroHeight = 1;
364
+ }
365
+ } else if (graphRotation > -135 && graphRotation < -45) {
366
+ if (ex >= ax && ey >= ay) {
367
+ zeroWidth = 0;
368
+ zeroHeight = 0;
369
+ } else {
370
+ zeroWidth = 1;
371
+ zeroHeight = 1;
372
+ }
373
+ } else if (graphRotation === -45) {
374
+ if (ey >= ay) {
375
+ zeroWidth = 0;
376
+ zeroHeight = 0;
377
+ } else {
378
+ zeroWidth = 1;
379
+ zeroHeight = 1;
380
+ }
381
+ }
382
+ break;
383
+ case 'bottom-left':
384
+ if (graphRotation > -45 && graphRotation < 45) {
385
+ if (ex >= ax && ey <= ay) {
386
+ zeroWidth = 0;
387
+ zeroHeight = 0;
388
+ } else {
389
+ zeroWidth = 1;
390
+ zeroHeight = 1;
391
+ }
392
+ } else if (graphRotation === 45) {
393
+ if (ex >= ax) {
394
+ zeroWidth = 0;
395
+ zeroHeight = 0;
396
+ } else {
397
+ zeroWidth = 1;
398
+ zeroHeight = 1;
399
+ }
400
+ } else if (graphRotation > 45 && graphRotation < 135) {
401
+ if (ex >= ax && ey >= ay) {
402
+ zeroWidth = 0;
403
+ zeroHeight = 0;
404
+ } else {
405
+ zeroWidth = 1;
406
+ zeroHeight = 1;
407
+ }
408
+ } else if (graphRotation === 135) {
409
+ if (ey >= ay) {
410
+ zeroWidth = 0;
411
+ zeroHeight = 0;
412
+ } else {
413
+ zeroWidth = 1;
414
+ zeroHeight = 1;
415
+ }
416
+ } else if ((graphRotation > 135 && graphRotation <= 180) || (graphRotation >= -180 && graphRotation < -135)) {
417
+ if (ex <= ax && ey >= ay) {
418
+ zeroWidth = 0;
419
+ zeroHeight = 0;
420
+ } else {
421
+ zeroWidth = 1;
422
+ zeroHeight = 1;
423
+ }
424
+ } else if (graphRotation === -135) {
425
+ if (ex <= ax) {
426
+ zeroWidth = 0;
427
+ zeroHeight = 0;
428
+ } else {
429
+ zeroWidth = 1;
430
+ zeroHeight = 1;
431
+ }
432
+ } else if (graphRotation > -135 && graphRotation < -45) {
433
+ if (ex <= ax && ey <= ay) {
434
+ zeroWidth = 0;
435
+ zeroHeight = 0;
436
+ } else {
437
+ zeroWidth = 1;
438
+ zeroHeight = 1;
439
+ }
440
+ } else if (graphRotation === -45) {
441
+ if (ey <= ay) {
442
+ zeroWidth = 0;
443
+ zeroHeight = 0;
444
+ } else {
445
+ zeroWidth = 1;
446
+ zeroHeight = 1;
447
+ }
448
+ }
449
+ break;
450
+ case 'bottom-right':
451
+ if (graphRotation > -45 && graphRotation < 45) {
452
+ if (ex <= ax && ey <= ay) {
453
+ zeroWidth = 0;
454
+ zeroHeight = 0;
455
+ } else {
456
+ zeroWidth = 1;
457
+ zeroHeight = 1;
458
+ }
459
+ } else if (graphRotation === 45) {
460
+ if (ey <= ay) {
461
+ zeroWidth = 0;
462
+ zeroHeight = 0;
463
+ } else {
464
+ zeroWidth = 1;
465
+ zeroHeight = 1;
466
+ }
467
+ } else if (graphRotation > 45 && graphRotation < 135) {
468
+ if (ex >= ax && ey <= ay) {
469
+ zeroWidth = 0;
470
+ zeroHeight = 0;
471
+ } else {
472
+ zeroWidth = 1;
473
+ zeroHeight = 1;
474
+ }
475
+ } else if (graphRotation === 135) {
476
+ if (ex >= ax) {
477
+ zeroWidth = 0;
478
+ zeroHeight = 0;
479
+ } else {
480
+ zeroWidth = 1;
481
+ zeroHeight = 1;
482
+ }
483
+ } else if ((graphRotation > 135 && graphRotation <= 180) || (graphRotation >= -180 && graphRotation < -135)) {
484
+ if (ex >= ax && ey >= ay) {
485
+ zeroWidth = 0;
486
+ zeroHeight = 0;
487
+ } else {
488
+ zeroWidth = 1;
489
+ zeroHeight = 1;
490
+ }
491
+ } else if (graphRotation === -135) {
492
+ if (ey >= ay) {
493
+ zeroWidth = 0;
494
+ zeroHeight = 0;
495
+ } else {
496
+ zeroWidth = 1;
497
+ zeroHeight = 1;
498
+ }
499
+ } else if (graphRotation > -135 && graphRotation < -45) {
500
+ if (ex <= ax && ey >= ay) {
501
+ zeroWidth = 0;
502
+ zeroHeight = 0;
503
+ } else {
504
+ zeroWidth = 1;
505
+ zeroHeight = 1;
506
+ }
507
+ } else if (graphRotation === -45) {
508
+ if (ex <= ax) {
509
+ zeroWidth = 0;
510
+ zeroHeight = 0;
511
+ } else {
512
+ zeroWidth = 1;
513
+ zeroHeight = 1;
514
+ }
515
+ }
516
+ break;
517
+ }
518
+ if (/-?(left|right)$/.test(adjustType)) {
519
+ graph.width(Math.max(2, graphSnap.width() * r1 * zeroWidth));
520
+ }
521
+ if (/^(top|bottom)-?/.test(adjustType)) {
522
+ graph.height(Math.max(2, graphSnap.height() * r1 * zeroHeight));
523
+ }
524
+ }
525
+ {
526
+ const [graphWidth, graphHeight] = [graph.width() * graph.scaleX(), graph.height() * graph.scaleY()];
527
+ const cos = Math.cos((graphRotation * Math.PI) / 180);
528
+ const sin = Math.sin((graphRotation * Math.PI) / 180);
529
+ const tan = Math.tan((graphRotation * Math.PI) / 180);
530
+ switch (adjustType) {
531
+ case 'top':
532
+ graph.x(ax - (graphWidth / 2 - graphHeight * tan) * cos);
533
+ if (graphRotation !== 90 && graphRotation !== -90) {
534
+ graph.y(ay - (graphHeight / cos + (graphWidth / 2 - graphHeight * tan) * sin));
535
+ }
536
+ break;
537
+ case 'bottom': // 无需处理
538
+ break;
539
+ case 'left':
540
+ if ([90, -90].includes(graphRotation)) {
541
+ graph.y(ay - graphWidth);
542
+ } else if (Math.abs(graphRotation) === 180) {
543
+ graph.x(ax + graphWidth);
544
+ } else {
545
+ const v1 = graphHeight / 2 / cos;
546
+ const v2 = v1 * sin;
547
+ const v3 = graphWidth - v2;
548
+ const v4 = v3 * sin;
549
+ graph.x(ax - v3 * cos);
550
+ graph.y(ay - (v1 + v4));
551
+ }
552
+ break;
553
+ case 'right': // 无需处理
554
+ break;
555
+ case 'top-left':
556
+ graph.x(ax - (graphWidth - graphHeight * tan) * cos);
557
+ graph.y(ay - (graphWidth * sin + graphHeight * cos));
558
+ break;
559
+ case 'top-right':
560
+ graph.x(ax + graphHeight * sin);
561
+ graph.y(ay - graphHeight * cos);
562
+ break;
563
+ case 'bottom-left':
564
+ graph.x(ax - graphWidth * cos);
565
+ graph.y(ay - graphWidth * sin);
566
+ break;
567
+ case 'bottom-right': // 无需处理
568
+ break;
569
+ }
570
+ }
571
+ }
572
+ const [graphWidth, graphHeight] = [graph.width(), graph.height()];
573
+ // 更新 圆/椭圆 大小
574
+ circle.x(graphWidth / 2);
575
+ circle.radiusX(graphWidth / 2);
576
+ circle.y(graphHeight / 2);
577
+ circle.radiusY(graphHeight / 2);
578
+ // 更新 调整点 的 锚点 位置
579
+ Circle.updateAnchorShadows(graph, anchors);
580
+ // 更新 图形 的 连接点 的 锚点位置
581
+ Circle.updateLinkAnchorShadows(graph, linkAnchors);
582
+ const stageState = render.getStageState();
583
+ // 更新 调整点 位置
584
+ for (const anchor of anchors) {
585
+ for (const { shape } of anchorAndShadows) {
586
+ if (shape) {
587
+ if (shape.attrs.anchor?.adjustType === anchor.attrs.adjustType) {
588
+ const anchorShadow = graph.find(`.anchor`).find((o) => o.attrs.adjustType === anchor.attrs.adjustType);
589
+ if (anchorShadow) {
590
+ shape.position({
591
+ x: render.toStageValue(anchorShadow.getAbsolutePosition().x - stageState.x),
592
+ y: render.toStageValue(anchorShadow.getAbsolutePosition().y - stageState.y)
593
+ });
594
+ shape.rotation(graph.getAbsoluteRotation());
595
+ }
596
+ }
597
+ }
598
+ }
599
+ }
600
+ render.redraw([GraphDraw.NAME, LinkDraw.NAME, PreviewDraw.NAME]); // 重绘
601
+ }
602
+ BaseGraph.adjust(render, graph, graphSnap, adjustShape, anchorAndShadows, startPoint, endPoint, hoverRect);
603
+ }
604
+
605
+ /**
606
+ * 提供给 GraphDraw draw 使用
607
+ */
608
+ static override draw(graph: Konva.Group, render: Render, adjustAnchor?: GraphAnchor) {
609
+ const { anchorAndShadows } = super.draw(graph, render, adjustAnchor);
610
+ return Circle.createAnchorShapes(render, graph, anchorAndShadows, adjustAnchor);
611
+ }
612
+
613
+ /**
614
+ * 默认图形大小
615
+ */
616
+ static size = 100;
617
+
618
+ /**
619
+ * 圆/椭圆 对应的 Konva 实例
620
+ */
621
+ private circle: Konva.Ellipse;
622
+
623
+ constructor(render: Render, dropPoint: Konva.Vector2d) {
624
+ super(render, dropPoint, {
625
+ type: "Circle",
626
+ anchors: [
627
+ { adjustType: 'top' },
628
+ { adjustType: 'bottom' },
629
+ { adjustType: 'left' },
630
+ { adjustType: 'right' },
631
+ { adjustType: 'top-left' },
632
+ { adjustType: 'top-right' },
633
+ { adjustType: 'bottom-left' },
634
+ { adjustType: 'bottom-right' }
635
+ ].map((o) => ({ adjustType: o.adjustType })),
636
+ linkAnchors: [
637
+ { x: 0, y: 0, alias: 'top', direction: 'top' },
638
+ { x: 0, y: 0, alias: 'bottom', direction: 'bottom' },
639
+ { x: 0, y: 0, alias: 'left', direction: 'left' },
640
+ { x: 0, y: 0, alias: 'right', direction: 'right' },
641
+ { x: 0, y: 0, alias: 'center' }
642
+ ] as AssetInfoPoint[]
643
+ });
644
+ this.circle = new Konva.Ellipse({
645
+ name: 'graph',
646
+ x: 0,
647
+ y: 0,
648
+ radiusX: 0,
649
+ radiusY: 0,
650
+ stroke: "#000000",
651
+ strokeWidth: 1,
652
+ });
653
+ this.group.add(this.circle);
654
+ this.group.position(this.dropPoint); // 鼠标按下位置 作为起点
655
+ }
656
+
657
+ // 实现:拖动进行时
658
+ override drawMove(point: Konva.Vector2d): void {
659
+ // 鼠标拖动偏移量
660
+ let offsetX = point.x - this.dropPoint.x,
661
+ offsetY = point.y - this.dropPoint.y;
662
+ if (offsetX < 1) offsetX = 1;
663
+ if (offsetY < 1) offsetY = 1;
664
+ // 半径
665
+ const radiusX = offsetX / 2, radiusY = offsetY / 2;
666
+ // 圆/椭圆 位置大小
667
+ this.circle.x(radiusX);
668
+ this.circle.y(radiusY);
669
+ this.circle.radiusX(radiusX);
670
+ this.circle.radiusY(radiusY);
671
+ this.group.size({ width: offsetX, height: offsetY });
672
+ Circle.updateAnchorShadows(this.group, this.anchorShadows);
673
+ Circle.updateLinkAnchorShadows(this.group, this.linkAnchorShadows);
674
+ this.render.redraw([GraphDraw.NAME, LinkDraw.NAME, PreviewDraw.NAME]);
675
+ }
676
+
677
+ // 实现:拖动结束
678
+ override drawEnd(): void {
679
+ if (this.circle.radiusX() <= 1 && this.circle.radiusY() <= 1) {
680
+ const width = Circle.size, height = width;
681
+ const radiusX = Circle.size / 2, radiusY = radiusX;
682
+ this.circle.x(radiusX);
683
+ this.circle.y(radiusY);
684
+ this.circle.radiusX(radiusX - this.circle.strokeWidth());
685
+ this.circle.radiusY(radiusY - this.circle.strokeWidth());
686
+ this.group.size({ width, height });
687
+ // 更新 图形 的 调整点 的 锚点位置
688
+ Circle.updateAnchorShadows(this.group, this.anchorShadows);
689
+ // 更新 图形 的 连接点 的 锚点位置
690
+ Circle.updateLinkAnchorShadows(this.group, this.linkAnchorShadows);
691
+ // 对齐线清除
692
+ this.render.attractTool.alignLinesClear();
693
+ // 更新历史
694
+ this.render.updateHistory();
695
+ // 重绘
696
+ this.render.redraw([GraphDraw.NAME, LinkDraw.NAME, PreviewDraw.NAME]);
697
+ }
698
+ super.drawEnd();
699
+ }
700
700
  }