@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
|
@@ -57,6 +57,13 @@ export interface ZoomCanvasOptions extends BaseBehaviorOptions {
|
|
|
57
57
|
* <en/> Callback when zooming is completed
|
|
58
58
|
*/
|
|
59
59
|
onFinish?: () => void;
|
|
60
|
+
/**
|
|
61
|
+
* <zh/> 是否阻止默认事件
|
|
62
|
+
*
|
|
63
|
+
* <en/> Whether to prevent the default event
|
|
64
|
+
* @defaultValue true
|
|
65
|
+
*/
|
|
66
|
+
preventDefault?: boolean;
|
|
60
67
|
}
|
|
61
68
|
|
|
62
69
|
/**
|
|
@@ -70,6 +77,7 @@ export class ZoomCanvas extends BaseBehavior<ZoomCanvasOptions> {
|
|
|
70
77
|
enable: true,
|
|
71
78
|
sensitivity: 1,
|
|
72
79
|
trigger: [],
|
|
80
|
+
preventDefault: true,
|
|
73
81
|
};
|
|
74
82
|
|
|
75
83
|
private shortcut: Shortcut;
|
|
@@ -171,7 +179,7 @@ export class ZoomCanvas extends BaseBehavior<ZoomCanvasOptions> {
|
|
|
171
179
|
}
|
|
172
180
|
|
|
173
181
|
private preventDefault = (event: Event) => {
|
|
174
|
-
event.preventDefault();
|
|
182
|
+
if (this.options.preventDefault) event.preventDefault();
|
|
175
183
|
};
|
|
176
184
|
|
|
177
185
|
/**
|
|
@@ -18,7 +18,7 @@ import type {
|
|
|
18
18
|
} from '../../types';
|
|
19
19
|
import { getBBoxHeight, getBBoxWidth, getNodeBBox } from '../../utils/bbox';
|
|
20
20
|
import { getArrowSize, getBadgePositionStyle, getCubicLoopPath, getLabelPositionStyle } from '../../utils/edge';
|
|
21
|
-
import { findPorts, getConnectionPoint, isSameNode } from '../../utils/element';
|
|
21
|
+
import { findPorts, getConnectionPoint, getPortPosition, isSameNode } from '../../utils/element';
|
|
22
22
|
import { omitStyleProps, subStyleProps } from '../../utils/prefix';
|
|
23
23
|
import { parseSize } from '../../utils/size';
|
|
24
24
|
import { mergeOptions } from '../../utils/style';
|
|
@@ -153,7 +153,7 @@ export interface BaseEdgeStyleProps
|
|
|
153
153
|
/**
|
|
154
154
|
* <zh/> 在路径除了 “起点” 和 “终点” 之外的每一个顶点上放置标记图形。在内部实现中,由于我们会把路径中部分命令转换成 C 命令,因此这些顶点实际是三阶贝塞尔曲线的控制点
|
|
155
155
|
*
|
|
156
|
-
* <en/> Place a marker graphic on each vertex of the path except for the "start point" and "end point". In the internal implementation, because we will convert some commands in the path to C commands, these
|
|
156
|
+
* <en/> Place a marker graphic on each vertex of the path except for the "start point" and "end point". In the internal implementation, because we will convert some commands in the path to C commands, these controlPoints are actually the control points of the cubic Bezier curve
|
|
157
157
|
*/
|
|
158
158
|
markerMid?: DisplayObject | null;
|
|
159
159
|
/**
|
|
@@ -258,14 +258,28 @@ export abstract class BaseEdge extends BaseElement<BaseEdgeStyleProps> implement
|
|
|
258
258
|
return getCubicLoopPath(node, placement, clockwise, dist, sourcePort, targetPort);
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
-
protected getEndpoints(
|
|
261
|
+
protected getEndpoints(
|
|
262
|
+
attributes: ParsedBaseEdgeStyleProps,
|
|
263
|
+
optimize = true,
|
|
264
|
+
controlPoints: Point[] | (() => Point[]) = [],
|
|
265
|
+
): [Point, Point] {
|
|
262
266
|
const { sourcePort: sourcePortKey, targetPort: targetPortKey } = attributes;
|
|
263
267
|
const { sourceNode, targetNode } = this;
|
|
264
268
|
|
|
265
269
|
const [sourcePort, targetPort] = findPorts(sourceNode, targetNode, sourcePortKey, targetPortKey);
|
|
266
270
|
|
|
267
|
-
|
|
268
|
-
|
|
271
|
+
if (!optimize) {
|
|
272
|
+
const sourcePoint = sourcePort ? getPortPosition(sourcePort) : sourceNode.getCenter();
|
|
273
|
+
const targetPoint = targetPort ? getPortPosition(targetPort) : targetNode.getCenter();
|
|
274
|
+
return [sourcePoint, targetPoint];
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const _controlPoints = typeof controlPoints === 'function' ? controlPoints() : controlPoints;
|
|
278
|
+
const sourcePoint = getConnectionPoint(sourcePort || sourceNode, _controlPoints[0] || targetPort || targetNode);
|
|
279
|
+
const targetPoint = getConnectionPoint(
|
|
280
|
+
targetPort || targetNode,
|
|
281
|
+
_controlPoints[_controlPoints.length - 1] || sourcePort || sourceNode,
|
|
282
|
+
);
|
|
269
283
|
|
|
270
284
|
return [sourcePoint, targetPoint];
|
|
271
285
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { DisplayObjectConfig } from '@antv/g';
|
|
2
2
|
import type { PathArray } from '@antv/util';
|
|
3
|
-
import type { LoopStyleProps,
|
|
3
|
+
import type { LoopStyleProps, Point, PolylineRouter } from '../../types';
|
|
4
4
|
import { getBBoxHeight, getBBoxWidth, getNodeBBox } from '../../utils/bbox';
|
|
5
5
|
import { getPolylineLoopPath, getPolylinePath } from '../../utils/edge';
|
|
6
|
-
import { findPorts, getConnectionPoint, getPortPosition } from '../../utils/element';
|
|
7
6
|
import { subStyleProps } from '../../utils/prefix';
|
|
8
7
|
import { orth } from '../../utils/router/orth';
|
|
8
|
+
import { aStarSearch } from '../../utils/router/shortest-path';
|
|
9
9
|
import { mergeOptions } from '../../utils/style';
|
|
10
10
|
import type { BaseEdgeStyleProps } from './base-edge';
|
|
11
11
|
import { BaseEdge } from './base-edge';
|
|
@@ -35,24 +35,9 @@ export interface PolylineStyleProps extends BaseEdgeStyleProps {
|
|
|
35
35
|
* <en/> Whether to enable routing, it is enabled by default and controlPoints will be automatically included
|
|
36
36
|
* @defaultValue false
|
|
37
37
|
*/
|
|
38
|
-
router?:
|
|
39
|
-
/**
|
|
40
|
-
* <zh/> 路由名称,目前支持 'orth'
|
|
41
|
-
*
|
|
42
|
-
* <en/> Routing name, currently supports 'orth'
|
|
43
|
-
* @defaultValue 'orth'
|
|
44
|
-
* @remarks
|
|
45
|
-
* <img width="300" src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*8Ia2RJFFQSoAAAAAAAAAAAAADmJ7AQ/original" />
|
|
46
|
-
*/
|
|
47
|
-
routerName?: 'orth';
|
|
48
|
-
/**
|
|
49
|
-
* <zh/> 节点边距
|
|
50
|
-
*
|
|
51
|
-
* <en/> Padding for routing calculation
|
|
52
|
-
* @defaultValue 10
|
|
53
|
-
*/
|
|
54
|
-
routerPadding?: Padding;
|
|
38
|
+
router?: PolylineRouter;
|
|
55
39
|
}
|
|
40
|
+
|
|
56
41
|
type ParsedPolylineStyleProps = Required<PolylineStyleProps>;
|
|
57
42
|
|
|
58
43
|
/**
|
|
@@ -65,63 +50,48 @@ export class Polyline extends BaseEdge {
|
|
|
65
50
|
radius: 0,
|
|
66
51
|
controlPoints: [],
|
|
67
52
|
router: false,
|
|
68
|
-
routerName: 'orth',
|
|
69
|
-
routerPadding: 10,
|
|
70
53
|
};
|
|
71
54
|
|
|
72
55
|
constructor(options: DisplayObjectConfig<PolylineStyleProps>) {
|
|
73
56
|
super(mergeOptions({ style: Polyline.defaultStyleProps }, options));
|
|
74
57
|
}
|
|
75
58
|
|
|
76
|
-
protected
|
|
77
|
-
const {
|
|
59
|
+
protected getControlPoints(attributes: ParsedPolylineStyleProps): Point[] {
|
|
60
|
+
const { router } = attributes;
|
|
78
61
|
const { sourceNode, targetNode } = this;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
62
|
+
const [sourcePoint, targetPoint] = this.getEndpoints(attributes, false);
|
|
63
|
+
|
|
64
|
+
let controlPoints: Point[] = [];
|
|
65
|
+
|
|
66
|
+
if (!router) {
|
|
67
|
+
controlPoints = attributes.controlPoints;
|
|
68
|
+
} else {
|
|
69
|
+
if (router.type === 'shortest-path') {
|
|
70
|
+
const nodes = this.context.element!.getNodes();
|
|
71
|
+
controlPoints = aStarSearch(sourceNode, targetNode, nodes, router);
|
|
72
|
+
if (!controlPoints.length) {
|
|
73
|
+
controlPoints = orth(sourcePoint, targetPoint, sourceNode, targetNode, attributes.controlPoints, {
|
|
74
|
+
padding: router.offset,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
} else if (router.type === 'orth') {
|
|
78
|
+
controlPoints = orth(sourcePoint, targetPoint, sourceNode, targetNode, attributes.controlPoints, router);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return controlPoints;
|
|
94
83
|
}
|
|
95
84
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
targetPoint: Point;
|
|
99
|
-
sourcePort: Port | undefined;
|
|
100
|
-
targetPort: Port | undefined;
|
|
101
|
-
} {
|
|
102
|
-
const { sourcePort: sourcePortKey, targetPort: targetPortKey } = attributes;
|
|
103
|
-
const { sourceNode, targetNode } = this;
|
|
85
|
+
protected getPoints(attributes: ParsedPolylineStyleProps): Point[] {
|
|
86
|
+
const controlPoints = this.getControlPoints(attributes);
|
|
104
87
|
|
|
105
|
-
const [
|
|
106
|
-
|
|
107
|
-
return {
|
|
108
|
-
sourcePoint: sourcePort ? getPortPosition(sourcePort) : sourceNode.getCenter(),
|
|
109
|
-
targetPoint: targetPort ? getPortPosition(targetPort) : targetNode.getCenter(),
|
|
110
|
-
sourcePort,
|
|
111
|
-
targetPort,
|
|
112
|
-
};
|
|
88
|
+
const [newSourcePoint, newTargetPoint] = this.getEndpoints(attributes, true, controlPoints);
|
|
89
|
+
return [newSourcePoint, ...controlPoints, newTargetPoint];
|
|
113
90
|
}
|
|
114
91
|
|
|
115
|
-
protected
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (!router) return [...controlPoints];
|
|
120
|
-
|
|
121
|
-
const sourceBBox = getNodeBBox(sourceNode, routerPadding);
|
|
122
|
-
const targetBBox = getNodeBBox(targetNode, routerPadding);
|
|
123
|
-
|
|
124
|
-
return orth(sourcePoint, targetPoint, sourceBBox, targetBBox, controlPoints, routerPadding);
|
|
92
|
+
protected getKeyPath(attributes: ParsedPolylineStyleProps): PathArray {
|
|
93
|
+
const points = this.getPoints(attributes);
|
|
94
|
+
return getPolylinePath(points, attributes.radius);
|
|
125
95
|
}
|
|
126
96
|
|
|
127
97
|
protected getLoopPath(attributes: ParsedPolylineStyleProps): PathArray {
|
|
@@ -129,7 +99,8 @@ export class Polyline extends BaseEdge {
|
|
|
129
99
|
const node = this.sourceNode;
|
|
130
100
|
|
|
131
101
|
const bbox = getNodeBBox(node);
|
|
132
|
-
// 默认转折点距离为 bbox 的最大宽高的 1/4
|
|
102
|
+
// 默认转折点距离为 bbox 的最大宽高的 1/4
|
|
103
|
+
// Default distance of the turning point is 1/4 of the maximum width and height of the bbox
|
|
133
104
|
const defaultDist = Math.max(getBBoxWidth(bbox), getBBoxHeight(bbox)) / 4;
|
|
134
105
|
|
|
135
106
|
const {
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import type { BaseStyleProps, DisplayObject, DisplayObjectConfig, Group, IAnimation } from '@antv/g';
|
|
2
2
|
import { CustomElement } from '@antv/g';
|
|
3
3
|
import { isEmpty, isFunction, upperFirst } from '@antv/util';
|
|
4
|
+
import { ExtensionCategory } from '../../constants';
|
|
4
5
|
import type { Keyframe } from '../../types';
|
|
5
6
|
import { createAnimationsProxy, preprocessKeyframes } from '../../utils/animation';
|
|
6
7
|
import { updateStyle } from '../../utils/element';
|
|
7
8
|
import { subObject } from '../../utils/prefix';
|
|
9
|
+
import { format } from '../../utils/print';
|
|
8
10
|
import { getSubShapeStyle } from '../../utils/style';
|
|
9
11
|
import { replaceTranslateInTransform } from '../../utils/transform';
|
|
10
12
|
import { setVisibility } from '../../utils/visibility';
|
|
13
|
+
import { getExtension } from './../../registry/get';
|
|
11
14
|
|
|
12
15
|
export interface BaseShapeStyleProps extends BaseStyleProps {}
|
|
13
16
|
|
|
@@ -46,37 +49,55 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
|
|
|
46
49
|
* @param Ctor - <zh> 图形类型 | <en> shape type
|
|
47
50
|
* @param style - <zh> 图形样式 | <en> shape style
|
|
48
51
|
* @param container - <zh> 容器 | <en> container
|
|
52
|
+
* @param hooks - <zh> 钩子函数 | <en> hooks
|
|
49
53
|
* @returns <zh> 图形实例 | <en> shape instance
|
|
50
54
|
*/
|
|
51
55
|
protected upsert<T extends DisplayObject>(
|
|
52
56
|
className: string,
|
|
53
|
-
Ctor: { new (...args: any[]): T },
|
|
57
|
+
Ctor: string | { new (...args: any[]): T },
|
|
54
58
|
style: T['attributes'] | false,
|
|
55
59
|
container: DisplayObject,
|
|
60
|
+
hooks?: UpsertHooks,
|
|
56
61
|
): T | undefined {
|
|
57
62
|
const target = this.shapeMap[className] as T | undefined;
|
|
58
63
|
// remove
|
|
59
64
|
// 如果 style 为 false,则删除图形 / remove shape if style is false
|
|
60
65
|
if (style === false) {
|
|
61
66
|
if (target) {
|
|
67
|
+
hooks?.beforeDestroy?.(target);
|
|
62
68
|
container.removeChild(target);
|
|
63
69
|
delete this.shapeMap[className];
|
|
70
|
+
hooks?.afterDestroy?.(target);
|
|
64
71
|
}
|
|
65
72
|
return;
|
|
66
73
|
}
|
|
67
74
|
|
|
75
|
+
const _Ctor = typeof Ctor === 'string' ? getExtension(ExtensionCategory.SHAPE, Ctor) : Ctor;
|
|
76
|
+
|
|
77
|
+
if (!_Ctor) {
|
|
78
|
+
throw new Error(format(`Shape ${Ctor} not found`));
|
|
79
|
+
}
|
|
80
|
+
|
|
68
81
|
// create
|
|
69
|
-
if (!target || target.destroyed || !(target instanceof
|
|
70
|
-
target
|
|
82
|
+
if (!target || target.destroyed || !(target instanceof _Ctor)) {
|
|
83
|
+
if (target) {
|
|
84
|
+
hooks?.beforeDestroy?.(target);
|
|
85
|
+
target?.destroy();
|
|
86
|
+
hooks?.afterDestroy?.(target);
|
|
87
|
+
}
|
|
71
88
|
|
|
72
|
-
|
|
89
|
+
hooks?.beforeCreate?.();
|
|
90
|
+
const instance = new _Ctor({ className, style });
|
|
73
91
|
container.appendChild(instance);
|
|
74
92
|
this.shapeMap[className] = instance;
|
|
75
|
-
|
|
93
|
+
hooks?.afterCreate?.(instance);
|
|
94
|
+
return instance as T;
|
|
76
95
|
}
|
|
77
96
|
|
|
78
97
|
// update
|
|
98
|
+
hooks?.beforeUpdate?.(target);
|
|
79
99
|
updateStyle(target, style);
|
|
100
|
+
hooks?.afterUpdate?.(target);
|
|
80
101
|
|
|
81
102
|
return target;
|
|
82
103
|
}
|
|
@@ -222,7 +243,7 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
|
|
|
222
243
|
|
|
223
244
|
private setVisibility() {
|
|
224
245
|
const { visibility } = this.attributes;
|
|
225
|
-
setVisibility(this, visibility);
|
|
246
|
+
setVisibility(this, visibility, true);
|
|
226
247
|
}
|
|
227
248
|
|
|
228
249
|
public destroy(): void {
|
|
@@ -248,3 +269,52 @@ function releaseAnimation(target: DisplayObject, animation: IAnimation) {
|
|
|
248
269
|
if (index > -1) target.activeAnimations.splice(index, 1);
|
|
249
270
|
});
|
|
250
271
|
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* <zh/> 图形 upsert 方法生命周期钩子
|
|
275
|
+
*
|
|
276
|
+
* <en/> Shape upsert method lifecycle hooks
|
|
277
|
+
*/
|
|
278
|
+
export interface UpsertHooks {
|
|
279
|
+
/**
|
|
280
|
+
* <zh/> 图形创建前
|
|
281
|
+
*
|
|
282
|
+
* <en/> Before creating the shape
|
|
283
|
+
*/
|
|
284
|
+
beforeCreate?: () => void;
|
|
285
|
+
/**
|
|
286
|
+
* <zh/> 图形创建后
|
|
287
|
+
*
|
|
288
|
+
* <en/> After creating the shape
|
|
289
|
+
* @param instance - <zh/> 图形实例 | <en/> shape instance
|
|
290
|
+
*/
|
|
291
|
+
afterCreate?: (instance: DisplayObject) => void;
|
|
292
|
+
/**
|
|
293
|
+
* <zh/> 图形更新前
|
|
294
|
+
*
|
|
295
|
+
* <en/> Before updating the shape
|
|
296
|
+
* @param instance - <zh/> 图形实例 | <en/> shape instance
|
|
297
|
+
*/
|
|
298
|
+
beforeUpdate?: (instance: DisplayObject) => void;
|
|
299
|
+
/**
|
|
300
|
+
* <zh/> 图形更新后
|
|
301
|
+
*
|
|
302
|
+
* <en/> After updating the shape
|
|
303
|
+
* @param instance - <zh/> 图形实例 | <en/> shape instance
|
|
304
|
+
*/
|
|
305
|
+
afterUpdate?: (instance: DisplayObject) => void;
|
|
306
|
+
/**
|
|
307
|
+
* <zh/> 图形销毁前
|
|
308
|
+
*
|
|
309
|
+
* <en/> Before destroying the shape
|
|
310
|
+
* @param instance - <zh/> 图形实例 | <en/> shape instance
|
|
311
|
+
*/
|
|
312
|
+
beforeDestroy?: (instance: DisplayObject) => void;
|
|
313
|
+
/**
|
|
314
|
+
* <zh/> 图形销毁后
|
|
315
|
+
*
|
|
316
|
+
* <en/> After destroying the shape
|
|
317
|
+
* @param instance - <zh/> 图形实例 | <en/> shape instance
|
|
318
|
+
*/
|
|
319
|
+
afterDestroy?: (instance: DisplayObject) => void;
|
|
320
|
+
}
|
package/src/exports.ts
CHANGED
|
@@ -67,12 +67,14 @@ export {
|
|
|
67
67
|
BubbleSets,
|
|
68
68
|
CameraSetting,
|
|
69
69
|
Contextmenu,
|
|
70
|
+
EdgeFilterLens,
|
|
70
71
|
Fullscreen,
|
|
71
72
|
GridLine,
|
|
72
73
|
History,
|
|
73
74
|
Hull,
|
|
74
75
|
Legend,
|
|
75
76
|
Minimap,
|
|
77
|
+
Snapline,
|
|
76
78
|
Timebar,
|
|
77
79
|
Toolbar,
|
|
78
80
|
Tooltip,
|
|
@@ -158,6 +160,7 @@ export type {
|
|
|
158
160
|
LabelStyleProps,
|
|
159
161
|
PolygonStyleProps,
|
|
160
162
|
} from './elements/shapes';
|
|
163
|
+
export type { UpsertHooks } from './elements/shapes/base-shape';
|
|
161
164
|
export type { ContourLabelStyleProps, ContourStyleProps } from './elements/shapes/contour';
|
|
162
165
|
export type { BaseLayoutOptions, WebWorkerLayoutOptions } from './layouts/types';
|
|
163
166
|
export type { CategoricalPalette } from './palettes/types';
|
|
@@ -166,12 +169,14 @@ export type {
|
|
|
166
169
|
BubbleSetsOptions,
|
|
167
170
|
CameraSettingOptions,
|
|
168
171
|
ContextmenuOptions,
|
|
172
|
+
EdgeFilterLensOptions,
|
|
169
173
|
FullscreenOptions,
|
|
170
174
|
GridLineOptions,
|
|
171
175
|
HistoryOptions,
|
|
172
176
|
HullOptions,
|
|
173
177
|
LegendOptions,
|
|
174
178
|
MinimapOptions,
|
|
179
|
+
SnaplineOptions,
|
|
175
180
|
TimebarOptions,
|
|
176
181
|
ToolbarOptions,
|
|
177
182
|
TooltipOptions,
|