@antv/g6 5.0.15 → 5.0.16
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/scroll-canvas.d.ts +7 -0
- package/dist/lib/behaviors/zoom-canvas.d.ts +7 -0
- package/dist/lib/elements/edges/base-edge.d.ts +2 -2
- package/dist/lib/elements/edges/polyline.d.ts +3 -20
- package/dist/lib/plugins/index.d.ts +2 -0
- package/dist/lib/plugins/snapline/index.d.ts +95 -0
- package/dist/lib/runtime/element.d.ts +1 -0
- 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.js +1 -1
- 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/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 +3 -20
- package/esm/elements/edges/polyline.js +29 -34
- package/esm/elements/edges/polyline.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/plugins/index.d.ts +2 -0
- package/esm/plugins/index.js +1 -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 +3 -2
- package/esm/registry/build-in.js.map +1 -1
- 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/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.js +1 -1
- 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/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 +3 -20
- package/lib/elements/edges/polyline.js +29 -34
- package/lib/elements/edges/polyline.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/plugins/index.d.ts +2 -0
- package/lib/plugins/index.js +3 -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 +2 -1
- package/lib/registry/build-in.js.map +1 -1
- 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/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 +1 -0
- package/src/behaviors/scroll-canvas.ts +9 -1
- package/src/behaviors/zoom-canvas.ts +9 -1
- package/src/elements/edges/base-edge.ts +19 -5
- package/src/elements/edges/polyline.ts +33 -68
- package/src/elements/shapes/base-shape.ts +1 -1
- package/src/plugins/grid-line.ts +1 -1
- package/src/plugins/index.ts +2 -0
- package/src/plugins/snapline/index.ts +383 -0
- package/src/registry/build-in.ts +3 -1
- package/src/runtime/element.ts +11 -4
- 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
package/src/runtime/viewport.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { AABB } from '@antv/g';
|
|
1
|
+
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
5
|
import { getAnimationOptions } from '../utils/animation';
|
|
6
|
-
import { getBBoxSize, getCombinedBBox } from '../utils/bbox';
|
|
6
|
+
import { getBBoxSize, getCombinedBBox, isPointInBBox } from '../utils/bbox';
|
|
7
7
|
import { AnimateEvent, ViewportEvent, emit } from '../utils/event';
|
|
8
|
+
import { isPoint } from '../utils/is';
|
|
8
9
|
import { parsePadding } from '../utils/padding';
|
|
9
10
|
import { add, divide, subtract } from '../utils/vector';
|
|
10
11
|
import type { RuntimeContext } from './types';
|
|
@@ -30,7 +31,25 @@ export class ViewportController {
|
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
private get camera() {
|
|
33
|
-
|
|
34
|
+
const { canvas } = this.context;
|
|
35
|
+
return new Proxy(canvas.getCamera(), {
|
|
36
|
+
get: (target, prop: keyof ICamera) => {
|
|
37
|
+
const layers = Object.entries(canvas.getLayers()).filter(([name]) => !['main'].includes(name));
|
|
38
|
+
const cameras = layers.map(([, layer]) => layer.getCamera());
|
|
39
|
+
|
|
40
|
+
const value = target[prop];
|
|
41
|
+
if (typeof value === 'function') {
|
|
42
|
+
return (...args: any[]) => {
|
|
43
|
+
const result = (value as (...args: any[]) => any).apply(target, args);
|
|
44
|
+
cameras.forEach((camera) => {
|
|
45
|
+
(camera[prop] as (...args: any[]) => any).apply(camera, args);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return result;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
});
|
|
34
53
|
}
|
|
35
54
|
|
|
36
55
|
private landmarkCounter = 0;
|
|
@@ -255,6 +274,26 @@ export class ViewportController {
|
|
|
255
274
|
return bboxInViewport;
|
|
256
275
|
}
|
|
257
276
|
|
|
277
|
+
/**
|
|
278
|
+
* <zh/> 判断点或包围盒是否在视口中
|
|
279
|
+
*
|
|
280
|
+
* <en/> Determine whether the point or bounding box is in the viewport
|
|
281
|
+
* @param target - <zh/> 点或包围盒 | <en/> Point or bounding box
|
|
282
|
+
* @returns - <zh/> 是否在视口中 | <en/> Whether it is in the viewport
|
|
283
|
+
*/
|
|
284
|
+
public isInViewport(target: Point | AABB) {
|
|
285
|
+
const { graph } = this.context;
|
|
286
|
+
const size = this.getCanvasSize();
|
|
287
|
+
|
|
288
|
+
const [x1, y1] = graph.getCanvasByViewport([0, 0]);
|
|
289
|
+
const [x2, y2] = graph.getCanvasByViewport(size);
|
|
290
|
+
|
|
291
|
+
const viewportBBox = new AABB();
|
|
292
|
+
viewportBBox.setMinMax([x1, y1, 0], [x2, y2, 0]);
|
|
293
|
+
|
|
294
|
+
return isPoint(target) ? isPointInBBox(target, viewportBBox) : viewportBBox.intersects(target);
|
|
295
|
+
}
|
|
296
|
+
|
|
258
297
|
public cancelAnimation() {
|
|
259
298
|
// @ts-expect-error landmarks is private
|
|
260
299
|
if (this.camera.landmarks?.length) {
|
package/src/types/index.ts
CHANGED
|
@@ -16,6 +16,7 @@ export type * from './padding';
|
|
|
16
16
|
export type * from './placement';
|
|
17
17
|
export type * from './point';
|
|
18
18
|
export type * from './prefix';
|
|
19
|
+
export type * from './router';
|
|
19
20
|
export type * from './size';
|
|
20
21
|
export type * from './state';
|
|
21
22
|
export type * from './style';
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { Padding } from './padding';
|
|
2
|
+
import type { CardinalPlacement } from './placement';
|
|
3
|
+
import { Point } from './point';
|
|
4
|
+
|
|
5
|
+
export type Direction = CardinalPlacement;
|
|
6
|
+
|
|
7
|
+
export type PolylineRouter = false | OrthRouter | ShortestPathRouter;
|
|
8
|
+
|
|
9
|
+
export interface OrthRouter extends OrthRouterOptions {
|
|
10
|
+
/**
|
|
11
|
+
* <zh/> 正交路由,通过在路径上添加额外的控制点,使得边的每一段都保持水平或垂直
|
|
12
|
+
*
|
|
13
|
+
* <en/> Orthogonal routing that adds additional control points on the path to ensure each segment of the edge horizontal or vertical
|
|
14
|
+
* @remarks
|
|
15
|
+
* <zh/> 采用基于节点的相对位置和专家经验得出的寻径算法来模糊计算控制点,非最优解但计算速度快。该路由支持 `controlPoints` 来作为额外的控制点,但不支持自动避障。
|
|
16
|
+
*
|
|
17
|
+
* <en/> It uses a pathfinding algorithm based on the relative position of the nodes and expert experience to calculate the control points, which is not the optimal solution but is fast to calculate. This routing supports `controlPoints` as additional control points, but does not support automatic obstacle avoidance.
|
|
18
|
+
*/
|
|
19
|
+
type: 'orth';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ShortestPathRouter extends ShortestPathRouterOptions {
|
|
23
|
+
/**
|
|
24
|
+
* <zh/> 最短路径路由,是正交路由 `'orth'` 的智能版本。该路由由水平或垂直的正交线段组成。采用 A* 算法计算最短路径,并支持自动避开路径上的其他节点(障碍)
|
|
25
|
+
*
|
|
26
|
+
* <en/> The shortest path routing is an intelligent version of the orthogonal routing `'orth'`. The routing consists of horizontal or vertical orthogonal line segments. It uses the A* algorithm to calculate the shortest path and supports automatic avoidance of other nodes (obstacles) on the path.
|
|
27
|
+
*/
|
|
28
|
+
type: 'shortest-path';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type RouterOptions = OrthRouterOptions | ShortestPathRouterOptions;
|
|
32
|
+
|
|
33
|
+
export interface OrthRouterOptions {
|
|
34
|
+
/**
|
|
35
|
+
* <zh/> 指定节点连接点与转角的最小距离
|
|
36
|
+
*
|
|
37
|
+
* <en/> The minimum distance between the node connection point and the corner
|
|
38
|
+
*/
|
|
39
|
+
padding?: Padding;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ShortestPathRouterOptions {
|
|
43
|
+
/**
|
|
44
|
+
* <zh/> 节点锚点与转角的最小距离
|
|
45
|
+
*
|
|
46
|
+
* <en/> The minimum distance between the node anchor point and the corner
|
|
47
|
+
*/
|
|
48
|
+
offset?: Padding;
|
|
49
|
+
/**
|
|
50
|
+
* <zh/> grid 格子大小
|
|
51
|
+
*
|
|
52
|
+
* <en/> grid size
|
|
53
|
+
*/
|
|
54
|
+
gridSize?: number;
|
|
55
|
+
/**
|
|
56
|
+
* <zh/> 支持的最大旋转角度(弧度)
|
|
57
|
+
*
|
|
58
|
+
* <en/> Maximum allowable rotation angle (radian)
|
|
59
|
+
*/
|
|
60
|
+
maxAllowedDirectionChange?: number;
|
|
61
|
+
/**
|
|
62
|
+
* <zh/> 节点的可能起始方向
|
|
63
|
+
*
|
|
64
|
+
* <en/> Possible starting directions from a node
|
|
65
|
+
*/
|
|
66
|
+
startDirections?: Direction[];
|
|
67
|
+
/**
|
|
68
|
+
* <zh/> 节点的可能结束方向
|
|
69
|
+
*
|
|
70
|
+
* <en/> Possible ending directions from a node
|
|
71
|
+
*/
|
|
72
|
+
endDirections?: Direction[];
|
|
73
|
+
/**
|
|
74
|
+
* <zh/> 指定可移动的方向
|
|
75
|
+
*
|
|
76
|
+
* <en/> Allowed edge directions
|
|
77
|
+
*/
|
|
78
|
+
directionMap?: {
|
|
79
|
+
[key in Direction]: { stepX: number; stepY: number };
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* <zh/> 表示在路径搜索过程中某些路径的额外代价。key 为弧度值,value 为代价
|
|
83
|
+
*
|
|
84
|
+
* <en/> Penalties for direction changes. Key is the radian value, value is the penalty
|
|
85
|
+
*/
|
|
86
|
+
penalties?: {
|
|
87
|
+
[key: string]: number;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* <zh/> 指定计算两点之间距离的函数
|
|
91
|
+
*
|
|
92
|
+
* <en/> Function to calculate the distance between two points
|
|
93
|
+
*/
|
|
94
|
+
distFunc?: (p1: Point, p2: Point) => number;
|
|
95
|
+
/**
|
|
96
|
+
* <zh/> 最大迭代次数
|
|
97
|
+
*
|
|
98
|
+
* <en/> Maximum loops
|
|
99
|
+
*/
|
|
100
|
+
maximumLoops?: number;
|
|
101
|
+
/**
|
|
102
|
+
* <zh/> 是否开启避障
|
|
103
|
+
*
|
|
104
|
+
* <en/> Whether to enable obstacle avoidance while computing the path
|
|
105
|
+
*/
|
|
106
|
+
enableObstacleAvoidance?: boolean;
|
|
107
|
+
}
|
package/src/utils/bbox.ts
CHANGED
|
@@ -247,3 +247,27 @@ export function getIncircleRadius(bbox: AABB, direction: TriangleDirection): num
|
|
|
247
247
|
// 三角形的内切圆半径
|
|
248
248
|
return (h ** 2 - (Math.sqrt((w / 2) ** 2 + h ** 2) - w / 2) ** 2) / (2 * h);
|
|
249
249
|
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* <zh/> 获取包围盒的四条边,顺序依次为上、右、下、左
|
|
253
|
+
*
|
|
254
|
+
* <en/> Get the four segments of the bounding box, in order from top, right, bottom, left
|
|
255
|
+
* @param bbox - <zh/> 包围盒 | <en/> Bounding box
|
|
256
|
+
* @returns <zh/> 包围盒的四条边 | <en/> The four segments of the bounding box
|
|
257
|
+
*/
|
|
258
|
+
export function getBBoxSegments(bbox: AABB): [Point, Point][] {
|
|
259
|
+
const {
|
|
260
|
+
min: [minX, minY],
|
|
261
|
+
max: [maxX, maxY],
|
|
262
|
+
} = bbox;
|
|
263
|
+
const topLeftCorner: Point = [minX, maxY];
|
|
264
|
+
const topRightCorner: Point = [maxX, maxY];
|
|
265
|
+
const bottomRightCorner: Point = [maxX, minY];
|
|
266
|
+
const bottomLeftCorner: Point = [minX, minY];
|
|
267
|
+
|
|
268
|
+
const top = [topLeftCorner, topRightCorner];
|
|
269
|
+
const right = [topRightCorner, bottomRightCorner];
|
|
270
|
+
const bottom = [bottomRightCorner, bottomLeftCorner];
|
|
271
|
+
const left = [bottomLeftCorner, topLeftCorner];
|
|
272
|
+
return [top, right, bottom, left] as [Point, Point][];
|
|
273
|
+
}
|
package/src/utils/router/orth.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AABB } from '@antv/g';
|
|
2
2
|
import { difference, isEqual } from '@antv/util';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Node, OrthRouterOptions, Point } from '../../types';
|
|
4
4
|
import {
|
|
5
5
|
getBBoxHeight,
|
|
6
6
|
getBBoxWidth,
|
|
@@ -21,26 +21,35 @@ type Route = {
|
|
|
21
21
|
direction: Direction;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
+
const defaultOptions: OrthRouterOptions = {
|
|
25
|
+
padding: 10,
|
|
26
|
+
};
|
|
27
|
+
|
|
24
28
|
/**
|
|
25
|
-
* <zh/>
|
|
29
|
+
* <zh/> 获取两点之间的正交线段路径
|
|
26
30
|
*
|
|
27
|
-
* <en/> Get
|
|
31
|
+
* <en/> Get orthogonal line segments between two points
|
|
28
32
|
* @param sourcePoint - <zh/> 起始点 | <en/> start point
|
|
29
33
|
* @param targetPoint - <zh/> 终止点 | <en/> end point
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
34
|
+
* @param sourceNode - <zh/> 起始节点 | <en/> source node
|
|
35
|
+
* @param targetNode - <zh/> 终止节点 | <en/> target node
|
|
32
36
|
* @param controlPoints - <zh/> 控制点 | <en/> control points
|
|
33
|
-
* @param
|
|
34
|
-
* @returns <zh/>
|
|
37
|
+
* @param options - <zh/> 配置项 | <en/> options
|
|
38
|
+
* @returns <zh/> 路径点集 | <en/> vertices
|
|
35
39
|
*/
|
|
36
40
|
export function orth(
|
|
37
41
|
sourcePoint: Point,
|
|
38
42
|
targetPoint: Point,
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
sourceNode: Node,
|
|
44
|
+
targetNode: Node,
|
|
41
45
|
controlPoints: Point[],
|
|
42
|
-
|
|
46
|
+
options: OrthRouterOptions,
|
|
43
47
|
) {
|
|
48
|
+
const { padding } = Object.assign(defaultOptions, options);
|
|
49
|
+
|
|
50
|
+
const sourceBBox = getNodeBBox(sourceNode, padding);
|
|
51
|
+
const targetBBox = getNodeBBox(targetNode, padding);
|
|
52
|
+
|
|
44
53
|
const points: Point[] = [sourcePoint, ...controlPoints, targetPoint];
|
|
45
54
|
|
|
46
55
|
// direction of previous route segment
|