@antv/g6 5.0.19 → 5.0.20
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 +9 -0
- package/dist/lib/behaviors/hover-activate.d.ts +14 -1
- package/dist/lib/behaviors/scroll-canvas.d.ts +9 -0
- package/dist/lib/elements/combos/circle.d.ts +1 -1
- package/dist/lib/elements/edges/cubic-radial.d.ts +24 -0
- package/dist/lib/elements/edges/index.d.ts +2 -0
- package/dist/lib/elements/nodes/base-node.d.ts +2 -1
- package/dist/lib/elements/nodes/circle.d.ts +1 -1
- package/dist/lib/elements/nodes/ellipse.d.ts +1 -1
- package/dist/lib/elements/shapes/polygon.d.ts +1 -1
- package/dist/lib/exports.d.ts +7 -5
- package/dist/lib/runtime/data.d.ts +1 -0
- package/dist/lib/runtime/element.d.ts +1 -0
- package/dist/lib/runtime/graph.d.ts +2 -0
- package/dist/lib/runtime/layout.d.ts +1 -0
- package/dist/lib/transforms/base-transform.d.ts +1 -0
- package/dist/lib/transforms/index.d.ts +3 -0
- package/dist/lib/transforms/position-radial-labels.d.ts +27 -0
- package/dist/lib/types/element.d.ts +2 -1
- package/dist/lib/utils/data.d.ts +14 -0
- package/dist/lib/utils/diff.d.ts +2 -1
- package/dist/lib/utils/point.d.ts +17 -5
- package/dist/lib/utils/position.d.ts +8 -0
- package/dist/lib/utils/relation.d.ts +6 -4
- package/dist/lib/utils/vector.d.ts +8 -0
- package/dist/lib/version.d.ts +1 -1
- package/esm/behaviors/drag-canvas.d.ts +9 -0
- package/esm/behaviors/drag-canvas.js +28 -3
- package/esm/behaviors/drag-canvas.js.map +1 -1
- package/esm/behaviors/hover-activate.d.ts +14 -1
- package/esm/behaviors/hover-activate.js +3 -2
- package/esm/behaviors/hover-activate.js.map +1 -1
- package/esm/behaviors/scroll-canvas.d.ts +9 -0
- package/esm/behaviors/scroll-canvas.js +31 -4
- package/esm/behaviors/scroll-canvas.js.map +1 -1
- package/esm/elements/combos/base-combo.js +2 -2
- package/esm/elements/combos/base-combo.js.map +1 -1
- package/esm/elements/combos/circle.d.ts +1 -1
- package/esm/elements/combos/circle.js +2 -2
- package/esm/elements/combos/circle.js.map +1 -1
- package/esm/elements/edges/cubic-radial.d.ts +24 -0
- package/esm/elements/edges/cubic-radial.js +52 -0
- package/esm/elements/edges/cubic-radial.js.map +1 -0
- package/esm/elements/edges/index.d.ts +2 -0
- package/esm/elements/edges/index.js +1 -0
- package/esm/elements/edges/index.js.map +1 -1
- package/esm/elements/nodes/base-node.d.ts +2 -1
- package/esm/elements/nodes/base-node.js +3 -2
- package/esm/elements/nodes/base-node.js.map +1 -1
- package/esm/elements/nodes/circle.d.ts +1 -1
- package/esm/elements/nodes/circle.js +2 -2
- package/esm/elements/nodes/circle.js.map +1 -1
- package/esm/elements/nodes/ellipse.d.ts +1 -1
- package/esm/elements/nodes/ellipse.js +2 -2
- package/esm/elements/nodes/ellipse.js.map +1 -1
- package/esm/elements/shapes/polygon.d.ts +1 -1
- package/esm/elements/shapes/polygon.js +2 -2
- package/esm/elements/shapes/polygon.js.map +1 -1
- package/esm/exports.d.ts +7 -5
- package/esm/exports.js +5 -3
- package/esm/exports.js.map +1 -1
- package/esm/plugins/tooltip.js +5 -2
- package/esm/plugins/tooltip.js.map +1 -1
- package/esm/registry/build-in.js +4 -2
- package/esm/registry/build-in.js.map +1 -1
- package/esm/runtime/animation.js +12 -10
- package/esm/runtime/animation.js.map +1 -1
- package/esm/runtime/data.d.ts +1 -0
- package/esm/runtime/data.js +21 -13
- package/esm/runtime/data.js.map +1 -1
- package/esm/runtime/element.d.ts +1 -0
- package/esm/runtime/element.js +21 -11
- package/esm/runtime/element.js.map +1 -1
- package/esm/runtime/graph.d.ts +2 -0
- package/esm/runtime/graph.js +42 -22
- package/esm/runtime/graph.js.map +1 -1
- package/esm/runtime/layout.d.ts +1 -0
- package/esm/runtime/layout.js +5 -0
- package/esm/runtime/layout.js.map +1 -1
- package/esm/transforms/base-transform.d.ts +1 -0
- package/esm/transforms/base-transform.js +1 -0
- package/esm/transforms/base-transform.js.map +1 -1
- package/esm/transforms/collapse-expand-combo.js +3 -0
- package/esm/transforms/collapse-expand-combo.js.map +1 -1
- package/esm/transforms/collapse-expand-node.js +2 -0
- package/esm/transforms/collapse-expand-node.js.map +1 -1
- package/esm/transforms/index.d.ts +3 -0
- package/esm/transforms/index.js +1 -0
- package/esm/transforms/index.js.map +1 -1
- package/esm/transforms/position-radial-labels.d.ts +27 -0
- package/esm/transforms/position-radial-labels.js +50 -0
- package/esm/transforms/position-radial-labels.js.map +1 -0
- package/esm/types/element.d.ts +2 -1
- package/esm/utils/data.d.ts +14 -0
- package/esm/utils/data.js +39 -0
- package/esm/utils/data.js.map +1 -1
- package/esm/utils/diff.d.ts +2 -1
- package/esm/utils/diff.js +3 -2
- package/esm/utils/diff.js.map +1 -1
- package/esm/utils/point.d.ts +17 -5
- package/esm/utils/point.js +24 -8
- package/esm/utils/point.js.map +1 -1
- package/esm/utils/position.d.ts +8 -0
- package/esm/utils/position.js +11 -0
- package/esm/utils/position.js.map +1 -1
- package/esm/utils/relation.d.ts +6 -4
- package/esm/utils/relation.js +10 -8
- package/esm/utils/relation.js.map +1 -1
- package/esm/utils/vector.d.ts +8 -0
- package/esm/utils/vector.js +13 -0
- package/esm/utils/vector.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/behaviors/drag-canvas.d.ts +9 -0
- package/lib/behaviors/drag-canvas.js +27 -2
- package/lib/behaviors/drag-canvas.js.map +1 -1
- package/lib/behaviors/hover-activate.d.ts +14 -1
- package/lib/behaviors/hover-activate.js +3 -2
- package/lib/behaviors/hover-activate.js.map +1 -1
- package/lib/behaviors/scroll-canvas.d.ts +9 -0
- package/lib/behaviors/scroll-canvas.js +31 -4
- package/lib/behaviors/scroll-canvas.js.map +1 -1
- package/lib/elements/combos/base-combo.js +1 -1
- package/lib/elements/combos/base-combo.js.map +1 -1
- package/lib/elements/combos/circle.d.ts +1 -1
- package/lib/elements/combos/circle.js +2 -2
- package/lib/elements/combos/circle.js.map +1 -1
- package/lib/elements/edges/cubic-radial.d.ts +24 -0
- package/lib/elements/edges/cubic-radial.js +56 -0
- package/lib/elements/edges/cubic-radial.js.map +1 -0
- package/lib/elements/edges/index.d.ts +2 -0
- package/lib/elements/edges/index.js +3 -1
- package/lib/elements/edges/index.js.map +1 -1
- package/lib/elements/nodes/base-node.d.ts +2 -1
- package/lib/elements/nodes/base-node.js +3 -2
- package/lib/elements/nodes/base-node.js.map +1 -1
- package/lib/elements/nodes/circle.d.ts +1 -1
- package/lib/elements/nodes/circle.js +2 -2
- package/lib/elements/nodes/circle.js.map +1 -1
- package/lib/elements/nodes/ellipse.d.ts +1 -1
- package/lib/elements/nodes/ellipse.js +2 -2
- package/lib/elements/nodes/ellipse.js.map +1 -1
- package/lib/elements/shapes/polygon.d.ts +1 -1
- package/lib/elements/shapes/polygon.js +2 -2
- package/lib/elements/shapes/polygon.js.map +1 -1
- package/lib/exports.d.ts +7 -5
- package/lib/exports.js +14 -6
- package/lib/exports.js.map +1 -1
- package/lib/plugins/tooltip.js +5 -2
- package/lib/plugins/tooltip.js.map +1 -1
- package/lib/registry/build-in.js +2 -0
- package/lib/registry/build-in.js.map +1 -1
- package/lib/runtime/animation.js +12 -10
- package/lib/runtime/animation.js.map +1 -1
- package/lib/runtime/data.d.ts +1 -0
- package/lib/runtime/data.js +19 -11
- package/lib/runtime/data.js.map +1 -1
- package/lib/runtime/element.d.ts +1 -0
- package/lib/runtime/element.js +21 -11
- package/lib/runtime/element.js.map +1 -1
- package/lib/runtime/graph.d.ts +2 -0
- package/lib/runtime/graph.js +42 -22
- package/lib/runtime/graph.js.map +1 -1
- package/lib/runtime/layout.d.ts +1 -0
- package/lib/runtime/layout.js +5 -0
- package/lib/runtime/layout.js.map +1 -1
- package/lib/transforms/base-transform.d.ts +1 -0
- package/lib/transforms/base-transform.js +1 -0
- package/lib/transforms/base-transform.js.map +1 -1
- package/lib/transforms/collapse-expand-combo.js +3 -0
- package/lib/transforms/collapse-expand-combo.js.map +1 -1
- package/lib/transforms/collapse-expand-node.js +2 -0
- package/lib/transforms/collapse-expand-node.js.map +1 -1
- package/lib/transforms/index.d.ts +3 -0
- package/lib/transforms/index.js +3 -1
- package/lib/transforms/index.js.map +1 -1
- package/lib/transforms/position-radial-labels.d.ts +27 -0
- package/lib/transforms/position-radial-labels.js +54 -0
- package/lib/transforms/position-radial-labels.js.map +1 -0
- package/lib/types/element.d.ts +2 -1
- package/lib/utils/data.d.ts +14 -0
- package/lib/utils/data.js +40 -0
- package/lib/utils/data.js.map +1 -1
- package/lib/utils/diff.d.ts +2 -1
- package/lib/utils/diff.js +3 -2
- package/lib/utils/diff.js.map +1 -1
- package/lib/utils/point.d.ts +17 -5
- package/lib/utils/point.js +25 -8
- package/lib/utils/point.js.map +1 -1
- package/lib/utils/position.d.ts +8 -0
- package/lib/utils/position.js +12 -0
- package/lib/utils/position.js.map +1 -1
- package/lib/utils/relation.d.ts +6 -4
- package/lib/utils/relation.js +10 -8
- package/lib/utils/relation.js.map +1 -1
- package/lib/utils/vector.d.ts +8 -0
- package/lib/utils/vector.js +14 -0
- package/lib/utils/vector.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +2 -2
- package/src/behaviors/drag-canvas.ts +42 -3
- package/src/behaviors/hover-activate.ts +17 -3
- package/src/behaviors/scroll-canvas.ts +45 -4
- package/src/elements/combos/base-combo.ts +2 -2
- package/src/elements/combos/circle.ts +2 -2
- package/src/elements/edges/cubic-radial.ts +77 -0
- package/src/elements/edges/index.ts +2 -0
- package/src/elements/nodes/base-node.ts +3 -2
- package/src/elements/nodes/circle.ts +2 -2
- package/src/elements/nodes/ellipse.ts +2 -2
- package/src/elements/shapes/polygon.ts +2 -2
- package/src/exports.ts +19 -7
- package/src/plugins/tooltip.ts +4 -2
- package/src/registry/build-in.ts +4 -0
- package/src/runtime/animation.ts +16 -11
- package/src/runtime/data.ts +20 -13
- package/src/runtime/element.ts +23 -11
- package/src/runtime/graph.ts +51 -22
- package/src/runtime/layout.ts +7 -0
- package/src/transforms/base-transform.ts +2 -0
- package/src/transforms/collapse-expand-combo.ts +2 -0
- package/src/transforms/collapse-expand-node.ts +3 -0
- package/src/transforms/index.ts +3 -0
- package/src/transforms/position-radial-labels.ts +76 -0
- package/src/types/element.ts +2 -1
- package/src/utils/data.ts +49 -0
- package/src/utils/diff.ts +8 -2
- package/src/utils/point.ts +25 -7
- package/src/utils/position.ts +12 -0
- package/src/utils/relation.ts +22 -9
- package/src/utils/vector.ts +13 -0
- package/src/version.ts +1 -1
package/lib/utils/relation.js
CHANGED
|
@@ -18,17 +18,18 @@ const traverse_1 = require("./traverse");
|
|
|
18
18
|
* @param elementType - <zh/> 元素类型 | <en/> element type
|
|
19
19
|
* @param elementId - <zh/> 起始元素的 ID | <en/> start element ID
|
|
20
20
|
* @param degree - <zh/> 指定的度数 | <en/> the specified degree
|
|
21
|
+
* @param direction - <zh/> 边的方向 | <en/> edge direction
|
|
21
22
|
* @returns - <zh/> 返回节点和边的 ID 数组 | <en/> Returns an array of node and edge IDs
|
|
22
23
|
*/
|
|
23
|
-
function getElementNthDegreeIds(graph, elementType, elementId, degree) {
|
|
24
|
+
function getElementNthDegreeIds(graph, elementType, elementId, degree, direction = 'both') {
|
|
24
25
|
if (elementType === 'combo' || elementType === 'node') {
|
|
25
|
-
return getNodeNthDegreeIds(graph, elementId, degree);
|
|
26
|
+
return getNodeNthDegreeIds(graph, elementId, degree, direction);
|
|
26
27
|
}
|
|
27
28
|
const edgeData = graph.getEdgeData(elementId);
|
|
28
29
|
if (!edgeData)
|
|
29
30
|
return [];
|
|
30
|
-
const sourceRelations = getNodeNthDegreeIds(graph, edgeData.source, degree - 1);
|
|
31
|
-
const targetRelations = getNodeNthDegreeIds(graph, edgeData.target, degree - 1);
|
|
31
|
+
const sourceRelations = getNodeNthDegreeIds(graph, edgeData.source, degree - 1, direction);
|
|
32
|
+
const targetRelations = getNodeNthDegreeIds(graph, edgeData.target, degree - 1, direction);
|
|
32
33
|
return Array.from(new Set([...sourceRelations, ...targetRelations, elementId]));
|
|
33
34
|
}
|
|
34
35
|
/**
|
|
@@ -37,14 +38,15 @@ function getElementNthDegreeIds(graph, elementType, elementId, degree) {
|
|
|
37
38
|
* <en/> Get all elements IDs within n-degree relationship of the specified node
|
|
38
39
|
* @remarks
|
|
39
40
|
* <zh/> 节点的 0 度关系是节点本身,1 度关系是节点的直接相邻节点和边,以此类推
|
|
40
|
-
*
|
|
41
|
+
* @param direction
|
|
41
42
|
* <en/> 0-degree relationship of a node is the node itself; 1-degree relationship is the node's neighboring nodes and related edges, etc
|
|
42
43
|
* @param graph - <zh/> 图实例 | <en/> graph instance
|
|
43
44
|
* @param startNodeId - <zh/> 起始节点的 ID | <en/> The ID of the starting node
|
|
44
45
|
* @param degree - <zh/> 指定的度数 | <en/> The specified degree
|
|
46
|
+
* @param direction - <zh/> 边的方向 | <en/> The direction of the edge
|
|
45
47
|
* @returns - <zh/> 返回节点和边的 ID 数组 | <en/> Returns an array of node and edge IDs
|
|
46
48
|
*/
|
|
47
|
-
function getNodeNthDegreeIds(graph, startNodeId, degree) {
|
|
49
|
+
function getNodeNthDegreeIds(graph, startNodeId, degree, direction = 'both') {
|
|
48
50
|
const visitedNodes = new Set();
|
|
49
51
|
const visitedEdges = new Set();
|
|
50
52
|
const relations = new Set();
|
|
@@ -52,7 +54,7 @@ function getNodeNthDegreeIds(graph, startNodeId, degree) {
|
|
|
52
54
|
if (depth > degree)
|
|
53
55
|
return;
|
|
54
56
|
relations.add(nodeId);
|
|
55
|
-
graph.getRelatedEdgesData(nodeId).forEach((edge) => {
|
|
57
|
+
graph.getRelatedEdgesData(nodeId, direction).forEach((edge) => {
|
|
56
58
|
const edgeId = (0, id_1.idOf)(edge);
|
|
57
59
|
if (!visitedEdges.has(edgeId) && depth < degree) {
|
|
58
60
|
relations.add(edgeId);
|
|
@@ -61,7 +63,7 @@ function getNodeNthDegreeIds(graph, startNodeId, degree) {
|
|
|
61
63
|
});
|
|
62
64
|
}, (nodeId) => {
|
|
63
65
|
return graph
|
|
64
|
-
.getRelatedEdgesData(nodeId)
|
|
66
|
+
.getRelatedEdgesData(nodeId, direction)
|
|
65
67
|
.map((edge) => (edge.source === nodeId ? edge.target : edge.source))
|
|
66
68
|
.filter((neighborNodeId) => {
|
|
67
69
|
if (!visitedNodes.has(neighborNodeId)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relation.js","sourceRoot":"src/","sources":["utils/relation.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"relation.js","sourceRoot":"src/","sources":["utils/relation.ts"],"names":[],"mappings":";;AAsBA,wDAkBC;AAgBD,kDAuCC;AA7FD,6BAA4B;AAC5B,yCAAiC;AAEjC;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,sBAAsB,CACpC,KAAY,EACZ,WAAwB,EACxB,SAAa,EACb,MAAc,EACd,YAA2B,MAAM;IAEjC,IAAI,WAAW,KAAK,OAAO,IAAI,WAAW,KAAK,MAAM,EAAE,CAAC;QACtD,OAAO,mBAAmB,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAC9C,IAAI,CAAC,QAAQ;QAAE,OAAO,EAAE,CAAC;IAEzB,MAAM,eAAe,GAAG,mBAAmB,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE,SAAS,CAAC,CAAC;IAC3F,MAAM,eAAe,GAAG,mBAAmB,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE,SAAS,CAAC,CAAC;IAE3F,OAAO,KAAK,CAAC,I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AAC,YAAY,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC;gBACtC,YAAY,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;gBACjC,OAAO,IAAI,CAAC;YACd,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;IACP,CAAC,CACF,CAAC;IAEF,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AAC/B,CAAC"}
|
package/lib/utils/vector.d.ts
CHANGED
|
@@ -141,3 +141,11 @@ export declare function toVector2(a: Vector2 | Vector3): Vector2;
|
|
|
141
141
|
* @returns - <zh/> 三维向量 | <en/> Three-dimensional vector
|
|
142
142
|
*/
|
|
143
143
|
export declare function toVector3(a: Vector2 | Vector3): Vector3;
|
|
144
|
+
/**
|
|
145
|
+
* <zh/> 计算向量与 x 轴正方向的夹角(弧度制)
|
|
146
|
+
*
|
|
147
|
+
* <en/> The angle between the vector and the positive direction of the x-axis (radians)
|
|
148
|
+
* @param a - <zh/> 向量 | <en/> The vector
|
|
149
|
+
* @returns <zh/> 弧度值 | <en/> The angle in radians
|
|
150
|
+
*/
|
|
151
|
+
export declare function rad(a: Vector2 | Vector3): number;
|
package/lib/utils/vector.js
CHANGED
|
@@ -16,6 +16,7 @@ exports.perpendicular = perpendicular;
|
|
|
16
16
|
exports.mod = mod;
|
|
17
17
|
exports.toVector2 = toVector2;
|
|
18
18
|
exports.toVector3 = toVector3;
|
|
19
|
+
exports.rad = rad;
|
|
19
20
|
const is_1 = require("./is");
|
|
20
21
|
const VECTOR_ZERO = [0, 0, 0];
|
|
21
22
|
/**
|
|
@@ -206,4 +207,17 @@ function toVector2(a) {
|
|
|
206
207
|
function toVector3(a) {
|
|
207
208
|
return (0, is_1.isVector2)(a) ? [a[0], a[1], 0] : a;
|
|
208
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* <zh/> 计算向量与 x 轴正方向的夹角(弧度制)
|
|
212
|
+
*
|
|
213
|
+
* <en/> The angle between the vector and the positive direction of the x-axis (radians)
|
|
214
|
+
* @param a - <zh/> 向量 | <en/> The vector
|
|
215
|
+
* @returns <zh/> 弧度值 | <en/> The angle in radians
|
|
216
|
+
*/
|
|
217
|
+
function rad(a) {
|
|
218
|
+
const [x, y] = a;
|
|
219
|
+
if (!x && !y)
|
|
220
|
+
return 0;
|
|
221
|
+
return Math.atan2(y, x);
|
|
222
|
+
}
|
|
209
223
|
//# sourceMappingURL=vector.js.map
|
package/lib/utils/vector.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector.js","sourceRoot":"src/","sources":["utils/vector.ts"],"names":[],"mappings":";;AAaA,kBAEC;AAUD,4BAEC;AAUD,4BAGC;AAUD,wBAGC;AAUD,kBAEC;AAUD,sBAIC;AAUD,sBAEC;AAUD,4BAEC;AAUD,8CAEC;AASD,8BAGC;AAWD,sBAWC;AAUD,kCAEC;AAUD,sCAEC;AAUD,kBAEC;AASD,8BAEC;AASD,8BAEC;
|
|
1
|
+
{"version":3,"file":"vector.js","sourceRoot":"src/","sources":["utils/vector.ts"],"names":[],"mappings":";;AAaA,kBAEC;AAUD,4BAEC;AAUD,4BAGC;AAUD,wBAGC;AAUD,kBAEC;AAUD,sBAIC;AAUD,sBAEC;AAUD,4BAEC;AAUD,8CAEC;AASD,8BAGC;AAWD,sBAWC;AAUD,kCAEC;AAUD,sCAEC;AAUD,kBAEC;AASD,8BAEC;AASD,8BAEC;AASD,kBAIC;AA3ND,6BAAiC;AAEjC,MAAM,WAAW,GAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAEvC;;;;;;;GAOG;AACH,SAAgB,GAAG,CAAC,CAAoB,EAAE,CAAoB;IAC5D,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAsB,CAAC;AACxD,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB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AU,EAAE,SAAS,GAAG,IAAI;IACxD,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,GAAG,CAAC,CAAoB,EAAE,CAAS;IACjD,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAsB,CAAC;AAClD,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,SAAS,CAAC,CAAoB;IAC5C,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtB,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,SAAS,CAAC,CAAoB;IAC5C,OAAO,IAAA,cAAS,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,GAAG,CAAC,CAAoB;IACtC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;IACjB,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC;IACvB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1B,CAAC"}
|
package/lib/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.0.
|
|
1
|
+
export declare const version = "5.0.20";
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/g6",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.20",
|
|
4
4
|
"description": "A Graph Visualization Framework in JavaScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antv",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@antv/g-canvas": "^2.0.10",
|
|
39
39
|
"@antv/g-plugin-dragndrop": "^2.0.8",
|
|
40
40
|
"@antv/graphlib": "^2.0.3",
|
|
41
|
-
"@antv/hierarchy": "^0.6.
|
|
41
|
+
"@antv/hierarchy": "^0.6.13",
|
|
42
42
|
"@antv/layout": "^1.2.14-beta.6",
|
|
43
43
|
"@antv/util": "^3.3.7",
|
|
44
44
|
"bubblesets-js": "^2.3.3",
|
|
@@ -3,9 +3,11 @@ import { debounce, isObject } from '@antv/util';
|
|
|
3
3
|
import { CommonEvent } from '../constants';
|
|
4
4
|
import type { RuntimeContext } from '../runtime/types';
|
|
5
5
|
import type { IKeyboardEvent, IPointerEvent, Vector2, ViewportAnimationEffectTiming } from '../types';
|
|
6
|
+
import { getExpandedBBox, getPointBBox, isPointInBBox } from '../utils/bbox';
|
|
7
|
+
import { parsePadding } from '../utils/padding';
|
|
6
8
|
import type { ShortcutKey } from '../utils/shortcut';
|
|
7
9
|
import { Shortcut } from '../utils/shortcut';
|
|
8
|
-
import { multiply } from '../utils/vector';
|
|
10
|
+
import { multiply, subtract } from '../utils/vector';
|
|
9
11
|
import type { BaseBehaviorOptions } from './base-behavior';
|
|
10
12
|
import { BaseBehavior } from './base-behavior';
|
|
11
13
|
|
|
@@ -41,6 +43,13 @@ export interface DragCanvasOptions extends BaseBehaviorOptions {
|
|
|
41
43
|
* @defaultValue `'both'`
|
|
42
44
|
*/
|
|
43
45
|
direction?: 'x' | 'y' | 'both';
|
|
46
|
+
/**
|
|
47
|
+
* <zh/> 可拖拽的视口范围,默认最多可拖拽一屏。可以分别设置上、右、下、左四个方向的范围,每个方向的范围在 [0, Infinity] 之间
|
|
48
|
+
*
|
|
49
|
+
* <en/> The draggable viewport range allows you to drag up to one screen by default. You can set the range for each direction (top, right, bottom, left) individually, with each direction's range between [0, Infinity]
|
|
50
|
+
* @defaultValue 1
|
|
51
|
+
*/
|
|
52
|
+
range?: number | number[];
|
|
44
53
|
/**
|
|
45
54
|
* <zh/> 触发拖拽的方式,默认使用指针按下拖拽
|
|
46
55
|
*
|
|
@@ -80,6 +89,7 @@ export class DragCanvas extends BaseBehavior<DragCanvasOptions> {
|
|
|
80
89
|
},
|
|
81
90
|
sensitivity: 10,
|
|
82
91
|
direction: 'both',
|
|
92
|
+
range: 1,
|
|
83
93
|
};
|
|
84
94
|
|
|
85
95
|
private shortcut: Shortcut;
|
|
@@ -169,16 +179,45 @@ export class DragCanvas extends BaseBehavior<DragCanvasOptions> {
|
|
|
169
179
|
* @internal
|
|
170
180
|
*/
|
|
171
181
|
protected async translate(offset: Vector2, animation?: ViewportAnimationEffectTiming) {
|
|
172
|
-
|
|
182
|
+
offset = this.clampByDirection(offset);
|
|
183
|
+
offset = this.clampByRange(offset);
|
|
173
184
|
|
|
185
|
+
await this.context.graph.translateBy(offset, animation);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
private clampByDirection([dx, dy]: Vector2): Vector2 {
|
|
174
189
|
const { direction } = this.options;
|
|
175
190
|
if (direction === 'x') {
|
|
176
191
|
dy = 0;
|
|
177
192
|
} else if (direction === 'y') {
|
|
178
193
|
dx = 0;
|
|
179
194
|
}
|
|
195
|
+
return [dx, dy];
|
|
196
|
+
}
|
|
180
197
|
|
|
181
|
-
|
|
198
|
+
private clampByRange([dx, dy]: Vector2): Vector2 {
|
|
199
|
+
const { viewport, canvas } = this.context;
|
|
200
|
+
|
|
201
|
+
const [canvasWidth, canvasHeight] = canvas.getSize();
|
|
202
|
+
const [top, right, bottom, left] = parsePadding(this.options.range);
|
|
203
|
+
const range = [canvasHeight * top, canvasWidth * right, canvasHeight * bottom, canvasWidth * left];
|
|
204
|
+
const draggableArea = getExpandedBBox(getPointBBox(viewport!.getCanvasCenter()), range);
|
|
205
|
+
|
|
206
|
+
const nextViewportCenter = subtract(viewport!.getViewportCenter(), [dx, dy, 0]);
|
|
207
|
+
if (!isPointInBBox(nextViewportCenter, draggableArea)) {
|
|
208
|
+
const {
|
|
209
|
+
min: [minX, minY],
|
|
210
|
+
max: [maxX, maxY],
|
|
211
|
+
} = draggableArea;
|
|
212
|
+
|
|
213
|
+
if ((nextViewportCenter[0] < minX && dx > 0) || (nextViewportCenter[0] > maxX && dx < 0)) {
|
|
214
|
+
dx = 0;
|
|
215
|
+
}
|
|
216
|
+
if ((nextViewportCenter[1] < minY && dy > 0) || (nextViewportCenter[1] > maxY && dy < 0)) {
|
|
217
|
+
dy = 0;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return [dx, dy];
|
|
182
221
|
}
|
|
183
222
|
|
|
184
223
|
private validate(event: IPointerEvent | IKeyboardEvent) {
|
|
@@ -2,7 +2,7 @@ import { isFunction } from '@antv/util';
|
|
|
2
2
|
import { CommonEvent } from '../constants';
|
|
3
3
|
import { ELEMENT_TYPES } from '../constants/element';
|
|
4
4
|
import type { RuntimeContext } from '../runtime/types';
|
|
5
|
-
import type { Element, ElementType, ID, IDragEvent, IPointerEvent, State } from '../types';
|
|
5
|
+
import type { EdgeDirection, Element, ElementType, ID, IDragEvent, IPointerEvent, State } from '../types';
|
|
6
6
|
import { idsOf } from '../utils/id';
|
|
7
7
|
import { getElementNthDegreeIds } from '../utils/relation';
|
|
8
8
|
import type { BaseBehaviorOptions } from './base-behavior';
|
|
@@ -39,6 +39,19 @@ export interface HoverActivateOptions extends BaseBehaviorOptions {
|
|
|
39
39
|
* @defaultValue 0
|
|
40
40
|
*/
|
|
41
41
|
degree?: number;
|
|
42
|
+
/**
|
|
43
|
+
* <zh/> 指定边的方向
|
|
44
|
+
* - `'both'`: 表示激活当前节点的所有关系
|
|
45
|
+
* - `'in'`: 表示激活当前节点的入边和入节点
|
|
46
|
+
* - `'out'`: 表示激活当前节点的出边和出节点
|
|
47
|
+
*
|
|
48
|
+
* <en/> Specify the direction of the edge
|
|
49
|
+
* - `'both'`: Activate all relationships of the current node
|
|
50
|
+
* - `'in'`: Activate the incoming edges and nodes of the current node
|
|
51
|
+
* - `'out'`: Activate the outgoing edges and nodes of the current node
|
|
52
|
+
* @defaultValue 'both'
|
|
53
|
+
*/
|
|
54
|
+
direction?: EdgeDirection;
|
|
42
55
|
/**
|
|
43
56
|
* <zh/> 激活元素的状态,默认为 `active`
|
|
44
57
|
*
|
|
@@ -80,6 +93,7 @@ export class HoverActivate extends BaseBehavior<HoverActivateOptions> {
|
|
|
80
93
|
animation: false,
|
|
81
94
|
enable: true,
|
|
82
95
|
degree: 0,
|
|
96
|
+
direction: 'both',
|
|
83
97
|
state: 'active',
|
|
84
98
|
inactiveState: undefined,
|
|
85
99
|
};
|
|
@@ -123,11 +137,11 @@ export class HoverActivate extends BaseBehavior<HoverActivateOptions> {
|
|
|
123
137
|
if (!this.options.state && !this.options.inactiveState) return;
|
|
124
138
|
|
|
125
139
|
const { graph } = this.context;
|
|
126
|
-
const { state, degree, animation, inactiveState } = this.options;
|
|
140
|
+
const { state, degree, direction, animation, inactiveState } = this.options;
|
|
127
141
|
const { targetType, target } = event;
|
|
128
142
|
|
|
129
143
|
const activeIds = degree
|
|
130
|
-
? getElementNthDegreeIds(graph, targetType as ElementType, target.id, degree)
|
|
144
|
+
? getElementNthDegreeIds(graph, targetType as ElementType, target.id, degree, direction)
|
|
131
145
|
: [target.id];
|
|
132
146
|
|
|
133
147
|
const states: Record<ID, State[]> = {};
|
|
@@ -2,7 +2,10 @@ import { isFunction, isObject } from '@antv/util';
|
|
|
2
2
|
import { CommonEvent } from '../constants';
|
|
3
3
|
import type { RuntimeContext } from '../runtime/types';
|
|
4
4
|
import type { IKeyboardEvent, Point } from '../types';
|
|
5
|
+
import { getExpandedBBox, getPointBBox, isPointInBBox } from '../utils/bbox';
|
|
6
|
+
import { parsePadding } from '../utils/padding';
|
|
5
7
|
import { Shortcut, ShortcutKey } from '../utils/shortcut';
|
|
8
|
+
import { multiply, subtract } from '../utils/vector';
|
|
6
9
|
import type { BaseBehaviorOptions } from './base-behavior';
|
|
7
10
|
import { BaseBehavior } from './base-behavior';
|
|
8
11
|
|
|
@@ -42,6 +45,13 @@ export interface ScrollCanvasOptions extends BaseBehaviorOptions {
|
|
|
42
45
|
* - `'y'`: only allow vertical scrolling
|
|
43
46
|
*/
|
|
44
47
|
direction?: 'x' | 'y';
|
|
48
|
+
/**
|
|
49
|
+
* <zh/> 可滚动的视口范围,默认最多可滚动一屏。可以分别设置上、右、下、左四个方向的范围,每个方向的范围在 [0, Infinity] 之间
|
|
50
|
+
*
|
|
51
|
+
* <en/> The scrollable viewport range allows you to scroll up to one screen by default. You can set the range for each direction (top, right, bottom, left) individually, with each direction's range between [0, Infinity]
|
|
52
|
+
* @defaultValue 1
|
|
53
|
+
*/
|
|
54
|
+
range?: number | number[];
|
|
45
55
|
/**
|
|
46
56
|
* <zh/> 滚动灵敏度
|
|
47
57
|
*
|
|
@@ -74,6 +84,7 @@ export class ScrollCanvas extends BaseBehavior<ScrollCanvasOptions> {
|
|
|
74
84
|
enable: true,
|
|
75
85
|
sensitivity: 1,
|
|
76
86
|
preventDefault: true,
|
|
87
|
+
range: 0.5,
|
|
77
88
|
};
|
|
78
89
|
|
|
79
90
|
private shortcut: Shortcut;
|
|
@@ -130,18 +141,48 @@ export class ScrollCanvas extends BaseBehavior<ScrollCanvasOptions> {
|
|
|
130
141
|
await this.scroll([-diffX, -diffY], event);
|
|
131
142
|
};
|
|
132
143
|
|
|
133
|
-
private formatDisplacement(
|
|
134
|
-
const {
|
|
144
|
+
private formatDisplacement(d: Point) {
|
|
145
|
+
const { sensitivity } = this.options;
|
|
135
146
|
|
|
136
|
-
|
|
137
|
-
|
|
147
|
+
d = multiply(d, sensitivity);
|
|
148
|
+
d = this.clampByDirection(d);
|
|
149
|
+
d = this.clampByRange(d);
|
|
138
150
|
|
|
151
|
+
return d;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private clampByDirection([dx, dy]: Point) {
|
|
155
|
+
const { direction } = this.options;
|
|
139
156
|
if (direction === 'x') {
|
|
140
157
|
dy = 0;
|
|
141
158
|
} else if (direction === 'y') {
|
|
142
159
|
dx = 0;
|
|
143
160
|
}
|
|
161
|
+
return [dx, dy] as Point;
|
|
162
|
+
}
|
|
144
163
|
|
|
164
|
+
private clampByRange([dx, dy]: Point) {
|
|
165
|
+
const { viewport, canvas } = this.context;
|
|
166
|
+
|
|
167
|
+
const [canvasWidth, canvasHeight] = canvas.getSize();
|
|
168
|
+
const [top, right, bottom, left] = parsePadding(this.options.range);
|
|
169
|
+
const range = [canvasHeight * top, canvasWidth * right, canvasHeight * bottom, canvasWidth * left];
|
|
170
|
+
const scrollableArea = getExpandedBBox(getPointBBox(viewport!.getCanvasCenter()), range);
|
|
171
|
+
|
|
172
|
+
const nextViewportCenter = subtract(viewport!.getViewportCenter(), [dx, dy, 0]);
|
|
173
|
+
if (!isPointInBBox(nextViewportCenter, scrollableArea)) {
|
|
174
|
+
const {
|
|
175
|
+
min: [minX, minY],
|
|
176
|
+
max: [maxX, maxY],
|
|
177
|
+
} = scrollableArea;
|
|
178
|
+
|
|
179
|
+
if ((nextViewportCenter[0] < minX && dx > 0) || (nextViewportCenter[0] > maxX && dx < 0)) {
|
|
180
|
+
dx = 0;
|
|
181
|
+
}
|
|
182
|
+
if ((nextViewportCenter[1] < minY && dy > 0) || (nextViewportCenter[1] > maxY && dy < 0)) {
|
|
183
|
+
dy = 0;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
145
186
|
return [dx, dy] as Point;
|
|
146
187
|
}
|
|
147
188
|
|
|
@@ -15,7 +15,7 @@ import type {
|
|
|
15
15
|
import { getBBoxHeight, getBBoxWidth, getCombinedBBox, getExpandedBBox } from '../../utils/bbox';
|
|
16
16
|
import { idOf } from '../../utils/id';
|
|
17
17
|
import { parsePadding } from '../../utils/padding';
|
|
18
|
-
import { getXYByPlacement, positionOf } from '../../utils/position';
|
|
18
|
+
import { getXYByPlacement, hasPosition, positionOf } from '../../utils/position';
|
|
19
19
|
import { subStyleProps } from '../../utils/prefix';
|
|
20
20
|
import { parseSize } from '../../utils/size';
|
|
21
21
|
import { mergeOptions } from '../../utils/style';
|
|
@@ -210,7 +210,7 @@ export abstract class BaseCombo<S extends BaseComboStyleProps = BaseComboStylePr
|
|
|
210
210
|
const { model } = context!;
|
|
211
211
|
const descendants = model.getDescendantsData(this.id).filter((datum) => !model.isCombo(idOf(datum)));
|
|
212
212
|
|
|
213
|
-
if (descendants.length > 0) {
|
|
213
|
+
if (descendants.length > 0 && descendants.some(hasPosition)) {
|
|
214
214
|
// combo 被收起,返回平均中心位置 / combo is collapsed, return the average center position
|
|
215
215
|
const totalPosition = descendants.reduce((acc, datum) => add(acc, positionOf(datum)), [0, 0, 0] as Point);
|
|
216
216
|
return divide(totalPosition, descendants.length);
|
|
@@ -54,8 +54,8 @@ export class CircleCombo extends BaseCombo<CircleComboStyleProps> {
|
|
|
54
54
|
return [expandedR * 2, expandedR * 2, 0];
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
public getIntersectPoint(point: Point): Point {
|
|
57
|
+
public getIntersectPoint(point: Point, useExtendedLine = false): Point {
|
|
58
58
|
const keyShapeBounds = this.getShape('key').getBounds();
|
|
59
|
-
return getEllipseIntersectPoint(point, keyShapeBounds);
|
|
59
|
+
return getEllipseIntersectPoint(point, keyShapeBounds, useExtendedLine);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { DisplayObjectConfig } from '@antv/g';
|
|
2
|
+
import type { NodeData } from '../../spec';
|
|
3
|
+
import type { Point } from '../../types';
|
|
4
|
+
import { positionOf } from '../../utils/position';
|
|
5
|
+
import { mergeOptions } from '../../utils/style';
|
|
6
|
+
import { distance, rad, subtract } from '../../utils/vector';
|
|
7
|
+
import type { CubicStyleProps } from './cubic';
|
|
8
|
+
import { Cubic } from './cubic';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* <zh/> 径向贝塞尔曲线样式配置项
|
|
12
|
+
*
|
|
13
|
+
* <en/> Radial cubic style props
|
|
14
|
+
*/
|
|
15
|
+
export interface CubicRadialStyleProps extends CubicStyleProps {}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* <zh/> 径向贝塞尔曲线
|
|
19
|
+
*
|
|
20
|
+
* <en/> Radial cubic edge
|
|
21
|
+
*/
|
|
22
|
+
export class CubicRadial extends Cubic {
|
|
23
|
+
static defaultStyleProps: Partial<CubicStyleProps> = {
|
|
24
|
+
curvePosition: 0.5,
|
|
25
|
+
curveOffset: 20,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
constructor(options: DisplayObjectConfig<CubicStyleProps>) {
|
|
29
|
+
super(mergeOptions({ style: CubicRadial.defaultStyleProps }, options));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private get ref(): NodeData {
|
|
33
|
+
return this.context.model.getRootsData()[0];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
protected getEndpoints(attributes: Required<CubicStyleProps>): [Point, Point] {
|
|
37
|
+
if (this.sourceNode.id === this.ref.id) {
|
|
38
|
+
return super.getEndpoints(attributes);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const refPoint = positionOf(this.ref);
|
|
42
|
+
const sourcePoint = this.sourceNode.getIntersectPoint(refPoint, true);
|
|
43
|
+
const targetPoint = this.targetNode.getIntersectPoint(refPoint);
|
|
44
|
+
|
|
45
|
+
return [sourcePoint, targetPoint];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private toRadialCoordinate(p: Point) {
|
|
49
|
+
const refPoint = positionOf(this.ref);
|
|
50
|
+
const r = distance(p, refPoint);
|
|
51
|
+
const radian = rad(subtract(p, refPoint));
|
|
52
|
+
return [r, radian];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
protected getControlPoints(
|
|
56
|
+
sourcePoint: Point,
|
|
57
|
+
targetPoint: Point,
|
|
58
|
+
curvePosition: [number, number],
|
|
59
|
+
curveOffset: [number, number],
|
|
60
|
+
): [Point, Point] {
|
|
61
|
+
const [r1, rad1] = this.toRadialCoordinate(sourcePoint);
|
|
62
|
+
const [r2] = this.toRadialCoordinate(targetPoint);
|
|
63
|
+
|
|
64
|
+
const rDist = r2 - r1;
|
|
65
|
+
|
|
66
|
+
return [
|
|
67
|
+
[
|
|
68
|
+
sourcePoint[0] + (rDist * curvePosition[0] + curveOffset[0]) * Math.cos(rad1),
|
|
69
|
+
sourcePoint[1] + (rDist * curvePosition[0] + curveOffset[0]) * Math.sin(rad1),
|
|
70
|
+
],
|
|
71
|
+
[
|
|
72
|
+
targetPoint[0] - (rDist * curvePosition[1] - curveOffset[0]) * Math.cos(rad1),
|
|
73
|
+
targetPoint[1] - (rDist * curvePosition[1] - curveOffset[0]) * Math.sin(rad1),
|
|
74
|
+
],
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { BaseEdge } from './base-edge';
|
|
2
2
|
export { Cubic } from './cubic';
|
|
3
3
|
export { CubicHorizontal } from './cubic-horizontal';
|
|
4
|
+
export { CubicRadial } from './cubic-radial';
|
|
4
5
|
export { CubicVertical } from './cubic-vertical';
|
|
5
6
|
export { Line } from './line';
|
|
6
7
|
export { Polyline } from './polyline';
|
|
@@ -9,6 +10,7 @@ export { Quadratic } from './quadratic';
|
|
|
9
10
|
export type { BaseEdgeStyleProps } from './base-edge';
|
|
10
11
|
export type { CubicStyleProps } from './cubic';
|
|
11
12
|
export type { CubicHorizontalStyleProps } from './cubic-horizontal';
|
|
13
|
+
export type { CubicRadialStyleProps } from './cubic-radial';
|
|
12
14
|
export type { CubicVerticalStyleProps } from './cubic-vertical';
|
|
13
15
|
export type { LineStyleProps } from './line';
|
|
14
16
|
export type { PolylineStyleProps } from './polyline';
|
|
@@ -354,11 +354,12 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
|
|
|
354
354
|
/**
|
|
355
355
|
* Get the point on the outer contour of the node that is the intersection with a line starting in the center the ending in the point `p`.
|
|
356
356
|
* @param point - The point to intersect with the node.
|
|
357
|
+
* @param useExtendedLine - Whether to use the extended line.
|
|
357
358
|
* @returns The intersection point.
|
|
358
359
|
*/
|
|
359
|
-
public getIntersectPoint(point: Point): Point {
|
|
360
|
+
public getIntersectPoint(point: Point, useExtendedLine = false): Point {
|
|
360
361
|
const keyShapeBounds = this.getShape('key').getBounds();
|
|
361
|
-
return getRectIntersectPoint(point, keyShapeBounds);
|
|
362
|
+
return getRectIntersectPoint(point, keyShapeBounds, useExtendedLine);
|
|
362
363
|
}
|
|
363
364
|
|
|
364
365
|
protected drawHaloShape(attributes: Required<S>, container: Group): void {
|
|
@@ -45,8 +45,8 @@ export class Circle extends BaseNode {
|
|
|
45
45
|
return style ? ({ width: size, height: size, ...style } as IconStyleProps) : false;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
public getIntersectPoint(point: Point): Point {
|
|
48
|
+
public getIntersectPoint(point: Point, useExtendedLine = false): Point {
|
|
49
49
|
const keyShapeBounds = this.getShape('key').getBounds();
|
|
50
|
-
return getEllipseIntersectPoint(point, keyShapeBounds);
|
|
50
|
+
return getEllipseIntersectPoint(point, keyShapeBounds, useExtendedLine);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -51,8 +51,8 @@ export class Ellipse extends BaseNode {
|
|
|
51
51
|
return style ? ({ width: size, height: size, ...style } as IconStyleProps) : false;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
public getIntersectPoint(point: Point): Point {
|
|
54
|
+
public getIntersectPoint(point: Point, useExtendedLine = false): Point {
|
|
55
55
|
const keyShapeBounds = this.getShape('key').getBounds();
|
|
56
|
-
return getEllipseIntersectPoint(point, keyShapeBounds);
|
|
56
|
+
return getEllipseIntersectPoint(point, keyShapeBounds, useExtendedLine);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -43,9 +43,9 @@ export abstract class Polygon<T extends PolygonStyleProps = PolygonStyleProps> e
|
|
|
43
43
|
|
|
44
44
|
protected abstract getPoints(attributes: Required<T>): Point[];
|
|
45
45
|
|
|
46
|
-
public getIntersectPoint(point: Point): Point {
|
|
46
|
+
public getIntersectPoint(point: Point, useExtendedLine = false): Point {
|
|
47
47
|
const { points } = this.getShape<GPolygon>('key').attributes;
|
|
48
48
|
const center: Point = [+(this.attributes?.x || 0), +(this.attributes?.y || 0)];
|
|
49
|
-
return getPolygonIntersectPoint(point, center, points
|
|
49
|
+
return getPolygonIntersectPoint(point, center, points!, true, useExtendedLine).point;
|
|
50
50
|
}
|
|
51
51
|
}
|
package/src/exports.ts
CHANGED
|
@@ -27,7 +27,17 @@ export {
|
|
|
27
27
|
NodeEvent,
|
|
28
28
|
} from './constants';
|
|
29
29
|
export { BaseCombo, CircleCombo, RectCombo } from './elements/combos';
|
|
30
|
-
export {
|
|
30
|
+
export {
|
|
31
|
+
BaseEdge,
|
|
32
|
+
Cubic,
|
|
33
|
+
CubicHorizontal,
|
|
34
|
+
CubicRadial,
|
|
35
|
+
CubicVertical,
|
|
36
|
+
Line,
|
|
37
|
+
Polyline,
|
|
38
|
+
Quadratic,
|
|
39
|
+
} from './elements/edges';
|
|
40
|
+
export { effect } from './elements/effect';
|
|
31
41
|
export {
|
|
32
42
|
BaseNode,
|
|
33
43
|
Circle,
|
|
@@ -47,20 +57,20 @@ export {
|
|
|
47
57
|
BaseLayout,
|
|
48
58
|
CircularLayout,
|
|
49
59
|
ComboCombinedLayout,
|
|
60
|
+
compactBox as CompactBoxLayout,
|
|
50
61
|
ConcentricLayout,
|
|
51
62
|
D3ForceLayout,
|
|
52
63
|
DagreLayout,
|
|
64
|
+
dendrogram as DendrogramLayout,
|
|
53
65
|
ForceAtlas2Layout,
|
|
54
66
|
ForceLayout,
|
|
55
67
|
FruchtermanLayout,
|
|
56
68
|
GridLayout,
|
|
69
|
+
indented as IndentedLayout,
|
|
57
70
|
MDSLayout,
|
|
71
|
+
mindmap as MindmapLayout,
|
|
58
72
|
RadialLayout,
|
|
59
73
|
RandomLayout,
|
|
60
|
-
compactBox,
|
|
61
|
-
dendrogram,
|
|
62
|
-
indented,
|
|
63
|
-
mindmap,
|
|
64
74
|
} from './layouts';
|
|
65
75
|
export {
|
|
66
76
|
BasePlugin,
|
|
@@ -84,10 +94,11 @@ export {
|
|
|
84
94
|
export { getExtension, getExtensions } from './registry/get';
|
|
85
95
|
export { register } from './registry/register';
|
|
86
96
|
export { Graph } from './runtime/graph';
|
|
87
|
-
export { BaseTransform } from './transforms';
|
|
97
|
+
export { BaseTransform, PositionRadialLabels, ProcessParallelEdges } from './transforms';
|
|
88
98
|
export { isCollapsed } from './utils/collapsibility';
|
|
89
99
|
export { idOf } from './utils/id';
|
|
90
100
|
export { invokeLayoutMethod } from './utils/layout';
|
|
101
|
+
export { positionOf } from './utils/position';
|
|
91
102
|
export { omitStyleProps, subStyleProps } from './utils/prefix';
|
|
92
103
|
export { Shortcut } from './utils/shortcut';
|
|
93
104
|
export { parseSize } from './utils/size';
|
|
@@ -135,6 +146,7 @@ export type { BaseComboStyleProps, CircleComboStyleProps, RectComboStyleProps }
|
|
|
135
146
|
export type {
|
|
136
147
|
BaseEdgeStyleProps,
|
|
137
148
|
CubicHorizontalStyleProps,
|
|
149
|
+
CubicRadialStyleProps,
|
|
138
150
|
CubicStyleProps,
|
|
139
151
|
CubicVerticalStyleProps,
|
|
140
152
|
LineStyleProps,
|
|
@@ -205,7 +217,7 @@ export type { CustomBehaviorOption } from './spec/behavior';
|
|
|
205
217
|
export type { AnimationStage } from './spec/element/animation';
|
|
206
218
|
export type { LayoutOptions, STDLayoutOptions, SingleLayoutOptions } from './spec/layout';
|
|
207
219
|
export type { CustomPluginOption } from './spec/plugin';
|
|
208
|
-
export type { BaseTransformOptions } from './transforms';
|
|
220
|
+
export type { BaseTransformOptions, PositionRadialLabelsOptions, ProcessParallelEdgesOptions } from './transforms';
|
|
209
221
|
export type { DrawData } from './transforms/types';
|
|
210
222
|
export type {
|
|
211
223
|
BaseElementStyleProps,
|
package/src/plugins/tooltip.ts
CHANGED
|
@@ -151,8 +151,8 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
|
|
|
151
151
|
} = event;
|
|
152
152
|
// click the same item twice, tooltip will be hidden
|
|
153
153
|
if (this.currentTarget === id) {
|
|
154
|
-
this.currentTarget = null;
|
|
155
154
|
this.hide(event);
|
|
155
|
+
this.currentTarget = null;
|
|
156
156
|
} else {
|
|
157
157
|
this.currentTarget = id;
|
|
158
158
|
this.show(event);
|
|
@@ -294,7 +294,9 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
|
|
|
294
294
|
this.tooltipElement?.hide();
|
|
295
295
|
return;
|
|
296
296
|
}
|
|
297
|
-
if (!this.tooltipElement
|
|
297
|
+
if (!this.tooltipElement) return;
|
|
298
|
+
// No target node: tooltip has been hidden. No need for duplicated call.
|
|
299
|
+
if (!this.currentTarget) return;
|
|
298
300
|
const {
|
|
299
301
|
client: { x, y },
|
|
300
302
|
} = event;
|