@antv/g6 5.0.33 → 5.0.34

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 (99) 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/spec/canvas.d.ts +26 -2
  13. package/dist/lib/spec/graph.d.ts +60 -12
  14. package/dist/lib/spec/viewport.d.ts +4 -0
  15. package/dist/lib/utils/cache.d.ts +5 -5
  16. package/dist/lib/utils/style.d.ts +5 -5
  17. package/dist/lib/version.d.ts +1 -1
  18. package/esm/behaviors/optimize-viewport-transform.d.ts +1 -1
  19. package/esm/elements/edges/base-edge.d.ts +5 -5
  20. package/esm/elements/nodes/base-node.d.ts +2 -0
  21. package/esm/elements/nodes/base-node.js +2 -2
  22. package/esm/elements/nodes/base-node.js.map +1 -1
  23. package/esm/elements/shapes/base-shape.d.ts +2 -2
  24. package/esm/elements/shapes/base-shape.js +2 -2
  25. package/esm/exports.d.ts +2 -2
  26. package/esm/exports.js +1 -1
  27. package/esm/exports.js.map +1 -1
  28. package/esm/layouts/fishbone.d.ts +2 -1
  29. package/esm/layouts/fishbone.js +1 -1
  30. package/esm/layouts/fishbone.js.map +1 -1
  31. package/esm/layouts/index.d.ts +2 -0
  32. package/esm/layouts/index.js +1 -0
  33. package/esm/layouts/index.js.map +1 -1
  34. package/esm/layouts/snake.d.ts +80 -0
  35. package/esm/layouts/snake.js +162 -0
  36. package/esm/layouts/snake.js.map +1 -0
  37. package/esm/layouts/types.d.ts +3 -1
  38. package/esm/plugins/minimap/index.d.ts +1 -1
  39. package/esm/registry/build-in.js +2 -1
  40. package/esm/registry/build-in.js.map +1 -1
  41. package/esm/spec/canvas.d.ts +26 -2
  42. package/esm/spec/graph.d.ts +60 -12
  43. package/esm/spec/viewport.d.ts +4 -0
  44. package/esm/utils/cache.d.ts +5 -5
  45. package/esm/utils/cache.js +5 -5
  46. package/esm/utils/style.d.ts +5 -5
  47. package/esm/utils/style.js +5 -5
  48. package/esm/version.d.ts +1 -1
  49. package/esm/version.js +1 -1
  50. package/lib/behaviors/optimize-viewport-transform.d.ts +1 -1
  51. package/lib/elements/edges/base-edge.d.ts +5 -5
  52. package/lib/elements/nodes/base-node.d.ts +2 -0
  53. package/lib/elements/nodes/base-node.js +2 -2
  54. package/lib/elements/nodes/base-node.js.map +1 -1
  55. package/lib/elements/shapes/base-shape.d.ts +2 -2
  56. package/lib/elements/shapes/base-shape.js +2 -2
  57. package/lib/exports.d.ts +2 -2
  58. package/lib/exports.js +3 -2
  59. package/lib/exports.js.map +1 -1
  60. package/lib/layouts/fishbone.d.ts +2 -1
  61. package/lib/layouts/fishbone.js +2 -2
  62. package/lib/layouts/fishbone.js.map +1 -1
  63. package/lib/layouts/index.d.ts +2 -0
  64. package/lib/layouts/index.js +3 -1
  65. package/lib/layouts/index.js.map +1 -1
  66. package/lib/layouts/snake.d.ts +80 -0
  67. package/lib/layouts/snake.js +166 -0
  68. package/lib/layouts/snake.js.map +1 -0
  69. package/lib/layouts/types.d.ts +3 -1
  70. package/lib/plugins/minimap/index.d.ts +1 -1
  71. package/lib/registry/build-in.js +1 -0
  72. package/lib/registry/build-in.js.map +1 -1
  73. package/lib/spec/canvas.d.ts +26 -2
  74. package/lib/spec/graph.d.ts +60 -12
  75. package/lib/spec/viewport.d.ts +4 -0
  76. package/lib/utils/cache.d.ts +5 -5
  77. package/lib/utils/cache.js +5 -5
  78. package/lib/utils/style.d.ts +5 -5
  79. package/lib/utils/style.js +5 -5
  80. package/lib/version.d.ts +1 -1
  81. package/lib/version.js +1 -1
  82. package/package.json +1 -1
  83. package/src/behaviors/optimize-viewport-transform.ts +1 -1
  84. package/src/elements/edges/base-edge.ts +5 -5
  85. package/src/elements/nodes/base-node.ts +4 -2
  86. package/src/elements/shapes/base-shape.ts +2 -2
  87. package/src/exports.ts +2 -1
  88. package/src/layouts/fishbone.ts +3 -2
  89. package/src/layouts/index.ts +3 -0
  90. package/src/layouts/snake.ts +235 -0
  91. package/src/layouts/types.ts +5 -1
  92. package/src/plugins/minimap/index.ts +1 -1
  93. package/src/registry/build-in.ts +2 -0
  94. package/src/spec/canvas.ts +26 -2
  95. package/src/spec/graph.ts +60 -12
  96. package/src/spec/viewport.ts +4 -0
  97. package/src/utils/cache.ts +5 -5
  98. package/src/utils/style.ts +5 -5
  99. package/src/version.ts +1 -1
@@ -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);
@@ -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,
@@ -18,18 +18,30 @@ export interface CanvasOptions {
18
18
  * <zh/> 画布宽度
19
19
  *
20
20
  * <en/> canvas width
21
+ * @remarks
22
+ * <zh/> 如果未设置,则会自动获取容器宽度
23
+ *
24
+ * <en/> If not set, the container width will be automatically obtained
21
25
  */
22
26
  width?: number;
23
27
  /**
24
28
  * <zh/> 画布高度
25
29
  *
26
30
  * <en/> canvas height
31
+ * @remarks
32
+ * <zh/> 如果未设置,则会自动获取容器高度
33
+ *
34
+ * <en/> If not set, the container height will be automatically obtained
27
35
  */
28
36
  height?: number;
29
37
  /**
30
- * <zh/> 获取渲染器
38
+ * <zh/> 手动置顶渲染器
39
+ *
40
+ * <en/> manually set renderer
41
+ * @remarks
42
+ * <zh/> G6 采用了分层渲染的方式,分为 background、main、label、transient 四层,用户可以通过该配置项分别设置每层画布的渲染器
31
43
  *
32
- * <en/> get renderer
44
+ * <en/> G6 adopts a layered rendering method, divided into four layers: background, main, label, transient. Users can set the renderer of each layer canvas separately through this configuration item
33
45
  */
34
46
  renderer?: (layer: 'background' | 'main' | 'label' | 'transient') => IRenderer;
35
47
  /**
@@ -37,18 +49,30 @@ export interface CanvasOptions {
37
49
  *
38
50
  * <en/> whether to auto resize canvas
39
51
  * @defaultValue false
52
+ * @remarks
53
+ * <zh/> 基于 window.onresize 事件自动调整画布大小
54
+ *
55
+ * <en/> Automatically adjust the canvas size based on the window.onresize event
40
56
  */
41
57
  autoResize?: boolean;
42
58
  /**
43
59
  * <zh/> 画布背景色
44
60
  *
45
61
  * <en/> canvas background color
62
+ * @remarks
63
+ * <zh/> 该颜色作为导出图片时的背景色
64
+ *
65
+ * <en/> This color is used as the background color when exporting images
46
66
  */
47
67
  background?: string;
48
68
  /**
49
69
  * <zh/> 设备像素比
50
70
  *
51
71
  * <en/> device pixel ratio
72
+ * @remarks
73
+ * <zh/> 用于高清屏的设备像素比,默认为 [window.devicePixelRatio](https://developer.mozilla.org/zh-CN/docs/Web/API/Window/devicePixelRatio)
74
+ *
75
+ * <en/> Device pixel ratio for high-definition screens, default is [window.devicePixelRatio](https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio)
52
76
  */
53
77
  devicePixelRatio?: number;
54
78
  /**
package/src/spec/graph.ts CHANGED
@@ -40,30 +40,50 @@ export interface GraphOptions extends CanvasOptions, ViewportOptions {
40
40
  * <zh/> 数据
41
41
  *
42
42
  * <en/> Data
43
+ * @remarks
44
+ * <zh/> 详见 [Data](/api/data/graph-data)
45
+ *
46
+ * <en/> See [Data](/en/api/data/graph-data)
43
47
  */
44
48
  data?: GraphData;
45
49
  /**
46
- * <zh/> 布局
50
+ * <zh/> 布局配置项
51
+ *
52
+ * <en/> Layout options
53
+ * @remarks
54
+ * <zh/> 详见 [Layout](/api/layouts/antv-dagre-layout)
47
55
  *
48
- * <en/> Layout
56
+ * <en/> See [Layout](/en/api/layouts/antv-dagre-layout)
49
57
  */
50
58
  layout?: LayoutOptions;
51
59
  /**
52
- * <zh/> 节点
60
+ * <zh/> 节点配置项
61
+ *
62
+ * <en/> Node options
63
+ * @remarks
64
+ * <zh/> 详见 [Node](/api/elements/nodes/base-node)
53
65
  *
54
- * <en/> Node
66
+ * <en/> See [Node](/en/api/elements/nodes/base-node)
55
67
  */
56
68
  node?: NodeOptions;
57
69
  /**
58
- * <zh/> 边
70
+ * <zh/> 边配置项
59
71
  *
60
- * <en/> Edge
72
+ * <en/> Edge options
73
+ * @remarks
74
+ * <zh/> 详见 [Edge](/api/elements/edges/base-edge)
75
+ *
76
+ * <en/> See [Edge](/en/api/elements/edges/base-edge)
61
77
  */
62
78
  edge?: EdgeOptions;
63
79
  /**
64
- * <zh/> Combo
80
+ * <zh/> 组合配置项
65
81
  *
66
- * <en/> Combo
82
+ * <en/> Combo options
83
+ * @remarks
84
+ * <zh/> 详见 [Combo](/api/elements/combos/base-combo)
85
+ *
86
+ * <en/> See [Combo](/en/api/elements/combos/base-combo)
67
87
  */
68
88
  combo?: ComboOptions;
69
89
  /**
@@ -73,15 +93,43 @@ export interface GraphOptions extends CanvasOptions, ViewportOptions {
73
93
  */
74
94
  theme?: ThemeOptions;
75
95
  /**
76
- * <zh/> 交互
96
+ * <zh/> 启用交互
97
+ *
98
+ * <en/> Enable interactions
99
+ * @remarks
100
+ * <zh/>
101
+ * - 概念:[核心概念 - 交互](/manual/core-concept/behavior)
102
+ *
103
+ * - 内置交互: [交互](/api/behaviors/auto-adapt-label)
104
+ *
105
+ * - 自定义交互: [自定义扩展 - 自定义交互](/manual/advanced/custom-behavior)
77
106
  *
78
- * <en/> Behaviors
107
+ * <en/>
108
+ * - Concept: [Concepts - Behavior](/en/manual/core-concept/behavior)
109
+ *
110
+ * - Built-in behaviors: [Behavior](/en/api/behaviors/auto-adapt-label)
111
+ *
112
+ * - Custom behaviors: [Custom Extension - Custom Behavior](/en/manual/advanced/custom-behavior)
79
113
  */
80
114
  behaviors?: BehaviorOptions;
81
115
  /**
82
- * <zh/> 画布插件
116
+ * <zh/> 启用插件
117
+ *
118
+ * <en/> Enable plugins
119
+ * @remarks
120
+ * <zh/>
121
+ * - 概念:[核心概念 - 插件](/manual/core-concept/plugin)
122
+ *
123
+ * - 内置插件: [插件](/en/api/plugins/background)
124
+ *
125
+ * - 自定义插件: [自定义扩展 - 自定义插件](/manual/advanced/custom-plugin)
126
+ *
127
+ * <en/>
128
+ * - Concept: [Concepts - Plugin](/en/manual/core-concept/plugin)
129
+ *
130
+ * - Built-in plugins: [Plugin](/en/api/plugins/background)
83
131
  *
84
- * <en/> Canvas plugins
132
+ * - Custom plugins: [Custom Extension - Custom Plugin](/en/manual/advanced/custom-plugin)
85
133
  */
86
134
  plugins?: PluginOptions;
87
135
  /**
@@ -24,6 +24,10 @@ export interface ViewportOptions {
24
24
  * <zh/> 是否自动适应
25
25
  *
26
26
  * <en/> whether to auto fit
27
+ * @remarks
28
+ * <zh/> 每次执行 `render` 时,都会根据 `autoFit` 进行自适应
29
+ *
30
+ * <en/> Every time `render` is executed, it will be adapted according to `autoFit`
27
31
  */
28
32
  autoFit?:
29
33
  | { type: 'view'; options?: FitViewOptions; animation?: ViewportAnimationEffectTiming }
@@ -8,8 +8,8 @@ const getStyleCacheKey = (name: string) => `__${name}__`;
8
8
  /**
9
9
  * <zh/> 缓存图形样式
10
10
  *
11
- * <en/> Cache graphic style
12
- * @param element - <zh/> 图形元素 | <en/> graphic element
11
+ * <en/> Cache shape style
12
+ * @param element - <zh/> 图形元素 | <en/> shape element
13
13
  * @param name - <zh/> 样式名 | <en/> style name
14
14
  */
15
15
  export function cacheStyle(element: DisplayObject, name: string | string[]) {
@@ -24,7 +24,7 @@ export function cacheStyle(element: DisplayObject, name: string | string[]) {
24
24
  * <zh/> 获取缓存的样式
25
25
  *
26
26
  * <en/> Get cached style
27
- * @param element - <zh/> 图形元素 | <en/> graphic element
27
+ * @param element - <zh/> 图形元素 | <en/> shape element
28
28
  * @param name - <zh/> 样式名 | <en/> style name
29
29
  * @returns <zh/> 样式值 | <en/> style value
30
30
  */
@@ -36,7 +36,7 @@ export function getCachedStyle(element: DisplayObject, name: string) {
36
36
  * <zh/> 是否有缓存的样式
37
37
  *
38
38
  * <en/> Whether there is a cached style
39
- * @param element - <zh/> 图形元素 | <en/> graphic element
39
+ * @param element - <zh/> 图形元素 | <en/> shape element
40
40
  * @param name - <zh/> 样式名 | <en/> style name
41
41
  * @returns <zh/> 是否有缓存的样式 | <en/> Whether there is a cached style
42
42
  */
@@ -48,7 +48,7 @@ export function hasCachedStyle(element: DisplayObject, name: string) {
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
  */
@@ -34,7 +34,7 @@ export function computeElementCallbackStyle(
34
34
  /**
35
35
  * <zh/> 合并图形配置项
36
36
  *
37
- * <en/> Merge graphic configuration
37
+ * <en/> Merge shape configuration
38
38
  * @param opt1 - <zh/> 配置项1 | <en/> configuration 1
39
39
  * @param opt2 - <zh/> 配置项2 | <en/> configuration 2
40
40
  * @returns <zh/> 合并后的配置项 | <en/> merged configuration
@@ -50,14 +50,14 @@ export function mergeOptions(opt1: DisplayObjectConfig<any>, opt2: DisplayObject
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
  export function getSubShapeStyle<T extends Record<string, any>>(
63
63
  style: T,