@antv/g6 5.0.33 → 5.0.35

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 (107) hide show
  1. package/dist/g6.min.js +3 -3
  2. package/dist/lib/behaviors/optimize-viewport-transform.d.ts +1 -1
  3. package/dist/lib/elements/edges/base-edge.d.ts +5 -5
  4. package/dist/lib/elements/nodes/base-node.d.ts +2 -0
  5. package/dist/lib/elements/shapes/base-shape.d.ts +2 -2
  6. package/dist/lib/exports.d.ts +2 -2
  7. package/dist/lib/layouts/fishbone.d.ts +2 -1
  8. package/dist/lib/layouts/index.d.ts +2 -0
  9. package/dist/lib/layouts/snake.d.ts +80 -0
  10. package/dist/lib/layouts/types.d.ts +3 -1
  11. package/dist/lib/plugins/minimap/index.d.ts +1 -1
  12. package/dist/lib/plugins/tooltip.d.ts +6 -0
  13. package/dist/lib/spec/canvas.d.ts +26 -2
  14. package/dist/lib/spec/graph.d.ts +60 -12
  15. package/dist/lib/spec/viewport.d.ts +4 -0
  16. package/dist/lib/utils/cache.d.ts +5 -5
  17. package/dist/lib/utils/style.d.ts +5 -5
  18. package/dist/lib/version.d.ts +1 -1
  19. package/esm/behaviors/optimize-viewport-transform.d.ts +1 -1
  20. package/esm/elements/edges/base-edge.d.ts +5 -5
  21. package/esm/elements/nodes/base-node.d.ts +2 -0
  22. package/esm/elements/nodes/base-node.js +2 -2
  23. package/esm/elements/nodes/base-node.js.map +1 -1
  24. package/esm/elements/shapes/base-shape.d.ts +2 -2
  25. package/esm/elements/shapes/base-shape.js +2 -2
  26. package/esm/exports.d.ts +2 -2
  27. package/esm/exports.js +1 -1
  28. package/esm/exports.js.map +1 -1
  29. package/esm/layouts/fishbone.d.ts +2 -1
  30. package/esm/layouts/fishbone.js +1 -1
  31. package/esm/layouts/fishbone.js.map +1 -1
  32. package/esm/layouts/index.d.ts +2 -0
  33. package/esm/layouts/index.js +1 -0
  34. package/esm/layouts/index.js.map +1 -1
  35. package/esm/layouts/snake.d.ts +80 -0
  36. package/esm/layouts/snake.js +162 -0
  37. package/esm/layouts/snake.js.map +1 -0
  38. package/esm/layouts/types.d.ts +3 -1
  39. package/esm/plugins/minimap/index.d.ts +1 -1
  40. package/esm/plugins/tooltip.d.ts +6 -0
  41. package/esm/plugins/tooltip.js +8 -6
  42. package/esm/plugins/tooltip.js.map +1 -1
  43. package/esm/registry/build-in.js +2 -1
  44. package/esm/registry/build-in.js.map +1 -1
  45. package/esm/spec/canvas.d.ts +26 -2
  46. package/esm/spec/graph.d.ts +60 -12
  47. package/esm/spec/viewport.d.ts +4 -0
  48. package/esm/utils/cache.d.ts +5 -5
  49. package/esm/utils/cache.js +5 -5
  50. package/esm/utils/style.d.ts +5 -5
  51. package/esm/utils/style.js +5 -5
  52. package/esm/version.d.ts +1 -1
  53. package/esm/version.js +1 -1
  54. package/lib/behaviors/optimize-viewport-transform.d.ts +1 -1
  55. package/lib/elements/edges/base-edge.d.ts +5 -5
  56. package/lib/elements/nodes/base-node.d.ts +2 -0
  57. package/lib/elements/nodes/base-node.js +2 -2
  58. package/lib/elements/nodes/base-node.js.map +1 -1
  59. package/lib/elements/shapes/base-shape.d.ts +2 -2
  60. package/lib/elements/shapes/base-shape.js +2 -2
  61. package/lib/exports.d.ts +2 -2
  62. package/lib/exports.js +3 -2
  63. package/lib/exports.js.map +1 -1
  64. package/lib/layouts/fishbone.d.ts +2 -1
  65. package/lib/layouts/fishbone.js +2 -2
  66. package/lib/layouts/fishbone.js.map +1 -1
  67. package/lib/layouts/index.d.ts +2 -0
  68. package/lib/layouts/index.js +3 -1
  69. package/lib/layouts/index.js.map +1 -1
  70. package/lib/layouts/snake.d.ts +80 -0
  71. package/lib/layouts/snake.js +166 -0
  72. package/lib/layouts/snake.js.map +1 -0
  73. package/lib/layouts/types.d.ts +3 -1
  74. package/lib/plugins/minimap/index.d.ts +1 -1
  75. package/lib/plugins/tooltip.d.ts +6 -0
  76. package/lib/plugins/tooltip.js +8 -6
  77. package/lib/plugins/tooltip.js.map +1 -1
  78. package/lib/registry/build-in.js +1 -0
  79. package/lib/registry/build-in.js.map +1 -1
  80. package/lib/spec/canvas.d.ts +26 -2
  81. package/lib/spec/graph.d.ts +60 -12
  82. package/lib/spec/viewport.d.ts +4 -0
  83. package/lib/utils/cache.d.ts +5 -5
  84. package/lib/utils/cache.js +5 -5
  85. package/lib/utils/style.d.ts +5 -5
  86. package/lib/utils/style.js +5 -5
  87. package/lib/version.d.ts +1 -1
  88. package/lib/version.js +1 -1
  89. package/package.json +1 -1
  90. package/src/behaviors/optimize-viewport-transform.ts +1 -1
  91. package/src/elements/edges/base-edge.ts +5 -5
  92. package/src/elements/nodes/base-node.ts +4 -2
  93. package/src/elements/shapes/base-shape.ts +2 -2
  94. package/src/exports.ts +2 -1
  95. package/src/layouts/fishbone.ts +3 -2
  96. package/src/layouts/index.ts +3 -0
  97. package/src/layouts/snake.ts +235 -0
  98. package/src/layouts/types.ts +5 -1
  99. package/src/plugins/minimap/index.ts +1 -1
  100. package/src/plugins/tooltip.ts +11 -4
  101. package/src/registry/build-in.ts +2 -0
  102. package/src/spec/canvas.ts +26 -2
  103. package/src/spec/graph.ts +60 -12
  104. package/src/spec/viewport.ts +4 -0
  105. package/src/utils/cache.ts +5 -5
  106. package/src/utils/style.ts +5 -5
  107. package/src/version.ts +1 -1
@@ -2,8 +2,8 @@ import type { DisplayObject } from '@antv/g';
2
2
  /**
3
3
  * <zh/> 缓存图形样式
4
4
  *
5
- * <en/> Cache graphic style
6
- * @param element - <zh/> 图形元素 | <en/> graphic element
5
+ * <en/> Cache shape style
6
+ * @param element - <zh/> 图形元素 | <en/> shape element
7
7
  * @param name - <zh/> 样式名 | <en/> style name
8
8
  */
9
9
  export declare function cacheStyle(element: DisplayObject, name: string | string[]): void;
@@ -11,7 +11,7 @@ export declare function cacheStyle(element: DisplayObject, name: string | string
11
11
  * <zh/> 获取缓存的样式
12
12
  *
13
13
  * <en/> Get cached style
14
- * @param element - <zh/> 图形元素 | <en/> graphic element
14
+ * @param element - <zh/> 图形元素 | <en/> shape element
15
15
  * @param name - <zh/> 样式名 | <en/> style name
16
16
  * @returns <zh/> 样式值 | <en/> style value
17
17
  */
@@ -20,7 +20,7 @@ export declare function getCachedStyle(element: DisplayObject, name: string): an
20
20
  * <zh/> 是否有缓存的样式
21
21
  *
22
22
  * <en/> Whether there is a cached style
23
- * @param element - <zh/> 图形元素 | <en/> graphic element
23
+ * @param element - <zh/> 图形元素 | <en/> shape element
24
24
  * @param name - <zh/> 样式名 | <en/> style name
25
25
  * @returns <zh/> 是否有缓存的样式 | <en/> Whether there is a cached style
26
26
  */
@@ -29,7 +29,7 @@ export declare function hasCachedStyle(element: DisplayObject, name: string): bo
29
29
  * <zh/> 设置缓存的样式
30
30
  *
31
31
  * <en/> Set cached style
32
- * @param element - <zh/> 图形元素 | <en/> graphic element
32
+ * @param element - <zh/> 图形元素 | <en/> shape element
33
33
  * @param name - <zh/> 样式名 | <en/> style name
34
34
  * @param value - <zh/> 样式值 | <en/> style value
35
35
  */
@@ -10,8 +10,8 @@ const getStyleCacheKey = (name) => `__${name}__`;
10
10
  /**
11
11
  * <zh/> 缓存图形样式
12
12
  *
13
- * <en/> Cache graphic style
14
- * @param element - <zh/> 图形元素 | <en/> graphic element
13
+ * <en/> Cache shape style
14
+ * @param element - <zh/> 图形元素 | <en/> shape element
15
15
  * @param name - <zh/> 样式名 | <en/> style name
16
16
  */
17
17
  function cacheStyle(element, name) {
@@ -26,7 +26,7 @@ function cacheStyle(element, name) {
26
26
  * <zh/> 获取缓存的样式
27
27
  *
28
28
  * <en/> Get cached style
29
- * @param element - <zh/> 图形元素 | <en/> graphic element
29
+ * @param element - <zh/> 图形元素 | <en/> shape element
30
30
  * @param name - <zh/> 样式名 | <en/> style name
31
31
  * @returns <zh/> 样式值 | <en/> style value
32
32
  */
@@ -37,7 +37,7 @@ function getCachedStyle(element, name) {
37
37
  * <zh/> 是否有缓存的样式
38
38
  *
39
39
  * <en/> Whether there is a cached style
40
- * @param element - <zh/> 图形元素 | <en/> graphic element
40
+ * @param element - <zh/> 图形元素 | <en/> shape element
41
41
  * @param name - <zh/> 样式名 | <en/> style name
42
42
  * @returns <zh/> 是否有缓存的样式 | <en/> Whether there is a cached style
43
43
  */
@@ -48,7 +48,7 @@ function hasCachedStyle(element, name) {
48
48
  * <zh/> 设置缓存的样式
49
49
  *
50
50
  * <en/> Set cached style
51
- * @param element - <zh/> 图形元素 | <en/> graphic element
51
+ * @param element - <zh/> 图形元素 | <en/> shape element
52
52
  * @param name - <zh/> 样式名 | <en/> style name
53
53
  * @param value - <zh/> 样式值 | <en/> style value
54
54
  */
@@ -17,7 +17,7 @@ export declare function computeElementCallbackStyle(callableStyle: Record<string
17
17
  /**
18
18
  * <zh/> 合并图形配置项
19
19
  *
20
- * <en/> Merge graphic configuration
20
+ * <en/> Merge shape configuration
21
21
  * @param opt1 - <zh/> 配置项1 | <en/> configuration 1
22
22
  * @param opt2 - <zh/> 配置项2 | <en/> configuration 2
23
23
  * @returns <zh/> 合并后的配置项 | <en/> merged configuration
@@ -26,13 +26,13 @@ export declare function mergeOptions(opt1: DisplayObjectConfig<any>, opt2: Displ
26
26
  /**
27
27
  * <zh/> 获取图形子图形样式
28
28
  *
29
- * <en/> Get the style of the sub-shape of the graphic
30
- * @param style - <zh/> 图形样式 | <en/> graphic style
29
+ * <en/> Get the style of the sub-shape of the shape
30
+ * @param style - <zh/> 图形样式 | <en/> shape style
31
31
  * @returns <zh/> 子图形样式 | <en/> sub-shape style
32
32
  * @remarks
33
33
  * <zh/> 从给定的属性对象中提取图形样式属性。删除特定的属性,如位置、变换和类名
34
34
  *
35
- * <en/> Extracts the graphic style properties from a given attribute object.
36
- * Removes specific properties like position, transformation, and class name.
35
+ * <en/> Extracts the shape styles from a given attribute object.
36
+ * Removes specific styles like position, transformation, and class name.
37
37
  */
38
38
  export declare function getSubShapeStyle<T extends Record<string, any>>(style: T): Omit<T, 'x' | 'y' | 'z' | 'transform' | 'transformOrigin' | 'className' | 'class' | 'zIndex' | 'visibility'>;
@@ -35,7 +35,7 @@ function computeElementCallbackStyle(callableStyle, context) {
35
35
  /**
36
36
  * <zh/> 合并图形配置项
37
37
  *
38
- * <en/> Merge graphic configuration
38
+ * <en/> Merge shape configuration
39
39
  * @param opt1 - <zh/> 配置项1 | <en/> configuration 1
40
40
  * @param opt2 - <zh/> 配置项2 | <en/> configuration 2
41
41
  * @returns <zh/> 合并后的配置项 | <en/> merged configuration
@@ -50,14 +50,14 @@ function mergeOptions(opt1, opt2) {
50
50
  /**
51
51
  * <zh/> 获取图形子图形样式
52
52
  *
53
- * <en/> Get the style of the sub-shape of the graphic
54
- * @param style - <zh/> 图形样式 | <en/> graphic style
53
+ * <en/> Get the style of the sub-shape of the shape
54
+ * @param style - <zh/> 图形样式 | <en/> shape style
55
55
  * @returns <zh/> 子图形样式 | <en/> sub-shape style
56
56
  * @remarks
57
57
  * <zh/> 从给定的属性对象中提取图形样式属性。删除特定的属性,如位置、变换和类名
58
58
  *
59
- * <en/> Extracts the graphic style properties from a given attribute object.
60
- * Removes specific properties like position, transformation, and class name.
59
+ * <en/> Extracts the shape styles from a given attribute object.
60
+ * Removes specific styles like position, transformation, and class name.
61
61
  */
62
62
  function getSubShapeStyle(style) {
63
63
  const { x, y, z, class: cls, className, transform, transformOrigin, zIndex, visibility } = style, rest = __rest(style, ["x", "y", "z", "class", "className", "transform", "transformOrigin", "zIndex", "visibility"]);
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.0.33";
1
+ export declare const version = "5.0.35";
package/lib/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
- exports.version = '5.0.33';
4
+ exports.version = '5.0.35';
5
5
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/g6",
3
- "version": "5.0.33",
3
+ "version": "5.0.35",
4
4
  "description": "A Graph Visualization Framework in JavaScript",
5
5
  "keywords": [
6
6
  "antv",
@@ -24,7 +24,7 @@ export interface OptimizeViewportTransformOptions extends BaseBehaviorOptions {
24
24
  /**
25
25
  * <zh/> 指定始终显示的图形元素。应用此交互后,在画布操作过程中,只有通过该属性指定的图形元素会保持可见,其余图形元素将被隐藏,从而提升渲染性能。默认情况下,节点始终可见,而其他图形元素在操作画布过程中会自动隐藏
26
26
  *
27
- * <en/> Specify the graphic elements that are always visible. After applying this interaction, only the graphic elements specified by this property will remain visible during the canvas operation, and the rest of the graphic elements will be hidden to improve rendering performance. By default, nodes are always visible, while other graphic elements are automatically hidden during canvas operations
27
+ * <en/> Specify the shapes that are always visible. After applying this interaction, only the shapes specified by this property will remain visible during the canvas operation, and the rest of the shapes will be hidden to improve rendering performance. By default, nodes are always visible, while other shapes are automatically hidden during canvas operations
28
28
  */
29
29
  shapes?:
30
30
  | { node?: string[]; edge?: string[]; combo?: string[] }
@@ -126,33 +126,33 @@ export interface BaseEdgeStyleProps
126
126
  /**
127
127
  * <zh/> 在 “起点” 处添加一个标记图形,其中 “起始点” 为边与起始节点的交点
128
128
  *
129
- * <en/> Add a marker graphic at the "start point", where the "start point" is the intersection of the edge and the source node
129
+ * <en/> Add a marker at the "start point", where the "start point" is the intersection of the edge and the source node
130
130
  */
131
131
  markerStart?: DisplayObject | null;
132
132
  /**
133
133
  * <zh/> 调整 “起点” 处标记图形的位置,正偏移量向内,负偏移量向外
134
134
  *
135
- * <en/> Adjust the position of the marker graphic at the "start point", positive offset inward, negative offset outward
135
+ * <en/> Adjust the position of the marker at the "start point", positive offset inward, negative offset outward
136
136
  * @defaultValue 0
137
137
  */
138
138
  markerStartOffset?: number;
139
139
  /**
140
140
  * <zh/> 在 “终点” 处添加一个标记图形,其中 “终点” 为边与终止节点的交点
141
141
  *
142
- * <en/> Add a marker graphic at the "end point", where the "end point" is the intersection of the edge and the target node
142
+ * <en/> Add a marker at the "end point", where the "end point" is the intersection of the edge and the target node
143
143
  */
144
144
  markerEnd?: DisplayObject | null;
145
145
  /**
146
146
  * <zh/> 调整 “终点” 处标记图形的位置,正偏移量向内,负偏移量向外
147
147
  *
148
- * <en/> Adjust the position of the marker graphic at the "end point", positive offset inward, negative offset outward
148
+ * <en/> Adjust the position of the marker at the "end point", positive offset inward, negative offset outward
149
149
  * @defaultValue 0
150
150
  */
151
151
  markerEndOffset?: number;
152
152
  /**
153
153
  * <zh/> 在路径除了 “起点” 和 “终点” 之外的每一个顶点上放置标记图形。在内部实现中,由于我们会把路径中部分命令转换成 C 命令,因此这些顶点实际是三阶贝塞尔曲线的控制点
154
154
  *
155
- * <en/> Place a marker graphic on each vertex of the path except for the "start point" and "end point". In the internal implementation, because we will convert some commands in the path to C commands, these controlPoints are actually the control points of the cubic Bezier curve
155
+ * <en/> Place a marker on each vertex of the path except for the "start point" and "end point". In the internal implementation, because we will convert some commands in the path to C commands, these controlPoints are actually the control points of the cubic Bezier curve
156
156
  */
157
157
  markerMid?: DisplayObject | null;
158
158
  /**
@@ -85,6 +85,7 @@ export interface BaseNodeStyleProps
85
85
  * <zh/> 仅在树图中生效
86
86
  *
87
87
  * <en/> Only valid in the tree graph
88
+ * @ignore
88
89
  */
89
90
  childrenNode?: ID[];
90
91
  /**
@@ -95,6 +96,7 @@ export interface BaseNodeStyleProps
95
96
  * <zh/> 仅在树图中生效。如果当前节点为收起状态,children 可能为空,通过 childrenData 能够获取完整的子元素数据
96
97
  *
97
98
  * <en/> Only valid in the tree graph. If the current node is collapsed, children may be empty, and the complete child element data can be obtained through childrenData
99
+ * @ignore
98
100
  */
99
101
  childrenData?: NodeData[];
100
102
  /**
@@ -450,7 +452,7 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
450
452
  /**
451
453
  * <zh/> 在离屏画布中获取图形包围盒
452
454
  *
453
- * <en/> Get the bounding box of the graphic in the off-screen canvas
455
+ * <en/> Get the bounding box of the shape in the off-screen canvas
454
456
  * @param context - <zh/> 运行时上下文 <en/> Runtime context
455
457
  * @param shape - <zh/> 图形实例 <en/> Graphic instance
456
458
  * @returns <zh/> 图形包围盒 <en/> Graphic bounding box
@@ -460,7 +462,7 @@ function getBoundsInOffscreen(context: RuntimeContext, shape: DisplayObject) {
460
462
 
461
463
  // 将主图形靠背至全局空间,避免受到父级 transform 的影响
462
464
  // 合理的操作应该是拷贝至离屏画布,但目前 G 有点问题
463
- // Move the main graphic to the global space to avoid being affected by the parent transform
465
+ // Move the main shape to the global space to avoid being affected by the parent transform
464
466
  // The reasonable operation should be moved to the off-screen canvas, but there is a problem with G at present
465
467
  const canvas = context.canvas.getLayer();
466
468
  const substitute = shape.cloneNode();
@@ -153,8 +153,8 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
153
153
  /**
154
154
  * <zh/> 从给定的属性对象中提取图形样式属性。删除特定的属性,如位置、变换和类名
155
155
  *
156
- * <en/> Extracts the graphic style properties from a given attribute object.
157
- * Removes specific properties like position, transformation, and class name.
156
+ * <en/> Extracts the shape styles from a given attribute object.
157
+ * Removes specific styles like position, transformation, and class name.
158
158
  * @param style - <zh/> 属性对象 | <en/> attribute object
159
159
  * @returns <zh/> 仅包含样式属性的对象 | <en/> An object containing only the style properties.
160
160
  */
package/src/exports.ts CHANGED
@@ -73,6 +73,7 @@ export {
73
73
  mindmap as MindmapLayout,
74
74
  RadialLayout,
75
75
  RandomLayout,
76
+ SnakeLayout,
76
77
  } from './layouts';
77
78
  export {
78
79
  Background,
@@ -181,7 +182,7 @@ export type {
181
182
  } from './elements/shapes';
182
183
  export type { UpsertHooks } from './elements/shapes/base-shape';
183
184
  export type { ContourLabelStyleProps, ContourStyleProps } from './elements/shapes/contour';
184
- export type { FishboneLayoutOptions } from './layouts';
185
+ export type { FishboneLayoutOptions, SnakeLayoutOptions } from './layouts';
185
186
  export type { BaseLayoutOptions, WebWorkerLayoutOptions } from './layouts/types';
186
187
  export type { CategoricalPalette } from './palettes/types';
187
188
  export type {
@@ -1,11 +1,12 @@
1
1
  import { isEmpty, memoize } from '@antv/util';
2
- import { idOf } from '../exports';
2
+ import type { BaseLayoutOptions } from '../layouts/types';
3
3
  import type { EdgeData, GraphData, NodeData } from '../spec';
4
4
  import type { ElementDatum, ID, Point, Size, STDSize } from '../types';
5
+ import { idOf } from '../utils/id';
5
6
  import { parseSize } from '../utils/size';
6
7
  import { BaseLayout } from './base-layout';
7
8
 
8
- export interface FishboneLayoutOptions {
9
+ export interface FishboneLayoutOptions extends BaseLayoutOptions {
9
10
  /**
10
11
  * <zh/> 节点大小
11
12
  *
@@ -16,4 +16,7 @@ export {
16
16
  } from '@antv/layout';
17
17
  export { BaseLayout } from './base-layout';
18
18
  export { FishboneLayout } from './fishbone';
19
+ export { SnakeLayout } from './snake';
20
+
19
21
  export type { FishboneLayoutOptions } from './fishbone';
22
+ export type { SnakeLayoutOptions } from './snake';
@@ -0,0 +1,235 @@
1
+ import type { GraphData, NodeData } from '../spec';
2
+ import type { ID, Padding, Size } from '../types';
3
+ import { parsePadding } from '../utils/padding';
4
+ import { parseSize } from '../utils/size';
5
+ import { BaseLayout } from './base-layout';
6
+ import type { BaseLayoutOptions } from './types';
7
+
8
+ export interface SnakeLayoutOptions extends BaseLayoutOptions {
9
+ /**
10
+ * <zh/> 节点尺寸
11
+ *
12
+ * <en/> Node size
13
+ */
14
+ nodeSize?: Size | ((node: NodeData) => Size);
15
+ /**
16
+ * <zh/> 内边距,即布局区域与画布边界的距离
17
+ *
18
+ * <en/> Padding, the distance between the layout area and the canvas boundary
19
+ * @defaultValue 0
20
+ */
21
+ padding?: Padding;
22
+ /**
23
+ * <zh/> 节点排序方法。默认按照在图中的路径顺序进行展示
24
+ *
25
+ * <en/> Node sorting method
26
+ */
27
+ sortBy?: (nodeA: NodeData, nodeB: NodeData) => -1 | 0 | 1;
28
+ /**
29
+ * <zh/> 节点列数
30
+ *
31
+ * <en/> Number of node columns
32
+ * @defaultValue 5
33
+ */
34
+ cols?: number;
35
+ /**
36
+ * <zh/> 节点行之间的间隙大小。默认将根据画布高度和节点总行数自动计算
37
+ *
38
+ * <en/> The size of the gap between a node's rows
39
+ */
40
+ rowGap?: number;
41
+ /**
42
+ * <zh/> 节点列之间的间隙大小。默认将根据画布宽度和节点总列数自动计算
43
+ *
44
+ * <en/> The size of the gap between a node's columns
45
+ */
46
+ colGap?: number;
47
+ /**
48
+ * <zh/> 节点排布方向是否顺时针
49
+ *
50
+ * <en/> Whether the node arrangement direction is clockwise
51
+ * @defaultValue true
52
+ * @remarks
53
+ * <zh/> 在顺时针排布时,节点从左上角开始,第一行从左到右排列,第二行从右到左排列,依次类推,形成 S 型路径。在逆时针排布时,节点从右上角开始,第一行从右到左排列,第二行从左到右排列,依次类推,形成反向 S 型路径。
54
+ *
55
+ * <en/> When arranged clockwise, the nodes start from the upper left corner, the first row is arranged from left to right, the second row is arranged from right to left, and so on, forming an S-shaped path. When arranged counterclockwise, the nodes start from the upper right corner, the first row is arranged from right to left, the second row is arranged from left to right, and so on, forming a reverse S-shaped path.
56
+ */
57
+ clockwise?: boolean;
58
+ }
59
+
60
+ /**
61
+ * <zh/> 蛇形布局
62
+ *
63
+ * <en/> Snake layout
64
+ * @remarks
65
+ * <zh/> 蛇形布局(Snake Layout)是一种特殊的图形布局方式,能够在较小的空间内更有效地展示长链结构。需要注意的是,其图数据需要确保节点按照从源节点到汇节点的顺序进行线性排列,形成一条明确的路径。
66
+ *
67
+ * <zh/> 节点按 S 字型排列,第一个节点位于第一行的起始位置,接下来的节点在第一行向右排列,直到行末尾。到达行末尾后,下一行的节点从右向左反向排列。这个过程重复进行,直到所有节点排列完毕。
68
+ *
69
+ * <en/> The Snake layout is a special way of graph layout that can more effectively display long chain structures in a smaller space. Note that the graph data needs to ensure that the nodes are linearly arranged in the order from the source node to the sink node to form a clear path.
70
+ *
71
+ * <en/> The nodes are arranged in an S-shaped pattern, with the first node at the beginning of the first row, and the following nodes arranged to the right until the end of the row. After reaching the end of the row, the nodes in the next row are arranged in reverse from right to left. This process is repeated until all nodes are arranged.
72
+ */
73
+ export class SnakeLayout extends BaseLayout {
74
+ public id = 'snake';
75
+
76
+ static defaultOptions: Partial<SnakeLayoutOptions> = {
77
+ padding: 0,
78
+ cols: 5,
79
+ clockwise: true,
80
+ };
81
+
82
+ private formatSize(nodes: NodeData[], size?: Size | ((node: NodeData) => Size)): [number, number] {
83
+ const sizeFn = typeof size === 'function' ? size : ((() => size) as (node: NodeData) => Size);
84
+ return nodes.reduce(
85
+ (acc, node) => {
86
+ const [w, h] = parseSize(sizeFn(node)) || [0, 0];
87
+ return [Math.max(acc[0], w), Math.max(acc[1], h)];
88
+ },
89
+ [0, 0],
90
+ );
91
+ }
92
+
93
+ /**
94
+ * Validates the graph data to ensure it meets the requirements for linear arrangement.
95
+ * @param data - Graph data
96
+ * @returns false if the graph is not connected, has more than one source or sink node, or contains cycles.
97
+ */
98
+ private validate(data: GraphData): boolean {
99
+ const { nodes = [], edges = [] } = data;
100
+ const inDegree: { [key: ID]: number } = {};
101
+ const outDegree: { [key: ID]: number } = {};
102
+ const adjList: { [key: ID]: ID[] } = {};
103
+
104
+ nodes.forEach((node) => {
105
+ inDegree[node.id] = 0;
106
+ outDegree[node.id] = 0;
107
+ adjList[node.id] = [];
108
+ });
109
+
110
+ edges.forEach((edge) => {
111
+ inDegree[edge.target]++;
112
+ outDegree[edge.source]++;
113
+ adjList[edge.source].push(edge.target);
114
+ });
115
+
116
+ // 检查图是否连通
117
+ // Check if the graph is connected
118
+ const visited: Set<ID> = new Set();
119
+ const dfs = (nodeId: ID) => {
120
+ if (visited.has(nodeId)) return;
121
+ visited.add(nodeId);
122
+ adjList[nodeId].forEach(dfs);
123
+ };
124
+ dfs(nodes[0].id);
125
+ if (visited.size !== nodes.length) return false;
126
+
127
+ // 检查是否有且仅有一个源节点和一个汇节点
128
+ // Check if there is exactly one source node and one sink node
129
+ const sourceNodes = nodes.filter((node) => inDegree[node.id] === 0);
130
+ const sinkNodes = nodes.filter((node) => outDegree[node.id] === 0);
131
+ if (sourceNodes.length !== 1 || sinkNodes.length !== 1) return false;
132
+
133
+ // 检查中间节点是否只有一个前驱和一个后继
134
+ // Check if the middle nodes have only one predecessor and one successor
135
+ const middleNodes = nodes.filter((node) => inDegree[node.id] === 1 && outDegree[node.id] === 1);
136
+ if (middleNodes.length !== nodes.length - 2) return false;
137
+
138
+ return true;
139
+ }
140
+
141
+ async execute(model: GraphData, options?: SnakeLayoutOptions): Promise<GraphData> {
142
+ if (!this.validate(model)) return model;
143
+
144
+ const {
145
+ nodeSize: propNodeSize,
146
+ padding: propPadding,
147
+ sortBy,
148
+ cols,
149
+ colGap: propColSep,
150
+ rowGap: propRowSep,
151
+ clockwise,
152
+ width,
153
+ height,
154
+ } = Object.assign({}, SnakeLayout.defaultOptions, this.options, options) as Required<SnakeLayoutOptions>;
155
+
156
+ const [top, right, bottom, left] = parsePadding(propPadding);
157
+ const nodeSize = this.formatSize(model.nodes || [], propNodeSize);
158
+
159
+ const rows = Math.ceil((model.nodes || []).length / cols);
160
+ let colSep = propColSep ? propColSep : (width - left - right - cols * nodeSize[0]) / (cols - 1);
161
+ let rowSep = propRowSep ? propRowSep : (height - top - bottom - rows * nodeSize[1]) / (rows - 1);
162
+ if (rowSep === Infinity || rowSep < 0) rowSep = 0;
163
+ if (colSep === Infinity || colSep < 0) colSep = 0;
164
+
165
+ const sortedNodes = sortBy ? model.nodes?.sort(sortBy) : topologicalSort(model);
166
+
167
+ const nodes = (sortedNodes || []).map((node, index) => {
168
+ const rowIndex = Math.floor(index / cols);
169
+ const colIndex = index % cols;
170
+
171
+ const actualColIndex = clockwise
172
+ ? rowIndex % 2 === 0
173
+ ? colIndex
174
+ : cols - 1 - colIndex
175
+ : rowIndex % 2 === 0
176
+ ? cols - 1 - colIndex
177
+ : colIndex;
178
+
179
+ const x = left + actualColIndex * (nodeSize[0] + colSep) + nodeSize[0] / 2;
180
+ const y = top + rowIndex * (nodeSize[1] + rowSep) + nodeSize[1] / 2;
181
+
182
+ return {
183
+ id: node.id,
184
+ style: { x, y },
185
+ };
186
+ });
187
+
188
+ return { nodes };
189
+ }
190
+ }
191
+
192
+ /**
193
+ * Topological sorting. The nodes are sorted according to the order of the paths(from the start node to the end node).
194
+ * @param data - Graph data
195
+ * @returns Sorted nodes
196
+ */
197
+ function topologicalSort(data: GraphData): NodeData[] {
198
+ const { nodes = [], edges = [] } = data;
199
+ const inDegree: { [key: ID]: number } = {};
200
+ const adjList: { [key: ID]: ID[] } = {};
201
+
202
+ nodes.forEach((node) => {
203
+ inDegree[node.id] = 0;
204
+ adjList[node.id] = [];
205
+ });
206
+
207
+ edges.forEach((edge) => {
208
+ inDegree[edge.target]++;
209
+ adjList[edge.source].push(edge.target);
210
+ });
211
+
212
+ const queue: ID[] = [];
213
+ const sortedNodes: NodeData[] = [];
214
+
215
+ nodes.forEach((node) => {
216
+ if (inDegree[node.id] === 0) {
217
+ queue.push(node.id);
218
+ }
219
+ });
220
+
221
+ while (queue.length > 0) {
222
+ const nodeId = queue.shift()!;
223
+ const node = nodes.find((n) => n.id === nodeId)!;
224
+ sortedNodes.push(node);
225
+
226
+ adjList[nodeId].forEach((neighbor) => {
227
+ inDegree[neighbor]--;
228
+ if (inDegree[neighbor] === 0) {
229
+ queue.push(neighbor);
230
+ }
231
+ });
232
+ }
233
+
234
+ return sortedNodes;
235
+ }
@@ -17,6 +17,8 @@ import type {
17
17
  } from '@antv/layout';
18
18
  import type { NodeData } from '../spec/data';
19
19
  import type { BaseLayout } from './base-layout';
20
+ import type { FishboneLayoutOptions } from './fishbone';
21
+ import type { SnakeLayoutOptions } from './snake';
20
22
 
21
23
  export type BuiltInLayoutOptions =
22
24
  | AntVDagreLayout
@@ -31,7 +33,9 @@ export type BuiltInLayoutOptions =
31
33
  | GridLayout
32
34
  | MDSLayout
33
35
  | RadialLayout
34
- | RandomLayout;
36
+ | RandomLayout
37
+ | SnakeLayoutOptions
38
+ | FishboneLayoutOptions;
35
39
 
36
40
  export interface BaseLayoutOptions extends AnimationOptions, WebWorkerLayoutOptions, Record<string, any> {
37
41
  /**
@@ -58,7 +58,7 @@ export interface MinimapOptions extends BasePluginOptions {
58
58
  * - 也可以传入一个函数,接收元素的 id 和类型,返回一个图形
59
59
  *
60
60
  * <en/>
61
- * - 'key' uses the key shape of the element as the thumbnail graphic
61
+ * - 'key' uses the key shape of the element as the thumbnail shape
62
62
  * - You can also pass in a function that receives the id and type of the element and returns a shape
63
63
  */
64
64
  shape?: 'key' | ((id: string, elementType: ElementType) => DisplayObject);
@@ -39,6 +39,12 @@ export interface TooltipOptions
39
39
  * @defaultValue true
40
40
  */
41
41
  enable?: boolean | ((event: IElementEvent) => boolean);
42
+ /**
43
+ * <zh/> 显示隐藏的回调
44
+ *
45
+ * <en/> Callback executed when visibility of the tooltip card is changed
46
+ */
47
+ onOpenChange: (open: boolean) => void;
42
48
  }
43
49
 
44
50
  /**
@@ -162,9 +168,7 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
162
168
  // click the same item twice, tooltip will be hidden
163
169
  if (this.currentTarget === id) {
164
170
  this.hide(event);
165
- this.currentTarget = null;
166
171
  } else {
167
- this.currentTarget = id;
168
172
  this.show(event);
169
173
  }
170
174
  };
@@ -190,7 +194,6 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
190
194
  */
191
195
  public onPointerLeave = (event: IElementEvent) => {
192
196
  this.hide(event);
193
- this.currentTarget = null;
194
197
  };
195
198
  /**
196
199
  * <zh/> 移动画布
@@ -200,7 +203,6 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
200
203
  */
201
204
  public onCanvasMove = (event: IElementEvent) => {
202
205
  this.hide(event);
203
- this.currentTarget = null;
204
206
  };
205
207
 
206
208
  private onPointerEnter = (event: IElementEvent) => {
@@ -280,6 +282,7 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
280
282
  }),
281
283
  };
282
284
  }
285
+ this.options.onOpenChange?.(true);
283
286
  this.tooltipElement.update({
284
287
  ...this.tooltipStyleProps,
285
288
  x,
@@ -301,7 +304,9 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
301
304
  public hide = (event?: IElementEvent) => {
302
305
  // if e is undefined, hide the tooltip, external call
303
306
  if (!event) {
307
+ this.options.onOpenChange?.(false);
304
308
  this.tooltipElement?.hide();
309
+ this.currentTarget = null;
305
310
  return;
306
311
  }
307
312
  if (!this.tooltipElement) return;
@@ -310,7 +315,9 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
310
315
  const {
311
316
  client: { x, y },
312
317
  } = event;
318
+ this.options.onOpenChange?.(false);
313
319
  this.tooltipElement.hide(x, y);
320
+ this.currentTarget = null;
314
321
  };
315
322
 
316
323
  private get tooltipStyleProps() {
@@ -65,6 +65,7 @@ import {
65
65
  MDSLayout,
66
66
  RadialLayout,
67
67
  RandomLayout,
68
+ SnakeLayout,
68
69
  compactBox,
69
70
  dendrogram,
70
71
  indented,
@@ -167,6 +168,7 @@ const BUILT_IN_EXTENSIONS: ExtensionRegistry = {
167
168
  mindmap,
168
169
  radial: RadialLayout,
169
170
  random: RandomLayout,
171
+ snake: SnakeLayout,
170
172
  },
171
173
  node: {
172
174
  circle: Circle,