@antv/g6 5.0.33 → 5.0.35-beta.1
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.
- package/dist/g6.min.js +11 -11
- package/dist/lib/behaviors/optimize-viewport-transform.d.ts +1 -1
- package/dist/lib/elements/edges/base-edge.d.ts +5 -5
- package/dist/lib/elements/nodes/base-node.d.ts +2 -0
- package/dist/lib/elements/shapes/base-shape.d.ts +2 -9
- package/dist/lib/exports.d.ts +2 -2
- package/dist/lib/layouts/fishbone.d.ts +2 -1
- package/dist/lib/layouts/index.d.ts +2 -0
- package/dist/lib/layouts/snake.d.ts +80 -0
- package/dist/lib/layouts/types.d.ts +23 -1
- package/dist/lib/plugins/minimap/index.d.ts +1 -1
- package/dist/lib/plugins/tooltip.d.ts +6 -0
- package/dist/lib/runtime/data.d.ts +2 -8
- package/dist/lib/runtime/element.d.ts +5 -2
- package/dist/lib/runtime/layout.d.ts +18 -1
- package/dist/lib/runtime/options.d.ts +9 -0
- package/dist/lib/runtime/transform.d.ts +2 -1
- package/dist/lib/spec/canvas.d.ts +26 -2
- package/dist/lib/spec/data.d.ts +0 -14
- package/dist/lib/spec/graph.d.ts +60 -12
- package/dist/lib/spec/viewport.d.ts +4 -0
- package/dist/lib/transforms/base-transform.d.ts +2 -1
- package/dist/lib/utils/cache.d.ts +5 -5
- package/dist/lib/utils/element.d.ts +9 -1
- package/dist/lib/utils/layout.d.ts +13 -1
- package/dist/lib/utils/style.d.ts +5 -5
- package/dist/lib/utils/transform.d.ts +2 -2
- package/dist/lib/version.d.ts +1 -1
- package/esm/animations/executor.js +3 -2
- package/esm/animations/executor.js.map +1 -1
- package/esm/behaviors/drag-element.js +9 -2
- package/esm/behaviors/drag-element.js.map +1 -1
- package/esm/behaviors/optimize-viewport-transform.d.ts +1 -1
- package/esm/elements/combos/base-combo.js +1 -1
- package/esm/elements/combos/base-combo.js.map +1 -1
- package/esm/elements/edges/base-edge.d.ts +5 -5
- package/esm/elements/edges/base-edge.js +8 -2
- package/esm/elements/edges/base-edge.js.map +1 -1
- package/esm/elements/nodes/base-node.d.ts +2 -0
- package/esm/elements/nodes/base-node.js +2 -2
- package/esm/elements/nodes/base-node.js.map +1 -1
- package/esm/elements/shapes/base-shape.d.ts +2 -9
- package/esm/elements/shapes/base-shape.js +24 -21
- package/esm/elements/shapes/base-shape.js.map +1 -1
- package/esm/exports.d.ts +2 -2
- package/esm/exports.js +1 -1
- package/esm/exports.js.map +1 -1
- package/esm/layouts/fishbone.d.ts +2 -1
- package/esm/layouts/fishbone.js +1 -1
- package/esm/layouts/fishbone.js.map +1 -1
- package/esm/layouts/index.d.ts +2 -0
- package/esm/layouts/index.js +1 -0
- package/esm/layouts/index.js.map +1 -1
- package/esm/layouts/snake.d.ts +80 -0
- package/esm/layouts/snake.js +162 -0
- package/esm/layouts/snake.js.map +1 -0
- package/esm/layouts/types.d.ts +23 -1
- package/esm/plugins/background/index.js +1 -0
- package/esm/plugins/background/index.js.map +1 -1
- package/esm/plugins/grid-line.js +1 -0
- package/esm/plugins/grid-line.js.map +1 -1
- package/esm/plugins/minimap/index.d.ts +1 -1
- package/esm/plugins/tooltip.d.ts +6 -0
- package/esm/plugins/tooltip.js +8 -6
- package/esm/plugins/tooltip.js.map +1 -1
- package/esm/registry/build-in.js +2 -1
- package/esm/registry/build-in.js.map +1 -1
- package/esm/runtime/data.d.ts +2 -8
- package/esm/runtime/data.js +14 -18
- package/esm/runtime/data.js.map +1 -1
- package/esm/runtime/element.d.ts +5 -2
- package/esm/runtime/element.js +39 -15
- package/esm/runtime/element.js.map +1 -1
- package/esm/runtime/graph.js +19 -7
- package/esm/runtime/graph.js.map +1 -1
- package/esm/runtime/layout.d.ts +18 -1
- package/esm/runtime/layout.js +85 -20
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/options.d.ts +9 -0
- package/esm/runtime/options.js +49 -0
- package/esm/runtime/options.js.map +1 -0
- package/esm/runtime/transform.d.ts +2 -1
- package/esm/runtime/transform.js.map +1 -1
- package/esm/spec/canvas.d.ts +26 -2
- package/esm/spec/data.d.ts +0 -14
- package/esm/spec/graph.d.ts +60 -12
- package/esm/spec/viewport.d.ts +4 -0
- package/esm/transforms/base-transform.d.ts +2 -1
- package/esm/transforms/base-transform.js +1 -1
- package/esm/transforms/base-transform.js.map +1 -1
- package/esm/utils/cache.d.ts +5 -5
- package/esm/utils/cache.js +5 -5
- package/esm/utils/element.d.ts +9 -1
- package/esm/utils/element.js +35 -1
- package/esm/utils/element.js.map +1 -1
- package/esm/utils/layout.d.ts +13 -1
- package/esm/utils/layout.js +14 -0
- package/esm/utils/layout.js.map +1 -1
- package/esm/utils/style.d.ts +5 -5
- package/esm/utils/style.js +5 -5
- package/esm/utils/transform.d.ts +2 -2
- package/esm/utils/transform.js +13 -8
- package/esm/utils/transform.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/esm/version.js.map +1 -1
- package/lib/animations/executor.js +3 -2
- package/lib/animations/executor.js.map +1 -1
- package/lib/behaviors/drag-element.js +9 -2
- package/lib/behaviors/drag-element.js.map +1 -1
- package/lib/behaviors/optimize-viewport-transform.d.ts +1 -1
- package/lib/elements/combos/base-combo.js +1 -1
- package/lib/elements/combos/base-combo.js.map +1 -1
- package/lib/elements/edges/base-edge.d.ts +5 -5
- package/lib/elements/edges/base-edge.js +7 -1
- package/lib/elements/edges/base-edge.js.map +1 -1
- package/lib/elements/nodes/base-node.d.ts +2 -0
- package/lib/elements/nodes/base-node.js +2 -2
- package/lib/elements/nodes/base-node.js.map +1 -1
- package/lib/elements/shapes/base-shape.d.ts +2 -9
- package/lib/elements/shapes/base-shape.js +23 -20
- package/lib/elements/shapes/base-shape.js.map +1 -1
- package/lib/exports.d.ts +2 -2
- package/lib/exports.js +3 -2
- package/lib/exports.js.map +1 -1
- package/lib/layouts/fishbone.d.ts +2 -1
- package/lib/layouts/fishbone.js +2 -2
- package/lib/layouts/fishbone.js.map +1 -1
- package/lib/layouts/index.d.ts +2 -0
- package/lib/layouts/index.js +3 -1
- package/lib/layouts/index.js.map +1 -1
- package/lib/layouts/snake.d.ts +80 -0
- package/lib/layouts/snake.js +166 -0
- package/lib/layouts/snake.js.map +1 -0
- package/lib/layouts/types.d.ts +23 -1
- package/lib/plugins/background/index.js +1 -0
- package/lib/plugins/background/index.js.map +1 -1
- package/lib/plugins/grid-line.js +1 -0
- package/lib/plugins/grid-line.js.map +1 -1
- package/lib/plugins/minimap/index.d.ts +1 -1
- package/lib/plugins/tooltip.d.ts +6 -0
- package/lib/plugins/tooltip.js +8 -6
- package/lib/plugins/tooltip.js.map +1 -1
- package/lib/registry/build-in.js +1 -0
- package/lib/registry/build-in.js.map +1 -1
- package/lib/runtime/data.d.ts +2 -8
- package/lib/runtime/data.js +14 -18
- package/lib/runtime/data.js.map +1 -1
- package/lib/runtime/element.d.ts +5 -2
- package/lib/runtime/element.js +39 -15
- package/lib/runtime/element.js.map +1 -1
- package/lib/runtime/graph.js +21 -9
- package/lib/runtime/graph.js.map +1 -1
- package/lib/runtime/layout.d.ts +18 -1
- package/lib/runtime/layout.js +84 -19
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/options.d.ts +9 -0
- package/lib/runtime/options.js +52 -0
- package/lib/runtime/options.js.map +1 -0
- package/lib/runtime/transform.d.ts +2 -1
- package/lib/runtime/transform.js.map +1 -1
- package/lib/spec/canvas.d.ts +26 -2
- package/lib/spec/data.d.ts +0 -14
- package/lib/spec/graph.d.ts +60 -12
- package/lib/spec/viewport.d.ts +4 -0
- package/lib/transforms/base-transform.d.ts +2 -1
- package/lib/transforms/base-transform.js +1 -1
- package/lib/transforms/base-transform.js.map +1 -1
- package/lib/utils/cache.d.ts +5 -5
- package/lib/utils/cache.js +5 -5
- package/lib/utils/element.d.ts +9 -1
- package/lib/utils/element.js +35 -0
- package/lib/utils/element.js.map +1 -1
- package/lib/utils/layout.d.ts +13 -1
- package/lib/utils/layout.js +15 -0
- package/lib/utils/layout.js.map +1 -1
- package/lib/utils/style.d.ts +5 -5
- package/lib/utils/style.js +5 -5
- package/lib/utils/transform.d.ts +2 -2
- package/lib/utils/transform.js +13 -8
- package/lib/utils/transform.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/version.js.map +1 -1
- package/package.json +2 -2
- package/src/animations/executor.ts +4 -4
- package/src/behaviors/drag-element.ts +9 -2
- package/src/behaviors/optimize-viewport-transform.ts +1 -1
- package/src/elements/combos/base-combo.ts +1 -1
- package/src/elements/edges/base-edge.ts +14 -10
- package/src/elements/nodes/base-node.ts +4 -2
- package/src/elements/shapes/base-shape.ts +23 -21
- package/src/exports.ts +2 -1
- package/src/layouts/fishbone.ts +3 -2
- package/src/layouts/index.ts +3 -0
- package/src/layouts/snake.ts +235 -0
- package/src/layouts/types.ts +25 -1
- package/src/plugins/background/index.ts +1 -0
- package/src/plugins/grid-line.ts +1 -0
- package/src/plugins/minimap/index.ts +1 -1
- package/src/plugins/tooltip.ts +11 -4
- package/src/registry/build-in.ts +2 -0
- package/src/runtime/data.ts +14 -19
- package/src/runtime/element.ts +62 -13
- package/src/runtime/graph.ts +19 -8
- package/src/runtime/layout.ts +79 -23
- package/src/runtime/options.ts +52 -0
- package/src/runtime/transform.ts +2 -0
- package/src/spec/canvas.ts +26 -2
- package/src/spec/data.ts +0 -14
- package/src/spec/graph.ts +60 -12
- package/src/spec/viewport.ts +4 -0
- package/src/transforms/base-transform.ts +3 -1
- package/src/utils/cache.ts +5 -5
- package/src/utils/element.ts +21 -2
- package/src/utils/layout.ts +16 -1
- package/src/utils/style.ts +5 -5
- package/src/utils/transform.ts +13 -9
- package/src/version.ts +1 -1
|
@@ -4,7 +4,7 @@ import { isEmpty, isFunction, upperFirst } from '@antv/util';
|
|
|
4
4
|
import { ExtensionCategory } from '../../constants';
|
|
5
5
|
import type { Keyframe } from '../../types';
|
|
6
6
|
import { createAnimationsProxy, preprocessKeyframes } from '../../utils/animation';
|
|
7
|
-
import { updateStyle } from '../../utils/element';
|
|
7
|
+
import { setAttributes, updateStyle } from '../../utils/element';
|
|
8
8
|
import { subObject } from '../../utils/prefix';
|
|
9
9
|
import { format } from '../../utils/print';
|
|
10
10
|
import { getSubShapeStyle } from '../../utils/style';
|
|
@@ -21,8 +21,8 @@ export interface BaseShapeStyleProps extends BaseStyleProps {}
|
|
|
21
21
|
*/
|
|
22
22
|
export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends CustomElement<StyleProps> {
|
|
23
23
|
constructor(options: DisplayObjectConfig<StyleProps>) {
|
|
24
|
+
applyTransform(options.style);
|
|
24
25
|
super(options);
|
|
25
|
-
this.transformPosition(this.attributes);
|
|
26
26
|
this.render(this.attributes as Required<StyleProps>, this);
|
|
27
27
|
this.setVisibility();
|
|
28
28
|
this.bindEvents();
|
|
@@ -116,26 +116,11 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
|
|
|
116
116
|
return target;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
/**
|
|
120
|
-
* <zh/> 使用 transform 更新图形位置
|
|
121
|
-
*
|
|
122
|
-
* <en/> Update the position of the shape using transform
|
|
123
|
-
* @param attributes - <zh/> 样式属性 | <en/> style attributes
|
|
124
|
-
*/
|
|
125
|
-
protected transformPosition(attributes: Partial<StyleProps>) {
|
|
126
|
-
// Use `transform: translate3d()` instead of `x/y/z`
|
|
127
|
-
if ('x' in attributes || 'y' in attributes || 'z' in attributes) {
|
|
128
|
-
const { x = 0, y = 0, z = 0, transform } = attributes as any;
|
|
129
|
-
const newTransform = replaceTranslateInTransform(+x, +y, +z, transform);
|
|
130
|
-
if (newTransform) this.style.transform = newTransform;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
119
|
public update(attr: Partial<StyleProps> = {}): void {
|
|
135
120
|
const attributes = Object.assign({}, this.attributes, attr) as Required<StyleProps>;
|
|
136
|
-
|
|
121
|
+
applyTransform(attributes);
|
|
122
|
+
setAttributes(this, attributes);
|
|
137
123
|
this.render(attributes, this);
|
|
138
|
-
this.transformPosition(attributes);
|
|
139
124
|
this.setVisibility();
|
|
140
125
|
}
|
|
141
126
|
|
|
@@ -153,8 +138,8 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
|
|
|
153
138
|
/**
|
|
154
139
|
* <zh/> 从给定的属性对象中提取图形样式属性。删除特定的属性,如位置、变换和类名
|
|
155
140
|
*
|
|
156
|
-
* <en/> Extracts the
|
|
157
|
-
* Removes specific
|
|
141
|
+
* <en/> Extracts the shape styles from a given attribute object.
|
|
142
|
+
* Removes specific styles like position, transformation, and class name.
|
|
158
143
|
* @param style - <zh/> 属性对象 | <en/> attribute object
|
|
159
144
|
* @returns <zh/> 仅包含样式属性的对象 | <en/> An object containing only the style properties.
|
|
160
145
|
*/
|
|
@@ -331,3 +316,20 @@ export interface UpsertHooks {
|
|
|
331
316
|
*/
|
|
332
317
|
afterDestroy?: (instance: DisplayObject) => void;
|
|
333
318
|
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* <zh/> 应用 transform
|
|
322
|
+
*
|
|
323
|
+
* <en/> Apply transform
|
|
324
|
+
* @param style - <zh/> 样式 | <en/> style
|
|
325
|
+
* @returns <zh/> 样式 | <en/> style
|
|
326
|
+
*/
|
|
327
|
+
function applyTransform(style?: BaseShapeStyleProps) {
|
|
328
|
+
if (!style) return {};
|
|
329
|
+
if ('x' in style || 'y' in style || 'z' in style) {
|
|
330
|
+
const { x = 0, y = 0, z, transform } = style as any;
|
|
331
|
+
const newTransform = replaceTranslateInTransform(x, y, z, transform);
|
|
332
|
+
if (newTransform) style.transform = newTransform;
|
|
333
|
+
}
|
|
334
|
+
return style;
|
|
335
|
+
}
|
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 {
|
package/src/layouts/fishbone.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { isEmpty, memoize } from '@antv/util';
|
|
2
|
-
import {
|
|
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
|
*
|
package/src/layouts/index.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/layouts/types.ts
CHANGED
|
@@ -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
|
/**
|
|
@@ -48,6 +52,26 @@ export interface BaseLayoutOptions extends AnimationOptions, WebWorkerLayoutOpti
|
|
|
48
52
|
* @returns <zh/> 是否参与布局 | <en/> Whether to participate in the layout
|
|
49
53
|
*/
|
|
50
54
|
nodeFilter?: (node: NodeData) => boolean;
|
|
55
|
+
/**
|
|
56
|
+
* <zh/> 使用前布局,在初始化元素前计算布局
|
|
57
|
+
*
|
|
58
|
+
* <en/> Use pre-layout to calculate the layout before initializing the elements
|
|
59
|
+
* @remarks
|
|
60
|
+
* <zh/> 不适用于流水线布局
|
|
61
|
+
*
|
|
62
|
+
* <en/> Not applicable to pipeline layout
|
|
63
|
+
*/
|
|
64
|
+
preLayout?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* <zh/> 不可见节点是否参与布局
|
|
67
|
+
*
|
|
68
|
+
* <en/> Whether invisible nodes participate in the layout
|
|
69
|
+
* @remarks
|
|
70
|
+
* <zh/> 当 preLayout 为 true 时生效
|
|
71
|
+
*
|
|
72
|
+
* <en/> Takes effect when preLayout is true
|
|
73
|
+
*/
|
|
74
|
+
isLayoutInvisibleNodes?: boolean;
|
|
51
75
|
}
|
|
52
76
|
|
|
53
77
|
interface CircularLayout extends BaseLayoutOptions, CircularLayoutOptions {
|
|
@@ -24,6 +24,7 @@ export class Background extends BasePlugin<BackgroundOptions> {
|
|
|
24
24
|
static defaultOptions: Partial<BackgroundOptions> = {
|
|
25
25
|
transition: 'background 0.5s',
|
|
26
26
|
backgroundSize: 'cover',
|
|
27
|
+
zIndex: '-1', // aviod to cover the other plugin's dom, eg: grid-line.
|
|
27
28
|
};
|
|
28
29
|
|
|
29
30
|
private $element: HTMLElement = createPluginContainer('background');
|
package/src/plugins/grid-line.ts
CHANGED
|
@@ -136,6 +136,7 @@ export class GridLine extends BasePlugin<GridLineOptions> {
|
|
|
136
136
|
border: border ? `${borderLineWidth}px ${borderStyle} ${borderStroke}` : 'none',
|
|
137
137
|
backgroundImage: `linear-gradient(${stroke} ${lineWidth}px, transparent ${lineWidth}px), linear-gradient(90deg, ${stroke} ${lineWidth}px, transparent ${lineWidth}px)`,
|
|
138
138
|
backgroundSize: `${size}px ${size}px`,
|
|
139
|
+
backgroundRepeat: 'repeat',
|
|
139
140
|
});
|
|
140
141
|
}
|
|
141
142
|
|
|
@@ -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
|
|
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);
|
package/src/plugins/tooltip.ts
CHANGED
|
@@ -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() {
|
package/src/registry/build-in.ts
CHANGED
|
@@ -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,
|
package/src/runtime/data.ts
CHANGED
|
@@ -608,15 +608,26 @@ export class DataController {
|
|
|
608
608
|
});
|
|
609
609
|
}
|
|
610
610
|
|
|
611
|
-
public
|
|
611
|
+
public syncNodeLikeDatum(datum: PartialNodeLikeData<NodeData>) {
|
|
612
612
|
const { model } = this;
|
|
613
613
|
|
|
614
614
|
const id = idOf(datum);
|
|
615
|
+
if (!model.hasNode(id)) return;
|
|
615
616
|
const original = toG6Data(model.getNode(id));
|
|
616
617
|
const value = mergeElementsData(original, datum);
|
|
617
618
|
model.mergeNodeData(id, value);
|
|
618
619
|
}
|
|
619
620
|
|
|
621
|
+
public syncEdgeDatum(datum: PartialEdgeData<EdgeData>) {
|
|
622
|
+
const { model } = this;
|
|
623
|
+
|
|
624
|
+
const id = idOf(datum);
|
|
625
|
+
if (!model.hasEdge(id)) return;
|
|
626
|
+
const original = toG6Data(model.getEdge(id));
|
|
627
|
+
const value = mergeElementsData(original, datum);
|
|
628
|
+
model.mergeEdgeData(id, value);
|
|
629
|
+
}
|
|
630
|
+
|
|
620
631
|
public updateEdgeData(edges: PartialEdgeData<EdgeData>[] = []) {
|
|
621
632
|
if (!edges.length) return;
|
|
622
633
|
const { model } = this;
|
|
@@ -679,8 +690,8 @@ export class DataController {
|
|
|
679
690
|
|
|
680
691
|
if (originalParentId !== parent && hierarchyKey === COMBO_KEY) {
|
|
681
692
|
const modifiedDatum = { id, combo: parent };
|
|
682
|
-
if (this.isCombo(id)) this.
|
|
683
|
-
else this.
|
|
693
|
+
if (this.isCombo(id)) this.syncNodeLikeDatum(modifiedDatum);
|
|
694
|
+
else this.syncNodeLikeDatum(modifiedDatum);
|
|
684
695
|
}
|
|
685
696
|
|
|
686
697
|
this.model.setParent(id, parent, hierarchyKey);
|
|
@@ -713,22 +724,6 @@ export class DataController {
|
|
|
713
724
|
});
|
|
714
725
|
}
|
|
715
726
|
|
|
716
|
-
/**
|
|
717
|
-
* <zh/> 将 combo 数据同步到 model 中
|
|
718
|
-
*
|
|
719
|
-
* <en/> Synchronize combo data to the model
|
|
720
|
-
* @param datum - <zh/> combo 数据 | <en/> combo data
|
|
721
|
-
*/
|
|
722
|
-
public syncComboDatum(datum: PartialNodeLikeData<ComboData>) {
|
|
723
|
-
const { model } = this;
|
|
724
|
-
|
|
725
|
-
const id = idOf(datum);
|
|
726
|
-
if (!model.hasNode(id)) return;
|
|
727
|
-
const original = toG6Data(model.getNode(id));
|
|
728
|
-
const value = mergeElementsData(original, datum);
|
|
729
|
-
model.mergeNodeData(id, value);
|
|
730
|
-
}
|
|
731
|
-
|
|
732
727
|
public getElementPosition(id: ID): Point {
|
|
733
728
|
const datum = this.getElementDataById(id) as NodeLikeData;
|
|
734
729
|
return positionOf(datum);
|