@antv/g6 5.0.1 → 5.0.3
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 +2 -2
- package/dist/lib/behaviors/click-select.d.ts +4 -5
- package/dist/lib/behaviors/hover-activate.d.ts +0 -1
- package/dist/lib/elements/base-element.d.ts +1 -22
- package/dist/lib/elements/combos/base-combo.d.ts +4 -4
- package/dist/lib/elements/edges/base-edge.d.ts +4 -2
- package/dist/lib/elements/effect.d.ts +17 -0
- package/dist/lib/elements/nodes/base-node.d.ts +5 -4
- package/dist/lib/elements/nodes/diamond.d.ts +0 -1
- package/dist/lib/elements/shapes/badge.d.ts +17 -6
- package/dist/lib/elements/shapes/base-shape.d.ts +9 -3
- package/dist/lib/elements/shapes/icon.d.ts +15 -3
- package/dist/lib/elements/shapes/label.d.ts +18 -7
- package/dist/lib/exports.d.ts +3 -2
- package/dist/lib/index.d.ts +5 -1
- package/dist/lib/layouts/base-layout.d.ts +3 -1
- package/dist/lib/plugins/bubble-sets.d.ts +2 -2
- package/dist/lib/plugins/contextmenu/index.d.ts +4 -3
- package/dist/lib/plugins/hull/index.d.ts +2 -2
- package/dist/lib/runtime/canvas.d.ts +15 -2
- package/dist/lib/runtime/data.d.ts +9 -16
- package/dist/lib/runtime/element.d.ts +18 -2
- package/dist/lib/runtime/graph.d.ts +374 -109
- package/dist/lib/spec/element/edge.d.ts +1 -1
- package/dist/lib/spec/element/node.d.ts +1 -1
- package/dist/lib/transforms/process-parallel-edges.d.ts +2 -2
- package/dist/lib/types/callable.d.ts +0 -11
- package/dist/lib/types/data.d.ts +12 -0
- package/dist/lib/types/edge.d.ts +11 -0
- package/dist/lib/types/element.d.ts +100 -9
- package/dist/lib/types/index.d.ts +0 -1
- package/dist/lib/types/point.d.ts +0 -1
- package/dist/lib/utils/element.d.ts +2 -2
- package/dist/lib/utils/layout.d.ts +2 -2
- package/dist/lib/utils/path.d.ts +3 -3
- package/dist/lib/utils/position.d.ts +8 -8
- package/dist/lib/utils/style.d.ts +13 -8
- package/esm/behaviors/click-select.d.ts +4 -5
- package/esm/behaviors/click-select.js +62 -50
- package/esm/behaviors/click-select.js.map +1 -1
- package/esm/behaviors/drag-element.js +2 -9
- package/esm/behaviors/drag-element.js.map +1 -1
- package/esm/behaviors/hover-activate.d.ts +0 -1
- package/esm/behaviors/hover-activate.js +18 -16
- package/esm/behaviors/hover-activate.js.map +1 -1
- package/esm/behaviors/lasso-select.js.map +1 -1
- package/esm/elements/base-element.d.ts +1 -22
- package/esm/elements/base-element.js +0 -21
- package/esm/elements/base-element.js.map +1 -1
- package/esm/elements/combos/base-combo.d.ts +4 -4
- package/esm/elements/combos/base-combo.js +27 -4
- package/esm/elements/combos/base-combo.js.map +1 -1
- package/esm/elements/edges/base-edge.d.ts +4 -2
- package/esm/elements/edges/base-edge.js +41 -7
- package/esm/elements/edges/base-edge.js.map +1 -1
- package/esm/elements/effect.d.ts +17 -0
- package/esm/elements/effect.js +70 -0
- package/esm/elements/effect.js.map +1 -0
- package/esm/elements/nodes/base-node.d.ts +5 -4
- package/esm/elements/nodes/base-node.js +33 -14
- package/esm/elements/nodes/base-node.js.map +1 -1
- package/esm/elements/nodes/circle.js +1 -1
- package/esm/elements/nodes/circle.js.map +1 -1
- package/esm/elements/nodes/diamond.d.ts +0 -1
- package/esm/elements/nodes/diamond.js +0 -6
- package/esm/elements/nodes/diamond.js.map +1 -1
- package/esm/elements/nodes/ellipse.js +1 -1
- package/esm/elements/nodes/ellipse.js.map +1 -1
- package/esm/elements/nodes/image.js +2 -2
- package/esm/elements/nodes/image.js.map +1 -1
- package/esm/elements/nodes/rect.js +1 -1
- package/esm/elements/nodes/rect.js.map +1 -1
- package/esm/elements/shapes/badge.d.ts +17 -6
- package/esm/elements/shapes/badge.js +9 -0
- package/esm/elements/shapes/badge.js.map +1 -1
- package/esm/elements/shapes/base-shape.d.ts +9 -3
- package/esm/elements/shapes/base-shape.js +33 -15
- package/esm/elements/shapes/base-shape.js.map +1 -1
- package/esm/elements/shapes/icon.d.ts +15 -3
- package/esm/elements/shapes/icon.js +12 -4
- package/esm/elements/shapes/icon.js.map +1 -1
- package/esm/elements/shapes/label.d.ts +18 -7
- package/esm/elements/shapes/label.js +10 -0
- package/esm/elements/shapes/label.js.map +1 -1
- package/esm/elements/shapes/polygon.js +1 -1
- package/esm/elements/shapes/polygon.js.map +1 -1
- package/esm/exports.d.ts +3 -2
- package/esm/exports.js +1 -1
- package/esm/exports.js.map +1 -1
- package/esm/index.d.ts +5 -1
- package/esm/index.js +5 -1
- package/esm/index.js.map +1 -1
- package/esm/layouts/base-layout.d.ts +3 -1
- package/esm/layouts/base-layout.js +3 -1
- package/esm/layouts/base-layout.js.map +1 -1
- package/esm/plugins/bubble-sets.d.ts +2 -2
- package/esm/plugins/bubble-sets.js.map +1 -1
- package/esm/plugins/contextmenu/index.d.ts +4 -3
- package/esm/plugins/contextmenu/index.js +12 -10
- package/esm/plugins/contextmenu/index.js.map +1 -1
- package/esm/plugins/hull/index.d.ts +2 -2
- package/esm/plugins/hull/index.js.map +1 -1
- package/esm/runtime/canvas.d.ts +15 -2
- package/esm/runtime/canvas.js.map +1 -1
- package/esm/runtime/data.d.ts +9 -16
- package/esm/runtime/data.js +26 -34
- package/esm/runtime/data.js.map +1 -1
- package/esm/runtime/element.d.ts +18 -2
- package/esm/runtime/element.js +75 -24
- package/esm/runtime/element.js.map +1 -1
- package/esm/runtime/graph.d.ts +374 -109
- package/esm/runtime/graph.js +278 -82
- package/esm/runtime/graph.js.map +1 -1
- package/esm/runtime/layout.js +1 -1
- package/esm/runtime/layout.js.map +1 -1
- package/esm/spec/element/edge.d.ts +1 -1
- package/esm/spec/element/node.d.ts +1 -1
- package/esm/themes/base.js +5 -0
- package/esm/themes/base.js.map +1 -1
- package/esm/transforms/collapse-expand-node.js +14 -4
- package/esm/transforms/collapse-expand-node.js.map +1 -1
- package/esm/transforms/process-parallel-edges.d.ts +2 -2
- package/esm/types/callable.d.ts +0 -11
- package/esm/types/data.d.ts +12 -0
- package/esm/types/edge.d.ts +11 -0
- package/esm/types/element.d.ts +100 -9
- package/esm/types/index.d.ts +0 -1
- package/esm/types/point.d.ts +0 -1
- package/esm/utils/element.d.ts +2 -2
- package/esm/utils/element.js.map +1 -1
- package/esm/utils/layout.d.ts +2 -2
- package/esm/utils/layout.js +4 -4
- package/esm/utils/layout.js.map +1 -1
- package/esm/utils/path.d.ts +3 -3
- package/esm/utils/path.js +1 -1
- package/esm/utils/path.js.map +1 -1
- package/esm/utils/position.d.ts +8 -8
- package/esm/utils/position.js +2 -2
- package/esm/utils/position.js.map +1 -1
- package/esm/utils/style.d.ts +13 -8
- package/esm/utils/style.js +16 -11
- package/esm/utils/style.js.map +1 -1
- package/lib/behaviors/click-select.d.ts +4 -5
- package/lib/behaviors/click-select.js +62 -50
- package/lib/behaviors/click-select.js.map +1 -1
- package/lib/behaviors/drag-element.js +2 -9
- package/lib/behaviors/drag-element.js.map +1 -1
- package/lib/behaviors/hover-activate.d.ts +0 -1
- package/lib/behaviors/hover-activate.js +18 -16
- package/lib/behaviors/hover-activate.js.map +1 -1
- package/lib/behaviors/lasso-select.js.map +1 -1
- package/lib/elements/base-element.d.ts +1 -22
- package/lib/elements/base-element.js +0 -21
- package/lib/elements/base-element.js.map +1 -1
- package/lib/elements/combos/base-combo.d.ts +4 -4
- package/lib/elements/combos/base-combo.js +27 -4
- package/lib/elements/combos/base-combo.js.map +1 -1
- package/lib/elements/edges/base-edge.d.ts +4 -2
- package/lib/elements/edges/base-edge.js +41 -7
- package/lib/elements/edges/base-edge.js.map +1 -1
- package/lib/elements/effect.d.ts +17 -0
- package/lib/elements/effect.js +74 -0
- package/lib/elements/effect.js.map +1 -0
- package/lib/elements/nodes/base-node.d.ts +5 -4
- package/lib/elements/nodes/base-node.js +33 -14
- package/lib/elements/nodes/base-node.js.map +1 -1
- package/lib/elements/nodes/circle.js +1 -1
- package/lib/elements/nodes/circle.js.map +1 -1
- package/lib/elements/nodes/diamond.d.ts +0 -1
- package/lib/elements/nodes/diamond.js +0 -6
- package/lib/elements/nodes/diamond.js.map +1 -1
- package/lib/elements/nodes/ellipse.js +1 -1
- package/lib/elements/nodes/ellipse.js.map +1 -1
- package/lib/elements/nodes/image.js +2 -2
- package/lib/elements/nodes/image.js.map +1 -1
- package/lib/elements/nodes/rect.js +1 -1
- package/lib/elements/nodes/rect.js.map +1 -1
- package/lib/elements/shapes/badge.d.ts +17 -6
- package/lib/elements/shapes/badge.js +9 -0
- package/lib/elements/shapes/badge.js.map +1 -1
- package/lib/elements/shapes/base-shape.d.ts +9 -3
- package/lib/elements/shapes/base-shape.js +33 -15
- package/lib/elements/shapes/base-shape.js.map +1 -1
- package/lib/elements/shapes/icon.d.ts +15 -3
- package/lib/elements/shapes/icon.js +12 -4
- package/lib/elements/shapes/icon.js.map +1 -1
- package/lib/elements/shapes/label.d.ts +18 -7
- package/lib/elements/shapes/label.js +10 -0
- package/lib/elements/shapes/label.js.map +1 -1
- package/lib/elements/shapes/polygon.js +1 -1
- package/lib/elements/shapes/polygon.js.map +1 -1
- package/lib/exports.d.ts +3 -2
- package/lib/exports.js +5 -2
- package/lib/exports.js.map +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.js +6 -2
- package/lib/index.js.map +1 -1
- package/lib/layouts/base-layout.d.ts +3 -1
- package/lib/layouts/base-layout.js +3 -1
- package/lib/layouts/base-layout.js.map +1 -1
- package/lib/plugins/bubble-sets.d.ts +2 -2
- package/lib/plugins/bubble-sets.js.map +1 -1
- package/lib/plugins/contextmenu/index.d.ts +4 -3
- package/lib/plugins/contextmenu/index.js +12 -10
- package/lib/plugins/contextmenu/index.js.map +1 -1
- package/lib/plugins/hull/index.d.ts +2 -2
- package/lib/plugins/hull/index.js.map +1 -1
- package/lib/runtime/canvas.d.ts +15 -2
- package/lib/runtime/canvas.js.map +1 -1
- package/lib/runtime/data.d.ts +9 -16
- package/lib/runtime/data.js +26 -34
- package/lib/runtime/data.js.map +1 -1
- package/lib/runtime/element.d.ts +18 -2
- package/lib/runtime/element.js +75 -24
- package/lib/runtime/element.js.map +1 -1
- package/lib/runtime/graph.d.ts +374 -109
- package/lib/runtime/graph.js +278 -82
- package/lib/runtime/graph.js.map +1 -1
- package/lib/runtime/layout.js +1 -1
- package/lib/runtime/layout.js.map +1 -1
- package/lib/spec/element/edge.d.ts +1 -1
- package/lib/spec/element/node.d.ts +1 -1
- package/lib/themes/base.js +5 -0
- package/lib/themes/base.js.map +1 -1
- package/lib/transforms/collapse-expand-node.js +14 -4
- package/lib/transforms/collapse-expand-node.js.map +1 -1
- package/lib/transforms/process-parallel-edges.d.ts +2 -2
- package/lib/types/callable.d.ts +0 -11
- package/lib/types/data.d.ts +12 -0
- package/lib/types/edge.d.ts +11 -0
- package/lib/types/element.d.ts +100 -9
- package/lib/types/index.d.ts +0 -1
- package/lib/types/point.d.ts +0 -1
- package/lib/utils/element.d.ts +2 -2
- package/lib/utils/element.js.map +1 -1
- package/lib/utils/layout.d.ts +2 -2
- package/lib/utils/layout.js +4 -4
- package/lib/utils/layout.js.map +1 -1
- package/lib/utils/path.d.ts +3 -3
- package/lib/utils/path.js +1 -1
- package/lib/utils/path.js.map +1 -1
- package/lib/utils/position.d.ts +8 -8
- package/lib/utils/position.js +2 -2
- package/lib/utils/position.js.map +1 -1
- package/lib/utils/style.d.ts +13 -8
- package/lib/utils/style.js +18 -13
- package/lib/utils/style.js.map +1 -1
- package/package.json +10 -10
- package/src/behaviors/click-select.ts +61 -60
- package/src/behaviors/drag-element.ts +2 -7
- package/src/behaviors/hover-activate.ts +18 -22
- package/src/behaviors/lasso-select.ts +2 -2
- package/src/elements/base-element.ts +1 -25
- package/src/elements/combos/base-combo.ts +27 -11
- package/src/elements/edges/base-edge.ts +28 -8
- package/src/elements/effect.ts +74 -0
- package/src/elements/nodes/base-node.ts +23 -18
- package/src/elements/nodes/circle.ts +1 -1
- package/src/elements/nodes/diamond.ts +0 -7
- package/src/elements/nodes/ellipse.ts +1 -1
- package/src/elements/nodes/image.ts +2 -2
- package/src/elements/nodes/rect.ts +1 -1
- package/src/elements/shapes/badge.ts +17 -5
- package/src/elements/shapes/base-shape.ts +35 -15
- package/src/elements/shapes/icon.ts +18 -7
- package/src/elements/shapes/label.ts +19 -6
- package/src/elements/shapes/polygon.ts +1 -1
- package/src/exports.ts +6 -2
- package/src/index.ts +6 -2
- package/src/layouts/base-layout.ts +5 -1
- package/src/plugins/bubble-sets.ts +2 -2
- package/src/plugins/contextmenu/index.ts +16 -16
- package/src/plugins/hull/index.ts +2 -2
- package/src/runtime/canvas.ts +15 -10
- package/src/runtime/data.ts +32 -44
- package/src/runtime/element.ts +87 -30
- package/src/runtime/graph.ts +405 -132
- package/src/runtime/layout.ts +2 -2
- package/src/spec/element/edge.ts +1 -1
- package/src/spec/element/node.ts +1 -1
- package/src/themes/base.ts +5 -0
- package/src/transforms/collapse-expand-node.ts +13 -4
- package/src/transforms/process-parallel-edges.ts +2 -2
- package/src/types/callable.ts +0 -12
- package/src/types/data.ts +13 -0
- package/src/types/edge.ts +11 -0
- package/src/types/element.ts +106 -10
- package/src/types/index.ts +0 -1
- package/src/types/point.ts +0 -1
- package/src/utils/element.ts +3 -13
- package/src/utils/layout.ts +6 -6
- package/src/utils/path.ts +3 -3
- package/src/utils/position.ts +8 -8
- package/src/utils/style.ts +19 -12
- package/dist/lib/types/position.d.ts +0 -2
- package/esm/types/position.d.ts +0 -2
- package/esm/types/position.js +0 -2
- package/esm/types/position.js.map +0 -1
- package/lib/types/position.d.ts +0 -2
- package/lib/types/position.js +0 -3
- package/lib/types/position.js.map +0 -1
- package/src/types/position.ts +0 -3
|
@@ -2,12 +2,24 @@ import { DisplayObjectConfig, Image as GImage, Text as GText, Group, ImageStyleP
|
|
|
2
2
|
import type { BaseShapeStyleProps } from './base-shape';
|
|
3
3
|
import { BaseShape } from './base-shape';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* <zh/> 图标样式
|
|
7
|
+
*
|
|
8
|
+
* <en/> Icon style
|
|
9
|
+
*/
|
|
5
10
|
export interface IconStyleProps extends BaseShapeStyleProps, Partial<TextStyleProps>, Omit<ImageStyleProps, 'z'> {}
|
|
6
11
|
|
|
7
|
-
|
|
8
|
-
|
|
12
|
+
/**
|
|
13
|
+
* <zh/> 图标
|
|
14
|
+
*
|
|
15
|
+
* <en/> Icon
|
|
16
|
+
* @remarks
|
|
17
|
+
* <zh/> 图标是一种特殊的图形,可以是图片或者文字。传入 src 属性时,会渲染图片;传入 text 属性时,会渲染文字。
|
|
18
|
+
*
|
|
19
|
+
* <en/> Icon is a special shape, which can be an image or text. When the src attribute is passed in, an image will be rendered; when the text attribute is passed in, text will be rendered.
|
|
20
|
+
*/
|
|
9
21
|
export class Icon extends BaseShape<IconStyleProps> {
|
|
10
|
-
constructor(options:
|
|
22
|
+
constructor(options: DisplayObjectConfig<IconStyleProps>) {
|
|
11
23
|
super(options);
|
|
12
24
|
}
|
|
13
25
|
|
|
@@ -16,13 +28,12 @@ export class Icon extends BaseShape<IconStyleProps> {
|
|
|
16
28
|
}
|
|
17
29
|
|
|
18
30
|
protected getIconStyle(attributes: IconStyleProps = this.attributes): IconStyleProps {
|
|
19
|
-
const {
|
|
31
|
+
const { width = 0, height = 0 } = attributes;
|
|
20
32
|
const style = this.getGraphicStyle(attributes);
|
|
21
|
-
const { width, height } = style;
|
|
22
33
|
if (this.isGImage()) {
|
|
23
34
|
return {
|
|
24
|
-
x:
|
|
25
|
-
y:
|
|
35
|
+
x: -width / 2,
|
|
36
|
+
y: -height / 2,
|
|
26
37
|
...style,
|
|
27
38
|
};
|
|
28
39
|
}
|
|
@@ -6,6 +6,11 @@ import { omitStyleProps, startsWith, subStyleProps } from '../../utils/prefix';
|
|
|
6
6
|
import { mergeOptions } from '../../utils/style';
|
|
7
7
|
import { BaseShape } from './base-shape';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* <zh/> 标签样式
|
|
11
|
+
*
|
|
12
|
+
* <en/> Label style
|
|
13
|
+
*/
|
|
9
14
|
export interface LabelStyleProps extends TextStyleProps, Prefix<'background', RectStyleProps> {
|
|
10
15
|
/**
|
|
11
16
|
* <zh/> 是否显示背景
|
|
@@ -21,13 +26,21 @@ export interface LabelStyleProps extends TextStyleProps, Prefix<'background', Re
|
|
|
21
26
|
*/
|
|
22
27
|
padding?: Padding;
|
|
23
28
|
}
|
|
24
|
-
type ParsedLabelStyleProps = Required<LabelStyleProps>;
|
|
25
|
-
type LabelOptions = DisplayObjectConfig<LabelStyleProps>;
|
|
26
29
|
|
|
30
|
+
/**
|
|
31
|
+
* <zh/> 标签
|
|
32
|
+
*
|
|
33
|
+
* <en/> Label
|
|
34
|
+
* @remarks
|
|
35
|
+
* <zh/> 标签是一种具有背景的文本图形。
|
|
36
|
+
*
|
|
37
|
+
* <en/> Label is a text shape with background.
|
|
38
|
+
*/
|
|
27
39
|
export class Label extends BaseShape<LabelStyleProps> {
|
|
28
40
|
static defaultStyleProps: Partial<LabelStyleProps> = {
|
|
29
41
|
padding: 0,
|
|
30
42
|
fontSize: 12,
|
|
43
|
+
fontFamily: 'system-ui, sans-serif',
|
|
31
44
|
wordWrap: true,
|
|
32
45
|
maxLines: 1,
|
|
33
46
|
wordWrapWidth: 128,
|
|
@@ -38,7 +51,7 @@ export class Label extends BaseShape<LabelStyleProps> {
|
|
|
38
51
|
backgroundLineWidth: 0,
|
|
39
52
|
};
|
|
40
53
|
|
|
41
|
-
constructor(options:
|
|
54
|
+
constructor(options: DisplayObjectConfig<LabelStyleProps>) {
|
|
42
55
|
super(mergeOptions({ style: Label.defaultStyleProps }, options));
|
|
43
56
|
}
|
|
44
57
|
|
|
@@ -50,12 +63,12 @@ export class Label extends BaseShape<LabelStyleProps> {
|
|
|
50
63
|
return startsWith(key, 'background');
|
|
51
64
|
}
|
|
52
65
|
|
|
53
|
-
protected getTextStyle(attributes:
|
|
66
|
+
protected getTextStyle(attributes: Required<LabelStyleProps>) {
|
|
54
67
|
const { padding, ...style } = this.getGraphicStyle(attributes);
|
|
55
68
|
return omitStyleProps<TextStyleProps>(style, 'background');
|
|
56
69
|
}
|
|
57
70
|
|
|
58
|
-
protected getBackgroundStyle(attributes:
|
|
71
|
+
protected getBackgroundStyle(attributes: Required<LabelStyleProps>) {
|
|
59
72
|
if (attributes.background === false) return false;
|
|
60
73
|
|
|
61
74
|
const style = this.getGraphicStyle(attributes);
|
|
@@ -94,7 +107,7 @@ export class Label extends BaseShape<LabelStyleProps> {
|
|
|
94
107
|
return backgroundStyle;
|
|
95
108
|
}
|
|
96
109
|
|
|
97
|
-
public render(attributes:
|
|
110
|
+
public render(attributes: Required<LabelStyleProps> = this.parsedAttributes, container: Group = this): void {
|
|
98
111
|
this.upsert('text', Text, this.getTextStyle(attributes), container);
|
|
99
112
|
this.upsert('background', Rect, this.getBackgroundStyle(attributes), container);
|
|
100
113
|
}
|
|
@@ -44,7 +44,7 @@ export abstract class Polygon<T extends PolygonStyleProps = PolygonStyleProps> e
|
|
|
44
44
|
protected abstract getPoints(attributes: Required<T>): Point[];
|
|
45
45
|
|
|
46
46
|
public getIntersectPoint(point: Point): Point {
|
|
47
|
-
const { points } = this.
|
|
47
|
+
const { points } = this.getShape<GPolygon>('key').attributes;
|
|
48
48
|
const center: Point = [+(this.attributes?.x || 0), +(this.attributes?.y || 0)];
|
|
49
49
|
return getPolygonIntersectPoint(point, center, points!).point;
|
|
50
50
|
}
|
package/src/exports.ts
CHANGED
|
@@ -39,7 +39,7 @@ export {
|
|
|
39
39
|
Star,
|
|
40
40
|
Triangle,
|
|
41
41
|
} from './elements/nodes';
|
|
42
|
-
export { BaseShape } from './elements/shapes';
|
|
42
|
+
export { Badge, BaseShape, Icon, Label } from './elements/shapes';
|
|
43
43
|
export {
|
|
44
44
|
AntVDagreLayout,
|
|
45
45
|
BaseLayout,
|
|
@@ -167,6 +167,7 @@ export type {
|
|
|
167
167
|
TooltipOptions,
|
|
168
168
|
WatermarkOptions,
|
|
169
169
|
} from './plugins';
|
|
170
|
+
export type { DataURLOptions } from './runtime/canvas';
|
|
170
171
|
export type { RuntimeContext } from './runtime/types';
|
|
171
172
|
export type {
|
|
172
173
|
BehaviorOptions,
|
|
@@ -190,7 +191,6 @@ export type { CustomPluginOption } from './spec/plugin';
|
|
|
190
191
|
export type { BaseTransformOptions } from './transforms';
|
|
191
192
|
export type {
|
|
192
193
|
BaseElementStyleProps,
|
|
193
|
-
CallableValue,
|
|
194
194
|
CardinalPlacement,
|
|
195
195
|
CollapsedMarkerStyleProps,
|
|
196
196
|
Combo,
|
|
@@ -198,11 +198,15 @@ export type {
|
|
|
198
198
|
DirectionalPlacement,
|
|
199
199
|
Edge,
|
|
200
200
|
EdgeArrowStyleProps,
|
|
201
|
+
EdgeDirection,
|
|
201
202
|
EdgeLabelStyleProps,
|
|
202
203
|
Element,
|
|
203
204
|
ElementDatum,
|
|
205
|
+
ElementHooks,
|
|
206
|
+
ElementMethods,
|
|
204
207
|
ElementType,
|
|
205
208
|
FitViewOptions,
|
|
209
|
+
HierarchyKey,
|
|
206
210
|
IAnimateEvent,
|
|
207
211
|
ID,
|
|
208
212
|
IDragEvent,
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import './preset';
|
|
2
2
|
|
|
3
|
-
export const version = '5.0.0';
|
|
4
|
-
|
|
5
3
|
export * from './exports';
|
|
4
|
+
|
|
5
|
+
export const version = '5.0.3';
|
|
6
|
+
export const iconfont = {
|
|
7
|
+
css: '//at.alicdn.com/t/a/font_470089_8hnbbf8n4u8.css',
|
|
8
|
+
js: '//at.alicdn.com/t/a/font_470089_8hnbbf8n4u8.js',
|
|
9
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RuntimeContext } from '../runtime/types';
|
|
1
2
|
import type { GraphData } from '../spec';
|
|
2
3
|
import type { BaseLayoutOptions } from './types';
|
|
3
4
|
|
|
@@ -6,7 +7,10 @@ export abstract class BaseLayout<O extends BaseLayoutOptions = any> {
|
|
|
6
7
|
|
|
7
8
|
public options: O;
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
protected context: RuntimeContext;
|
|
11
|
+
|
|
12
|
+
constructor(context: RuntimeContext, options?: O) {
|
|
13
|
+
this.context = context;
|
|
10
14
|
this.options = options || ({} as O);
|
|
11
15
|
}
|
|
12
16
|
|
|
@@ -7,7 +7,7 @@ import type { ContourStyleProps } from '../elements/shapes';
|
|
|
7
7
|
import { Contour } from '../elements/shapes';
|
|
8
8
|
import type { Graph } from '../runtime/graph';
|
|
9
9
|
import type { RuntimeContext } from '../runtime/types';
|
|
10
|
-
import type {
|
|
10
|
+
import type { ID } from '../types';
|
|
11
11
|
import { getBBoxHeight, getBBoxWidth } from '../utils/bbox';
|
|
12
12
|
import { arrayDiff } from '../utils/diff';
|
|
13
13
|
import type { ElementLifeCycleEvent } from '../utils/event';
|
|
@@ -225,7 +225,7 @@ export class BubbleSets extends BasePlugin<BubbleSetsOptions> {
|
|
|
225
225
|
* <en/> Update member elements
|
|
226
226
|
* @param members - <zh/> 值或者回调函数 | <en/> value or callback function
|
|
227
227
|
*/
|
|
228
|
-
public updateMember(members:
|
|
228
|
+
public updateMember(members: ID[] | ((prev: ID[]) => ID[])) {
|
|
229
229
|
this.options.members = isFunction(members) ? members(this.options.members) : members;
|
|
230
230
|
this.drawBubbleSets();
|
|
231
231
|
}
|
|
@@ -13,9 +13,9 @@ import { CONTEXTMENU_CSS, getContentFromItems } from './util';
|
|
|
13
13
|
*/
|
|
14
14
|
export interface ContextmenuOptions extends BasePluginOptions {
|
|
15
15
|
/**
|
|
16
|
-
* <zh/> 给菜单的 DOM
|
|
16
|
+
* <zh/> 给菜单的 DOM 追加的类名
|
|
17
17
|
*
|
|
18
|
-
* <en/> The
|
|
18
|
+
* <en/> The class name appended to the menu DOM for custom styles
|
|
19
19
|
* @defaultValue 'g6-contextmenu'
|
|
20
20
|
*/
|
|
21
21
|
className?: string;
|
|
@@ -42,7 +42,7 @@ export interface ContextmenuOptions extends BasePluginOptions {
|
|
|
42
42
|
*
|
|
43
43
|
* <en/> The callback method triggered when the menu is clicked
|
|
44
44
|
*/
|
|
45
|
-
onClick?: (
|
|
45
|
+
onClick?: (value: string, target: HTMLElement) => void;
|
|
46
46
|
/**
|
|
47
47
|
* <zh/> 返回菜单的项目列表,支持 `Promise` 类型的返回值。是 `getContent` 的快捷配置
|
|
48
48
|
*
|
|
@@ -88,18 +88,24 @@ export class Contextmenu extends BasePlugin<ContextmenuOptions> {
|
|
|
88
88
|
enable: () => true,
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
-
private $element
|
|
91
|
+
private $element!: HTMLElement;
|
|
92
92
|
|
|
93
93
|
constructor(context: RuntimeContext, options: ContextmenuOptions) {
|
|
94
94
|
super(context, Object.assign({}, Contextmenu.defaultOptions, options));
|
|
95
95
|
|
|
96
|
+
this.initElement();
|
|
97
|
+
this.update(options);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private initElement() {
|
|
101
|
+
this.$element = createPluginContainer('contextmenu', false);
|
|
102
|
+
const { className } = this.options;
|
|
103
|
+
if (className) this.$element.classList.add(className);
|
|
104
|
+
|
|
96
105
|
const $container = this.context.canvas.getContainer();
|
|
97
106
|
$container!.appendChild(this.$element);
|
|
98
107
|
|
|
99
|
-
// 设置样式
|
|
100
108
|
insertDOM('g6-contextmenu-css', 'style', {}, CONTEXTMENU_CSS, document.head);
|
|
101
|
-
|
|
102
|
-
this.update(options);
|
|
103
109
|
}
|
|
104
110
|
|
|
105
111
|
/**
|
|
@@ -210,16 +216,10 @@ export class Contextmenu extends BasePlugin<ContextmenuOptions> {
|
|
|
210
216
|
const { onClick } = this.options;
|
|
211
217
|
if (event.target instanceof HTMLElement) {
|
|
212
218
|
if (event.target.className.includes('g6-contextmenu-li')) {
|
|
213
|
-
const
|
|
214
|
-
onClick
|
|
215
|
-
|
|
216
|
-
this.hide();
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// 点击其他地方,隐藏菜单
|
|
220
|
-
if (!this.context.graph.getCanvas().getContainer()!.contains(event.target)) {
|
|
221
|
-
this.hide();
|
|
219
|
+
const value = event.target.getAttribute('value') as string;
|
|
220
|
+
onClick?.(value, event.target);
|
|
222
221
|
}
|
|
223
222
|
}
|
|
223
|
+
this.hide();
|
|
224
224
|
};
|
|
225
225
|
}
|
|
@@ -4,7 +4,7 @@ import { GraphEvent } from '../../constants';
|
|
|
4
4
|
import type { ContourStyleProps } from '../../elements/shapes';
|
|
5
5
|
import { Contour } from '../../elements/shapes';
|
|
6
6
|
import type { RuntimeContext } from '../../runtime/types';
|
|
7
|
-
import type {
|
|
7
|
+
import type { ID, Point } from '../../types';
|
|
8
8
|
import type { ElementLifeCycleEvent } from '../../utils/event';
|
|
9
9
|
import { idOf } from '../../utils/id';
|
|
10
10
|
import { positionOf } from '../../utils/position';
|
|
@@ -185,7 +185,7 @@ export class Hull extends BasePlugin<HullOptions> {
|
|
|
185
185
|
* <en/> Update Hull member
|
|
186
186
|
* @param members - <zh/> 元素 Ids | <en/> Element Ids
|
|
187
187
|
*/
|
|
188
|
-
public updateMember(members:
|
|
188
|
+
public updateMember(members: ID[] | ((prev: ID[]) => ID[])) {
|
|
189
189
|
this.options.members = isFunction(members) ? members(this.options.members) : members;
|
|
190
190
|
this.shape.update(this.getHullStyle(true));
|
|
191
191
|
}
|
package/src/runtime/canvas.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Cursor,
|
|
3
|
-
DisplayObject,
|
|
4
|
-
CanvasConfig as GCanvasConfig,
|
|
5
|
-
DataURLOptions as GDataURLOptions,
|
|
6
|
-
IAnimation,
|
|
7
|
-
IRenderer,
|
|
8
|
-
PointLike,
|
|
9
|
-
} from '@antv/g';
|
|
1
|
+
import type { Cursor, DisplayObject, CanvasConfig as GCanvasConfig, IAnimation, IRenderer, PointLike } from '@antv/g';
|
|
10
2
|
import { CanvasEvent, Canvas as GCanvas } from '@antv/g';
|
|
11
3
|
import { Renderer as CanvasRenderer } from '@antv/g-canvas';
|
|
12
4
|
import { Plugin as DragNDropPlugin } from '@antv/g-plugin-dragndrop';
|
|
@@ -21,7 +13,7 @@ export interface CanvasConfig
|
|
|
21
13
|
background?: string;
|
|
22
14
|
}
|
|
23
15
|
|
|
24
|
-
export interface DataURLOptions
|
|
16
|
+
export interface DataURLOptions {
|
|
25
17
|
/**
|
|
26
18
|
* <zh/> 导出模式
|
|
27
19
|
* - viewport: 导出视口内容
|
|
@@ -32,6 +24,19 @@ export interface DataURLOptions extends GDataURLOptions {
|
|
|
32
24
|
* - overall: export the entire canvas
|
|
33
25
|
*/
|
|
34
26
|
mode?: 'viewport' | 'overall';
|
|
27
|
+
/**
|
|
28
|
+
* <zh/> 图片类型
|
|
29
|
+
*
|
|
30
|
+
* <en/> image type
|
|
31
|
+
* @defaultValue 'image/png'
|
|
32
|
+
*/
|
|
33
|
+
type: 'image/png' | 'image/jpeg' | 'image/webp' | 'image/bmp';
|
|
34
|
+
/**
|
|
35
|
+
* <zh/> 图片质量, 仅对 image/jpeg 和 image/webp 有效,取值范围 0 ~ 1
|
|
36
|
+
*
|
|
37
|
+
* <en/> image quality, only valid for image/jpeg and image/webp, range 0 ~ 1
|
|
38
|
+
*/
|
|
39
|
+
encoderOptions: number;
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
/**
|
package/src/runtime/data.ts
CHANGED
|
@@ -9,24 +9,22 @@ import type {
|
|
|
9
9
|
DataRemoved,
|
|
10
10
|
DataUpdated,
|
|
11
11
|
ElementDatum,
|
|
12
|
+
HierarchyKey,
|
|
12
13
|
ID,
|
|
13
14
|
NodeLikeData,
|
|
14
15
|
PartialEdgeData,
|
|
15
16
|
PartialGraphData,
|
|
16
17
|
PartialNodeLikeData,
|
|
17
|
-
|
|
18
|
+
Point,
|
|
18
19
|
State,
|
|
19
20
|
} from '../types';
|
|
20
21
|
import type { EdgeDirection } from '../types/edge';
|
|
21
22
|
import type { ElementType } from '../types/element';
|
|
22
|
-
import type { Point } from '../types/point';
|
|
23
|
-
import { isCollapsed } from '../utils/collapsibility';
|
|
24
23
|
import { cloneElementData, mergeElementsData } from '../utils/data';
|
|
25
24
|
import { arrayDiff } from '../utils/diff';
|
|
26
25
|
import { toG6Data, toGraphlibData } from '../utils/graphlib';
|
|
27
26
|
import { idOf, parentIdOf } from '../utils/id';
|
|
28
27
|
import { positionOf } from '../utils/position';
|
|
29
|
-
import { zIndexOf } from '../utils/style';
|
|
30
28
|
import { dfs } from '../utils/traverse';
|
|
31
29
|
import { add } from '../utils/vector';
|
|
32
30
|
|
|
@@ -368,6 +366,14 @@ export class DataController {
|
|
|
368
366
|
this.updateNodeLikeHierarchy(combos);
|
|
369
367
|
}
|
|
370
368
|
|
|
369
|
+
public addChildrenData(parentId: ID, childrenData: NodeData[]) {
|
|
370
|
+
const parentData = this.getNodeLikeDatum(parentId) as NodeData;
|
|
371
|
+
const childrenId = childrenData.map(idOf);
|
|
372
|
+
this.addNodeData(childrenData);
|
|
373
|
+
this.updateNodeData([{ id: parentId, children: [...(parentData.children || []), ...childrenId] }]);
|
|
374
|
+
this.addEdgeData(childrenId.map((childId) => ({ source: parentId, target: childId })));
|
|
375
|
+
}
|
|
376
|
+
|
|
371
377
|
protected updateNodeLikeHierarchy(data: NodeLikeData[]) {
|
|
372
378
|
if (!this.enableUpdateNodeLikeHierarchy) return;
|
|
373
379
|
const { model } = this;
|
|
@@ -381,9 +387,13 @@ export class DataController {
|
|
|
381
387
|
const children = (datum as NodeData).children;
|
|
382
388
|
if (children !== undefined) {
|
|
383
389
|
model.attachTreeStructure(TREE_KEY);
|
|
384
|
-
children.
|
|
385
|
-
|
|
386
|
-
|
|
390
|
+
const _children = children.filter((child) => model.hasNode(child));
|
|
391
|
+
_children.forEach((child) => this.setParent(child, id, TREE_KEY));
|
|
392
|
+
if (_children.length !== children.length) {
|
|
393
|
+
// 从数据中移除不存在的子节点
|
|
394
|
+
// Remove non-existent child nodes from the data
|
|
395
|
+
this.updateNodeData([{ id, children: _children }]);
|
|
396
|
+
}
|
|
387
397
|
}
|
|
388
398
|
});
|
|
389
399
|
}
|
|
@@ -565,25 +575,35 @@ export class DataController {
|
|
|
565
575
|
model.mergeNodeData(id, value);
|
|
566
576
|
}
|
|
567
577
|
|
|
568
|
-
public getElementPosition(id: ID):
|
|
578
|
+
public getElementPosition(id: ID): Point {
|
|
569
579
|
const datum = this.getElementDataById(id) as NodeLikeData;
|
|
570
580
|
return positionOf(datum);
|
|
571
581
|
}
|
|
572
582
|
|
|
573
|
-
public
|
|
583
|
+
public translateNodeLikeBy(id: ID, offset: Point) {
|
|
584
|
+
if (this.isCombo(id)) this.translateComboBy(id, offset);
|
|
585
|
+
else this.translateNodeBy(id, offset);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
public translateNodeLikeTo(id: ID, position: Point) {
|
|
589
|
+
if (this.isCombo(id)) this.translateComboTo(id, position);
|
|
590
|
+
else this.translateNodeTo(id, position);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
public translateNodeBy(id: ID, offset: Point) {
|
|
574
594
|
const curr = this.getElementPosition(id);
|
|
575
595
|
const position = add(curr, [...offset, 0].slice(0, 3) as Point);
|
|
576
596
|
this.translateNodeTo(id, position);
|
|
577
597
|
}
|
|
578
598
|
|
|
579
|
-
public translateNodeTo(id: ID, position:
|
|
599
|
+
public translateNodeTo(id: ID, position: Point) {
|
|
580
600
|
const [x = 0, y = 0, z = 0] = position;
|
|
581
601
|
this.preventUpdateNodeLikeHierarchy(() => {
|
|
582
602
|
this.updateNodeData([{ id, style: { x, y, z } }]);
|
|
583
603
|
});
|
|
584
604
|
}
|
|
585
605
|
|
|
586
|
-
public translateComboBy(id: ID, offset:
|
|
606
|
+
public translateComboBy(id: ID, offset: Point) {
|
|
587
607
|
const [dx = 0, dy = 0, dz = 0] = offset;
|
|
588
608
|
if ([dx, dy, dz].some(isNaN) || [dx, dy, dz].every((o) => o === 0)) return;
|
|
589
609
|
const combo = this.getComboData([id])[0];
|
|
@@ -610,7 +630,7 @@ export class DataController {
|
|
|
610
630
|
);
|
|
611
631
|
}
|
|
612
632
|
|
|
613
|
-
public translateComboTo(id: ID, position:
|
|
633
|
+
public translateComboTo(id: ID, position: Point) {
|
|
614
634
|
if (position.some(isNaN)) return;
|
|
615
635
|
const [tx = 0, ty = 0, tz = 0] = position;
|
|
616
636
|
const combo = this.getComboData([id])?.[0];
|
|
@@ -743,36 +763,6 @@ export class DataController {
|
|
|
743
763
|
throw new Error(`Unknown element type of id: ${id}`);
|
|
744
764
|
}
|
|
745
765
|
|
|
746
|
-
/**
|
|
747
|
-
* <zh/> 计算元素置顶后的 zIndex
|
|
748
|
-
*
|
|
749
|
-
* <en/> Calculate the zIndex after the element is placed on top
|
|
750
|
-
* @param id - <zh/> 元素 ID | <en/> ID of the element
|
|
751
|
-
* @returns <zh/> zIndex | <en/> zIndex
|
|
752
|
-
*/
|
|
753
|
-
public getFrontZIndex(id: ID) {
|
|
754
|
-
const elementType = this.getElementType(id);
|
|
755
|
-
let elementsToCompare: NodeLikeData[] = [];
|
|
756
|
-
|
|
757
|
-
if (elementType === 'combo') {
|
|
758
|
-
const ancestors = [id, ...this.getAncestorsData(id, COMBO_KEY).map(idOf)];
|
|
759
|
-
// 过滤掉以下 combo 不参与 zIndex 计算
|
|
760
|
-
// - 未展开的 combo
|
|
761
|
-
// - 当前 combo 及其祖先和后代
|
|
762
|
-
// The following combos do not participate in zIndex calculation
|
|
763
|
-
// - collapsed combo
|
|
764
|
-
// - current combo and its ancestors and descendants
|
|
765
|
-
elementsToCompare = this.getComboData().filter((combo) => {
|
|
766
|
-
const comboId = idOf(combo);
|
|
767
|
-
const comboAncestors = this.getAncestorsData(comboId, COMBO_KEY);
|
|
768
|
-
const comboAncestorIds = comboAncestors.map(idOf);
|
|
769
|
-
return !comboAncestors.some(isCollapsed) && !ancestors.includes(comboId) && !comboAncestorIds.includes(comboId);
|
|
770
|
-
});
|
|
771
|
-
} else elementsToCompare = this.getNodeData().filter((node) => idOf(node) !== id);
|
|
772
|
-
|
|
773
|
-
return Math.max(0, ...elementsToCompare.map(zIndexOf)) + 1;
|
|
774
|
-
}
|
|
775
|
-
|
|
776
766
|
public destroy() {
|
|
777
767
|
const { model } = this;
|
|
778
768
|
const nodes = model.getAllNodes();
|
|
@@ -785,5 +775,3 @@ export class DataController {
|
|
|
785
775
|
this.context = {};
|
|
786
776
|
}
|
|
787
777
|
}
|
|
788
|
-
|
|
789
|
-
export type HierarchyKey = typeof TREE_KEY | typeof COMBO_KEY;
|