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