@antv/g6 5.0.44 → 5.0.46

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 (204) hide show
  1. package/dist/g6.min.js +11 -11
  2. package/dist/lib/behaviors/zoom-canvas.d.ts +9 -1
  3. package/dist/lib/elements/nodes/image.d.ts +1 -0
  4. package/dist/lib/plugins/edge-filter-lens/index.d.ts +2 -2
  5. package/dist/lib/plugins/grid-line.d.ts +19 -1
  6. package/dist/lib/plugins/hull/hull/format.d.ts +9 -0
  7. package/dist/lib/plugins/hull/hull/grid_handle.d.ts +15 -0
  8. package/dist/lib/plugins/hull/hull/index.d.ts +3 -0
  9. package/dist/lib/plugins/hull/hull/monotone-convex-hull-2d.d.ts +2 -0
  10. package/dist/lib/plugins/hull/hull/robust-orientation.d.ts +2 -0
  11. package/dist/lib/plugins/hull/hull/robust-scale.d.ts +1 -0
  12. package/dist/lib/plugins/hull/hull/robust-segment-intersect.d.ts +2 -0
  13. package/dist/lib/plugins/hull/hull/robust-subtract.d.ts +1 -0
  14. package/dist/lib/plugins/hull/hull/robust-sum.d.ts +1 -0
  15. package/dist/lib/plugins/hull/hull/two-product.d.ts +1 -0
  16. package/dist/lib/plugins/hull/hull/two-sum.d.ts +1 -0
  17. package/dist/lib/plugins/toolbar/util.d.ts +4 -0
  18. package/dist/lib/registry/register.d.ts +1 -5
  19. package/dist/lib/transforms/process-parallel-edges.d.ts +14 -2
  20. package/dist/lib/utils/element.d.ts +9 -9
  21. package/dist/lib/version.d.ts +1 -1
  22. package/esm/behaviors/brush-select.js +3 -1
  23. package/esm/behaviors/brush-select.js.map +1 -1
  24. package/esm/behaviors/drag-element.js +2 -0
  25. package/esm/behaviors/drag-element.js.map +1 -1
  26. package/esm/behaviors/zoom-canvas.d.ts +9 -1
  27. package/esm/behaviors/zoom-canvas.js +2 -2
  28. package/esm/behaviors/zoom-canvas.js.map +1 -1
  29. package/esm/elements/nodes/image.d.ts +1 -0
  30. package/esm/elements/nodes/image.js +13 -2
  31. package/esm/elements/nodes/image.js.map +1 -1
  32. package/esm/plugins/edge-filter-lens/index.d.ts +2 -2
  33. package/esm/plugins/edge-filter-lens/index.js +2 -0
  34. package/esm/plugins/edge-filter-lens/index.js.map +1 -1
  35. package/esm/plugins/fisheye/index.js +3 -0
  36. package/esm/plugins/fisheye/index.js.map +1 -1
  37. package/esm/plugins/grid-line.d.ts +19 -1
  38. package/esm/plugins/grid-line.js +42 -5
  39. package/esm/plugins/grid-line.js.map +1 -1
  40. package/esm/plugins/hull/hull/format.d.ts +9 -0
  41. package/esm/plugins/hull/hull/format.js +20 -0
  42. package/esm/plugins/hull/hull/format.js.map +1 -0
  43. package/esm/plugins/hull/hull/grid_handle.d.ts +15 -0
  44. package/esm/plugins/hull/hull/grid_handle.js +66 -0
  45. package/esm/plugins/hull/hull/grid_handle.js.map +1 -0
  46. package/esm/plugins/hull/hull/index.d.ts +3 -0
  47. package/esm/plugins/hull/hull/index.js +150 -0
  48. package/esm/plugins/hull/hull/index.js.map +1 -0
  49. package/esm/plugins/hull/hull/monotone-convex-hull-2d.d.ts +2 -0
  50. package/esm/plugins/hull/hull/monotone-convex-hull-2d.js +63 -0
  51. package/esm/plugins/hull/hull/monotone-convex-hull-2d.js.map +1 -0
  52. package/esm/plugins/hull/hull/robust-orientation.d.ts +2 -0
  53. package/esm/plugins/hull/hull/robust-orientation.js +145 -0
  54. package/esm/plugins/hull/hull/robust-orientation.js.map +1 -0
  55. package/esm/plugins/hull/hull/robust-scale.d.ts +1 -0
  56. package/esm/plugins/hull/hull/robust-scale.js +47 -0
  57. package/esm/plugins/hull/hull/robust-scale.js.map +1 -0
  58. package/esm/plugins/hull/hull/robust-segment-intersect.d.ts +2 -0
  59. package/esm/plugins/hull/hull/robust-segment-intersect.js +29 -0
  60. package/esm/plugins/hull/hull/robust-segment-intersect.js.map +1 -0
  61. package/esm/plugins/hull/hull/robust-subtract.d.ts +1 -0
  62. package/esm/plugins/hull/hull/robust-subtract.js +161 -0
  63. package/esm/plugins/hull/hull/robust-subtract.js.map +1 -0
  64. package/esm/plugins/hull/hull/robust-sum.d.ts +1 -0
  65. package/esm/plugins/hull/hull/robust-sum.js +155 -0
  66. package/esm/plugins/hull/hull/robust-sum.js.map +1 -0
  67. package/esm/plugins/hull/hull/two-product.d.ts +1 -0
  68. package/esm/plugins/hull/hull/two-product.js +24 -0
  69. package/esm/plugins/hull/hull/two-product.js.map +1 -0
  70. package/esm/plugins/hull/hull/two-sum.d.ts +1 -0
  71. package/esm/plugins/hull/hull/two-sum.js +15 -0
  72. package/esm/plugins/hull/hull/two-sum.js.map +1 -0
  73. package/esm/plugins/hull/index.js +1 -1
  74. package/esm/plugins/hull/index.js.map +1 -1
  75. package/esm/plugins/minimap/index.js +3 -1
  76. package/esm/plugins/minimap/index.js.map +1 -1
  77. package/esm/plugins/toolbar/index.js +6 -3
  78. package/esm/plugins/toolbar/index.js.map +1 -1
  79. package/esm/plugins/toolbar/util.d.ts +4 -0
  80. package/esm/plugins/toolbar/util.js.map +1 -1
  81. package/esm/registry/register.d.ts +1 -5
  82. package/esm/registry/register.js +4 -10
  83. package/esm/registry/register.js.map +1 -1
  84. package/esm/runtime/graph.js +1 -1
  85. package/esm/runtime/graph.js.map +1 -1
  86. package/esm/runtime/layout.js +4 -4
  87. package/esm/runtime/layout.js.map +1 -1
  88. package/esm/transforms/process-parallel-edges.d.ts +14 -2
  89. package/esm/transforms/process-parallel-edges.js +35 -10
  90. package/esm/transforms/process-parallel-edges.js.map +1 -1
  91. package/esm/utils/edge.js +5 -4
  92. package/esm/utils/edge.js.map +1 -1
  93. package/esm/utils/element.d.ts +9 -9
  94. package/esm/utils/element.js +30 -20
  95. package/esm/utils/element.js.map +1 -1
  96. package/esm/version.d.ts +1 -1
  97. package/esm/version.js +1 -1
  98. package/lib/behaviors/brush-select.js +3 -1
  99. package/lib/behaviors/brush-select.js.map +1 -1
  100. package/lib/behaviors/drag-element.js +2 -0
  101. package/lib/behaviors/drag-element.js.map +1 -1
  102. package/lib/behaviors/zoom-canvas.d.ts +9 -1
  103. package/lib/behaviors/zoom-canvas.js +2 -2
  104. package/lib/behaviors/zoom-canvas.js.map +1 -1
  105. package/lib/elements/nodes/image.d.ts +1 -0
  106. package/lib/elements/nodes/image.js +13 -2
  107. package/lib/elements/nodes/image.js.map +1 -1
  108. package/lib/plugins/edge-filter-lens/index.d.ts +2 -2
  109. package/lib/plugins/edge-filter-lens/index.js +2 -0
  110. package/lib/plugins/edge-filter-lens/index.js.map +1 -1
  111. package/lib/plugins/fisheye/index.js +3 -0
  112. package/lib/plugins/fisheye/index.js.map +1 -1
  113. package/lib/plugins/grid-line.d.ts +19 -1
  114. package/lib/plugins/grid-line.js +41 -4
  115. package/lib/plugins/grid-line.js.map +1 -1
  116. package/lib/plugins/hull/hull/format.d.ts +9 -0
  117. package/lib/plugins/hull/hull/format.js +23 -0
  118. package/lib/plugins/hull/hull/format.js.map +1 -0
  119. package/lib/plugins/hull/hull/grid_handle.d.ts +15 -0
  120. package/lib/plugins/hull/hull/grid_handle.js +71 -0
  121. package/lib/plugins/hull/hull/grid_handle.js.map +1 -0
  122. package/lib/plugins/hull/hull/index.d.ts +3 -0
  123. package/lib/plugins/hull/hull/index.js +153 -0
  124. package/lib/plugins/hull/hull/index.js.map +1 -0
  125. package/lib/plugins/hull/hull/monotone-convex-hull-2d.d.ts +2 -0
  126. package/lib/plugins/hull/hull/monotone-convex-hull-2d.js +68 -0
  127. package/lib/plugins/hull/hull/monotone-convex-hull-2d.js.map +1 -0
  128. package/lib/plugins/hull/hull/robust-orientation.d.ts +2 -0
  129. package/lib/plugins/hull/hull/robust-orientation.js +146 -0
  130. package/lib/plugins/hull/hull/robust-orientation.js.map +1 -0
  131. package/lib/plugins/hull/hull/robust-scale.d.ts +1 -0
  132. package/lib/plugins/hull/hull/robust-scale.js +49 -0
  133. package/lib/plugins/hull/hull/robust-scale.js.map +1 -0
  134. package/lib/plugins/hull/hull/robust-segment-intersect.d.ts +2 -0
  135. package/lib/plugins/hull/hull/robust-segment-intersect.js +35 -0
  136. package/lib/plugins/hull/hull/robust-segment-intersect.js.map +1 -0
  137. package/lib/plugins/hull/hull/robust-subtract.d.ts +1 -0
  138. package/lib/plugins/hull/hull/robust-subtract.js +163 -0
  139. package/lib/plugins/hull/hull/robust-subtract.js.map +1 -0
  140. package/lib/plugins/hull/hull/robust-sum.d.ts +1 -0
  141. package/lib/plugins/hull/hull/robust-sum.js +157 -0
  142. package/lib/plugins/hull/hull/robust-sum.js.map +1 -0
  143. package/lib/plugins/hull/hull/two-product.d.ts +1 -0
  144. package/lib/plugins/hull/hull/two-product.js +26 -0
  145. package/lib/plugins/hull/hull/two-product.js.map +1 -0
  146. package/lib/plugins/hull/hull/two-sum.d.ts +1 -0
  147. package/lib/plugins/hull/hull/two-sum.js +17 -0
  148. package/lib/plugins/hull/hull/two-sum.js.map +1 -0
  149. package/lib/plugins/hull/index.js +2 -5
  150. package/lib/plugins/hull/index.js.map +1 -1
  151. package/lib/plugins/minimap/index.js +3 -1
  152. package/lib/plugins/minimap/index.js.map +1 -1
  153. package/lib/plugins/toolbar/index.js +6 -3
  154. package/lib/plugins/toolbar/index.js.map +1 -1
  155. package/lib/plugins/toolbar/util.d.ts +4 -0
  156. package/lib/plugins/toolbar/util.js.map +1 -1
  157. package/lib/registry/register.d.ts +1 -5
  158. package/lib/registry/register.js +4 -10
  159. package/lib/registry/register.js.map +1 -1
  160. package/lib/runtime/graph.js +1 -1
  161. package/lib/runtime/graph.js.map +1 -1
  162. package/lib/runtime/layout.js +4 -4
  163. package/lib/runtime/layout.js.map +1 -1
  164. package/lib/transforms/process-parallel-edges.d.ts +14 -2
  165. package/lib/transforms/process-parallel-edges.js +35 -10
  166. package/lib/transforms/process-parallel-edges.js.map +1 -1
  167. package/lib/utils/edge.js +5 -4
  168. package/lib/utils/edge.js.map +1 -1
  169. package/lib/utils/element.d.ts +9 -9
  170. package/lib/utils/element.js +30 -20
  171. package/lib/utils/element.js.map +1 -1
  172. package/lib/version.d.ts +1 -1
  173. package/lib/version.js +1 -1
  174. package/package.json +9 -10
  175. package/src/behaviors/brush-select.ts +3 -2
  176. package/src/behaviors/drag-element.ts +1 -0
  177. package/src/behaviors/zoom-canvas.ts +10 -2
  178. package/src/elements/nodes/image.ts +14 -2
  179. package/src/plugins/edge-filter-lens/index.ts +4 -4
  180. package/src/plugins/fisheye/index.ts +2 -0
  181. package/src/plugins/grid-line.ts +72 -8
  182. package/src/plugins/hull/hull/README.md +1 -0
  183. package/src/plugins/hull/hull/format.ts +29 -0
  184. package/src/plugins/hull/hull/grid_handle.ts +73 -0
  185. package/src/plugins/hull/hull/index.ts +203 -0
  186. package/src/plugins/hull/hull/monotone-convex-hull-2d.ts +76 -0
  187. package/src/plugins/hull/hull/robust-orientation.ts +443 -0
  188. package/src/plugins/hull/hull/robust-scale.ts +53 -0
  189. package/src/plugins/hull/hull/robust-segment-intersect.ts +29 -0
  190. package/src/plugins/hull/hull/robust-subtract.ts +187 -0
  191. package/src/plugins/hull/hull/robust-sum.ts +175 -0
  192. package/src/plugins/hull/hull/two-product.ts +31 -0
  193. package/src/plugins/hull/hull/two-sum.ts +17 -0
  194. package/src/plugins/hull/index.ts +1 -1
  195. package/src/plugins/minimap/index.ts +6 -8
  196. package/src/plugins/toolbar/index.ts +1 -1
  197. package/src/plugins/toolbar/util.ts +4 -0
  198. package/src/registry/register.ts +5 -8
  199. package/src/runtime/graph.ts +1 -1
  200. package/src/runtime/layout.ts +4 -4
  201. package/src/transforms/process-parallel-edges.ts +41 -10
  202. package/src/utils/edge.ts +5 -4
  203. package/src/utils/element.ts +33 -22
  204. package/src/version.ts +1 -1
@@ -78,6 +78,12 @@ export class ProcessParallelEdges extends BaseTransform<ProcessParallelEdgesOpti
78
78
  super(context, Object.assign({}, ProcessParallelEdges.defaultOptions, options));
79
79
  }
80
80
 
81
+ /**
82
+ * <zh/> 在每次绘制前处理平行边
83
+ *
84
+ * <en/> Process parallel edges before each drawing
85
+ * @param input
86
+ */
81
87
  public beforeDraw(input: DrawData): DrawData {
82
88
  const edges = this.getAffectedParallelEdges(input);
83
89
 
@@ -90,6 +96,12 @@ export class ProcessParallelEdges extends BaseTransform<ProcessParallelEdgesOpti
90
96
  return input;
91
97
  }
92
98
 
99
+ /**
100
+ * <zh/> 获取受影响的平行边
101
+ *
102
+ * <en/> Get affected parallel edges
103
+ * @param input
104
+ */
93
105
  private getAffectedParallelEdges = (input: DrawData): Map<ID, EdgeData> => {
94
106
  const {
95
107
  add: { edges: edgesToAdd },
@@ -240,9 +252,9 @@ export class ProcessParallelEdges extends BaseTransform<ProcessParallelEdgesOpti
240
252
  }
241
253
 
242
254
  /**
243
- * <zh/> 按照端点分组
255
+ * <zh/> 优化的按照端点分组方法,时间复杂度O(n)
244
256
  *
245
- * <en/> Group by endpoints
257
+ * <en/> Optimized method to group by endpoints, time complexity O(n)
246
258
  * @param edges - <zh/> 边集合 | <en/> Edges
247
259
  * @returns <zh/> 端点分组后的边集合 | <en/> Edges grouped by endpoints
248
260
  */
@@ -250,6 +262,7 @@ export const groupByEndpoints = (edges: Map<ID, EdgeData>) => {
250
262
  const edgeMap = new Map<string, EdgeData[]>();
251
263
  const processedEdgesSet = new Set<ID>();
252
264
  const reverses: Record<string, boolean> = {};
265
+ const includedEdgesInGroup = new Map<string, Set<ID>>();
253
266
 
254
267
  for (const [id, edge] of edges) {
255
268
  if (processedEdgesSet.has(id)) continue;
@@ -257,18 +270,36 @@ export const groupByEndpoints = (edges: Map<ID, EdgeData>) => {
257
270
  const { source, target } = edge;
258
271
  const sourceTarget = `${source}-${target}`;
259
272
 
260
- if (!edgeMap.has(sourceTarget)) edgeMap.set(sourceTarget, []);
261
- edgeMap.get(sourceTarget)!.push(edge);
262
- processedEdgesSet.add(id);
273
+ if (!edgeMap.has(sourceTarget)) {
274
+ edgeMap.set(sourceTarget, []);
275
+ includedEdgesInGroup.set(sourceTarget, new Set<ID>());
276
+ }
277
+
278
+ const sourceTargetEdges = edgeMap.get(sourceTarget);
279
+ const includedEdges = includedEdgesInGroup.get(sourceTarget);
280
+
281
+ if (sourceTargetEdges && includedEdges && !includedEdges.has(id)) {
282
+ sourceTargetEdges.push(edge);
283
+ includedEdges.add(id);
284
+ processedEdgesSet.add(id);
285
+ }
263
286
 
264
287
  for (const [otherId, sedge] of edges) {
265
- if (processedEdgesSet.has(otherId)) continue;
288
+ if (processedEdgesSet.has(otherId) || otherId === id) continue;
266
289
 
267
290
  if (isParallelEdges(edge, sedge)) {
268
- edgeMap.get(sourceTarget)!.push(sedge);
269
- processedEdgesSet.add(otherId);
270
- if (source === sedge.target && target === sedge.source) {
271
- reverses[`${sedge.source}|${sedge.target}|${edgeMap.get(sourceTarget)!.length - 1}`] = true;
291
+ const groupEdges = edgeMap.get(sourceTarget);
292
+ const includedGroupEdges = includedEdgesInGroup.get(sourceTarget);
293
+
294
+ if (groupEdges && includedGroupEdges && !includedGroupEdges.has(otherId)) {
295
+ groupEdges.push(sedge);
296
+ includedGroupEdges.add(otherId);
297
+
298
+ if (source === sedge.target && target === sedge.source) {
299
+ reverses[`${sedge.source}|${sedge.target}|${groupEdges.length - 1}`] = true;
300
+ }
301
+
302
+ processedEdgesSet.add(otherId);
272
303
  }
273
304
  }
274
305
  }
package/src/utils/edge.ts CHANGED
@@ -241,9 +241,10 @@ export function getCubicPath(sourcePoint: Point, targetPoint: Point, controlPoin
241
241
  * @returns <zh/> 返回绘制折线的路径 | <en/> Returns the path for drawing a polyline
242
242
  */
243
243
  export function getPolylinePath(points: Point[], radius = 0, z = false): PathArray {
244
+ const targetIndex = points.length - 1;
244
245
  const sourcePoint = points[0];
245
- const targetPoint = points[points.length - 1];
246
- const controlPoints = points.slice(1, points.length - 1);
246
+ const targetPoint = points[targetIndex];
247
+ const controlPoints = points.slice(1, targetIndex);
247
248
  const pathArray: PathArray = [['M', sourcePoint[0], sourcePoint[1]]];
248
249
  controlPoints.forEach((midPoint, i) => {
249
250
  const prevPoint = controlPoints[i - 1] || sourcePoint;
@@ -390,7 +391,7 @@ export function getCubicLoopPath(
390
391
 
391
392
  // 3. 如果定义了连接桩,调整端点以与连接桩边界相交 | If the port is defined, adjust the endpoint to intersect with the port boundary
392
393
  if (sourcePort) sourcePoint = getPortConnectionPoint(sourcePort, controlPoints[0]);
393
- if (targetPort) targetPoint = getPortConnectionPoint(targetPort, controlPoints[controlPoints.length - 1]);
394
+ if (targetPort) targetPoint = getPortConnectionPoint(targetPort, controlPoints.at(-1) as Point);
394
395
 
395
396
  return getCubicPath(sourcePoint, targetPoint, controlPoints);
396
397
  }
@@ -463,7 +464,7 @@ export function getPolylineLoopPath(
463
464
 
464
465
  // 3. 如果定义了连接桩,调整端点以与连接桩边界相交 | If the port is defined, adjust the endpoint to intersect with the port boundary
465
466
  if (sourcePort) sourcePoint = getPortConnectionPoint(sourcePort, controlPoints[0]);
466
- if (targetPort) targetPoint = getPortConnectionPoint(targetPort, controlPoints[controlPoints.length - 1]);
467
+ if (targetPort) targetPoint = getPortConnectionPoint(targetPort, controlPoints.at(-1) as Point);
467
468
 
468
469
  return getPolylinePath([sourcePoint, ...controlPoints, targetPoint], radius);
469
470
  }
@@ -1,7 +1,7 @@
1
1
  import type { AABB, DisplayObject, TextStyleProps } from '@antv/g';
2
2
  import { get, isNumber, isString, set } from '@antv/util';
3
3
  import { BaseCombo, BaseEdge, BaseNode } from '../elements';
4
- import type { BaseShape } from '../elements/shapes';
4
+ import type { BaseShape, BaseShapeStyleProps } from '../elements/shapes';
5
5
  import type { Combo, Edge, Element, Node, NodePortStyleProps, Placement, Point, TriangleDirection } from '../types';
6
6
  import type { NodeLabelStyleProps, Port } from '../types/node';
7
7
  import { getBBoxHeight, getBBoxWidth } from './bbox';
@@ -71,6 +71,14 @@ const PORT_MAP: Record<string, Point> = {
71
71
  right: [1, 0.5],
72
72
  bottom: [0.5, 1],
73
73
  left: [0, 0.5],
74
+ 'left-top': [0, 0],
75
+ 'top-left': [0, 0],
76
+ 'left-bottom': [0, 1],
77
+ 'bottom-left': [0, 1],
78
+ 'right-top': [1, 0],
79
+ 'top-right': [1, 0],
80
+ 'right-bottom': [1, 1],
81
+ 'bottom-right': [1, 1],
74
82
  default: [0.5, 0.5],
75
83
  };
76
84
 
@@ -78,18 +86,18 @@ const PORT_MAP: Record<string, Point> = {
78
86
  * Get the Port x, y by `position`.
79
87
  * @param bbox - BBox of element.
80
88
  * @param placement - The position relative with element.
81
- * @param ports - The map of position.
89
+ * @param portMap - The map of position.
82
90
  * @param isRelative - Whether the position in MAP is relative.
83
91
  * @returns [x, y]
84
92
  */
85
93
  export function getPortXYByPlacement(
86
94
  bbox: AABB,
87
95
  placement?: Placement,
88
- ports: Record<string, Point> = PORT_MAP,
96
+ portMap: Record<string, Point> = PORT_MAP,
89
97
  isRelative = true,
90
98
  ): Point {
91
99
  const DEFAULT = [0.5, 0.5];
92
- const p: [number, number] = isString(placement) ? get(ports, placement.toLocaleLowerCase(), DEFAULT) : placement;
100
+ const p: [number, number] = isString(placement) ? get(portMap, placement.toLocaleLowerCase(), DEFAULT) : placement;
93
101
 
94
102
  if (!isRelative && isString(placement)) return p;
95
103
 
@@ -174,7 +182,7 @@ export function findPorts(
174
182
  * 3. If the node has no ports, return undefined.
175
183
  * @param node - <zh/> 节点 | <en/> Node
176
184
  * @param oppositeNode - <zh/> 对端节点 | <en/> Opposite Node
177
- * @param portKey - <zh/> 连接桩的 key | <en/> Port Key
185
+ * @param portKey - <zh/> 连接桩的键值(key) | <en/> Port Key
178
186
  * @param oppositePortKey - <zh/> 对端连接桩的 key | <en/> Opposite Port Key
179
187
  * @returns <zh/> 连接桩 | <en/> Port
180
188
  */
@@ -200,7 +208,7 @@ export function findPort(node: Node, oppositeNode: Node, portKey?: string, oppos
200
208
  * 2. If `portKey` is not specified, return positions of all ports.
201
209
  * 3. If the node has no ports, return the center of the node.
202
210
  * @param node - <zh/> 节点 | <en/> Node
203
- * @param portKey
211
+ * @param portKey - <zh/> 连接桩的键值(key),如不指定则返回所有 | <en/> Port Key, return all if not specified
204
212
  * @returns <zh/> 连接点 | <en/> Connection Point
205
213
  */
206
214
  function findConnectionPoints(node: Node, portKey?: string): Point[] {
@@ -230,7 +238,7 @@ export function getConnectionPoint(node: Port | Node | Combo, opposite: Node | P
230
238
  * <en/> Get the connection point of the port
231
239
  * @param port - <zh/> 连接桩 | <en/> Port
232
240
  * @param opposite - <zh/> 对端的具体点或节点 | <en/> Opposite Point or Node
233
- * @param oppositePort - <zh/> 对端连接桩 | <en/> Opposite Port
241
+ * // @param oppositePort - <zh/> 对端连接桩 | <en/> Opposite Port
234
242
  * @returns <zh/> 连接桩的连接点 | <en/> Port Point
235
243
  */
236
244
  export function getPortConnectionPoint(port: Port, opposite: Node | Port): Point {
@@ -240,8 +248,8 @@ export function getPortConnectionPoint(port: Port, opposite: Node | Port): Point
240
248
  // 1. linkToCenter 为 true,则返回连接桩的中心 | If linkToCenter is true, return the center of the port
241
249
  if (port.attributes.linkToCenter) return port.getPosition();
242
250
 
243
- // 2. 推导对端的具体点:如果是连接桩,则返回连接桩的中心;如果是节点,则返回节点的中心;如果是具体点则直接返回
244
- // 2. Derive the specific point of the opposite: if it is a port, return the center of the port; if it is a node, return the center of the node; if it is a specific point, return directly
251
+ // 2. 推导对端的具体点:如果是连接桩或节点,则返回它的中心;如果是具体点,则直接返回
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
245
253
  const oppositePosition = isPoint(opposite)
246
254
  ? opposite
247
255
  : isNode(opposite)
@@ -256,19 +264,19 @@ export function getPortConnectionPoint(port: Port, opposite: Node | Port): Point
256
264
  * <zh/> 获取节点的连接点
257
265
  *
258
266
  * <en/> Get the Node Connection Point
259
- * @param node - <zh/> 节点 | <en/> Node
267
+ * @param nodeLike - <zh/> 节点或组合 | <en/> Node or Combo
260
268
  * @param opposite - <zh/> 对端的具体点或节点 | <en/> Opposite Point or Node
261
- * @param oppositePort - <zh/> 对端连接桩 | <en/> Opposite Port
269
+ * // @param oppositePort - <zh/> 对端连接桩 | <en/> Opposite Port
262
270
  * @returns <zh/> 节点的连接点 | <en/> Node Point
263
271
  */
264
- export function getNodeConnectionPoint(node: Node, opposite: Node | Port): Point {
265
- if (!node || !opposite) return [0, 0, 0];
272
+ export function getNodeConnectionPoint(nodeLike: Node | Combo, opposite: Node | Port): Point {
273
+ if (!nodeLike || !opposite) return [0, 0, 0];
266
274
  const oppositePosition = isPoint(opposite)
267
275
  ? opposite
268
276
  : isNode(opposite)
269
277
  ? opposite.getCenter()
270
278
  : opposite.getPosition();
271
- return node.getIntersectPoint(oppositePosition) || node.getCenter();
279
+ return nodeLike.getIntersectPoint(oppositePosition) || nodeLike.getCenter();
272
280
  }
273
281
 
274
282
  /**
@@ -290,16 +298,19 @@ export function getTextStyleByPlacement(
290
298
  const direction = placement.split('-');
291
299
  const [x, y] = getXYByPlacement(bbox, placement);
292
300
 
293
- const textAlign = direction.includes('left') ? 'right' : direction.includes('right') ? 'left' : 'center';
301
+ const [top, bottom]: TextStyleProps['textBaseline'][] = isReverseBaseline ? ['bottom', 'top'] : ['top', 'bottom'];
294
302
 
295
- let textBaseline: TextStyleProps['textBaseline'] = direction.includes('top')
296
- ? 'bottom'
303
+ const textBaseline: TextStyleProps['textBaseline'] = direction.includes('top')
304
+ ? bottom
297
305
  : direction.includes('bottom')
298
- ? 'top'
306
+ ? top
299
307
  : 'middle';
300
- if (isReverseBaseline) {
301
- textBaseline = textBaseline === 'top' ? 'bottom' : textBaseline === 'bottom' ? 'top' : textBaseline;
302
- }
308
+
309
+ const textAlign: TextStyleProps['textAlign'] = direction.includes('left')
310
+ ? 'right'
311
+ : direction.includes('right')
312
+ ? 'left'
313
+ : 'center';
303
314
 
304
315
  return {
305
316
  transform: [['translate', x + offsetX, y + offsetY]],
@@ -475,7 +486,7 @@ export function isVisible(element: DisplayObject) {
475
486
  * @param element - <zh/> 元素 | <en/> element
476
487
  * @param style - <zh/> 样式 | <en/> style
477
488
  */
478
- export function setAttributes(element: BaseShape<any>, style: Record<string, any>) {
489
+ export function setAttributes(element: BaseShape<any>, style: Partial<BaseShapeStyleProps> & Record<string, any>) {
479
490
  const { zIndex, transform, transformOrigin, visibility, cursor, clipPath, component, ...rest } = style;
480
491
  Object.assign(element.attributes, rest);
481
492
 
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '5.0.44';
1
+ export const version = '5.0.46';