@antv/g6 5.0.12 → 5.0.14
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 +0 -1
- package/dist/lib/elements/shapes/badge.d.ts +1 -1
- package/dist/lib/elements/shapes/base-shape.d.ts +1 -1
- package/dist/lib/elements/shapes/icon.d.ts +1 -1
- package/dist/lib/exports.d.ts +2 -1
- package/dist/lib/runtime/layout.d.ts +1 -0
- package/dist/lib/spec/canvas.d.ts +7 -1
- package/dist/lib/utils/style.d.ts +1 -1
- package/dist/lib/utils/tree.d.ts +1 -1
- package/dist/lib/utils/visibility.d.ts +2 -2
- package/dist/lib/version.d.ts +1 -1
- package/esm/behaviors/click-select.js +2 -3
- package/esm/behaviors/click-select.js.map +1 -1
- package/esm/behaviors/drag-canvas.d.ts +0 -1
- package/esm/behaviors/drag-canvas.js +9 -11
- 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/elements/shapes/badge.d.ts +1 -1
- package/esm/elements/shapes/base-shape.d.ts +1 -1
- package/esm/elements/shapes/base-shape.js +2 -1
- package/esm/elements/shapes/base-shape.js.map +1 -1
- package/esm/elements/shapes/icon.d.ts +1 -1
- package/esm/elements/shapes/icon.js +5 -4
- package/esm/elements/shapes/icon.js.map +1 -1
- package/esm/exports.d.ts +2 -1
- package/esm/exports.js +1 -0
- package/esm/exports.js.map +1 -1
- package/esm/plugins/history/util.js +1 -1
- package/esm/plugins/history/util.js.map +1 -1
- package/esm/plugins/tooltip.js +4 -1
- package/esm/plugins/tooltip.js.map +1 -1
- package/esm/runtime/graph.js +8 -2
- package/esm/runtime/graph.js.map +1 -1
- package/esm/runtime/layout.d.ts +1 -0
- package/esm/runtime/layout.js +48 -0
- package/esm/runtime/layout.js.map +1 -1
- package/esm/spec/canvas.d.ts +7 -1
- package/esm/utils/style.d.ts +1 -1
- package/esm/utils/style.js +1 -1
- package/esm/utils/style.js.map +1 -1
- package/esm/utils/tree.d.ts +1 -1
- package/esm/utils/tree.js +2 -2
- package/esm/utils/tree.js.map +1 -1
- package/esm/utils/visibility.d.ts +2 -2
- package/esm/utils/visibility.js +35 -18
- package/esm/utils/visibility.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/behaviors/click-select.js +2 -3
- package/lib/behaviors/click-select.js.map +1 -1
- package/lib/behaviors/drag-canvas.d.ts +0 -1
- package/lib/behaviors/drag-canvas.js +8 -10
- 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/elements/shapes/badge.d.ts +1 -1
- package/lib/elements/shapes/base-shape.d.ts +1 -1
- package/lib/elements/shapes/base-shape.js +2 -1
- package/lib/elements/shapes/base-shape.js.map +1 -1
- package/lib/elements/shapes/icon.d.ts +1 -1
- package/lib/elements/shapes/icon.js +5 -4
- package/lib/elements/shapes/icon.js.map +1 -1
- package/lib/exports.d.ts +2 -1
- package/lib/exports.js +3 -1
- package/lib/exports.js.map +1 -1
- package/lib/plugins/history/util.js +1 -1
- package/lib/plugins/history/util.js.map +1 -1
- package/lib/plugins/tooltip.js +4 -1
- package/lib/plugins/tooltip.js.map +1 -1
- package/lib/runtime/graph.js +8 -2
- package/lib/runtime/graph.js.map +1 -1
- package/lib/runtime/layout.d.ts +1 -0
- package/lib/runtime/layout.js +48 -0
- package/lib/runtime/layout.js.map +1 -1
- package/lib/spec/canvas.d.ts +7 -1
- package/lib/utils/style.d.ts +1 -1
- package/lib/utils/style.js +1 -1
- package/lib/utils/style.js.map +1 -1
- package/lib/utils/tree.d.ts +1 -1
- package/lib/utils/tree.js +2 -2
- package/lib/utils/tree.js.map +1 -1
- package/lib/utils/visibility.d.ts +2 -2
- package/lib/utils/visibility.js +35 -18
- 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/click-select.ts +2 -3
- package/src/behaviors/drag-canvas.ts +9 -12
- package/src/behaviors/optimize-viewport-transform.ts +1 -1
- package/src/elements/shapes/base-shape.ts +7 -2
- package/src/elements/shapes/icon.ts +5 -4
- package/src/exports.ts +2 -0
- package/src/plugins/history/util.ts +1 -1
- package/src/plugins/tooltip.ts +4 -1
- package/src/runtime/graph.ts +7 -3
- package/src/runtime/layout.ts +55 -0
- package/src/spec/canvas.ts +7 -1
- package/src/utils/style.ts +5 -2
- package/src/utils/tree.ts +3 -3
- package/src/utils/visibility.ts +33 -16
- package/src/version.ts +1 -1
package/lib/utils/style.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.js","sourceRoot":"src/","sources":["utils/style.ts"],"names":[],"mappings":";;AAYA,kEAmBC;AAUD,oCAMC;AAcD,
|
|
1
|
+
{"version":3,"file":"style.js","sourceRoot":"src/","sources":["utils/style.ts"],"names":[],"mappings":";;AAYA,kEAmBC;AAUD,oCAMC;AAcD,4CAQC;AAjED;;;;;;;GAOG;AACH,SAAgB,2BAA2B,CACzC,aAKK,EACL,OAA8B;IAE9B,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAEjC,IAAI,OAAO,aAAa,KAAK,UAAU;QAAE,OAAO,aAAa,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAEjF,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACjD,IAAI,OAAO,KAAK,KAAK,UAAU;YAAE,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;QACxE,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACtB,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,YAAY,CAAC,IAA8B,EAAE,IAA8B;IACzF,MAAM,EAAE,GAAG,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;IAC7B,MAAM,EAAE,GAAG,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;IAC7B,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE;QACnC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;KACjC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,gBAAgB,CAC9B,KAAQ;IAKR,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IACnH,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/lib/utils/tree.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { EdgeData, GraphData, NodeData } from '../spec';
|
|
2
2
|
import type { TreeData } from '../types';
|
|
3
3
|
type TreeDataGetter = {
|
|
4
|
-
getNodeData?: (datum: TreeData) => NodeData;
|
|
4
|
+
getNodeData?: (datum: TreeData, depth: number) => NodeData;
|
|
5
5
|
getEdgeData?: (source: TreeData, target: TreeData) => EdgeData;
|
|
6
6
|
getChildren?: (datum: TreeData) => TreeData[];
|
|
7
7
|
};
|
package/lib/utils/tree.js
CHANGED
|
@@ -19,8 +19,8 @@ function treeToGraphData(treeData, getter) {
|
|
|
19
19
|
}, getEdgeData = (source, target) => ({ source: source.id, target: target.id }), getChildren = (datum) => datum.children || [], } = getter || {};
|
|
20
20
|
const nodes = [];
|
|
21
21
|
const edges = [];
|
|
22
|
-
(0, traverse_1.dfs)(treeData, (node) => {
|
|
23
|
-
nodes.push(getNodeData(node));
|
|
22
|
+
(0, traverse_1.dfs)(treeData, (node, depth) => {
|
|
23
|
+
nodes.push(getNodeData(node, depth));
|
|
24
24
|
const children = getChildren(node);
|
|
25
25
|
for (const child of children) {
|
|
26
26
|
edges.push(getEdgeData(node, child));
|
package/lib/utils/tree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree.js","sourceRoot":"src/","sources":["utils/tree.ts"],"names":[],"mappings":";;AAkBA,0CA4BC;AA5CD,yCAAiC;AAQjC;;;;;;;GAOG;AACH,SAAgB,eAAe,CAAC,QAAkB,EAAE,MAAuB;IACzE,MAAM,EACJ,WAAW,GAAG,CAAC,KAAe,EAAE,EAAE;QAChC,IAAI,CAAC,KAAK,CAAC,QAAQ;YAAE,OAAO,KAAiB,CAAC;QAC9C,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;QACzC,OAAO,EAAE,GAAG,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,EAAc,CAAC;IACnF,CAAC,EACD,WAAW,GAAG,CAAC,MAAgB,EAAE,MAAgB,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,EAChG,WAAW,GAAG,CAAC,KAAe,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,IAAI,EAAE,GACxD,GAAG,MAAM,IAAI,EAAE,CAAC;IAEjB,MAAM,KAAK,GAAe,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAe,EAAE,CAAC;IAE7B,IAAA,cAAG,EACD,QAAQ,EACR,CAAC,IAAI,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"tree.js","sourceRoot":"src/","sources":["utils/tree.ts"],"names":[],"mappings":";;AAkBA,0CA4BC;AA5CD,yCAAiC;AAQjC;;;;;;;GAOG;AACH,SAAgB,eAAe,CAAC,QAAkB,EAAE,MAAuB;IACzE,MAAM,EACJ,WAAW,GAAG,CAAC,KAAe,EAAE,EAAE;QAChC,IAAI,CAAC,KAAK,CAAC,QAAQ;YAAE,OAAO,KAAiB,CAAC;QAC9C,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;QACzC,OAAO,EAAE,GAAG,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,EAAc,CAAC;IACnF,CAAC,EACD,WAAW,GAAG,CAAC,MAAgB,EAAE,MAAgB,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,EAChG,WAAW,GAAG,CAAC,KAAe,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,IAAI,EAAE,GACxD,GAAG,MAAM,IAAI,EAAE,CAAC;IAEjB,MAAM,KAAK,GAAe,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAe,EAAE,CAAC;IAE7B,IAAA,cAAG,EACD,QAAQ,EACR,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACd,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;QACrC,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;QACnC,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;YAC7B,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;QACvC,CAAC;IACH,CAAC,EACD,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,EAC3B,IAAI,CACL,CAAC;IAEF,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;AAC1B,CAAC"}
|
|
@@ -4,11 +4,11 @@ import type { BaseStyleProps, DisplayObject } from '@antv/g';
|
|
|
4
4
|
*
|
|
5
5
|
* <en/> Set the visibility of the shape instance
|
|
6
6
|
* @param shape - <zh/> 图形实例 | <en/> shape instance
|
|
7
|
-
* @param
|
|
7
|
+
* @param value - <zh/> 可见性 | <en/> visibility
|
|
8
8
|
* @param filter - <zh/> 筛选出需要设置可见性的图形 | <en/> Filter out the shapes that need to set visibility
|
|
9
9
|
* @remarks
|
|
10
10
|
* <zh/> 在设置 enableCSSParsing 为 false 的情况下,复合图形无法继承父属性,因此需要对所有子图形应用相同的可见性
|
|
11
11
|
*
|
|
12
12
|
* <en/> After setting enableCSSParsing to false, the compound shape cannot inherit the parent attribute, so the same visibility needs to be applied to all child shapes
|
|
13
13
|
*/
|
|
14
|
-
export declare function setVisibility(shape: DisplayObject,
|
|
14
|
+
export declare function setVisibility(shape: DisplayObject, value: BaseStyleProps['visibility'], filter?: (shape: DisplayObject) => boolean): void;
|
package/lib/utils/visibility.js
CHANGED
|
@@ -1,34 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setVisibility = setVisibility;
|
|
4
|
-
const
|
|
5
|
-
const shape_1 = require("./shape");
|
|
6
|
-
const PropertyKey = 'visibility';
|
|
4
|
+
const ORIGINAL_MAP = new WeakMap();
|
|
7
5
|
/**
|
|
8
6
|
* <zh/> 设置图形实例的可见性
|
|
9
7
|
*
|
|
10
8
|
* <en/> Set the visibility of the shape instance
|
|
11
9
|
* @param shape - <zh/> 图形实例 | <en/> shape instance
|
|
12
|
-
* @param
|
|
10
|
+
* @param value - <zh/> 可见性 | <en/> visibility
|
|
13
11
|
* @param filter - <zh/> 筛选出需要设置可见性的图形 | <en/> Filter out the shapes that need to set visibility
|
|
14
12
|
* @remarks
|
|
15
13
|
* <zh/> 在设置 enableCSSParsing 为 false 的情况下,复合图形无法继承父属性,因此需要对所有子图形应用相同的可见性
|
|
16
14
|
*
|
|
17
15
|
* <en/> After setting enableCSSParsing to false, the compound shape cannot inherit the parent attribute, so the same visibility needs to be applied to all child shapes
|
|
18
16
|
*/
|
|
19
|
-
function setVisibility(shape,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (!(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
17
|
+
function setVisibility(shape, value, filter) {
|
|
18
|
+
if (value === undefined)
|
|
19
|
+
return;
|
|
20
|
+
const traverse = (current, scope = value) => {
|
|
21
|
+
const walk = (val = scope) => current.childNodes.forEach((node) => traverse(node, val));
|
|
22
|
+
if (filter && !filter(current))
|
|
23
|
+
return walk();
|
|
24
|
+
if (current === shape) {
|
|
25
|
+
shape.style.visibility = value;
|
|
26
|
+
ORIGINAL_MAP.delete(shape);
|
|
27
|
+
walk(value);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
if (!ORIGINAL_MAP.has(current))
|
|
31
|
+
ORIGINAL_MAP.set(current, current.style.visibility);
|
|
32
|
+
const computedValue = scope === 'hidden' || getOriginalValue(current) === 'hidden' ? 'hidden' : 'visible';
|
|
33
|
+
current.style.visibility = computedValue;
|
|
34
|
+
walk(computedValue);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
traverse(shape);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* <zh/> 获取图形原本的可见性
|
|
41
|
+
*
|
|
42
|
+
* <en/> Get the original visibility of the shape
|
|
43
|
+
* @param shape - <zh/> 图形实例 | <en/> shape instance
|
|
44
|
+
* @returns <zh/> 可见性 | <en/> visibility
|
|
45
|
+
*/
|
|
46
|
+
function getOriginalValue(shape) {
|
|
47
|
+
if (ORIGINAL_MAP.has(shape))
|
|
48
|
+
return ORIGINAL_MAP.get(shape);
|
|
49
|
+
return shape.style.visibility;
|
|
33
50
|
}
|
|
34
51
|
//# sourceMappingURL=visibility.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visibility.js","sourceRoot":"src/","sources":["utils/visibility.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"visibility.js","sourceRoot":"src/","sources":["utils/visibility.ts"],"names":[],"mappings":";;AAgBA,sCA0BC;AAxCD,MAAM,YAAY,GAAG,IAAI,OAAO,EAA+C,CAAC;AAEhF;;;;;;;;;;;GAWG;AACH,SAAgB,aAAa,CAC3B,KAAoB,EACpB,KAAmC,EACnC,MAA0C;IAE1C,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO;IAEhC,MAAM,QAAQ,GAAG,CAAC,OAAsB,EAAE,KAAK,GAAG,KAAK,EAAE,EAAE;QACzD,MAAM,IAAI,GAAG,CAAC,GAAG,GAAG,KAAK,EAAE,EAAE,CAAE,OAAO,CAAC,UAA8B,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;QAE7G,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;YAAE,OAAO,IAAI,EAAE,CAAC;QAE9C,IAAI,OAAO,KAAK,KAAK,EAAE,CAAC;YACtB,KAAK,CAAC,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC;YAC/B,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC3B,IAAI,CAAC,KAAK,CAAC,CAAC;QACd,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC;gBAAE,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YAEpF,MAAM,aAAa,GAAG,KAAK,KAAK,QAAQ,IAAI,gBAAgB,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;YAC1G,OAAO,CAAC,KAAK,CAAC,UAAU,GAAG,aAAa,CAAC;YACzC,IAAI,CAAC,aAAa,CAAC,CAAC;QACtB,CAAC;IACH,CAAC,CAAC;IAEF,QAAQ,CAAC,KAAK,CAAC,CAAC;AAClB,CAAC;AAED;;;;;;GAMG;AACH,SAAS,gBAAgB,CAAC,KAAoB;IAC5C,IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,OAAO,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC5D,OAAO,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC;AAChC,CAAC"}
|
package/lib/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.0.
|
|
1
|
+
export declare const version = "5.0.14";
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -188,7 +188,7 @@ export class ClickSelect extends BaseBehavior<ClickSelectOptions> {
|
|
|
188
188
|
Object.assign(states, this.getClearStates(!!unselectedState));
|
|
189
189
|
const addState = (list: ID[], state: State) => {
|
|
190
190
|
list.forEach((id) => {
|
|
191
|
-
if (!states[id]) states[id] =
|
|
191
|
+
if (!states[id]) states[id] = graph.getElementState(id);
|
|
192
192
|
states[id].push(state);
|
|
193
193
|
});
|
|
194
194
|
};
|
|
@@ -206,8 +206,7 @@ export class ClickSelect extends BaseBehavior<ClickSelectOptions> {
|
|
|
206
206
|
if (type === 'select') {
|
|
207
207
|
const addState = (list: ID[], state: State) => {
|
|
208
208
|
list.forEach((id) => {
|
|
209
|
-
const
|
|
210
|
-
const dataStatesSet = new Set(statesOf(datum));
|
|
209
|
+
const dataStatesSet = new Set(graph.getElementState(id));
|
|
211
210
|
dataStatesSet.add(state);
|
|
212
211
|
dataStatesSet.delete(unselectedState);
|
|
213
212
|
states[id] = Array.from(dataStatesSet);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Cursor } from '@antv/g';
|
|
2
2
|
import { debounce, isObject } from '@antv/util';
|
|
3
|
-
import {
|
|
3
|
+
import { CommonEvent } from '../constants';
|
|
4
4
|
import type { RuntimeContext } from '../runtime/types';
|
|
5
5
|
import type { IKeyboardEvent, IPointerEvent, Vector2, ViewportAnimationEffectTiming } from '../types';
|
|
6
6
|
import type { ShortcutKey } from '../utils/shortcut';
|
|
@@ -72,10 +72,6 @@ export class DragCanvas extends BaseBehavior<DragCanvasOptions> {
|
|
|
72
72
|
|
|
73
73
|
private defaultCursor: Cursor;
|
|
74
74
|
|
|
75
|
-
private get canvas() {
|
|
76
|
-
return this.context.canvas.getLayer();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
75
|
constructor(context: RuntimeContext, options: DragCanvasOptions) {
|
|
80
76
|
super(context, Object.assign({}, DragCanvas.defaultOptions, options));
|
|
81
77
|
|
|
@@ -108,9 +104,10 @@ export class DragCanvas extends BaseBehavior<DragCanvasOptions> {
|
|
|
108
104
|
this.shortcut.bind(left, (event) => this.onTranslate([1, 0], event));
|
|
109
105
|
this.shortcut.bind(right, (event) => this.onTranslate([-1, 0], event));
|
|
110
106
|
} else {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
107
|
+
const { graph } = this.context;
|
|
108
|
+
graph.on(CommonEvent.DRAG_START, this.onDragStart);
|
|
109
|
+
graph.on(CommonEvent.DRAG, this.onDrag);
|
|
110
|
+
graph.on(CommonEvent.DRAG_END, this.onDragEnd);
|
|
114
111
|
}
|
|
115
112
|
}
|
|
116
113
|
|
|
@@ -170,10 +167,10 @@ export class DragCanvas extends BaseBehavior<DragCanvasOptions> {
|
|
|
170
167
|
|
|
171
168
|
private unbindEvents() {
|
|
172
169
|
this.shortcut.unbindAll();
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
170
|
+
const { graph } = this.context;
|
|
171
|
+
graph.off(CommonEvent.DRAG_START, this.onDragStart);
|
|
172
|
+
graph.off(CommonEvent.DRAG, this.onDrag);
|
|
173
|
+
graph.off(CommonEvent.DRAG_END, this.onDragEnd);
|
|
177
174
|
}
|
|
178
175
|
|
|
179
176
|
public destroy(): void {
|
|
@@ -72,7 +72,7 @@ export class OptimizeViewportTransform extends BaseBehavior<OptimizeViewportTran
|
|
|
72
72
|
setVisibility(
|
|
73
73
|
element,
|
|
74
74
|
visibility,
|
|
75
|
-
|
|
75
|
+
(shape) => !!shape.className && !excludedClassnames?.includes(shape.className),
|
|
76
76
|
);
|
|
77
77
|
});
|
|
78
78
|
};
|
|
@@ -66,7 +66,9 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
// create
|
|
69
|
-
if (!target || target.destroyed) {
|
|
69
|
+
if (!target || target.destroyed || !(target instanceof Ctor)) {
|
|
70
|
+
target?.destroy();
|
|
71
|
+
|
|
70
72
|
const instance = new Ctor({ className, style });
|
|
71
73
|
container.appendChild(instance);
|
|
72
74
|
this.shapeMap[className] = instance;
|
|
@@ -122,7 +124,10 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
|
|
|
122
124
|
*/
|
|
123
125
|
public getGraphicStyle<T extends Record<string, any>>(
|
|
124
126
|
style: T,
|
|
125
|
-
): Omit<
|
|
127
|
+
): Omit<
|
|
128
|
+
T,
|
|
129
|
+
'x' | 'y' | 'z' | 'transform' | 'transformOrigin' | 'className' | 'class' | 'context' | 'zIndex' | 'visibility'
|
|
130
|
+
> {
|
|
126
131
|
return getSubShapeStyle(style);
|
|
127
132
|
}
|
|
128
133
|
|
|
@@ -25,14 +25,15 @@ export class Icon extends BaseShape<IconStyleProps> {
|
|
|
25
25
|
super(options);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
private
|
|
29
|
-
|
|
28
|
+
private isImage() {
|
|
29
|
+
const { src } = this.attributes;
|
|
30
|
+
return !!src;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
protected getIconStyle(attributes: IconStyleProps = this.attributes): IconStyleProps {
|
|
33
34
|
const { width = 0, height = 0 } = attributes;
|
|
34
35
|
const style = this.getGraphicStyle(attributes);
|
|
35
|
-
if (this.
|
|
36
|
+
if (this.isImage()) {
|
|
36
37
|
return {
|
|
37
38
|
x: -width / 2,
|
|
38
39
|
y: -height / 2,
|
|
@@ -47,6 +48,6 @@ export class Icon extends BaseShape<IconStyleProps> {
|
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
public render(attributes = this.attributes, container: Group = this): void {
|
|
50
|
-
this.upsert('icon', (this.
|
|
51
|
+
this.upsert('icon', (this.isImage() ? GImage : GText) as any, this.getIconStyle(attributes), container);
|
|
51
52
|
}
|
|
52
53
|
}
|
package/src/exports.ts
CHANGED
|
@@ -89,6 +89,7 @@ export { omitStyleProps, subStyleProps } from './utils/prefix';
|
|
|
89
89
|
export { Shortcut } from './utils/shortcut';
|
|
90
90
|
export { parseSize } from './utils/size';
|
|
91
91
|
export { treeToGraphData } from './utils/tree';
|
|
92
|
+
export { setVisibility } from './utils/visibility';
|
|
92
93
|
|
|
93
94
|
export type { BaseStyleProps } from '@antv/g';
|
|
94
95
|
export type {
|
|
@@ -246,6 +247,7 @@ export type {
|
|
|
246
247
|
Size,
|
|
247
248
|
State,
|
|
248
249
|
TransformOptions,
|
|
250
|
+
TreeData,
|
|
249
251
|
TriangleDirection,
|
|
250
252
|
Vector2,
|
|
251
253
|
Vector3,
|
|
@@ -18,7 +18,7 @@ export function alignFields(refObject: Record<string, any>, targetObject: Record
|
|
|
18
18
|
if (isObject(refObject[key]) && !Array.isArray(refObject[key]) && refObject[key] !== null) {
|
|
19
19
|
if (!targetObject[key]) targetObject[key] = {};
|
|
20
20
|
alignFields(refObject[key], targetObject[key]);
|
|
21
|
-
} else if (
|
|
21
|
+
} else if (targetObject[key] === undefined) {
|
|
22
22
|
targetObject[key] = inferDefaultValue(key);
|
|
23
23
|
}
|
|
24
24
|
}
|
package/src/plugins/tooltip.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Tooltip as TooltipComponent } from '@antv/component';
|
|
|
3
3
|
import { get } from '@antv/util';
|
|
4
4
|
import type { RuntimeContext } from '../runtime/types';
|
|
5
5
|
import type { ElementDatum, ElementType, ID, IElementEvent } from '../types';
|
|
6
|
+
import { isToBeDestroyed } from '../utils/element';
|
|
6
7
|
import type { BasePluginOptions } from './base-plugin';
|
|
7
8
|
import { BasePlugin } from './base-plugin';
|
|
8
9
|
|
|
@@ -235,8 +236,10 @@ export class Tooltip extends BasePlugin<TooltipOptions> {
|
|
|
235
236
|
client,
|
|
236
237
|
target: { id },
|
|
237
238
|
} = event;
|
|
238
|
-
|
|
239
|
+
if (isToBeDestroyed(event.target)) return;
|
|
239
240
|
if (!this.tooltipElement || !this.isEnable(event)) return;
|
|
241
|
+
|
|
242
|
+
const targetType = this.context.graph.getElementType(id);
|
|
240
243
|
const { getContent, title } = this.options;
|
|
241
244
|
this.currentTarget = id;
|
|
242
245
|
const items: ElementDatum[] = this.getElementData(id, targetType as ElementType);
|
package/src/runtime/graph.ts
CHANGED
|
@@ -117,7 +117,8 @@ export class Graph extends EventEmitter {
|
|
|
117
117
|
* @apiCategory option
|
|
118
118
|
*/
|
|
119
119
|
public setOptions(options: GraphOptions): void {
|
|
120
|
-
const { behaviors, combo, data, edge, height, layout, node, plugins, theme, transforms, width, renderer } =
|
|
120
|
+
const { behaviors, combo, data, edge, height, layout, node, plugins, theme, transforms, width, cursor, renderer } =
|
|
121
|
+
options;
|
|
121
122
|
|
|
122
123
|
if (renderer) {
|
|
123
124
|
const canvas = this.context.canvas;
|
|
@@ -130,6 +131,7 @@ export class Graph extends EventEmitter {
|
|
|
130
131
|
|
|
131
132
|
Object.assign(this.options, options);
|
|
132
133
|
|
|
134
|
+
if (cursor) this.context.canvas?.setCursor(cursor);
|
|
133
135
|
if (behaviors) this.setBehaviors(behaviors);
|
|
134
136
|
if (combo) this.setCombo(combo);
|
|
135
137
|
if (data) this.setData(data);
|
|
@@ -1013,10 +1015,10 @@ export class Graph extends EventEmitter {
|
|
|
1013
1015
|
private async initCanvas() {
|
|
1014
1016
|
if (this.context.canvas) return await this.context.canvas.ready;
|
|
1015
1017
|
|
|
1016
|
-
const { container = 'container', width, height, renderer, background } = this.options;
|
|
1017
|
-
|
|
1018
|
+
const { container = 'container', width, height, renderer, cursor, background } = this.options;
|
|
1018
1019
|
if (container instanceof Canvas) {
|
|
1019
1020
|
this.context.canvas = container;
|
|
1021
|
+
if (cursor) container.setCursor(cursor);
|
|
1020
1022
|
await container.ready;
|
|
1021
1023
|
} else {
|
|
1022
1024
|
const $container = isString(container) ? document.getElementById(container!) : container;
|
|
@@ -1030,6 +1032,7 @@ export class Graph extends EventEmitter {
|
|
|
1030
1032
|
height: height || containerSize[1],
|
|
1031
1033
|
background,
|
|
1032
1034
|
renderer,
|
|
1035
|
+
cursor,
|
|
1033
1036
|
});
|
|
1034
1037
|
|
|
1035
1038
|
this.context.canvas = canvas;
|
|
@@ -1733,6 +1736,7 @@ export class Graph extends EventEmitter {
|
|
|
1733
1736
|
|
|
1734
1737
|
const elementType = model.getElementType(id);
|
|
1735
1738
|
|
|
1739
|
+
await this.frontElement(id);
|
|
1736
1740
|
this.isCollapsingExpanding = true;
|
|
1737
1741
|
this.setElementCollapsibility(id, true);
|
|
1738
1742
|
if (elementType === 'node') await element!.collapseNode(id, animation);
|
package/src/runtime/layout.ts
CHANGED
|
@@ -156,6 +156,7 @@ export class LayoutController {
|
|
|
156
156
|
|
|
157
157
|
createTreeStructure(model);
|
|
158
158
|
|
|
159
|
+
const layoutPreset: GraphData = { nodes: [], edges: [] };
|
|
159
160
|
const layoutResult: GraphData = { nodes: [], edges: [] };
|
|
160
161
|
|
|
161
162
|
const roots = model.getRoots(TREE_KEY) as unknown as TreeData[];
|
|
@@ -170,11 +171,13 @@ export class LayoutController {
|
|
|
170
171
|
);
|
|
171
172
|
|
|
172
173
|
const result = layout(root, options);
|
|
174
|
+
const { x: rx, y: ry, z: rz = 0 } = result;
|
|
173
175
|
// 将布局结果转化为 LayoutMapping 格式 / Convert the layout result to LayoutMapping format
|
|
174
176
|
dfs(
|
|
175
177
|
result,
|
|
176
178
|
(node) => {
|
|
177
179
|
const { id, x, y, z = 0 } = node;
|
|
180
|
+
layoutPreset.nodes!.push({ id, style: { x: rx, y: ry, z: rz } });
|
|
178
181
|
layoutResult.nodes!.push({ id, style: { x, y, z } });
|
|
179
182
|
},
|
|
180
183
|
(node) => node.children,
|
|
@@ -182,13 +185,45 @@ export class LayoutController {
|
|
|
182
185
|
);
|
|
183
186
|
});
|
|
184
187
|
|
|
188
|
+
const offset = this.inferTreeLayoutOffset(layoutResult);
|
|
189
|
+
applyTreeLayoutOffset(layoutResult, offset);
|
|
190
|
+
|
|
185
191
|
if (animation) {
|
|
192
|
+
// 先将所有节点移动到根节点位置 / Move all nodes to the root node position first
|
|
193
|
+
applyTreeLayoutOffset(layoutPreset, offset);
|
|
194
|
+
this.updateElementPosition(layoutPreset, false);
|
|
195
|
+
|
|
186
196
|
this.updateElementPosition(layoutResult, animation);
|
|
187
197
|
}
|
|
188
198
|
|
|
189
199
|
return layoutResult;
|
|
190
200
|
}
|
|
191
201
|
|
|
202
|
+
private inferTreeLayoutOffset(data: GraphData) {
|
|
203
|
+
let [minX, maxX] = [Infinity, -Infinity];
|
|
204
|
+
let [minY, maxY] = [Infinity, -Infinity];
|
|
205
|
+
|
|
206
|
+
data.nodes?.forEach((node) => {
|
|
207
|
+
const { x = 0, y = 0 } = node.style || {};
|
|
208
|
+
minX = Math.min(minX, x);
|
|
209
|
+
maxX = Math.max(maxX, x);
|
|
210
|
+
minY = Math.min(minY, y);
|
|
211
|
+
maxY = Math.max(maxY, y);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const { canvas } = this.context;
|
|
215
|
+
const canvasSize = canvas.getSize();
|
|
216
|
+
const [x1, y1] = canvas.getCanvasByViewport([0, 0]);
|
|
217
|
+
const [x2, y2] = canvas.getCanvasByViewport(canvasSize);
|
|
218
|
+
|
|
219
|
+
if (minX >= x1 && maxX <= x2 && minY >= y1 && maxY <= y2) return [0, 0] as [number, number];
|
|
220
|
+
|
|
221
|
+
const cx = (x1 + x2) / 2;
|
|
222
|
+
const cy = (y1 + y2) / 2;
|
|
223
|
+
|
|
224
|
+
return [cx - (minX + maxX) / 2, cy - (minY + maxY) / 2] as [number, number];
|
|
225
|
+
}
|
|
226
|
+
|
|
192
227
|
public stopLayout() {
|
|
193
228
|
if (this.instance && isLayoutWithIterations(this.instance)) {
|
|
194
229
|
this.instance.stop();
|
|
@@ -303,3 +338,23 @@ export class LayoutController {
|
|
|
303
338
|
this.animationResult = undefined;
|
|
304
339
|
}
|
|
305
340
|
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* <zh/> 对树形布局结果应用偏移
|
|
344
|
+
*
|
|
345
|
+
* <en/> Apply offset to tree layout result
|
|
346
|
+
* @param data - <zh/> 布局数据 | <en/> Layout data
|
|
347
|
+
* @param offset - <zh/> 偏移量 | <en/> Offset
|
|
348
|
+
*/
|
|
349
|
+
const applyTreeLayoutOffset = (data: GraphData, offset: [number, number]) => {
|
|
350
|
+
const [ox, oy] = offset;
|
|
351
|
+
data.nodes?.forEach((node) => {
|
|
352
|
+
if (node.style) {
|
|
353
|
+
const { x = 0, y = 0 } = node.style;
|
|
354
|
+
node.style.x = x + ox;
|
|
355
|
+
node.style.y = y + oy;
|
|
356
|
+
} else {
|
|
357
|
+
node.style = { x: ox, y: oy };
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
};
|
package/src/spec/canvas.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IRenderer } from '@antv/g';
|
|
1
|
+
import type { Cursor, IRenderer } from '@antv/g';
|
|
2
2
|
import type { Canvas } from '../runtime/canvas';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -51,4 +51,10 @@ export interface CanvasOptions {
|
|
|
51
51
|
* <en/> device pixel ratio
|
|
52
52
|
*/
|
|
53
53
|
devicePixelRatio?: number;
|
|
54
|
+
/**
|
|
55
|
+
* <zh/> 指针样式
|
|
56
|
+
*
|
|
57
|
+
* <en/> cursor style
|
|
58
|
+
*/
|
|
59
|
+
cursor?: Cursor;
|
|
54
60
|
}
|
package/src/utils/style.ts
CHANGED
|
@@ -61,7 +61,10 @@ export function mergeOptions(opt1: DisplayObjectConfig<any>, opt2: DisplayObject
|
|
|
61
61
|
*/
|
|
62
62
|
export function getSubShapeStyle<T extends Record<string, any>>(
|
|
63
63
|
style: T,
|
|
64
|
-
): Omit<
|
|
65
|
-
|
|
64
|
+
): Omit<
|
|
65
|
+
T,
|
|
66
|
+
'x' | 'y' | 'z' | 'transform' | 'transformOrigin' | 'className' | 'class' | 'context' | 'zIndex' | 'visibility'
|
|
67
|
+
> {
|
|
68
|
+
const { x, y, z, class: cls, className, transform, transformOrigin, context, zIndex, visibility, ...rest } = style;
|
|
66
69
|
return rest;
|
|
67
70
|
}
|
package/src/utils/tree.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { TreeData } from '../types';
|
|
|
3
3
|
import { dfs } from './traverse';
|
|
4
4
|
|
|
5
5
|
type TreeDataGetter = {
|
|
6
|
-
getNodeData?: (datum: TreeData) => NodeData;
|
|
6
|
+
getNodeData?: (datum: TreeData, depth: number) => NodeData;
|
|
7
7
|
getEdgeData?: (source: TreeData, target: TreeData) => EdgeData;
|
|
8
8
|
getChildren?: (datum: TreeData) => TreeData[];
|
|
9
9
|
};
|
|
@@ -32,8 +32,8 @@ export function treeToGraphData(treeData: TreeData, getter?: TreeDataGetter): Gr
|
|
|
32
32
|
|
|
33
33
|
dfs(
|
|
34
34
|
treeData,
|
|
35
|
-
(node) => {
|
|
36
|
-
nodes.push(getNodeData(node));
|
|
35
|
+
(node, depth) => {
|
|
36
|
+
nodes.push(getNodeData(node, depth));
|
|
37
37
|
const children = getChildren(node);
|
|
38
38
|
for (const child of children) {
|
|
39
39
|
edges.push(getEdgeData(node, child));
|
package/src/utils/visibility.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import type { BaseStyleProps, DisplayObject } from '@antv/g';
|
|
2
|
-
import { cacheStyle, getCachedStyle, hasCachedStyle } from './cache';
|
|
3
|
-
import { getDescendantShapes } from './shape';
|
|
4
2
|
|
|
5
|
-
const
|
|
3
|
+
const ORIGINAL_MAP = new WeakMap<DisplayObject, BaseStyleProps['visibility']>();
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* <zh/> 设置图形实例的可见性
|
|
9
7
|
*
|
|
10
8
|
* <en/> Set the visibility of the shape instance
|
|
11
9
|
* @param shape - <zh/> 图形实例 | <en/> shape instance
|
|
12
|
-
* @param
|
|
10
|
+
* @param value - <zh/> 可见性 | <en/> visibility
|
|
13
11
|
* @param filter - <zh/> 筛选出需要设置可见性的图形 | <en/> Filter out the shapes that need to set visibility
|
|
14
12
|
* @remarks
|
|
15
13
|
* <zh/> 在设置 enableCSSParsing 为 false 的情况下,复合图形无法继承父属性,因此需要对所有子图形应用相同的可见性
|
|
@@ -18,21 +16,40 @@ const PropertyKey = 'visibility';
|
|
|
18
16
|
*/
|
|
19
17
|
export function setVisibility(
|
|
20
18
|
shape: DisplayObject,
|
|
21
|
-
|
|
22
|
-
filter?: (
|
|
19
|
+
value: BaseStyleProps['visibility'],
|
|
20
|
+
filter?: (shape: DisplayObject) => boolean,
|
|
23
21
|
) {
|
|
24
|
-
|
|
22
|
+
if (value === undefined) return;
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
const traverse = (current: DisplayObject, scope = value) => {
|
|
25
|
+
const walk = (val = scope) => (current.childNodes as DisplayObject[]).forEach((node) => traverse(node, val));
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
if (!hasCachedStyle(sp, PropertyKey)) cacheStyle(sp, PropertyKey);
|
|
30
|
-
const cachedVisibility = getCachedStyle(sp, PropertyKey);
|
|
27
|
+
if (filter && !filter(current)) return walk();
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
if (current === shape) {
|
|
30
|
+
shape.style.visibility = value;
|
|
31
|
+
ORIGINAL_MAP.delete(shape);
|
|
32
|
+
walk(value);
|
|
33
|
+
} else {
|
|
34
|
+
if (!ORIGINAL_MAP.has(current)) ORIGINAL_MAP.set(current, current.style.visibility);
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
const computedValue = scope === 'hidden' || getOriginalValue(current) === 'hidden' ? 'hidden' : 'visible';
|
|
37
|
+
current.style.visibility = computedValue;
|
|
38
|
+
walk(computedValue);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
traverse(shape);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* <zh/> 获取图形原本的可见性
|
|
47
|
+
*
|
|
48
|
+
* <en/> Get the original visibility of the shape
|
|
49
|
+
* @param shape - <zh/> 图形实例 | <en/> shape instance
|
|
50
|
+
* @returns <zh/> 可见性 | <en/> visibility
|
|
51
|
+
*/
|
|
52
|
+
function getOriginalValue(shape: DisplayObject) {
|
|
53
|
+
if (ORIGINAL_MAP.has(shape)) return ORIGINAL_MAP.get(shape);
|
|
54
|
+
return shape.style.visibility;
|
|
38
55
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.0.
|
|
1
|
+
export const version = '5.0.14';
|