@antv/g6 5.0.32 → 5.0.33
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/README.md +33 -34
- package/README.zh-CN.md +117 -0
- package/dist/g6.min.js +29 -29
- package/dist/lib/behaviors/collapse-expand.d.ts +6 -0
- package/dist/lib/behaviors/drag-element.d.ts +1 -1
- package/dist/lib/elements/nodes/html.d.ts +4 -0
- package/dist/lib/exports.d.ts +1 -0
- package/dist/lib/plugins/snapline/index.d.ts +1 -1
- package/dist/lib/runtime/data.d.ts +1 -1
- package/dist/lib/runtime/element.d.ts +29 -2
- package/dist/lib/runtime/graph.d.ts +11 -9
- package/dist/lib/runtime/viewport.d.ts +22 -2
- package/dist/lib/spec/data.d.ts +2 -2
- package/dist/lib/utils/event/events.d.ts +4 -4
- package/dist/lib/utils/id.d.ts +1 -1
- package/dist/lib/utils/visibility.d.ts +1 -2
- package/dist/lib/version.d.ts +1 -1
- package/esm/behaviors/collapse-expand.d.ts +6 -0
- package/esm/behaviors/collapse-expand.js +4 -3
- package/esm/behaviors/collapse-expand.js.map +1 -1
- package/esm/behaviors/drag-element.d.ts +1 -1
- package/esm/behaviors/optimize-viewport-transform.js +1 -1
- package/esm/behaviors/optimize-viewport-transform.js.map +1 -1
- package/esm/elements/nodes/html.d.ts +4 -0
- package/esm/elements/nodes/html.js +7 -0
- package/esm/elements/nodes/html.js.map +1 -1
- package/esm/elements/shapes/base-shape.js +1 -1
- package/esm/elements/shapes/base-shape.js.map +1 -1
- package/esm/exports.d.ts +1 -0
- package/esm/plugins/hull/util.js +6 -1
- package/esm/plugins/hull/util.js.map +1 -1
- package/esm/plugins/snapline/index.d.ts +1 -1
- package/esm/preset.js +0 -2
- package/esm/preset.js.map +1 -1
- package/esm/runtime/data.d.ts +1 -1
- package/esm/runtime/data.js +8 -3
- package/esm/runtime/data.js.map +1 -1
- package/esm/runtime/element.d.ts +29 -2
- package/esm/runtime/element.js +34 -4
- package/esm/runtime/element.js.map +1 -1
- package/esm/runtime/graph.d.ts +11 -9
- package/esm/runtime/graph.js +20 -15
- package/esm/runtime/graph.js.map +1 -1
- package/esm/runtime/viewport.d.ts +22 -2
- package/esm/runtime/viewport.js +12 -11
- package/esm/runtime/viewport.js.map +1 -1
- package/esm/spec/data.d.ts +2 -2
- package/esm/transforms/place-radial-labels.js +6 -1
- package/esm/transforms/place-radial-labels.js.map +1 -1
- package/esm/utils/event/events.d.ts +4 -4
- package/esm/utils/id.d.ts +1 -1
- package/esm/utils/visibility.d.ts +1 -2
- package/esm/utils/visibility.js +8 -34
- package/esm/utils/visibility.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/behaviors/collapse-expand.d.ts +6 -0
- package/lib/behaviors/collapse-expand.js +4 -3
- package/lib/behaviors/collapse-expand.js.map +1 -1
- package/lib/behaviors/drag-element.d.ts +1 -1
- package/lib/behaviors/optimize-viewport-transform.js +1 -1
- package/lib/behaviors/optimize-viewport-transform.js.map +1 -1
- package/lib/elements/edges/base-edge.js +17 -7
- package/lib/elements/edges/base-edge.js.map +1 -1
- package/lib/elements/nodes/html.d.ts +4 -0
- package/lib/elements/nodes/html.js +7 -0
- package/lib/elements/nodes/html.js.map +1 -1
- package/lib/elements/shapes/base-shape.js +1 -1
- package/lib/elements/shapes/base-shape.js.map +1 -1
- package/lib/exports.d.ts +1 -0
- package/lib/plugins/hull/util.js +5 -0
- package/lib/plugins/hull/util.js.map +1 -1
- package/lib/plugins/snapline/index.d.ts +1 -1
- package/lib/preset.js +0 -2
- package/lib/preset.js.map +1 -1
- package/lib/runtime/data.d.ts +1 -1
- package/lib/runtime/data.js +7 -2
- package/lib/runtime/data.js.map +1 -1
- package/lib/runtime/element.d.ts +29 -2
- package/lib/runtime/element.js +34 -4
- package/lib/runtime/element.js.map +1 -1
- package/lib/runtime/graph.d.ts +11 -9
- package/lib/runtime/graph.js +20 -15
- package/lib/runtime/graph.js.map +1 -1
- package/lib/runtime/viewport.d.ts +22 -2
- package/lib/runtime/viewport.js +12 -11
- package/lib/runtime/viewport.js.map +1 -1
- package/lib/spec/data.d.ts +2 -2
- package/lib/transforms/place-radial-labels.js +6 -1
- package/lib/transforms/place-radial-labels.js.map +1 -1
- package/lib/utils/event/events.d.ts +4 -4
- package/lib/utils/id.d.ts +1 -1
- package/lib/utils/visibility.d.ts +1 -2
- package/lib/utils/visibility.js +8 -34
- package/lib/utils/visibility.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +8 -8
- package/src/behaviors/collapse-expand.ts +10 -3
- package/src/behaviors/optimize-viewport-transform.ts +1 -1
- package/src/elements/nodes/html.ts +9 -0
- package/src/elements/shapes/base-shape.ts +1 -1
- package/src/exports.ts +1 -0
- package/src/plugins/hull/util.ts +7 -1
- package/src/preset.ts +0 -3
- package/src/runtime/data.ts +11 -4
- package/src/runtime/element.ts +51 -4
- package/src/runtime/graph.ts +21 -17
- package/src/runtime/viewport.ts +36 -10
- package/src/spec/data.ts +2 -2
- package/src/transforms/place-radial-labels.ts +5 -1
- package/src/utils/visibility.ts +6 -35
- package/src/version.ts +1 -1
- package/README.en-US.md +0 -118
|
@@ -6,14 +6,14 @@ export declare class BaseEvent {
|
|
|
6
6
|
constructor(type: string);
|
|
7
7
|
}
|
|
8
8
|
export declare class GraphLifeCycleEvent extends BaseEvent implements IGraphLifeCycleEvent {
|
|
9
|
-
data?: any;
|
|
10
|
-
constructor(type: GraphEvent.BEFORE_RENDER | GraphEvent.AFTER_RENDER | GraphEvent.BEFORE_DRAW | GraphEvent.AFTER_DRAW | GraphEvent.BEFORE_LAYOUT | GraphEvent.AFTER_LAYOUT | GraphEvent.BEFORE_STAGE_LAYOUT | GraphEvent.AFTER_STAGE_LAYOUT | GraphEvent.BEFORE_SIZE_CHANGE | GraphEvent.AFTER_SIZE_CHANGE | GraphEvent.BATCH_START | GraphEvent.BATCH_END | GraphEvent.BEFORE_DESTROY | GraphEvent.AFTER_DESTROY, data?: any);
|
|
9
|
+
data?: any | undefined;
|
|
10
|
+
constructor(type: GraphEvent.BEFORE_RENDER | GraphEvent.AFTER_RENDER | GraphEvent.BEFORE_DRAW | GraphEvent.AFTER_DRAW | GraphEvent.BEFORE_LAYOUT | GraphEvent.AFTER_LAYOUT | GraphEvent.BEFORE_STAGE_LAYOUT | GraphEvent.AFTER_STAGE_LAYOUT | GraphEvent.BEFORE_SIZE_CHANGE | GraphEvent.AFTER_SIZE_CHANGE | GraphEvent.BATCH_START | GraphEvent.BATCH_END | GraphEvent.BEFORE_DESTROY | GraphEvent.AFTER_DESTROY, data?: any | undefined);
|
|
11
11
|
}
|
|
12
12
|
export declare class AnimateEvent extends BaseEvent implements IAnimateEvent {
|
|
13
13
|
animationType: AnimationType;
|
|
14
14
|
animation: IAnimation | null;
|
|
15
|
-
data?: any;
|
|
16
|
-
constructor(type: GraphEvent.BEFORE_ANIMATE | GraphEvent.AFTER_ANIMATE, animationType: AnimationType, animation: IAnimation | null, data?: any);
|
|
15
|
+
data?: any | undefined;
|
|
16
|
+
constructor(type: GraphEvent.BEFORE_ANIMATE | GraphEvent.AFTER_ANIMATE, animationType: AnimationType, animation: IAnimation | null, data?: any | undefined);
|
|
17
17
|
}
|
|
18
18
|
export declare class ElementLifeCycleEvent extends BaseEvent implements IElementLifeCycleEvent {
|
|
19
19
|
elementType: ElementType;
|
package/lib/utils/id.d.ts
CHANGED
|
@@ -15,6 +15,6 @@ export declare function idOf(data: Partial<NodeData | EdgeData | ComboData>): ID
|
|
|
15
15
|
* @param data - <zh/> 节点/Combo 的数据 | <en/> data of node/combo
|
|
16
16
|
* @returns <zh/> 节点/Combo 的父节点 ID | <en/> parent id of node/combo
|
|
17
17
|
*/
|
|
18
|
-
export declare function parentIdOf(data: Partial<NodeData | ComboData>): string | undefined;
|
|
18
|
+
export declare function parentIdOf(data: Partial<NodeData | ComboData>): string | null | undefined;
|
|
19
19
|
export declare function idsOf(data: GraphData, flat: true): ID[];
|
|
20
20
|
export declare function idsOf(data: GraphData, flat: false): DataID;
|
|
@@ -5,11 +5,10 @@ import type { BaseStyleProps, DisplayObject } from '@antv/g';
|
|
|
5
5
|
* <en/> Set the visibility of the shape instance
|
|
6
6
|
* @param shape - <zh/> 图形实例 | <en/> shape instance
|
|
7
7
|
* @param value - <zh/> 可见性 | <en/> visibility
|
|
8
|
-
* @param inherited - <zh/> 是否是来自继承样式 | <en/> Whether it is from inherited styles
|
|
9
8
|
* @param filter - <zh/> 筛选出需要设置可见性的图形 | <en/> Filter out the shapes that need to set visibility
|
|
10
9
|
* @remarks
|
|
11
10
|
* <zh/> 在设置 enableCSSParsing 为 false 的情况下,复合图形无法继承父属性,因此需要对所有子图形应用相同的可见性
|
|
12
11
|
*
|
|
13
12
|
* <en/> After setting enableCSSParsing to false, the compound shape cannot inherit the parent attribute, so the same visibility needs to be applied to all child shapes
|
|
14
13
|
*/
|
|
15
|
-
export declare function setVisibility(shape: DisplayObject, value: BaseStyleProps['visibility'],
|
|
14
|
+
export declare function setVisibility(shape: DisplayObject, value: BaseStyleProps['visibility'], filter?: (shape: DisplayObject) => boolean): void;
|
package/lib/utils/visibility.js
CHANGED
|
@@ -1,52 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setVisibility = setVisibility;
|
|
4
|
-
const ORIGINAL_MAP = new WeakMap();
|
|
5
4
|
/**
|
|
6
5
|
* <zh/> 设置图形实例的可见性
|
|
7
6
|
*
|
|
8
7
|
* <en/> Set the visibility of the shape instance
|
|
9
8
|
* @param shape - <zh/> 图形实例 | <en/> shape instance
|
|
10
9
|
* @param value - <zh/> 可见性 | <en/> visibility
|
|
11
|
-
* @param inherited - <zh/> 是否是来自继承样式 | <en/> Whether it is from inherited styles
|
|
12
10
|
* @param filter - <zh/> 筛选出需要设置可见性的图形 | <en/> Filter out the shapes that need to set visibility
|
|
13
11
|
* @remarks
|
|
14
12
|
* <zh/> 在设置 enableCSSParsing 为 false 的情况下,复合图形无法继承父属性,因此需要对所有子图形应用相同的可见性
|
|
15
13
|
*
|
|
16
14
|
* <en/> After setting enableCSSParsing to false, the compound shape cannot inherit the parent attribute, so the same visibility needs to be applied to all child shapes
|
|
17
15
|
*/
|
|
18
|
-
function setVisibility(shape, value,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (filter && !filter(current))
|
|
24
|
-
return walk();
|
|
25
|
-
if (!inherited && current === shape) {
|
|
26
|
-
shape.style.visibility = value;
|
|
27
|
-
ORIGINAL_MAP.delete(shape);
|
|
28
|
-
walk(value);
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
if (!ORIGINAL_MAP.has(current))
|
|
32
|
-
ORIGINAL_MAP.set(current, current.style.visibility);
|
|
33
|
-
const computedValue = scope === 'hidden' || getOriginalValue(current) === 'hidden' ? 'hidden' : 'visible';
|
|
34
|
-
current.style.visibility = computedValue;
|
|
35
|
-
walk(computedValue);
|
|
36
|
-
}
|
|
16
|
+
function setVisibility(shape, value, filter) {
|
|
17
|
+
const callback = (node) => {
|
|
18
|
+
if (filter && !filter(node))
|
|
19
|
+
return;
|
|
20
|
+
node.style.visibility = value;
|
|
37
21
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
* <zh/> 获取图形原本的可见性
|
|
42
|
-
*
|
|
43
|
-
* <en/> Get the original visibility of the shape
|
|
44
|
-
* @param shape - <zh/> 图形实例 | <en/> shape instance
|
|
45
|
-
* @returns <zh/> 可见性 | <en/> visibility
|
|
46
|
-
*/
|
|
47
|
-
function getOriginalValue(shape) {
|
|
48
|
-
if (ORIGINAL_MAP.has(shape))
|
|
49
|
-
return ORIGINAL_MAP.get(shape);
|
|
50
|
-
return shape.style.visibility;
|
|
22
|
+
shape.forEach((node) => {
|
|
23
|
+
callback(node);
|
|
24
|
+
});
|
|
51
25
|
}
|
|
52
26
|
//# sourceMappingURL=visibility.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visibility.js","sourceRoot":"src/","sources":["utils/visibility.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"visibility.js","sourceRoot":"src/","sources":["utils/visibility.ts"],"names":[],"mappings":";;AAcA,sCAaC;AAzBD;;;;;;;;;;;GAWG;AACH,SAAgB,aAAa,CAC3B,KAAoB,EACpB,KAAmC,EACnC,MAA0C;IAE1C,MAAM,QAAQ,GAAG,CAAC,IAAmB,EAAE,EAAE;QACvC,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YAAE,OAAO;QACpC,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC;IAChC,CAAC,CAAC;IAEF,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACrB,QAAQ,CAAC,IAAqB,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/lib/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.0.
|
|
1
|
+
export declare const version = "5.0.33";
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/g6",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.33",
|
|
4
4
|
"description": "A Graph Visualization Framework in JavaScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antv",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@antv/algorithm": "^0.1.26",
|
|
36
|
-
"@antv/component": "^2.1.
|
|
36
|
+
"@antv/component": "^2.1.2",
|
|
37
37
|
"@antv/event-emitter": "^0.1.3",
|
|
38
|
-
"@antv/g": "^6.1.
|
|
39
|
-
"@antv/g-canvas": "^2.0.
|
|
40
|
-
"@antv/g-plugin-dragndrop": "^2.0.
|
|
41
|
-
"@antv/graphlib": "^2.0.
|
|
38
|
+
"@antv/g": "^6.1.14",
|
|
39
|
+
"@antv/g-canvas": "^2.0.32",
|
|
40
|
+
"@antv/g-plugin-dragndrop": "^2.0.25",
|
|
41
|
+
"@antv/graphlib": "^2.0.4",
|
|
42
42
|
"@antv/hierarchy": "^0.6.14",
|
|
43
43
|
"@antv/layout": "1.2.14-beta.9",
|
|
44
44
|
"@antv/util": "^3.3.10",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"hull.js": "^1.0.6"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@antv/g-svg": "^2.0.
|
|
50
|
-
"@antv/g-webgl": "^2.0.
|
|
49
|
+
"@antv/g-svg": "^2.0.27",
|
|
50
|
+
"@antv/g-webgl": "^2.0.36",
|
|
51
51
|
"@antv/layout-gpu": "^1.1.7",
|
|
52
52
|
"@antv/layout-wasm": "^1.4.2",
|
|
53
53
|
"@types/hull.js": "^1.0.4",
|
|
@@ -46,6 +46,12 @@ export interface CollapseExpandOptions extends BaseBehaviorOptions {
|
|
|
46
46
|
* <en/> Callback when expand is completed
|
|
47
47
|
*/
|
|
48
48
|
onExpand?: (id: ID) => void;
|
|
49
|
+
/**
|
|
50
|
+
* <zh/> 是否对准目标元素,避免视图偏移
|
|
51
|
+
*
|
|
52
|
+
* <en/> Whether to focus on the target element to avoid view offset
|
|
53
|
+
*/
|
|
54
|
+
align?: boolean;
|
|
49
55
|
}
|
|
50
56
|
|
|
51
57
|
/**
|
|
@@ -62,6 +68,7 @@ export class CollapseExpand extends BaseBehavior<CollapseExpandOptions> {
|
|
|
62
68
|
enable: true,
|
|
63
69
|
animation: true,
|
|
64
70
|
trigger: CommonEvent.DBLCLICK,
|
|
71
|
+
align: true,
|
|
65
72
|
};
|
|
66
73
|
|
|
67
74
|
constructor(context: RuntimeContext, options: CollapseExpandOptions) {
|
|
@@ -100,12 +107,12 @@ export class CollapseExpand extends BaseBehavior<CollapseExpandOptions> {
|
|
|
100
107
|
const data = model.getElementDataById(id) as NodeLikeData;
|
|
101
108
|
if (!data) return false;
|
|
102
109
|
|
|
103
|
-
const { onCollapse, onExpand, animation } = this.options;
|
|
110
|
+
const { onCollapse, onExpand, animation, align } = this.options;
|
|
104
111
|
if (isCollapsed(data)) {
|
|
105
|
-
await graph.expandElement(id, animation);
|
|
112
|
+
await graph.expandElement(id, { animation, align });
|
|
106
113
|
onExpand?.(id);
|
|
107
114
|
} else {
|
|
108
|
-
await graph.collapseElement(id, animation);
|
|
115
|
+
await graph.collapseElement(id, { animation, align });
|
|
109
116
|
onCollapse?.(id);
|
|
110
117
|
}
|
|
111
118
|
};
|
|
@@ -70,7 +70,7 @@ export class OptimizeViewportTransform extends BaseBehavior<OptimizeViewportTran
|
|
|
70
70
|
} else if (visibility === 'visible' && this.hiddenShapes.includes(element)) {
|
|
71
71
|
this.hiddenShapes.splice(this.hiddenShapes.indexOf(element), 1);
|
|
72
72
|
} else {
|
|
73
|
-
setVisibility(element, visibility,
|
|
73
|
+
setVisibility(element, visibility, filter);
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
76
|
};
|
|
@@ -83,6 +83,15 @@ export class HTML extends BaseNode<HTMLStyleProps> {
|
|
|
83
83
|
return this.getShape<GHTML>('key').getDomElement();
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
/**
|
|
87
|
+
* @override
|
|
88
|
+
*/
|
|
89
|
+
public render(attributes: Required<HTMLStyleProps> = this.parsedAttributes, container: Group = this): void {
|
|
90
|
+
this.drawKeyShape(attributes, container);
|
|
91
|
+
|
|
92
|
+
this.drawPortShapes(attributes, container);
|
|
93
|
+
}
|
|
94
|
+
|
|
86
95
|
protected getKeyStyle(attributes: Required<HTMLStyleProps>): GHTMLStyleProps {
|
|
87
96
|
const {
|
|
88
97
|
dx = 0,
|
|
@@ -256,7 +256,7 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
|
|
|
256
256
|
|
|
257
257
|
private setVisibility() {
|
|
258
258
|
const { visibility } = this.attributes;
|
|
259
|
-
setVisibility(this, visibility
|
|
259
|
+
setVisibility(this, visibility);
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
public destroy(): void {
|
package/src/exports.ts
CHANGED
|
@@ -206,6 +206,7 @@ export type {
|
|
|
206
206
|
WatermarkOptions,
|
|
207
207
|
} from './plugins';
|
|
208
208
|
export type { CanvasConfig, DataURLOptions } from './runtime/canvas';
|
|
209
|
+
export type { CollapseExpandNodeOptions } from './runtime/element';
|
|
209
210
|
export type { RuntimeContext } from './runtime/types';
|
|
210
211
|
export type {
|
|
211
212
|
BehaviorOptions,
|
package/src/plugins/hull/util.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type PathArray } from '@antv/util';
|
|
|
2
2
|
import type { Point, Vector2 } from '../../types';
|
|
3
3
|
import { getLinesIntersection } from '../../utils/line';
|
|
4
4
|
import { getClosedSpline } from '../../utils/path';
|
|
5
|
-
import { sortByClockwise } from '../../utils/point';
|
|
5
|
+
import { isCollinear, sortByClockwise } from '../../utils/point';
|
|
6
6
|
import { add, angle, normalize, perpendicular, scale, subtract, toVector2, toVector3 } from '../../utils/vector';
|
|
7
7
|
import type { HullOptions } from '../hull';
|
|
8
8
|
|
|
@@ -18,6 +18,11 @@ import type { HullOptions } from '../hull';
|
|
|
18
18
|
export function computeHullPath(points: Point[], padding: number, corner: 'rounded' | 'smooth' | 'sharp'): PathArray {
|
|
19
19
|
if (points.length === 1) return genSinglePointHullPath(points[0], padding, corner);
|
|
20
20
|
if (points.length === 2) return genTwoPointsHullPath(points, padding, corner);
|
|
21
|
+
if (points.length === 3) {
|
|
22
|
+
const [p1, p2, p3] = sortByClockwise(points);
|
|
23
|
+
if (isCollinear(p1, p2, p3)) return genTwoPointsHullPath([p1, p3], padding, corner);
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
switch (corner) {
|
|
22
27
|
case 'smooth':
|
|
23
28
|
return genMultiPointsSmoothHull(points, padding);
|
|
@@ -134,6 +139,7 @@ const genMultiPointsRoundedHull = (points: Point[], padding: number): PathArray
|
|
|
134
139
|
},
|
|
135
140
|
];
|
|
136
141
|
});
|
|
142
|
+
|
|
137
143
|
const arcData = [padding, padding, 0, 0, 0];
|
|
138
144
|
const startIndex = segments.findIndex(
|
|
139
145
|
(segment, i) =>
|
package/src/preset.ts
CHANGED
package/src/runtime/data.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Graph as GraphLib } from '@antv/graphlib';
|
|
2
|
-
import {
|
|
2
|
+
import { isNil, isNumber, uniq } from '@antv/util';
|
|
3
3
|
import { COMBO_KEY, ChangeType, TREE_KEY } from '../constants';
|
|
4
4
|
import type { ComboData, EdgeData, GraphData, NodeData } from '../spec';
|
|
5
5
|
import type {
|
|
@@ -518,8 +518,15 @@ export class DataController {
|
|
|
518
518
|
const id = idOf(datum);
|
|
519
519
|
const parent = parentIdOf(datum);
|
|
520
520
|
|
|
521
|
-
if (parent) {
|
|
521
|
+
if (parent !== undefined) {
|
|
522
522
|
if (!model.hasTreeStructure(COMBO_KEY)) model.attachTreeStructure(COMBO_KEY);
|
|
523
|
+
|
|
524
|
+
// 解除原父节点的子节点关系,更新原父节点及其祖先的数据
|
|
525
|
+
// Remove the child relationship of the original parent node, update the data of the original parent node and its ancestors
|
|
526
|
+
if (parent === null) {
|
|
527
|
+
this.refreshComboData(id);
|
|
528
|
+
}
|
|
529
|
+
|
|
523
530
|
this.setParent(id, parentIdOf(datum), COMBO_KEY);
|
|
524
531
|
}
|
|
525
532
|
|
|
@@ -665,7 +672,7 @@ export class DataController {
|
|
|
665
672
|
* @param hierarchyKey - <zh/> 层次结构类型 | <en/> hierarchy type
|
|
666
673
|
* @param update - <zh/> 添加新/旧父节点数据更新记录 | <en/> add new/old parent node data update record
|
|
667
674
|
*/
|
|
668
|
-
public setParent(id: ID, parent: ID | undefined, hierarchyKey: HierarchyKey, update: boolean = true) {
|
|
675
|
+
public setParent(id: ID, parent: ID | undefined | null, hierarchyKey: HierarchyKey, update: boolean = true) {
|
|
669
676
|
if (id === parent) return;
|
|
670
677
|
const elementData = this.getNodeLikeDatum(id);
|
|
671
678
|
const originalParentId = parentIdOf(elementData);
|
|
@@ -891,7 +898,7 @@ export class DataController {
|
|
|
891
898
|
this.model.mergeNodeData(idOf(childData), value);
|
|
892
899
|
});
|
|
893
900
|
|
|
894
|
-
if (!
|
|
901
|
+
if (!isNil(grandParent)) this.refreshComboData(grandParent);
|
|
895
902
|
}
|
|
896
903
|
}
|
|
897
904
|
|
package/src/runtime/element.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { groupBy } from '@antv/util';
|
|
|
6
6
|
import { AnimationType, COMBO_KEY, ChangeType, GraphEvent } from '../constants';
|
|
7
7
|
import { ELEMENT_TYPES } from '../constants/element';
|
|
8
8
|
import { getExtension } from '../registry/get';
|
|
9
|
-
import type { ComboData, EdgeData, NodeData } from '../spec';
|
|
9
|
+
import type { ComboData, EdgeData, GraphData, NodeData } from '../spec';
|
|
10
10
|
import type { AnimationStage } from '../spec/element/animation';
|
|
11
11
|
import type { DrawData, ProcedureData } from '../transforms/types';
|
|
12
12
|
import type {
|
|
@@ -35,6 +35,7 @@ import { positionOf } from '../utils/position';
|
|
|
35
35
|
import { print } from '../utils/print';
|
|
36
36
|
import { computeElementCallbackStyle } from '../utils/style';
|
|
37
37
|
import { themeOf } from '../utils/theme';
|
|
38
|
+
import { subtract } from '../utils/vector';
|
|
38
39
|
import { setVisibility } from '../utils/visibility';
|
|
39
40
|
import type { RuntimeContext } from './types';
|
|
40
41
|
|
|
@@ -590,6 +591,28 @@ export class ElementController {
|
|
|
590
591
|
delete this.shapeTypeMap[id];
|
|
591
592
|
}
|
|
592
593
|
|
|
594
|
+
/**
|
|
595
|
+
* <zh/> 将布局结果对齐到元素,避免视图偏移。会修改布局结果
|
|
596
|
+
*
|
|
597
|
+
* <en/> Align the layout result to the element to avoid view offset. Will modify the layout result
|
|
598
|
+
* @param layoutResult - <zh/> 布局结果 | <en/> layout result
|
|
599
|
+
* @param id - <zh/> 元素 ID | <en/> element ID
|
|
600
|
+
*/
|
|
601
|
+
private alignLayoutResultToElement(layoutResult: GraphData, id: ID) {
|
|
602
|
+
const target = layoutResult.nodes?.find((node) => idOf(node) === id);
|
|
603
|
+
|
|
604
|
+
if (target) {
|
|
605
|
+
const originalPosition = positionOf(this.context.model.getNodeLikeDatum(id));
|
|
606
|
+
const modifiedPosition = positionOf(target);
|
|
607
|
+
const delta = subtract(originalPosition, modifiedPosition);
|
|
608
|
+
layoutResult.nodes?.forEach((node) => {
|
|
609
|
+
if (node.style?.x) node.style.x += delta[0];
|
|
610
|
+
if (node.style?.y) node.style.y += delta[1];
|
|
611
|
+
if (node.style?.z) node.style.z += delta[2] || 0;
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
593
616
|
/**
|
|
594
617
|
* <zh/> 收起节点
|
|
595
618
|
*
|
|
@@ -597,7 +620,9 @@ export class ElementController {
|
|
|
597
620
|
* @param id - <zh/> 元素 ID | <en/> element ID
|
|
598
621
|
* @param animation - <zh/> 是否使用动画,默认为 true | <en/> Whether to use animation, default is true
|
|
599
622
|
*/
|
|
600
|
-
public async collapseNode(id: ID,
|
|
623
|
+
public async collapseNode(id: ID, options: CollapseExpandNodeOptions): Promise<void> {
|
|
624
|
+
const { animation, align } = options;
|
|
625
|
+
|
|
601
626
|
const { model, layout } = this.context;
|
|
602
627
|
|
|
603
628
|
const preLayoutData = this.computeChangesAndDrawData({ stage: 'collapse', animation });
|
|
@@ -608,6 +633,7 @@ export class ElementController {
|
|
|
608
633
|
// 进行预布局,计算出所有元素的位置
|
|
609
634
|
// Perform pre-layout to calculate the position of all elements
|
|
610
635
|
const result = await layout!.simulate();
|
|
636
|
+
if (align) this.alignLayoutResultToElement(result, id);
|
|
611
637
|
model.updateData(result);
|
|
612
638
|
|
|
613
639
|
// 重新计算数据 / Recalculate data
|
|
@@ -647,9 +673,9 @@ export class ElementController {
|
|
|
647
673
|
* @param id - <zh/> 元素 ID | <en/> element ID
|
|
648
674
|
* @param animation - <zh/> 是否使用动画,默认为 true | <en/> Whether to use animation, default is true
|
|
649
675
|
*/
|
|
650
|
-
public async expandNode(id: ID,
|
|
676
|
+
public async expandNode(id: ID, options: CollapseExpandNodeOptions): Promise<void> {
|
|
651
677
|
const { model, layout } = this.context;
|
|
652
|
-
|
|
678
|
+
const { animation, align } = options;
|
|
653
679
|
|
|
654
680
|
const position = positionOf(model.getNodeData([id])[0]);
|
|
655
681
|
|
|
@@ -666,6 +692,7 @@ export class ElementController {
|
|
|
666
692
|
this.context.animation!.clear();
|
|
667
693
|
|
|
668
694
|
const result = await layout!.simulate();
|
|
695
|
+
if (align) this.alignLayoutResultToElement(result, id);
|
|
669
696
|
model.updateData(result);
|
|
670
697
|
|
|
671
698
|
// 重新计算数据 / Recalculate data
|
|
@@ -809,3 +836,23 @@ export interface DrawContext {
|
|
|
809
836
|
/** <zh/> 展开阶段的目标元素 id | <en/> ID of the target element in the expand stage */
|
|
810
837
|
target?: ID;
|
|
811
838
|
}
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* <zh/> 展开/收起节点选项
|
|
842
|
+
*
|
|
843
|
+
* <en/> Expand / collapse node options
|
|
844
|
+
*/
|
|
845
|
+
export interface CollapseExpandNodeOptions {
|
|
846
|
+
/**
|
|
847
|
+
* <zh/> 是否使用动画
|
|
848
|
+
*
|
|
849
|
+
* <en/> Whether to use animation
|
|
850
|
+
*/
|
|
851
|
+
animation?: boolean;
|
|
852
|
+
/**
|
|
853
|
+
* <zh/> 保证展开/收起的节点位置不变
|
|
854
|
+
*
|
|
855
|
+
* <en/> Ensure that the position of the expanded/collapsed node remains unchanged
|
|
856
|
+
*/
|
|
857
|
+
align?: boolean;
|
|
858
|
+
}
|
package/src/runtime/graph.ts
CHANGED
|
@@ -53,6 +53,7 @@ import { BehaviorController } from './behavior';
|
|
|
53
53
|
import type { DataURLOptions } from './canvas';
|
|
54
54
|
import { Canvas } from './canvas';
|
|
55
55
|
import { DataController } from './data';
|
|
56
|
+
import type { CollapseExpandNodeOptions } from './element';
|
|
56
57
|
import { ElementController } from './element';
|
|
57
58
|
import { LayoutController } from './layout';
|
|
58
59
|
import { PluginController } from './plugin';
|
|
@@ -424,7 +425,7 @@ export class Graph extends EventEmitter {
|
|
|
424
425
|
* <zh/> 获取插件实例
|
|
425
426
|
*
|
|
426
427
|
* <en/> Get plugin instance
|
|
427
|
-
* @param key - <zh/> 插件 key | <en/> plugin key
|
|
428
|
+
* @param key - <zh/> 插件 key(在配置 plugin 时需要手动传入指定) | <en/> plugin key(need to be specified manually when configuring plugin)
|
|
428
429
|
* @returns <zh/> 插件实例 | <en/> plugin instance
|
|
429
430
|
* @remarks
|
|
430
431
|
* <zh/> 一些插件提供了 API 方法可供调用,例如全屏插件可以调用 `request` 和 `exit` 方法来请求和退出全屏
|
|
@@ -1286,7 +1287,7 @@ export class Graph extends EventEmitter {
|
|
|
1286
1287
|
* @apiCategory viewport
|
|
1287
1288
|
*/
|
|
1288
1289
|
public async fitCenter(animation?: ViewportAnimationEffectTiming): Promise<void> {
|
|
1289
|
-
await this.context.viewport?.fitCenter(animation);
|
|
1290
|
+
await this.context.viewport?.fitCenter({ animation });
|
|
1290
1291
|
}
|
|
1291
1292
|
|
|
1292
1293
|
private async autoFit(): Promise<void> {
|
|
@@ -1316,7 +1317,7 @@ export class Graph extends EventEmitter {
|
|
|
1316
1317
|
* @apiCategory viewport
|
|
1317
1318
|
*/
|
|
1318
1319
|
public async focusElement(id: ID | ID[], animation?: ViewportAnimationEffectTiming): Promise<void> {
|
|
1319
|
-
await this.context.viewport?.focusElements(Array.isArray(id) ? id : [id], animation);
|
|
1320
|
+
await this.context.viewport?.focusElements(Array.isArray(id) ? id : [id], { animation });
|
|
1320
1321
|
}
|
|
1321
1322
|
|
|
1322
1323
|
/**
|
|
@@ -1782,50 +1783,53 @@ export class Graph extends EventEmitter {
|
|
|
1782
1783
|
private isCollapsingExpanding = false;
|
|
1783
1784
|
|
|
1784
1785
|
/**
|
|
1785
|
-
* <zh/>
|
|
1786
|
+
* <zh/> 收起元素
|
|
1786
1787
|
*
|
|
1787
|
-
* <en/> Collapse
|
|
1788
|
+
* <en/> Collapse element
|
|
1788
1789
|
* @param id - <zh/> 元素 ID | <en/> element ID
|
|
1789
|
-
* @param
|
|
1790
|
+
* @param options - <zh/> 是否启用动画或者配置收起节点的配置项 | <en/> whether to enable animation or the options of collapsing node
|
|
1790
1791
|
* @apiCategory element
|
|
1791
1792
|
*/
|
|
1792
|
-
public async collapseElement(id: ID,
|
|
1793
|
+
public async collapseElement(id: ID, options: boolean | CollapseExpandNodeOptions = true): Promise<void> {
|
|
1793
1794
|
const { model, element } = this.context;
|
|
1794
1795
|
if (isCollapsed(model.getNodeLikeData([id])[0])) return;
|
|
1795
|
-
|
|
1796
1796
|
if (this.isCollapsingExpanding) return;
|
|
1797
1797
|
|
|
1798
|
+
if (typeof options === 'boolean') options = { animation: options, align: true };
|
|
1799
|
+
|
|
1798
1800
|
const elementType = model.getElementType(id);
|
|
1799
1801
|
|
|
1800
1802
|
await this.frontElement(id);
|
|
1801
1803
|
this.isCollapsingExpanding = true;
|
|
1802
1804
|
this.setElementCollapsibility(id, true);
|
|
1803
|
-
if (elementType === 'node') await element!.collapseNode(id,
|
|
1804
|
-
else if (elementType === 'combo') await element!.collapseCombo(id, animation);
|
|
1805
|
+
if (elementType === 'node') await element!.collapseNode(id, options);
|
|
1806
|
+
else if (elementType === 'combo') await element!.collapseCombo(id, !!options.animation);
|
|
1805
1807
|
|
|
1806
1808
|
this.isCollapsingExpanding = false;
|
|
1807
1809
|
}
|
|
1808
1810
|
|
|
1809
1811
|
/**
|
|
1810
|
-
* <zh/>
|
|
1812
|
+
* <zh/> 展开元素
|
|
1811
1813
|
*
|
|
1812
|
-
* <en/> Expand
|
|
1814
|
+
* <en/> Expand Element
|
|
1813
1815
|
* @param id - <zh/> 元素 ID | <en/> element ID
|
|
1814
|
-
* @param animation - <zh/>
|
|
1816
|
+
* @param animation - <zh/> 是否启用动画或者配置收起节点的配置项 | <en/> whether to enable animation or the options of collapsing node
|
|
1817
|
+
* @param options
|
|
1815
1818
|
* @apiCategory element
|
|
1816
1819
|
*/
|
|
1817
|
-
public async expandElement(id: ID,
|
|
1820
|
+
public async expandElement(id: ID, options: boolean | CollapseExpandNodeOptions = true): Promise<void> {
|
|
1818
1821
|
const { model, element } = this.context;
|
|
1819
1822
|
if (!isCollapsed(model.getNodeLikeData([id])[0])) return;
|
|
1820
|
-
|
|
1821
1823
|
if (this.isCollapsingExpanding) return;
|
|
1822
1824
|
|
|
1825
|
+
if (typeof options === 'boolean') options = { animation: options, align: true };
|
|
1826
|
+
|
|
1823
1827
|
const elementType = model.getElementType(id);
|
|
1824
1828
|
|
|
1825
1829
|
this.isCollapsingExpanding = true;
|
|
1826
1830
|
this.setElementCollapsibility(id, false);
|
|
1827
|
-
if (elementType === 'node') await element!.expandNode(id,
|
|
1828
|
-
else if (elementType === 'combo') await element!.expandCombo(id, animation);
|
|
1831
|
+
if (elementType === 'node') await element!.expandNode(id, options);
|
|
1832
|
+
else if (elementType === 'combo') await element!.expandCombo(id, !!options.animation);
|
|
1829
1833
|
|
|
1830
1834
|
this.isCollapsingExpanding = false;
|
|
1831
1835
|
}
|
package/src/runtime/viewport.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { AABB, ICamera } from '@antv/g';
|
|
|
2
2
|
import { clamp, isNumber, pick } from '@antv/util';
|
|
3
3
|
import { AnimationType, GraphEvent } from '../constants';
|
|
4
4
|
import type { FitViewOptions, ID, Point, TransformOptions, Vector2, ViewportAnimationEffectTiming } from '../types';
|
|
5
|
+
import type { Element } from '../types/element';
|
|
5
6
|
import { getAnimationOptions } from '../utils/animation';
|
|
6
7
|
import { getBBoxSize, getCombinedBBox, getExpandedBBox, isBBoxInside, isPointInBBox } from '../utils/bbox';
|
|
7
8
|
import { AnimateEvent, ViewportEvent, emit } from '../utils/event';
|
|
@@ -217,7 +218,7 @@ export class ViewportController {
|
|
|
217
218
|
(direction === 'y' && contentHeight >= innerHeight) ||
|
|
218
219
|
(direction === 'both' && contentWidth >= innerWidth && contentHeight >= innerHeight);
|
|
219
220
|
|
|
220
|
-
if (when === 'overflow' && !isOverflow) return await this.fitCenter(animation);
|
|
221
|
+
if (when === 'overflow' && !isOverflow) return await this.fitCenter({ animation });
|
|
221
222
|
|
|
222
223
|
const scaleX = innerWidth / contentWidth;
|
|
223
224
|
const scaleY = innerHeight / contentHeight;
|
|
@@ -237,23 +238,27 @@ export class ViewportController {
|
|
|
237
238
|
);
|
|
238
239
|
}
|
|
239
240
|
|
|
240
|
-
public async fitCenter(
|
|
241
|
+
public async fitCenter(options: FocusOptions): Promise<void> {
|
|
241
242
|
const canvasBounds = this.context.canvas.getBounds();
|
|
242
|
-
await this.focus(canvasBounds,
|
|
243
|
+
await this.focus(canvasBounds, options);
|
|
243
244
|
}
|
|
244
245
|
|
|
245
|
-
public async focusElements(ids: ID[],
|
|
246
|
+
public async focusElements(ids: ID[], options: FocusOptions = {}): Promise<void> {
|
|
246
247
|
const { element } = this.context;
|
|
247
248
|
if (!element) return;
|
|
248
|
-
|
|
249
|
-
|
|
249
|
+
|
|
250
|
+
const getBoundsOf = (el: Element) =>
|
|
251
|
+
options.shapes ? el.getShape(options.shapes).getRenderBounds() : el.getRenderBounds();
|
|
252
|
+
|
|
253
|
+
const elementsBounds = getCombinedBBox(ids.map((id) => getBoundsOf(element.getElement(id)!)));
|
|
254
|
+
await this.focus(elementsBounds, options);
|
|
250
255
|
}
|
|
251
256
|
|
|
252
|
-
private async focus(bbox: AABB,
|
|
257
|
+
private async focus(bbox: AABB, options: FocusOptions) {
|
|
253
258
|
const center = this.context.graph.getViewportByCanvas(bbox.center);
|
|
254
|
-
const
|
|
255
|
-
const delta = subtract(
|
|
256
|
-
await this.transform({ mode: 'relative', translate: add(delta, this.paddingOffset) }, animation);
|
|
259
|
+
const position = options.position || this.getCanvasCenter();
|
|
260
|
+
const delta = subtract(position, center);
|
|
261
|
+
await this.transform({ mode: 'relative', translate: add(delta, this.paddingOffset) }, options.animation);
|
|
257
262
|
}
|
|
258
263
|
|
|
259
264
|
/**
|
|
@@ -312,3 +317,24 @@ export class ViewportController {
|
|
|
312
317
|
this.transformResolver?.();
|
|
313
318
|
}
|
|
314
319
|
}
|
|
320
|
+
|
|
321
|
+
export interface FocusOptions {
|
|
322
|
+
/**
|
|
323
|
+
* <zh/> 动画配置
|
|
324
|
+
*
|
|
325
|
+
* <en/> Animation configuration
|
|
326
|
+
*/
|
|
327
|
+
animation?: ViewportAnimationEffectTiming;
|
|
328
|
+
/**
|
|
329
|
+
* <zh/> 使用子图形计算包围盒
|
|
330
|
+
*
|
|
331
|
+
* <en/> Calculate the bounding box by using sub-shapes
|
|
332
|
+
*/
|
|
333
|
+
shapes?: string;
|
|
334
|
+
/**
|
|
335
|
+
* <zh/> 对齐位置,默认为画布中心
|
|
336
|
+
*
|
|
337
|
+
* <en/> Alignment position, default is the center of the canvas
|
|
338
|
+
*/
|
|
339
|
+
position?: Point;
|
|
340
|
+
}
|
package/src/spec/data.ts
CHANGED
|
@@ -92,7 +92,7 @@ export interface NodeData {
|
|
|
92
92
|
*
|
|
93
93
|
* <en/> ID of the combo to which the node belongs
|
|
94
94
|
*/
|
|
95
|
-
combo?: ID;
|
|
95
|
+
combo?: ID | null;
|
|
96
96
|
/**
|
|
97
97
|
* <zh/> 子节点 ID
|
|
98
98
|
*
|
|
@@ -161,7 +161,7 @@ export interface ComboData {
|
|
|
161
161
|
*
|
|
162
162
|
* <en/> ID of the combo to which the combo belongs
|
|
163
163
|
*/
|
|
164
|
-
combo?: ID;
|
|
164
|
+
combo?: ID | null;
|
|
165
165
|
[key: string]: unknown;
|
|
166
166
|
}
|
|
167
167
|
|
|
@@ -54,7 +54,11 @@ export class PlaceRadialLabels extends BaseTransform<PlaceRadialLabelsOptions> {
|
|
|
54
54
|
const isLeft = Math.abs(radian) > Math.PI / 2;
|
|
55
55
|
|
|
56
56
|
const isLeaf = !datum.children || datum.children.length === 0;
|
|
57
|
-
const
|
|
57
|
+
const nodeId = idOf(datum);
|
|
58
|
+
const node = this.context.element?.getElement(nodeId);
|
|
59
|
+
if (!node || !node.isVisible()) return;
|
|
60
|
+
|
|
61
|
+
const nodeHalfWidth = parseSize(graph.getElementRenderStyle(nodeId).size)[0] / 2;
|
|
58
62
|
const offset = (isLeaf ? 1 : -1) * (nodeHalfWidth + this.options.offset);
|
|
59
63
|
|
|
60
64
|
const labelTransform: TransformArray = [
|