@antv/g6 5.0.15 → 5.0.17
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/drag-canvas.d.ts +13 -0
- package/dist/lib/behaviors/optimize-viewport-transform.d.ts +0 -1
- package/dist/lib/behaviors/scroll-canvas.d.ts +7 -0
- package/dist/lib/behaviors/zoom-canvas.d.ts +7 -0
- package/dist/lib/constants/registry.d.ts +7 -1
- package/dist/lib/elements/edges/base-edge.d.ts +2 -2
- package/dist/lib/elements/edges/polyline.d.ts +4 -20
- package/dist/lib/elements/shapes/base-shape.d.ts +51 -2
- package/dist/lib/exports.d.ts +3 -2
- package/dist/lib/plugins/edge-filter-lens/index.d.ts +125 -0
- package/dist/lib/plugins/index.d.ts +4 -0
- package/dist/lib/plugins/snapline/index.d.ts +95 -0
- package/dist/lib/registry/types.d.ts +4 -0
- package/dist/lib/runtime/element.d.ts +1 -0
- package/dist/lib/runtime/plugin.d.ts +1 -1
- package/dist/lib/runtime/viewport.d.ts +8 -0
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/types/router.d.ts +103 -0
- package/dist/lib/utils/bbox.d.ts +8 -0
- package/dist/lib/utils/router/orth.d.ts +8 -8
- package/dist/lib/utils/router/shortest-path.d.ts +57 -0
- package/dist/lib/utils/text.d.ts +1 -1
- package/dist/lib/utils/visibility.d.ts +2 -1
- package/dist/lib/version.d.ts +1 -1
- package/esm/behaviors/brush-select.js +11 -6
- package/esm/behaviors/brush-select.js.map +1 -1
- package/esm/behaviors/drag-canvas.d.ts +13 -0
- package/esm/behaviors/drag-canvas.js +10 -1
- package/esm/behaviors/drag-canvas.js.map +1 -1
- package/esm/behaviors/optimize-viewport-transform.d.ts +0 -1
- package/esm/behaviors/optimize-viewport-transform.js +5 -4
- package/esm/behaviors/optimize-viewport-transform.js.map +1 -1
- package/esm/behaviors/scroll-canvas.d.ts +7 -0
- package/esm/behaviors/scroll-canvas.js +3 -1
- package/esm/behaviors/scroll-canvas.js.map +1 -1
- package/esm/behaviors/zoom-canvas.d.ts +7 -0
- package/esm/behaviors/zoom-canvas.js +3 -1
- package/esm/behaviors/zoom-canvas.js.map +1 -1
- package/esm/constants/registry.d.ts +7 -1
- package/esm/constants/registry.js +6 -0
- package/esm/constants/registry.js.map +1 -1
- package/esm/elements/edges/base-edge.d.ts +2 -2
- package/esm/elements/edges/base-edge.js +10 -4
- package/esm/elements/edges/base-edge.js.map +1 -1
- package/esm/elements/edges/polyline.d.ts +4 -20
- package/esm/elements/edges/polyline.js +32 -33
- package/esm/elements/edges/polyline.js.map +1 -1
- package/esm/elements/shapes/base-shape.d.ts +51 -2
- package/esm/elements/shapes/base-shape.js +23 -5
- package/esm/elements/shapes/base-shape.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/plugins/edge-filter-lens/index.d.ts +125 -0
- package/esm/plugins/edge-filter-lens/index.js +236 -0
- package/esm/plugins/edge-filter-lens/index.js.map +1 -0
- package/esm/plugins/index.d.ts +4 -0
- package/esm/plugins/index.js +2 -0
- package/esm/plugins/index.js.map +1 -1
- package/esm/plugins/snapline/index.d.ts +95 -0
- package/esm/plugins/snapline/index.js +268 -0
- package/esm/plugins/snapline/index.js.map +1 -0
- package/esm/registry/build-in.js +21 -2
- package/esm/registry/build-in.js.map +1 -1
- package/esm/registry/store.js +1 -0
- package/esm/registry/store.js.map +1 -1
- package/esm/registry/types.d.ts +4 -0
- package/esm/runtime/element.d.ts +1 -0
- package/esm/runtime/element.js +10 -4
- package/esm/runtime/element.js.map +1 -1
- package/esm/runtime/plugin.d.ts +1 -1
- package/esm/runtime/plugin.js +8 -1
- package/esm/runtime/plugin.js.map +1 -1
- package/esm/runtime/viewport.d.ts +8 -0
- package/esm/runtime/viewport.js +35 -2
- package/esm/runtime/viewport.js.map +1 -1
- package/esm/types/index.d.ts +1 -0
- package/esm/types/router.d.ts +103 -0
- package/esm/types/router.js +2 -0
- package/esm/types/router.js.map +1 -0
- package/esm/utils/bbox.d.ts +8 -0
- package/esm/utils/bbox.js +19 -0
- package/esm/utils/bbox.js.map +1 -1
- package/esm/utils/router/orth.d.ts +8 -8
- package/esm/utils/router/orth.js +13 -7
- package/esm/utils/router/orth.js.map +1 -1
- package/esm/utils/router/shortest-path.d.ts +57 -0
- package/esm/utils/router/shortest-path.js +387 -0
- package/esm/utils/router/shortest-path.js.map +1 -0
- package/esm/utils/text.d.ts +1 -1
- package/esm/utils/visibility.d.ts +2 -1
- package/esm/utils/visibility.js +3 -2
- package/esm/utils/visibility.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/behaviors/brush-select.js +11 -6
- package/lib/behaviors/brush-select.js.map +1 -1
- package/lib/behaviors/drag-canvas.d.ts +13 -0
- package/lib/behaviors/drag-canvas.js +10 -1
- package/lib/behaviors/drag-canvas.js.map +1 -1
- package/lib/behaviors/optimize-viewport-transform.d.ts +0 -1
- package/lib/behaviors/optimize-viewport-transform.js +5 -4
- package/lib/behaviors/optimize-viewport-transform.js.map +1 -1
- package/lib/behaviors/scroll-canvas.d.ts +7 -0
- package/lib/behaviors/scroll-canvas.js +3 -1
- package/lib/behaviors/scroll-canvas.js.map +1 -1
- package/lib/behaviors/zoom-canvas.d.ts +7 -0
- package/lib/behaviors/zoom-canvas.js +3 -1
- package/lib/behaviors/zoom-canvas.js.map +1 -1
- package/lib/constants/registry.d.ts +7 -1
- package/lib/constants/registry.js +6 -0
- package/lib/constants/registry.js.map +1 -1
- package/lib/elements/edges/base-edge.d.ts +2 -2
- package/lib/elements/edges/base-edge.js +9 -3
- package/lib/elements/edges/base-edge.js.map +1 -1
- package/lib/elements/edges/polyline.d.ts +4 -20
- package/lib/elements/edges/polyline.js +32 -33
- package/lib/elements/edges/polyline.js.map +1 -1
- package/lib/elements/shapes/base-shape.d.ts +51 -2
- package/lib/elements/shapes/base-shape.js +23 -5
- package/lib/elements/shapes/base-shape.js.map +1 -1
- package/lib/exports.d.ts +3 -2
- package/lib/exports.js +3 -1
- package/lib/exports.js.map +1 -1
- package/lib/plugins/edge-filter-lens/index.d.ts +125 -0
- package/lib/plugins/edge-filter-lens/index.js +240 -0
- package/lib/plugins/edge-filter-lens/index.js.map +1 -0
- package/lib/plugins/index.d.ts +4 -0
- package/lib/plugins/index.js +5 -1
- package/lib/plugins/index.js.map +1 -1
- package/lib/plugins/snapline/index.d.ts +95 -0
- package/lib/plugins/snapline/index.js +272 -0
- package/lib/plugins/snapline/index.js.map +1 -0
- package/lib/registry/build-in.js +20 -1
- package/lib/registry/build-in.js.map +1 -1
- package/lib/registry/store.js +1 -0
- package/lib/registry/store.js.map +1 -1
- package/lib/registry/types.d.ts +4 -0
- package/lib/runtime/element.d.ts +1 -0
- package/lib/runtime/element.js +9 -3
- package/lib/runtime/element.js.map +1 -1
- package/lib/runtime/plugin.d.ts +1 -1
- package/lib/runtime/plugin.js +8 -1
- package/lib/runtime/plugin.js.map +1 -1
- package/lib/runtime/viewport.d.ts +8 -0
- package/lib/runtime/viewport.js +34 -1
- package/lib/runtime/viewport.js.map +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/router.d.ts +103 -0
- package/lib/types/router.js +3 -0
- package/lib/types/router.js.map +1 -0
- package/lib/utils/bbox.d.ts +8 -0
- package/lib/utils/bbox.js +20 -0
- package/lib/utils/bbox.js.map +1 -1
- package/lib/utils/router/orth.d.ts +8 -8
- package/lib/utils/router/orth.js +13 -7
- package/lib/utils/router/orth.js.map +1 -1
- package/lib/utils/router/shortest-path.d.ts +57 -0
- package/lib/utils/router/shortest-path.js +394 -0
- package/lib/utils/router/shortest-path.js.map +1 -0
- package/lib/utils/text.d.ts +1 -1
- package/lib/utils/visibility.d.ts +2 -1
- package/lib/utils/visibility.js +3 -2
- package/lib/utils/visibility.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/behaviors/brush-select.ts +12 -5
- package/src/behaviors/drag-canvas.ts +24 -1
- package/src/behaviors/optimize-viewport-transform.ts +4 -9
- package/src/behaviors/scroll-canvas.ts +9 -1
- package/src/behaviors/zoom-canvas.ts +9 -1
- package/src/constants/registry.ts +6 -0
- package/src/elements/edges/base-edge.ts +19 -5
- package/src/elements/edges/polyline.ts +36 -65
- package/src/elements/shapes/base-shape.ts +76 -6
- package/src/exports.ts +5 -0
- package/src/plugins/edge-filter-lens/index.ts +391 -0
- package/src/plugins/grid-line.ts +1 -1
- package/src/plugins/index.ts +4 -0
- package/src/plugins/snapline/index.ts +383 -0
- package/src/registry/build-in.ts +33 -1
- package/src/registry/store.ts +1 -0
- package/src/registry/types.ts +2 -0
- package/src/runtime/element.ts +11 -4
- package/src/runtime/plugin.ts +8 -1
- package/src/runtime/viewport.ts +42 -3
- package/src/types/index.ts +1 -0
- package/src/types/router.ts +107 -0
- package/src/utils/bbox.ts +24 -0
- package/src/utils/router/orth.ts +19 -10
- package/src/utils/router/shortest-path.ts +470 -0
- package/src/utils/text.ts +1 -1
- package/src/utils/visibility.ts +3 -1
- package/src/version.ts +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { getBBoxHeight, getBBoxWidth, getNodeBBox } from '../../utils/bbox';
|
|
2
2
|
import { getPolylineLoopPath, getPolylinePath } from '../../utils/edge';
|
|
3
|
-
import { findPorts, getConnectionPoint, getPortPosition } from '../../utils/element';
|
|
4
3
|
import { subStyleProps } from '../../utils/prefix';
|
|
5
4
|
import { orth } from '../../utils/router/orth';
|
|
5
|
+
import { aStarSearch } from '../../utils/router/shortest-path';
|
|
6
6
|
import { mergeOptions } from '../../utils/style';
|
|
7
7
|
import { BaseEdge } from './base-edge';
|
|
8
8
|
/**
|
|
@@ -15,50 +15,49 @@ export class Polyline extends BaseEdge {
|
|
|
15
15
|
radius: 0,
|
|
16
16
|
controlPoints: [],
|
|
17
17
|
router: false,
|
|
18
|
-
routerName: 'orth',
|
|
19
|
-
routerPadding: 10,
|
|
20
18
|
};
|
|
21
19
|
constructor(options) {
|
|
22
20
|
super(mergeOptions({ style: Polyline.defaultStyleProps }, options));
|
|
23
21
|
}
|
|
24
|
-
|
|
25
|
-
const {
|
|
22
|
+
getControlPoints(attributes) {
|
|
23
|
+
const { router } = attributes;
|
|
26
24
|
const { sourceNode, targetNode } = this;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
const [sourcePoint, targetPoint] = this.getEndpoints(attributes, false);
|
|
26
|
+
let controlPoints = [];
|
|
27
|
+
if (!router) {
|
|
28
|
+
controlPoints = attributes.controlPoints;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
if (router.type === 'shortest-path') {
|
|
32
|
+
const nodes = this.context.element.getNodes();
|
|
33
|
+
controlPoints = aStarSearch(sourceNode, targetNode, nodes, router);
|
|
34
|
+
if (!controlPoints.length) {
|
|
35
|
+
controlPoints = orth(sourcePoint, targetPoint, sourceNode, targetNode, attributes.controlPoints, {
|
|
36
|
+
padding: router.offset,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else if (router.type === 'orth') {
|
|
41
|
+
controlPoints = orth(sourcePoint, targetPoint, sourceNode, targetNode, attributes.controlPoints, router);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return controlPoints;
|
|
36
45
|
}
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
sourcePoint: sourcePort ? getPortPosition(sourcePort) : sourceNode.getCenter(),
|
|
43
|
-
targetPoint: targetPort ? getPortPosition(targetPort) : targetNode.getCenter(),
|
|
44
|
-
sourcePort,
|
|
45
|
-
targetPort,
|
|
46
|
-
};
|
|
46
|
+
getPoints(attributes) {
|
|
47
|
+
const controlPoints = this.getControlPoints(attributes);
|
|
48
|
+
const [newSourcePoint, newTargetPoint] = this.getEndpoints(attributes, true, controlPoints);
|
|
49
|
+
return [newSourcePoint, ...controlPoints, newTargetPoint];
|
|
47
50
|
}
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
if (!router)
|
|
52
|
-
return [...controlPoints];
|
|
53
|
-
const sourceBBox = getNodeBBox(sourceNode, routerPadding);
|
|
54
|
-
const targetBBox = getNodeBBox(targetNode, routerPadding);
|
|
55
|
-
return orth(sourcePoint, targetPoint, sourceBBox, targetBBox, controlPoints, routerPadding);
|
|
51
|
+
getKeyPath(attributes) {
|
|
52
|
+
const points = this.getPoints(attributes);
|
|
53
|
+
return getPolylinePath(points, attributes.radius);
|
|
56
54
|
}
|
|
57
55
|
getLoopPath(attributes) {
|
|
58
56
|
const { sourcePort: sourcePortKey, targetPort: targetPortKey, radius } = attributes;
|
|
59
57
|
const node = this.sourceNode;
|
|
60
58
|
const bbox = getNodeBBox(node);
|
|
61
|
-
// 默认转折点距离为 bbox 的最大宽高的 1/4
|
|
59
|
+
// 默认转折点距离为 bbox 的最大宽高的 1/4
|
|
60
|
+
// Default distance of the turning point is 1/4 of the maximum width and height of the bbox
|
|
62
61
|
const defaultDist = Math.max(getBBoxWidth(bbox), getBBoxHeight(bbox)) / 4;
|
|
63
62
|
const { placement, clockwise, dist = defaultDist, } = subStyleProps(this.getGraphicStyle(attributes), 'loop');
|
|
64
63
|
return getPolylineLoopPath(node, radius, placement, clockwise, dist, sourcePortKey, targetPortKey);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polyline.js","sourceRoot":"src/","sources":["elements/edges/polyline.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,
|
|
1
|
+
{"version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C;QAE7B,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;QAC/B,2BAA2B;QAC3B,2FAA2F;QAC3F,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QAE1E,MAAM,EACJ,SAAS,EACT,SAAS,EACT,IAAI,GAAG,WAAW,GACnB,GAAG,aAAa,CAA2B,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC;QAEtF,OAAO,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC;IACrG,CAAC"}
|
|
@@ -26,11 +26,12 @@ export declare abstract class BaseShape<StyleProps extends BaseShapeStyleProps>
|
|
|
26
26
|
* @param Ctor - <zh> 图形类型 | <en> shape type
|
|
27
27
|
* @param style - <zh> 图形样式 | <en> shape style
|
|
28
28
|
* @param container - <zh> 容器 | <en> container
|
|
29
|
+
* @param hooks - <zh> 钩子函数 | <en> hooks
|
|
29
30
|
* @returns <zh> 图形实例 | <en> shape instance
|
|
30
31
|
*/
|
|
31
|
-
protected upsert<T extends DisplayObject>(className: string, Ctor: {
|
|
32
|
+
protected upsert<T extends DisplayObject>(className: string, Ctor: string | {
|
|
32
33
|
new (...args: any[]): T;
|
|
33
|
-
}, style: T['attributes'] | false, container: DisplayObject): T | undefined;
|
|
34
|
+
}, style: T['attributes'] | false, container: DisplayObject, hooks?: UpsertHooks): T | undefined;
|
|
34
35
|
/**
|
|
35
36
|
* <zh/> 使用 transform 更新图形位置
|
|
36
37
|
*
|
|
@@ -67,3 +68,51 @@ export declare abstract class BaseShape<StyleProps extends BaseShapeStyleProps>
|
|
|
67
68
|
private setVisibility;
|
|
68
69
|
destroy(): void;
|
|
69
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* <zh/> 图形 upsert 方法生命周期钩子
|
|
73
|
+
*
|
|
74
|
+
* <en/> Shape upsert method lifecycle hooks
|
|
75
|
+
*/
|
|
76
|
+
export interface UpsertHooks {
|
|
77
|
+
/**
|
|
78
|
+
* <zh/> 图形创建前
|
|
79
|
+
*
|
|
80
|
+
* <en/> Before creating the shape
|
|
81
|
+
*/
|
|
82
|
+
beforeCreate?: () => void;
|
|
83
|
+
/**
|
|
84
|
+
* <zh/> 图形创建后
|
|
85
|
+
*
|
|
86
|
+
* <en/> After creating the shape
|
|
87
|
+
* @param instance - <zh/> 图形实例 | <en/> shape instance
|
|
88
|
+
*/
|
|
89
|
+
afterCreate?: (instance: DisplayObject) => void;
|
|
90
|
+
/**
|
|
91
|
+
* <zh/> 图形更新前
|
|
92
|
+
*
|
|
93
|
+
* <en/> Before updating the shape
|
|
94
|
+
* @param instance - <zh/> 图形实例 | <en/> shape instance
|
|
95
|
+
*/
|
|
96
|
+
beforeUpdate?: (instance: DisplayObject) => void;
|
|
97
|
+
/**
|
|
98
|
+
* <zh/> 图形更新后
|
|
99
|
+
*
|
|
100
|
+
* <en/> After updating the shape
|
|
101
|
+
* @param instance - <zh/> 图形实例 | <en/> shape instance
|
|
102
|
+
*/
|
|
103
|
+
afterUpdate?: (instance: DisplayObject) => void;
|
|
104
|
+
/**
|
|
105
|
+
* <zh/> 图形销毁前
|
|
106
|
+
*
|
|
107
|
+
* <en/> Before destroying the shape
|
|
108
|
+
* @param instance - <zh/> 图形实例 | <en/> shape instance
|
|
109
|
+
*/
|
|
110
|
+
beforeDestroy?: (instance: DisplayObject) => void;
|
|
111
|
+
/**
|
|
112
|
+
* <zh/> 图形销毁后
|
|
113
|
+
*
|
|
114
|
+
* <en/> After destroying the shape
|
|
115
|
+
* @param instance - <zh/> 图形实例 | <en/> shape instance
|
|
116
|
+
*/
|
|
117
|
+
afterDestroy?: (instance: DisplayObject) => void;
|
|
118
|
+
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { CustomElement } from '@antv/g';
|
|
2
2
|
import { isEmpty, isFunction, upperFirst } from '@antv/util';
|
|
3
|
+
import { ExtensionCategory } from '../../constants';
|
|
3
4
|
import { createAnimationsProxy, preprocessKeyframes } from '../../utils/animation';
|
|
4
5
|
import { updateStyle } from '../../utils/element';
|
|
5
6
|
import { subObject } from '../../utils/prefix';
|
|
7
|
+
import { format } from '../../utils/print';
|
|
6
8
|
import { getSubShapeStyle } from '../../utils/style';
|
|
7
9
|
import { replaceTranslateInTransform } from '../../utils/transform';
|
|
8
10
|
import { setVisibility } from '../../utils/visibility';
|
|
11
|
+
import { getExtension } from './../../registry/get';
|
|
9
12
|
export class BaseShape extends CustomElement {
|
|
10
13
|
constructor(options) {
|
|
11
14
|
super(options);
|
|
@@ -37,29 +40,44 @@ export class BaseShape extends CustomElement {
|
|
|
37
40
|
* @param Ctor - <zh> 图形类型 | <en> shape type
|
|
38
41
|
* @param style - <zh> 图形样式 | <en> shape style
|
|
39
42
|
* @param container - <zh> 容器 | <en> container
|
|
43
|
+
* @param hooks - <zh> 钩子函数 | <en> hooks
|
|
40
44
|
* @returns <zh> 图形实例 | <en> shape instance
|
|
41
45
|
*/
|
|
42
|
-
upsert(className, Ctor, style, container) {
|
|
46
|
+
upsert(className, Ctor, style, container, hooks) {
|
|
43
47
|
const target = this.shapeMap[className];
|
|
44
48
|
// remove
|
|
45
49
|
// 如果 style 为 false,则删除图形 / remove shape if style is false
|
|
46
50
|
if (style === false) {
|
|
47
51
|
if (target) {
|
|
52
|
+
hooks?.beforeDestroy?.(target);
|
|
48
53
|
container.removeChild(target);
|
|
49
54
|
delete this.shapeMap[className];
|
|
55
|
+
hooks?.afterDestroy?.(target);
|
|
50
56
|
}
|
|
51
57
|
return;
|
|
52
58
|
}
|
|
59
|
+
const _Ctor = typeof Ctor === 'string' ? getExtension(ExtensionCategory.SHAPE, Ctor) : Ctor;
|
|
60
|
+
if (!_Ctor) {
|
|
61
|
+
throw new Error(format(`Shape ${Ctor} not found`));
|
|
62
|
+
}
|
|
53
63
|
// create
|
|
54
|
-
if (!target || target.destroyed || !(target instanceof
|
|
55
|
-
target
|
|
56
|
-
|
|
64
|
+
if (!target || target.destroyed || !(target instanceof _Ctor)) {
|
|
65
|
+
if (target) {
|
|
66
|
+
hooks?.beforeDestroy?.(target);
|
|
67
|
+
target?.destroy();
|
|
68
|
+
hooks?.afterDestroy?.(target);
|
|
69
|
+
}
|
|
70
|
+
hooks?.beforeCreate?.();
|
|
71
|
+
const instance = new _Ctor({ className, style });
|
|
57
72
|
container.appendChild(instance);
|
|
58
73
|
this.shapeMap[className] = instance;
|
|
74
|
+
hooks?.afterCreate?.(instance);
|
|
59
75
|
return instance;
|
|
60
76
|
}
|
|
61
77
|
// update
|
|
78
|
+
hooks?.beforeUpdate?.(target);
|
|
62
79
|
updateStyle(target, style);
|
|
80
|
+
hooks?.afterUpdate?.(target);
|
|
63
81
|
return target;
|
|
64
82
|
}
|
|
65
83
|
/**
|
|
@@ -174,7 +192,7 @@ export class BaseShape extends CustomElement {
|
|
|
174
192
|
}
|
|
175
193
|
setVisibility() {
|
|
176
194
|
const { visibility } = this.attributes;
|
|
177
|
-
setVisibility(this, visibility);
|
|
195
|
+
setVisibility(this, visibility, true);
|
|
178
196
|
}
|
|
179
197
|
destroy() {
|
|
180
198
|
this.shapeMap = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-shape.js","sourceRoot":"src/","sources":["elements/shapes/base-shape.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"base-shape.js","sourceRoot":"src/","sources":["elements/shapes/base-shape.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE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;IAC7C,CAAC;IAEM,QAAQ,CAA0B,IAAY;QACnD,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAM,CAAC;IAClC,CAAC;IAEO,aAAa;QACnB,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC;QACvC,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;IACxC,CAAC;IAEM,OAAO;QACZ,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,KAAK,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC;CACF;AAED;;;;;;;GAOG;AACH,SAAS,gBAAgB,CAAC,MAAqB,EAAE,SAAqB;IACpE,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE;QAC5B,oCAAoC;QACpC,MAAM,KAAK,GAAG,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;QACxE,oCAAoC;QACpC,IAAI,KAAK,GAAG,CAAC,CAAC;YAAE,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/esm/exports.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { BaseEdge, Cubic, CubicHorizontal, CubicVertical, Line, Polyline, Quadra
|
|
|
5
5
|
export { BaseNode, Circle, Diamond, Donut, Ellipse, HTML, Hexagon, Image, Rect, Star, Triangle, } from './elements/nodes';
|
|
6
6
|
export { Badge, BaseShape, Icon, Label } from './elements/shapes';
|
|
7
7
|
export { AntVDagreLayout, BaseLayout, CircularLayout, ComboCombinedLayout, ConcentricLayout, D3ForceLayout, DagreLayout, ForceAtlas2Layout, ForceLayout, FruchtermanLayout, GridLayout, MDSLayout, RadialLayout, RandomLayout, compactBox, dendrogram, indented, mindmap, } from './layouts';
|
|
8
|
-
export { BasePlugin, BubbleSets, CameraSetting, Contextmenu, Fullscreen, GridLine, History, Hull, Legend, Minimap, Timebar, Toolbar, Tooltip, Watermark, } from './plugins';
|
|
8
|
+
export { BasePlugin, BubbleSets, CameraSetting, Contextmenu, EdgeFilterLens, Fullscreen, GridLine, History, Hull, Legend, Minimap, Snapline, Timebar, Toolbar, Tooltip, Watermark, } from './plugins';
|
|
9
9
|
export { getExtension, getExtensions } from './registry/get';
|
|
10
10
|
export { register } from './registry/register';
|
|
11
11
|
export { Graph } from './runtime/graph';
|
|
@@ -28,10 +28,11 @@ export type { BaseComboStyleProps, CircleComboStyleProps, RectComboStyleProps }
|
|
|
28
28
|
export type { BaseEdgeStyleProps, CubicHorizontalStyleProps, CubicStyleProps, CubicVerticalStyleProps, LineStyleProps, PolylineStyleProps, QuadraticStyleProps, } from './elements/edges';
|
|
29
29
|
export type { BaseNodeStyleProps, CircleStyleProps, DiamondStyleProps, DonutStyleProps, EllipseStyleProps, HTMLStyleProps, HexagonStyleProps, ImageStyleProps, RectStyleProps, StarStyleProps, TriangleStyleProps, } from './elements/nodes';
|
|
30
30
|
export type { BadgeStyleProps, BaseShapeStyleProps, IconStyleProps, LabelStyleProps, PolygonStyleProps, } from './elements/shapes';
|
|
31
|
+
export type { UpsertHooks } from './elements/shapes/base-shape';
|
|
31
32
|
export type { ContourLabelStyleProps, ContourStyleProps } from './elements/shapes/contour';
|
|
32
33
|
export type { BaseLayoutOptions, WebWorkerLayoutOptions } from './layouts/types';
|
|
33
34
|
export type { CategoricalPalette } from './palettes/types';
|
|
34
|
-
export type { BasePluginOptions, BubbleSetsOptions, CameraSettingOptions, ContextmenuOptions, FullscreenOptions, GridLineOptions, HistoryOptions, HullOptions, LegendOptions, MinimapOptions, TimebarOptions, ToolbarOptions, TooltipOptions, WatermarkOptions, } from './plugins';
|
|
35
|
+
export type { BasePluginOptions, BubbleSetsOptions, CameraSettingOptions, ContextmenuOptions, EdgeFilterLensOptions, FullscreenOptions, GridLineOptions, HistoryOptions, HullOptions, LegendOptions, MinimapOptions, SnaplineOptions, TimebarOptions, ToolbarOptions, TooltipOptions, WatermarkOptions, } from './plugins';
|
|
35
36
|
export type { DataURLOptions } from './runtime/canvas';
|
|
36
37
|
export type { RuntimeContext } from './runtime/types';
|
|
37
38
|
export type { BehaviorOptions, CanvasOptions, ComboData, ComboOptions, EdgeData, EdgeOptions, GraphData, GraphOptions, NodeData, NodeOptions, PluginOptions, ThemeOptions, ViewportOptions, } from './spec';
|
package/esm/exports.js
CHANGED
|
@@ -5,7 +5,7 @@ export { BaseEdge, Cubic, CubicHorizontal, CubicVertical, Line, Polyline, Quadra
|
|
|
5
5
|
export { BaseNode, Circle, Diamond, Donut, Ellipse, HTML, Hexagon, Image, Rect, Star, Triangle, } from './elements/nodes';
|
|
6
6
|
export { Badge, BaseShape, Icon, Label } from './elements/shapes';
|
|
7
7
|
export { AntVDagreLayout, BaseLayout, CircularLayout, ComboCombinedLayout, ConcentricLayout, D3ForceLayout, DagreLayout, ForceAtlas2Layout, ForceLayout, FruchtermanLayout, GridLayout, MDSLayout, RadialLayout, RandomLayout, compactBox, dendrogram, indented, mindmap, } from './layouts';
|
|
8
|
-
export { BasePlugin, BubbleSets, CameraSetting, Contextmenu, Fullscreen, GridLine, History, Hull, Legend, Minimap, Timebar, Toolbar, Tooltip, Watermark, } from './plugins';
|
|
8
|
+
export { BasePlugin, BubbleSets, CameraSetting, Contextmenu, EdgeFilterLens, Fullscreen, GridLine, History, Hull, Legend, Minimap, Snapline, Timebar, Toolbar, Tooltip, Watermark, } from './plugins';
|
|
9
9
|
export { getExtension, getExtensions } from './registry/get';
|
|
10
10
|
export { register } from './registry/register';
|
|
11
11
|
export { Graph } from './runtime/graph';
|
package/esm/exports.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports.js","sourceRoot":"src/","sources":["exports.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,E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,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { BaseStyleProps } from '@antv/g';
|
|
2
|
+
import type { RuntimeContext } from '../../runtime/types';
|
|
3
|
+
import type { EdgeData, NodeData } from '../../spec';
|
|
4
|
+
import type { EdgeStyle } from '../../spec/element/edge';
|
|
5
|
+
import type { NodeStyle } from '../../spec/element/node';
|
|
6
|
+
import type { ElementType, ID, IPointerEvent } from '../../types';
|
|
7
|
+
import type { BasePluginOptions } from '../base-plugin';
|
|
8
|
+
import { BasePlugin } from '../base-plugin';
|
|
9
|
+
export interface EdgeFilterLensOptions extends BasePluginOptions {
|
|
10
|
+
/**
|
|
11
|
+
* <zh/> 移动透镜的方式
|
|
12
|
+
* - `'pointermove'`:始终跟随鼠标移动
|
|
13
|
+
* - `'click'`:鼠标点击时透镜移动
|
|
14
|
+
* - `'drag'`:拖拽透镜
|
|
15
|
+
*
|
|
16
|
+
* <en/> The way to move the lens
|
|
17
|
+
* - `'pointermove'`: always follow the mouse movement
|
|
18
|
+
* - `'click'`: move the lens when the mouse clicks
|
|
19
|
+
* - `'drag'`: drag the lens
|
|
20
|
+
* @defaultValue 'pointermove'
|
|
21
|
+
*/
|
|
22
|
+
trigger?: 'pointermove' | 'click' | 'drag';
|
|
23
|
+
/**
|
|
24
|
+
* <zh/> 透镜的半径
|
|
25
|
+
*
|
|
26
|
+
* <en/> The radius of the lens
|
|
27
|
+
* @defaultValue 60
|
|
28
|
+
*/
|
|
29
|
+
r?: number;
|
|
30
|
+
/**
|
|
31
|
+
* <zh/> 透镜的最大半径。只有在开启 `scaleRByWheel` 时生效
|
|
32
|
+
*
|
|
33
|
+
* <en/> The maximum radius of the lens. Only valid when `scaleRByWheel` is enabled
|
|
34
|
+
* @defaultValue canvas 宽高最小值的一半
|
|
35
|
+
*/
|
|
36
|
+
maxR?: number;
|
|
37
|
+
/**
|
|
38
|
+
* <zh/> 透镜的最小半径。只有在开启 `scaleRByWheel` 时生效
|
|
39
|
+
*
|
|
40
|
+
* <en/> The minimum radius of the lens. Only valid when `scaleRByWheel` is enabled
|
|
41
|
+
* @defaultValue 0
|
|
42
|
+
*/
|
|
43
|
+
minR?: number;
|
|
44
|
+
/**
|
|
45
|
+
* <zh/> 是否通过滚轮缩放透镜的半径
|
|
46
|
+
*
|
|
47
|
+
* <en/> Whether to scale the radius of the lens by wheel
|
|
48
|
+
* @defaultValue true
|
|
49
|
+
*/
|
|
50
|
+
scaleRByWheel?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* <zh/> 边显示的条件
|
|
53
|
+
* - `'both'`:只有起始节点和目标节点都在透镜中时,边才会显示
|
|
54
|
+
* - `'source'`:只有起始节点在透镜中时,边才会显示
|
|
55
|
+
* - `'target'`:只有目标节点在透镜中时,边才会显示
|
|
56
|
+
* - `'either'`:只要起始节点或目标节点有一个在透镜中时,边就会显示
|
|
57
|
+
*
|
|
58
|
+
* <zh/> The condition for displaying the edge
|
|
59
|
+
* - `'both'`: The edge is displayed only when both the source node and the target node are in the lens
|
|
60
|
+
* - `'source'`: The edge is displayed only when the source node is in the lens
|
|
61
|
+
* - `'target'`: The edge is displayed only when the target node is in the lens
|
|
62
|
+
* - `'either'`: The edge is displayed when either the source node or the target node is in the lens
|
|
63
|
+
* @defaultValue 'both'
|
|
64
|
+
*/
|
|
65
|
+
nodeType?: 'both' | 'source' | 'target' | 'either';
|
|
66
|
+
/**
|
|
67
|
+
* <zh/> 过滤出始终不在透镜中显示的元素
|
|
68
|
+
*
|
|
69
|
+
* <en/> Filter elements that are never displayed in the lens
|
|
70
|
+
* @param id - <zh/> 元素的 id | <en/> The id of the element
|
|
71
|
+
* @param elementType - <zh/> 元素的类型 | <en/> The type of the element
|
|
72
|
+
* @returns <zh/> 是否显示 | <en/> Whether to display
|
|
73
|
+
*/
|
|
74
|
+
filter?: (id: ID, elementType: ElementType) => boolean;
|
|
75
|
+
/**
|
|
76
|
+
* <zh/> 透镜的样式
|
|
77
|
+
*
|
|
78
|
+
* <en/> The style of the lens
|
|
79
|
+
*/
|
|
80
|
+
style?: BaseStyleProps;
|
|
81
|
+
/**
|
|
82
|
+
* <zh/> 在透镜中节点的样式
|
|
83
|
+
*
|
|
84
|
+
* <en/> The style of the nodes displayed in the lens
|
|
85
|
+
*/
|
|
86
|
+
nodeStyle?: NodeStyle | ((datum: NodeData) => NodeStyle);
|
|
87
|
+
/**
|
|
88
|
+
* <zh/> 在透镜中边的样式
|
|
89
|
+
*
|
|
90
|
+
* <en/> The style of the edges displayed in the lens
|
|
91
|
+
*/
|
|
92
|
+
edgeStyle?: EdgeStyle | ((datum: EdgeData) => EdgeStyle);
|
|
93
|
+
/**
|
|
94
|
+
* <zh/> 是否阻止默认事件
|
|
95
|
+
*
|
|
96
|
+
* <en/> Whether to prevent the default event
|
|
97
|
+
* @defaultValue true
|
|
98
|
+
*/
|
|
99
|
+
preventDefault?: boolean;
|
|
100
|
+
}
|
|
101
|
+
export declare class EdgeFilterLens extends BasePlugin<EdgeFilterLensOptions> {
|
|
102
|
+
static defaultOptions: Partial<EdgeFilterLensOptions>;
|
|
103
|
+
constructor(context: RuntimeContext, options: EdgeFilterLensOptions);
|
|
104
|
+
private lens;
|
|
105
|
+
private shapes;
|
|
106
|
+
private r;
|
|
107
|
+
private get canvas();
|
|
108
|
+
private get isLensOn();
|
|
109
|
+
protected onEdgeFilter: (event: IPointerEvent) => void;
|
|
110
|
+
private renderLens;
|
|
111
|
+
private getFilterData;
|
|
112
|
+
private getFocusElements;
|
|
113
|
+
private renderFocusElements;
|
|
114
|
+
private getElementStyle;
|
|
115
|
+
private scaleRByWheel;
|
|
116
|
+
get graphDom(): import("@antv/g").CanvasLike | null;
|
|
117
|
+
private isLensDragging;
|
|
118
|
+
private onDragStart;
|
|
119
|
+
private onDrag;
|
|
120
|
+
private onDragEnd;
|
|
121
|
+
private bindEvents;
|
|
122
|
+
private unbindEvents;
|
|
123
|
+
update(options: Partial<EdgeFilterLensOptions>): void;
|
|
124
|
+
destroy(): void;
|
|
125
|
+
}
|