@antv/g6 5.0.49 → 5.0.50

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 (129) hide show
  1. package/README.md +1 -1
  2. package/README.zh-CN.md +1 -1
  3. package/dist/g6.min.js +31 -31
  4. package/dist/lib/behaviors/brush-select.d.ts +1 -1
  5. package/dist/lib/behaviors/drag-element.d.ts +3 -2
  6. package/dist/lib/exports.d.ts +1 -1
  7. package/dist/lib/layouts/types.d.ts +9 -1
  8. package/dist/lib/plugins/index.d.ts +2 -0
  9. package/dist/lib/plugins/minimap/index.d.ts +7 -4
  10. package/dist/lib/plugins/title/index.d.ts +85 -0
  11. package/dist/lib/runtime/graph.d.ts +27 -0
  12. package/dist/lib/utils/element.d.ts +1 -1
  13. package/dist/lib/utils/vector.d.ts +9 -0
  14. package/dist/lib/version.d.ts +1 -1
  15. package/esm/behaviors/brush-select.d.ts +1 -1
  16. package/esm/behaviors/brush-select.js +12 -3
  17. package/esm/behaviors/brush-select.js.map +1 -1
  18. package/esm/behaviors/drag-canvas.js +2 -7
  19. package/esm/behaviors/drag-canvas.js.map +1 -1
  20. package/esm/behaviors/drag-element-force.js +1 -1
  21. package/esm/behaviors/drag-element-force.js.map +1 -1
  22. package/esm/behaviors/drag-element.d.ts +3 -2
  23. package/esm/behaviors/drag-element.js +6 -2
  24. package/esm/behaviors/drag-element.js.map +1 -1
  25. package/esm/behaviors/lasso-select.js +3 -3
  26. package/esm/behaviors/lasso-select.js.map +1 -1
  27. package/esm/exports.d.ts +1 -1
  28. package/esm/exports.js +1 -1
  29. package/esm/exports.js.map +1 -1
  30. package/esm/layouts/types.d.ts +9 -1
  31. package/esm/plugins/grid-line.js +1 -1
  32. package/esm/plugins/grid-line.js.map +1 -1
  33. package/esm/plugins/index.d.ts +2 -0
  34. package/esm/plugins/index.js +1 -0
  35. package/esm/plugins/index.js.map +1 -1
  36. package/esm/plugins/minimap/index.d.ts +7 -4
  37. package/esm/plugins/minimap/index.js +41 -52
  38. package/esm/plugins/minimap/index.js.map +1 -1
  39. package/esm/plugins/title/index.d.ts +85 -0
  40. package/esm/plugins/title/index.js +172 -0
  41. package/esm/plugins/title/index.js.map +1 -0
  42. package/esm/registry/build-in.js +2 -1
  43. package/esm/registry/build-in.js.map +1 -1
  44. package/esm/runtime/graph.d.ts +27 -0
  45. package/esm/runtime/graph.js +33 -0
  46. package/esm/runtime/graph.js.map +1 -1
  47. package/esm/runtime/layout.js +4 -3
  48. package/esm/runtime/layout.js.map +1 -1
  49. package/esm/runtime/viewport.js +3 -0
  50. package/esm/runtime/viewport.js.map +1 -1
  51. package/esm/themes/base.js +1 -0
  52. package/esm/themes/base.js.map +1 -1
  53. package/esm/transforms/process-parallel-edges.js +16 -3
  54. package/esm/transforms/process-parallel-edges.js.map +1 -1
  55. package/esm/utils/element.d.ts +1 -1
  56. package/esm/utils/element.js.map +1 -1
  57. package/esm/utils/vector.d.ts +9 -0
  58. package/esm/utils/vector.js +17 -0
  59. package/esm/utils/vector.js.map +1 -1
  60. package/esm/version.d.ts +1 -1
  61. package/esm/version.js +1 -1
  62. package/lib/behaviors/brush-select.d.ts +1 -1
  63. package/lib/behaviors/brush-select.js +12 -3
  64. package/lib/behaviors/brush-select.js.map +1 -1
  65. package/lib/behaviors/drag-canvas.js +1 -6
  66. package/lib/behaviors/drag-canvas.js.map +1 -1
  67. package/lib/behaviors/drag-element-force.js +1 -1
  68. package/lib/behaviors/drag-element-force.js.map +1 -1
  69. package/lib/behaviors/drag-element.d.ts +3 -2
  70. package/lib/behaviors/drag-element.js +5 -1
  71. package/lib/behaviors/drag-element.js.map +1 -1
  72. package/lib/behaviors/lasso-select.js +3 -3
  73. package/lib/behaviors/lasso-select.js.map +1 -1
  74. package/lib/exports.d.ts +1 -1
  75. package/lib/exports.js +3 -2
  76. package/lib/exports.js.map +1 -1
  77. package/lib/layouts/types.d.ts +9 -1
  78. package/lib/plugins/grid-line.js +1 -1
  79. package/lib/plugins/grid-line.js.map +1 -1
  80. package/lib/plugins/index.d.ts +2 -0
  81. package/lib/plugins/index.js +3 -1
  82. package/lib/plugins/index.js.map +1 -1
  83. package/lib/plugins/minimap/index.d.ts +7 -4
  84. package/lib/plugins/minimap/index.js +41 -52
  85. package/lib/plugins/minimap/index.js.map +1 -1
  86. package/lib/plugins/title/index.d.ts +85 -0
  87. package/lib/plugins/title/index.js +176 -0
  88. package/lib/plugins/title/index.js.map +1 -0
  89. package/lib/registry/build-in.js +1 -0
  90. package/lib/registry/build-in.js.map +1 -1
  91. package/lib/runtime/graph.d.ts +27 -0
  92. package/lib/runtime/graph.js +33 -0
  93. package/lib/runtime/graph.js.map +1 -1
  94. package/lib/runtime/layout.js +4 -3
  95. package/lib/runtime/layout.js.map +1 -1
  96. package/lib/runtime/viewport.js +3 -0
  97. package/lib/runtime/viewport.js.map +1 -1
  98. package/lib/themes/base.js +1 -0
  99. package/lib/themes/base.js.map +1 -1
  100. package/lib/transforms/process-parallel-edges.js +16 -3
  101. package/lib/transforms/process-parallel-edges.js.map +1 -1
  102. package/lib/utils/element.d.ts +1 -1
  103. package/lib/utils/element.js.map +1 -1
  104. package/lib/utils/vector.d.ts +9 -0
  105. package/lib/utils/vector.js +18 -0
  106. package/lib/utils/vector.js.map +1 -1
  107. package/lib/version.d.ts +1 -1
  108. package/lib/version.js +1 -1
  109. package/package.json +8 -8
  110. package/src/behaviors/brush-select.ts +14 -3
  111. package/src/behaviors/drag-canvas.ts +2 -6
  112. package/src/behaviors/drag-element-force.ts +2 -1
  113. package/src/behaviors/drag-element.ts +8 -3
  114. package/src/behaviors/lasso-select.ts +3 -3
  115. package/src/exports.ts +1 -0
  116. package/src/layouts/types.ts +9 -1
  117. package/src/plugins/grid-line.ts +1 -1
  118. package/src/plugins/index.ts +2 -0
  119. package/src/plugins/minimap/index.ts +50 -63
  120. package/src/plugins/title/index.ts +300 -0
  121. package/src/registry/build-in.ts +2 -0
  122. package/src/runtime/graph.ts +34 -0
  123. package/src/runtime/layout.ts +9 -3
  124. package/src/runtime/viewport.ts +14 -3
  125. package/src/themes/base.ts +1 -0
  126. package/src/transforms/process-parallel-edges.ts +17 -3
  127. package/src/utils/element.ts +5 -5
  128. package/src/utils/vector.ts +17 -0
  129. package/src/version.ts +1 -1
@@ -0,0 +1,300 @@
1
+ import { Canvas } from '@antv/g';
2
+ import { GraphEvent } from '../../constants';
3
+ import type { LabelStyleProps } from '../../elements/shapes/label';
4
+ import { Label } from '../../elements/shapes/label';
5
+ import type { RuntimeContext } from '../../runtime/types';
6
+ import type { Prefix } from '../../types';
7
+ import { parsePadding } from '../../utils/padding';
8
+ import { subStyleProps } from '../../utils/prefix';
9
+ import type { BasePluginOptions } from '../base-plugin';
10
+ import { BasePlugin } from '../base-plugin';
11
+ import { createPluginCanvas } from '../utils/canvas';
12
+
13
+ const commonStyle: Partial<LabelStyleProps> = {
14
+ fill: '#1D2129',
15
+ wordWrap: true, // 自动换行
16
+ maxLines: 1, // 最大行数
17
+ textOverflow: 'ellipsis', // 溢出隐藏省略号
18
+ textBaseline: 'top',
19
+
20
+ /**
21
+ * textAlign 需要和 x 结合使用
22
+ * 举例: 前提条件: 画布 width = 600
23
+ * - textAlign: 'start' | 'left
24
+ * 需要设 x = 0
25
+ * - textAlign: 'end' | 'right'
26
+ * 需要设 x = 600 (即画布的宽度)
27
+ * - textAlign: 'center'
28
+ * 需要设 x = 300 (即画布的宽度 / 2)
29
+ */
30
+ textAlign: 'start',
31
+ x: 0,
32
+ };
33
+ const defaultTitleStyle: Partial<LabelStyleProps> = {
34
+ ...commonStyle,
35
+ fillOpacity: 0.9,
36
+ fontSize: 16,
37
+ fontWeight: 'bold',
38
+ };
39
+ const defaultSubTitleStyle: Partial<LabelStyleProps> = {
40
+ ...commonStyle,
41
+ fillOpacity: 0.65,
42
+ fontSize: 12,
43
+ fontWeight: 'normal',
44
+ };
45
+ const defaultOptions: Partial<TitleOptions> = {
46
+ align: 'left',
47
+ spacing: 8,
48
+ size: 44,
49
+ padding: [16, 24, 0, 24],
50
+ };
51
+
52
+ const titleKey = 'title';
53
+ const subtitleKey = 'subtitle';
54
+
55
+ /**
56
+ * <zh/> 标题的样式
57
+ *
58
+ * <en/> Title styles
59
+ */
60
+ export type TitleStyle = Prefix<typeof titleKey, Omit<LabelStyleProps, 'x' | 'y' | 'text'>>;
61
+ /**
62
+ * <zh/> 副标题的样式
63
+ *
64
+ * <en/> Subtitle styles
65
+ */
66
+ export type SubTitleStyle = Prefix<typeof subtitleKey, Omit<LabelStyleProps, 'x' | 'y' | 'text'>>;
67
+
68
+ /**
69
+ * <zh/> 标题插件配置项
70
+ *
71
+ * <en/> Title plugin options
72
+ */
73
+ export interface TitleOptions extends BasePluginOptions, TitleStyle, SubTitleStyle {
74
+ /**
75
+ * <zh/> 整个标题的高度
76
+ *
77
+ * <en/> whole title height
78
+ * @defaultValue 44
79
+ */
80
+ size?: number;
81
+ /**
82
+ * <zh/> 整个标题位于图的位置
83
+ *
84
+ * <en/> The entire title is located at the position of the graph
85
+ * @defaultValue 'left'
86
+ */
87
+ align?: 'left' | 'center' | 'right';
88
+ /**
89
+ * <zh/> 主标题、副标题之间的上下间距
90
+ *
91
+ * <en/> The y spacing between the title and subtitle
92
+ * @defaultValue 8
93
+ */
94
+ spacing?: number;
95
+ /**
96
+ * <zh/> 标题内边距
97
+ *
98
+ * <en/> whole title padding
99
+ * @defaultValue [16, 24, 0, 24]
100
+ */
101
+ padding?: number | number[];
102
+ /**
103
+ * <zh/> 标题内容
104
+ *
105
+ * <en/> title text
106
+ */
107
+ [titleKey]: string;
108
+ /**
109
+ * <zh/> 副标题内容
110
+ *
111
+ * <en/> subtitle text
112
+ */
113
+ [subtitleKey]?: string | null;
114
+ /**
115
+ * <zh/> 标题画布类名,传入外置容器时不生效
116
+ *
117
+ * <en/> The class name of the title canvas, which does not take effect when an external container is passed in
118
+ */
119
+ className?: string;
120
+ }
121
+
122
+ export class Title extends BasePlugin<TitleOptions> {
123
+ private canvas!: Canvas;
124
+ private container!: HTMLElement;
125
+
126
+ private get padding() {
127
+ return parsePadding(this.options.padding);
128
+ }
129
+
130
+ constructor(context: RuntimeContext, options: TitleOptions) {
131
+ const combineOption = Object.assign({}, defaultOptions, options);
132
+ super(context, combineOption);
133
+
134
+ this.bindEvents();
135
+ }
136
+
137
+ private onRender = () => {
138
+ const canvas = this.updateCanvas();
139
+ this.renderTitle(canvas);
140
+ };
141
+
142
+ private bindEvents() {
143
+ const { graph } = this.context;
144
+ graph.on(GraphEvent.AFTER_RENDER, this.onRender);
145
+ graph.on(GraphEvent.AFTER_ANIMATE, this.onRender);
146
+ }
147
+
148
+ private unbindEvents() {
149
+ const { graph } = this.context;
150
+ graph.off(GraphEvent.AFTER_RENDER, this.onRender);
151
+ graph.off(GraphEvent.AFTER_ANIMATE, this.onRender);
152
+ }
153
+
154
+ public destroy(): void {
155
+ this.unbindEvents();
156
+ this.canvas?.destroy();
157
+ this.container?.remove();
158
+ super.destroy();
159
+ }
160
+
161
+ private updateCanvas() {
162
+ const { size, className, align } = this.options;
163
+ const [width] = this.context.canvas.getSize();
164
+ const [pt = 0, , pb = 0] = this.padding;
165
+ const height = size + pt + pb;
166
+
167
+ if (this.canvas) {
168
+ const { width: w, height: h } = this.canvas.getConfig();
169
+ if (width !== w || height !== h) this.canvas.resize(width, height);
170
+ } else {
171
+ const positions = {
172
+ left: 'left-top',
173
+ center: 'top',
174
+ right: 'right-top',
175
+ } as const;
176
+
177
+ const [$container, canvas] = createPluginCanvas({
178
+ width,
179
+ height,
180
+ placement: positions[align] || positions.left,
181
+ className: 'title-canvas',
182
+ graphCanvas: this.context.canvas,
183
+ });
184
+
185
+ if (className) $container.classList.add(className);
186
+
187
+ this.container = $container;
188
+ this.canvas = canvas;
189
+ }
190
+
191
+ return this.canvas;
192
+ }
193
+
194
+ private renderTitle(canvas: Canvas) {
195
+ const titles = new TitleComponent({
196
+ options: this.options,
197
+ ctx: this.context,
198
+ });
199
+
200
+ canvas.removeChildren();
201
+ titles.getTitle().forEach((label) => {
202
+ if (label) canvas.appendChild(label);
203
+ });
204
+ }
205
+ }
206
+
207
+ class TitleComponent {
208
+ private options: TitleOptions;
209
+
210
+ private context: RuntimeContext;
211
+ private get padding() {
212
+ return parsePadding(this.options.padding);
213
+ }
214
+
215
+ constructor(props: { ctx: RuntimeContext; options: TitleOptions }) {
216
+ const { options, ctx } = props;
217
+
218
+ this.options = options;
219
+
220
+ this.context = ctx;
221
+ }
222
+
223
+ public getTitle() {
224
+ const {
225
+ [titleKey]: propsTitle,
226
+ [subtitleKey]: propsSubtitle,
227
+ spacing = 44,
228
+ padding,
229
+ align,
230
+ ...style
231
+ } = this.options;
232
+
233
+ const titleText = propsTitle;
234
+ const subTitleText = propsSubtitle;
235
+
236
+ const titleStyle = subStyleProps(style, titleKey) as LabelStyleProps;
237
+ const subtitleStyle = subStyleProps(style, subtitleKey) as LabelStyleProps;
238
+
239
+ const [topGraphWidth] = this.context.graph.getSize();
240
+ const [pt = 0, pr = 0, , pl = 0] = this.padding;
241
+ const canvasWidth = topGraphWidth;
242
+ const textWidth = canvasWidth - pl - pr;
243
+
244
+ let subTitle: Label | null = null;
245
+
246
+ let alignX = pl;
247
+ let textAlign = 'left' as 'left' | 'center' | 'right';
248
+
249
+ switch (align) {
250
+ case 'left':
251
+ alignX = pl;
252
+ textAlign = 'left';
253
+ break;
254
+ case 'center':
255
+ alignX = canvasWidth / 2;
256
+ textAlign = 'center';
257
+ break;
258
+
259
+ case 'right':
260
+ alignX = canvasWidth - pr;
261
+ textAlign = 'right';
262
+ break;
263
+ default:
264
+ alignX = pl;
265
+ textAlign = 'left';
266
+ }
267
+
268
+ const title = new Label({
269
+ className: titleKey,
270
+ style: {
271
+ ...defaultTitleStyle,
272
+ wordWrapWidth: textWidth - 5,
273
+ x: alignX,
274
+ y: pt,
275
+ textAlign,
276
+ ...titleStyle,
277
+ text: titleText,
278
+ },
279
+ });
280
+
281
+ const titleBBox = title.getBBox();
282
+
283
+ if (subTitleText) {
284
+ subTitle = new Label({
285
+ className: 'subTitle',
286
+ style: {
287
+ ...defaultSubTitleStyle,
288
+ wordWrapWidth: textWidth - 5,
289
+ x: alignX,
290
+ y: titleBBox.height + spacing + pt,
291
+ textAlign,
292
+ ...subtitleStyle,
293
+ text: subTitleText,
294
+ },
295
+ });
296
+ }
297
+
298
+ return [title, subTitle];
299
+ }
300
+ }
@@ -87,6 +87,7 @@ import {
87
87
  Minimap,
88
88
  Snapline,
89
89
  Timebar,
90
+ Title,
90
91
  Toolbar,
91
92
  Tooltip,
92
93
  Watermark,
@@ -208,6 +209,7 @@ const BUILT_IN_EXTENSIONS: ExtensionRegistry = {
208
209
  minimap: Minimap,
209
210
  snapline: Snapline,
210
211
  timebar: Timebar,
212
+ title: Title,
211
213
  toolbar: Toolbar,
212
214
  tooltip: Tooltip,
213
215
  watermark: Watermark,
@@ -504,6 +504,40 @@ export class Graph extends EventEmitter {
504
504
  public getData(): Required<GraphData> {
505
505
  return this.context.model.getData();
506
506
  }
507
+ /**
508
+ * <zh/> 判断图中是否存在指定节点
509
+ * <en/> Determine whether a specified node exists in the graph
510
+ * @param {ID} id
511
+ * @returns {boolean}
512
+ * @remarks <zh/> 判断图中是否存在指定节点,避免在不存在的节点上进行操作
513
+ * <en/> Determine whether a specified node exists in the graph and avoid operating on non-existent nodes
514
+ */
515
+ public hasNode(id: ID): boolean {
516
+ return this.context.model.hasNode(id);
517
+ }
518
+ /**
519
+ * <zh/> 判断图中是否存在指定边
520
+ * <en/> Determine whether a specified edge exists in the graph
521
+ * @param {ID} id
522
+ * @returns {boolean}
523
+ * @remarks <zh/> 判断图中是否存在指定边,避免在不存在的边上进行操作
524
+ * <en/> Determine whether a specified edge exists in the graph and avoid operating on non-existent edges
525
+ */
526
+ public hasEdge(id: ID): boolean {
527
+ return this.context.model.hasEdge(id);
528
+ }
529
+
530
+ /**
531
+ * <zh/> 判断图中是否存在指定组合
532
+ * <en/> Determine whether a specified combo exists in the graph
533
+ * @param {ID} id
534
+ * @returns {boolean}
535
+ * @remarks <zh/> 判断图中是否存在指定组合,避免在不存在的组合上进行操作
536
+ * <en/> Determine whether a specified combo exists in the graph and avoid operating on non-existent combos
537
+ */
538
+ public hasCombo(id: ID): boolean {
539
+ return this.context.model.hasCombo(id);
540
+ }
507
541
 
508
542
  /**
509
543
  * <zh/> 获取单个元素数据
@@ -296,7 +296,12 @@ export class LayoutController {
296
296
  }
297
297
 
298
298
  public getLayoutData(options: STDLayoutOptions): GraphData {
299
- const { nodeFilter = () => true, preLayout = false, isLayoutInvisibleNodes = false } = options;
299
+ const {
300
+ nodeFilter = () => true,
301
+ comboFilter = () => true,
302
+ preLayout = false,
303
+ isLayoutInvisibleNodes = false,
304
+ } = options;
300
305
  const { nodes, edges, combos } = this.context.model.getData();
301
306
 
302
307
  const { element, model } = this.context;
@@ -320,9 +325,10 @@ export class LayoutController {
320
325
  };
321
326
 
322
327
  const nodesToLayout = nodes.filter(filterFn);
328
+ const combosToLayout = combos.filter(comboFilter);
323
329
 
324
330
  const nodeLikeIdsMap = new Map<ID, NodeData>(nodesToLayout.map((node) => [idOf(node), node]));
325
- combos.forEach((combo) => nodeLikeIdsMap.set(idOf(combo), combo));
331
+ combosToLayout.forEach((combo) => nodeLikeIdsMap.set(idOf(combo), combo));
326
332
 
327
333
  const edgesToLayout = edges.filter(({ source, target }) => {
328
334
  return nodeLikeIdsMap.has(source) && nodeLikeIdsMap.has(target);
@@ -331,7 +337,7 @@ export class LayoutController {
331
337
  return {
332
338
  nodes: nodesToLayout,
333
339
  edges: edgesToLayout,
334
- combos,
340
+ combos: combosToLayout,
335
341
  };
336
342
  }
337
343
 
@@ -1,7 +1,15 @@
1
1
  import { AABB, ICamera } from '@antv/g';
2
2
  import { clamp, isNumber, pick } from '@antv/util';
3
3
  import { AnimationType, GraphEvent } from '../constants';
4
- import type { FitViewOptions, ID, Point, TransformOptions, Vector2, ViewportAnimationEffectTiming } from '../types';
4
+ import type {
5
+ FitViewOptions,
6
+ ID,
7
+ Point,
8
+ TransformOptions,
9
+ Vector2,
10
+ Vector3,
11
+ ViewportAnimationEffectTiming,
12
+ } from '../types';
5
13
  import type { Element } from '../types/element';
6
14
  import { getAnimationOptions } from '../utils/animation';
7
15
  import { getBBoxSize, getCombinedBBox, getExpandedBBox, isBBoxInside, isPointInBBox } from '../utils/bbox';
@@ -131,8 +139,8 @@ export class ViewportController {
131
139
 
132
140
  return mode === 'relative'
133
141
  ? {
134
- position: add(position, delta),
135
- focalPoint: add(focalPoint, delta),
142
+ position: add(position as Vector3, delta),
143
+ focalPoint: add(focalPoint as Vector3, delta),
136
144
  }
137
145
  : {
138
146
  position: add([cx, cy, position[2]], delta),
@@ -225,6 +233,9 @@ export class ViewportController {
225
233
  const scale = direction === 'x' ? scaleX : direction === 'y' ? scaleY : Math.min(scaleX, scaleY);
226
234
 
227
235
  const _animation = this.getAnimation(animation);
236
+ if (!Number.isFinite(scale)) {
237
+ return;
238
+ }
228
239
  await this.transform(
229
240
  {
230
241
  mode: 'relative',
@@ -179,6 +179,7 @@ export function create(tokens: ThemeTokens): Theme {
179
179
  badgeFill: '#fff',
180
180
  badgeFontSize: 8,
181
181
  badgeOffsetX: 10,
182
+ badgeBackgroundOpacity: 1,
182
183
  fillOpacity: 1,
183
184
  halo: false,
184
185
  haloLineWidth: 12,
@@ -121,9 +121,23 @@ export class ProcessParallelEdges extends BaseTransform<ProcessParallelEdgesOpti
121
121
  combosToUpdate.forEach(addRelatedEdges);
122
122
 
123
123
  const pushParallelEdges = (edge: EdgeData) => {
124
- const edgeData = model.getEdgeData().map((edge) => getEdgeEndsContext(model, edge));
125
- const parallelEdges = getParallelEdges(edge, edgeData, true);
126
- parallelEdges.forEach((e) => !edges.has(idOf(e)) && edges.set(idOf(e), e));
124
+ // 获取已被标记删除的边ID集合
125
+ // Get the set of edge IDs that have been marked for removal
126
+ const removedEdgeIds = new Set(input.remove.edges.keys());
127
+
128
+ // 过滤掉已删除的边,避免重定向后重新添加(修复combo收起时内部边变成loop边的问题)
129
+ // Filter out removed edges to prevent them from being re-added after redirection (fixes the issue where internal edges become loop edges when combo collapses)
130
+ const validEdgeData = model
131
+ .getEdgeData()
132
+ .filter((edge) => !removedEdgeIds.has(idOf(edge)))
133
+ .map((edge) => getEdgeEndsContext(model, edge));
134
+
135
+ // 查找平行边并添加到处理列表,确保只处理有效的边
136
+ // Find parallel edges and add them to the processing list, ensuring only valid edges are processed
137
+ getParallelEdges(edge, validEdgeData, true).forEach((e) => {
138
+ const id = idOf(e);
139
+ if (!edges.has(id)) edges.set(id, e);
140
+ });
127
141
  };
128
142
 
129
143
  if (edgesToRemove.size) edgesToRemove.forEach(pushParallelEdges);
@@ -148,7 +148,7 @@ export function isSimplePort(portStyle: NodePortStyleProps): boolean {
148
148
  * @returns <zh/> 连接桩的位置 | <en/> Port Position
149
149
  */
150
150
  export function getPortPosition(port: Port): Point {
151
- return isPoint(port) ? port : port.getPosition();
151
+ return isPoint(port) ? port : (port.getPosition() as Point);
152
152
  }
153
153
 
154
154
  /**
@@ -246,7 +246,7 @@ export function getPortConnectionPoint(port: Port, opposite: Node | Port): Point
246
246
  if (isPoint(port)) return port;
247
247
 
248
248
  // 1. linkToCenter 为 true,则返回连接桩的中心 | If linkToCenter is true, return the center of the port
249
- if (port.attributes.linkToCenter) return port.getPosition();
249
+ if (port.attributes.linkToCenter) return port.getPosition() as Point;
250
250
 
251
251
  // 2. 推导对端的具体点:如果是连接桩或节点,则返回它的中心;如果是具体点,则直接返回
252
252
  // 2. Get a specific opposite point: if it is a port or a node, return its center; if it is a specific point, return directly
@@ -257,7 +257,7 @@ export function getPortConnectionPoint(port: Port, opposite: Node | Port): Point
257
257
  : opposite.getPosition();
258
258
 
259
259
  // 3. 返回连接桩边界上的交点 | Return the intersection point on the port boundary
260
- return getEllipseIntersectPoint(oppositePosition, port.getBounds());
260
+ return getEllipseIntersectPoint(oppositePosition as Point, port.getBounds());
261
261
  }
262
262
 
263
263
  /**
@@ -275,7 +275,7 @@ export function getNodeConnectionPoint(nodeLike: Node | Combo, opposite: Node |
275
275
  ? opposite
276
276
  : isNode(opposite)
277
277
  ? opposite.getCenter()
278
- : opposite.getPosition();
278
+ : (opposite.getPosition() as Point);
279
279
  return nodeLike.getIntersectPoint(oppositePosition) || nodeLike.getCenter();
280
280
  }
281
281
 
@@ -544,6 +544,6 @@ export function markToBeDestroyed(element: DisplayObject) {
544
544
  * @param element - <zh/> 图形 | <en/> element
545
545
  * @returns <zh/> 是否即将销毁 | <en/> whether the element is to be destroyed
546
546
  */
547
- export function isToBeDestroyed(element: DisplayObject) {
547
+ export function isToBeDestroyed(element: DisplayObject | unknown) {
548
548
  return get(element, '__to_be_destroyed__', false);
549
549
  }
@@ -219,3 +219,20 @@ export function rad(a: Vector2 | Vector3): number {
219
219
  if (!x && !y) return 0;
220
220
  return Math.atan2(y, x);
221
221
  }
222
+
223
+ /**
224
+ * <zh/> 旋转向量(角度制)
225
+ *
226
+ * <en/> Rotational vector (Angle system)
227
+ * @param a - <zh/> 向量 | <en/> The vector
228
+ * @param angle - <zh/> 旋转角度 | <en/> The rotation angle
229
+ * @returns <zh/> 向量 | <en/> The vector
230
+ */
231
+ export function rotate(a: Vector2, angle: number): Vector2 {
232
+ const [dx, dy] = a;
233
+ if (angle % 360 === 0) return [dx, dy];
234
+ const rad = (angle * Math.PI) / 180;
235
+ const cos = Math.cos(rad);
236
+ const sin = Math.sin(rad);
237
+ return [dx * cos - dy * sin, dx * sin + dy * cos];
238
+ }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '5.0.49';
1
+ export const version = '5.0.50';