@antv/g6 5.0.25 → 5.0.26
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/auto-adapt-label.d.ts +99 -0
- package/dist/lib/behaviors/fix-element-size.d.ts +63 -19
- package/dist/lib/behaviors/index.d.ts +2 -0
- package/dist/lib/behaviors/optimize-viewport-transform.d.ts +3 -3
- package/dist/lib/exports.d.ts +3 -3
- package/dist/lib/plugins/edge-bundling/index.d.ts +97 -0
- package/dist/lib/plugins/index.d.ts +2 -0
- package/dist/lib/runtime/data.d.ts +1 -1
- package/dist/lib/runtime/element.d.ts +1 -1
- package/dist/lib/runtime/viewport.d.ts +3 -1
- package/dist/lib/transforms/map-node-size.d.ts +12 -21
- package/dist/lib/transforms/process-parallel-edges.d.ts +4 -0
- package/dist/lib/transforms/utils.d.ts +9 -0
- package/dist/lib/types/centrality.d.ts +20 -0
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/utils/animation.d.ts +1 -1
- package/dist/lib/utils/bbox.d.ts +9 -0
- package/dist/lib/utils/centrality.d.ts +53 -0
- package/dist/lib/utils/padding.d.ts +16 -0
- package/dist/lib/utils/transform.d.ts +0 -13
- package/dist/lib/version.d.ts +1 -1
- package/esm/behaviors/auto-adapt-label.d.ts +99 -0
- package/esm/behaviors/auto-adapt-label.js +167 -0
- package/esm/behaviors/auto-adapt-label.js.map +1 -0
- package/esm/behaviors/fix-element-size.d.ts +63 -19
- package/esm/behaviors/fix-element-size.js +142 -59
- package/esm/behaviors/fix-element-size.js.map +1 -1
- package/esm/behaviors/hover-activate.js +1 -2
- package/esm/behaviors/hover-activate.js.map +1 -1
- package/esm/behaviors/index.d.ts +2 -0
- package/esm/behaviors/index.js +1 -0
- package/esm/behaviors/index.js.map +1 -1
- package/esm/behaviors/optimize-viewport-transform.d.ts +3 -3
- package/esm/exports.d.ts +3 -3
- package/esm/exports.js +1 -1
- package/esm/exports.js.map +1 -1
- package/esm/plugins/edge-bundling/index.d.ts +97 -0
- package/esm/plugins/edge-bundling/index.js +252 -0
- package/esm/plugins/edge-bundling/index.js.map +1 -0
- 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/registry/build-in.js +4 -2
- package/esm/registry/build-in.js.map +1 -1
- package/esm/runtime/behavior.js +1 -1
- package/esm/runtime/behavior.js.map +1 -1
- package/esm/runtime/data.d.ts +1 -1
- package/esm/runtime/element.d.ts +1 -1
- package/esm/runtime/viewport.d.ts +3 -1
- package/esm/runtime/viewport.js +13 -4
- package/esm/runtime/viewport.js.map +1 -1
- package/esm/transforms/collapse-expand-combo.js +0 -1
- package/esm/transforms/collapse-expand-combo.js.map +1 -1
- package/esm/transforms/map-node-size.d.ts +12 -21
- package/esm/transforms/map-node-size.js +34 -178
- package/esm/transforms/map-node-size.js.map +1 -1
- package/esm/transforms/process-parallel-edges.d.ts +4 -0
- package/esm/transforms/process-parallel-edges.js +41 -37
- package/esm/transforms/process-parallel-edges.js.map +1 -1
- package/esm/transforms/utils.d.ts +9 -0
- package/esm/transforms/utils.js +11 -0
- package/esm/transforms/utils.js.map +1 -1
- package/esm/types/centrality.d.ts +20 -0
- package/esm/types/centrality.js +2 -0
- package/esm/types/centrality.js.map +1 -0
- package/esm/types/index.d.ts +1 -0
- package/esm/utils/animation.d.ts +1 -1
- package/esm/utils/bbox.d.ts +9 -0
- package/esm/utils/bbox.js +15 -0
- package/esm/utils/bbox.js.map +1 -1
- package/esm/utils/centrality.d.ts +53 -0
- package/esm/utils/centrality.js +177 -0
- package/esm/utils/centrality.js.map +1 -0
- package/esm/utils/padding.d.ts +16 -0
- package/esm/utils/padding.js +22 -0
- package/esm/utils/padding.js.map +1 -1
- package/esm/utils/transform.d.ts +0 -13
- package/esm/utils/transform.js +0 -23
- package/esm/utils/transform.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/behaviors/auto-adapt-label.d.ts +99 -0
- package/lib/behaviors/auto-adapt-label.js +171 -0
- package/lib/behaviors/auto-adapt-label.js.map +1 -0
- package/lib/behaviors/fix-element-size.d.ts +63 -19
- package/lib/behaviors/fix-element-size.js +141 -58
- package/lib/behaviors/fix-element-size.js.map +1 -1
- package/lib/behaviors/hover-activate.js +1 -2
- package/lib/behaviors/hover-activate.js.map +1 -1
- package/lib/behaviors/index.d.ts +2 -0
- package/lib/behaviors/index.js +3 -1
- package/lib/behaviors/index.js.map +1 -1
- package/lib/behaviors/optimize-viewport-transform.d.ts +3 -3
- package/lib/exports.d.ts +3 -3
- package/lib/exports.js +3 -2
- package/lib/exports.js.map +1 -1
- package/lib/plugins/edge-bundling/index.d.ts +97 -0
- package/lib/plugins/edge-bundling/index.js +256 -0
- package/lib/plugins/edge-bundling/index.js.map +1 -0
- 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/registry/build-in.js +2 -0
- package/lib/registry/build-in.js.map +1 -1
- package/lib/runtime/behavior.js +1 -1
- package/lib/runtime/behavior.js.map +1 -1
- package/lib/runtime/data.d.ts +1 -1
- package/lib/runtime/element.d.ts +1 -1
- package/lib/runtime/viewport.d.ts +3 -1
- package/lib/runtime/viewport.js +12 -3
- package/lib/runtime/viewport.js.map +1 -1
- package/lib/transforms/collapse-expand-combo.js +0 -1
- package/lib/transforms/collapse-expand-combo.js.map +1 -1
- package/lib/transforms/map-node-size.d.ts +12 -21
- package/lib/transforms/map-node-size.js +33 -177
- package/lib/transforms/map-node-size.js.map +1 -1
- package/lib/transforms/process-parallel-edges.d.ts +4 -0
- package/lib/transforms/process-parallel-edges.js +41 -37
- package/lib/transforms/process-parallel-edges.js.map +1 -1
- package/lib/transforms/utils.d.ts +9 -0
- package/lib/transforms/utils.js +12 -0
- package/lib/transforms/utils.js.map +1 -1
- package/lib/types/centrality.d.ts +20 -0
- package/lib/types/centrality.js +3 -0
- package/lib/types/centrality.js.map +1 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/utils/animation.d.ts +1 -1
- package/lib/utils/bbox.d.ts +9 -0
- package/lib/utils/bbox.js +16 -0
- package/lib/utils/bbox.js.map +1 -1
- package/lib/utils/centrality.d.ts +53 -0
- package/lib/utils/centrality.js +187 -0
- package/lib/utils/centrality.js.map +1 -0
- package/lib/utils/padding.d.ts +16 -0
- package/lib/utils/padding.js +24 -0
- package/lib/utils/padding.js.map +1 -1
- package/lib/utils/transform.d.ts +0 -13
- package/lib/utils/transform.js +0 -25
- package/lib/utils/transform.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/auto-adapt-label.ts +255 -0
- package/src/behaviors/fix-element-size.ts +213 -83
- package/src/behaviors/hover-activate.ts +2 -3
- package/src/behaviors/index.ts +2 -0
- package/src/behaviors/optimize-viewport-transform.ts +3 -3
- package/src/exports.ts +3 -0
- package/src/plugins/edge-bundling/index.ts +373 -0
- package/src/plugins/index.ts +2 -0
- package/src/registry/build-in.ts +4 -0
- package/src/runtime/behavior.ts +1 -0
- package/src/runtime/viewport.ts +14 -4
- package/src/transforms/collapse-expand-combo.ts +0 -1
- package/src/transforms/map-node-size.ts +52 -209
- package/src/transforms/process-parallel-edges.ts +50 -41
- package/src/transforms/utils.ts +12 -0
- package/src/types/centrality.ts +8 -0
- package/src/types/index.ts +1 -0
- package/src/utils/bbox.ts +17 -0
- package/src/utils/centrality.ts +209 -0
- package/src/utils/padding.ts +24 -0
- package/src/utils/transform.ts +0 -32
- package/src/version.ts +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { DisplayObject } from '@antv/g';
|
|
2
|
-
import { isFunction, isNumber } from '@antv/util';
|
|
2
|
+
import { isEmpty, isFunction, isNumber } from '@antv/util';
|
|
3
3
|
import { GraphEvent } from '../constants';
|
|
4
4
|
import type { RuntimeContext } from '../runtime/types';
|
|
5
|
-
import type {
|
|
6
|
-
import {
|
|
5
|
+
import type { ComboData, EdgeData, NodeData } from '../spec';
|
|
6
|
+
import type { Combo, Edge, Element, ID, IViewportEvent, Node, NodeLikeData, State } from '../types';
|
|
7
7
|
import { idOf } from '../utils/id';
|
|
8
8
|
import { getDescendantShapes } from '../utils/shape';
|
|
9
9
|
import type { BaseBehaviorOptions } from './base-behavior';
|
|
@@ -11,17 +11,17 @@ import { BaseBehavior } from './base-behavior';
|
|
|
11
11
|
|
|
12
12
|
export type FixShapeConfig = {
|
|
13
13
|
/**
|
|
14
|
-
* <zh/>
|
|
14
|
+
* <zh/> 指定要固定大小的图形,可以是图形的类名字,或者是一个函数,该函数接收构成元素的所有图形并返回目标图形
|
|
15
15
|
*
|
|
16
|
-
* <en/> Specify the shape
|
|
16
|
+
* <en/> Specify the shape to be fixed in size. This can be a class name string of the shape, or a function that takes all shapes composing the element and returns the target shape
|
|
17
17
|
*/
|
|
18
|
-
shape: (shapes: DisplayObject[]) => DisplayObject;
|
|
18
|
+
shape: string | ((shapes: DisplayObject[]) => DisplayObject);
|
|
19
19
|
/**
|
|
20
|
-
* <zh/>
|
|
20
|
+
* <zh/> 指定要固定大小的图形属性字段。如果未指定,则默认固定整个图形的大小
|
|
21
21
|
*
|
|
22
|
-
* <en/> Specify
|
|
22
|
+
* <en/> Specify the fields of the shape to be fixed in size. If not specified, the entire shape's size will be fixed by default
|
|
23
23
|
*/
|
|
24
|
-
fields
|
|
24
|
+
fields?: string[];
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -34,32 +34,57 @@ export interface FixElementSizeOptions extends BaseBehaviorOptions {
|
|
|
34
34
|
* <zh/> 是否启用固定元素大小交互。默认在缩小画布时启用
|
|
35
35
|
*
|
|
36
36
|
* <en/> Whether to enable the fix element size behavior. Enabled by default when zooming out
|
|
37
|
-
* @
|
|
37
|
+
* @remarks
|
|
38
|
+
* <zh/> 默认在缩小画布时启用,设置 `enable: (event) => event.data.scale < 1`;如果希望在放大画布时启用,设置 `enable: (event) => event.data.scale > 1`;如果希望在放大缩小画布时都启用,设置 `enable: true`
|
|
39
|
+
*
|
|
40
|
+
* <en/> Enabled by default when zooming out, set `enable: (event) => event.data.scale < 1`; If you want to enable it when zooming in, set `enable: (event) => event.data.scale > 1`; If you want to enable it when zooming in and out, set `enable: true`
|
|
41
|
+
* @defaultValue (event) => Boolean(event.data.scale < 1)
|
|
38
42
|
*/
|
|
39
43
|
enable?: boolean | ((event: IViewportEvent) => boolean);
|
|
40
44
|
/**
|
|
41
45
|
* <zh/> 指定要固定大小的元素状态
|
|
42
46
|
*
|
|
43
47
|
* <en/> Specify the state of elements to be fixed in size
|
|
48
|
+
* @defaultValue `'selected'`
|
|
44
49
|
*/
|
|
45
50
|
state?: State;
|
|
51
|
+
/**
|
|
52
|
+
* <zh/> 节点过滤器,用于过滤哪些节点在缩放过程中保持固定大小
|
|
53
|
+
*
|
|
54
|
+
* <en/> Node filter for filtering which nodes remain fixed in size during zooming
|
|
55
|
+
* @defaultValue () => true
|
|
56
|
+
*/
|
|
57
|
+
nodeFilter?: (datum: NodeData) => boolean;
|
|
58
|
+
/**
|
|
59
|
+
* <zh/> 边过滤器,用于过滤哪些边在缩放过程中保持固定大小
|
|
60
|
+
*
|
|
61
|
+
* <en/> Edge filter for filtering which edges remain fixed in size during zooming
|
|
62
|
+
* @defaultValue () => true
|
|
63
|
+
*/
|
|
64
|
+
edgeFilter?: (datum: EdgeData) => boolean;
|
|
65
|
+
/**
|
|
66
|
+
* <zh/> Combo 过滤器,用于过滤哪些 Combo 在缩放过程中保持固定大小
|
|
67
|
+
*
|
|
68
|
+
* <en/> Combo filter for filtering which combos remain fixed in size during zooming
|
|
69
|
+
* @defaultValue () => true
|
|
70
|
+
*/
|
|
71
|
+
comboFilter?: (datum: ComboData) => boolean;
|
|
46
72
|
/**
|
|
47
73
|
* <zh/> 节点配置项,用于定义哪些属性在视觉上保持固定大小。若未指定(即为 undefined),则整个节点将被固定
|
|
48
74
|
*
|
|
49
75
|
* <en/> Node configuration for defining which node attributes should remain fixed in size visually. If not specified (i.e., undefined), the entire node will be fixed in size.
|
|
50
76
|
* @example
|
|
51
|
-
* <zh/>
|
|
77
|
+
* <zh/> 如果在缩放过程中希望固定节点主图形的 lineWidth,可以这样配置:
|
|
78
|
+
*
|
|
79
|
+
* <en/> If you want to fix the lineWidth of the key shape of the node during zooming, you can configure it like this:
|
|
80
|
+
* ```ts
|
|
81
|
+
* { node: [{ shape: 'key', fields: ['lineWidth'] }] }
|
|
82
|
+
*```
|
|
83
|
+
* <zh/> 如果在缩放过程中想保持元素标签大小不变,可以这样配置:
|
|
52
84
|
*
|
|
53
|
-
* <en/>
|
|
85
|
+
* <en/> If you want to keep the label size of the element unchanged during zooming, you can configure it like this:
|
|
54
86
|
* ```ts
|
|
55
|
-
*
|
|
56
|
-
* node: [
|
|
57
|
-
* {
|
|
58
|
-
* shape: (shapes: DisplayObject[]) => shapes.find((shape) => shape.className === 'key'),
|
|
59
|
-
* fields: ['lineWidth'],
|
|
60
|
-
* },
|
|
61
|
-
* ],
|
|
62
|
-
* }
|
|
87
|
+
* { shape: 'label' }
|
|
63
88
|
* ```
|
|
64
89
|
*/
|
|
65
90
|
node?: FixShapeConfig | FixShapeConfig[];
|
|
@@ -67,6 +92,7 @@ export interface FixElementSizeOptions extends BaseBehaviorOptions {
|
|
|
67
92
|
* <zh/> 边配置项,用于定义哪些属性在视觉上保持固定大小。默认固定 lineWidth、labelFontSize 属性
|
|
68
93
|
*
|
|
69
94
|
* <en/> Edge configuration for defining which edge attributes should remain fixed in size visually. By default, the lineWidth and labelFontSize attributes are fixed
|
|
95
|
+
* @defaultValue [{ shape: 'key', fields: ['lineWidth'] }, { shape: 'halo', fields: ['lineWidth'] }, { shape: 'label' }]
|
|
70
96
|
*/
|
|
71
97
|
edge?: FixShapeConfig | FixShapeConfig[];
|
|
72
98
|
/**
|
|
@@ -75,6 +101,13 @@ export interface FixElementSizeOptions extends BaseBehaviorOptions {
|
|
|
75
101
|
* <en/> Combo configuration for defining which combo attributes should remain fixed in size visually. By default, the entire combo will be fixed
|
|
76
102
|
*/
|
|
77
103
|
combo?: FixShapeConfig | FixShapeConfig[];
|
|
104
|
+
/**
|
|
105
|
+
* <zh/> 元素重绘时是否还原样式
|
|
106
|
+
*
|
|
107
|
+
* <en/> Whether to reset styles when elements are redrawn
|
|
108
|
+
* @defaultValue false
|
|
109
|
+
*/
|
|
110
|
+
reset?: boolean;
|
|
78
111
|
}
|
|
79
112
|
|
|
80
113
|
/**
|
|
@@ -82,98 +115,195 @@ export interface FixElementSizeOptions extends BaseBehaviorOptions {
|
|
|
82
115
|
*
|
|
83
116
|
* <en/> Fix element size while zooming
|
|
84
117
|
*/
|
|
85
|
-
export class FixElementSize extends BaseBehavior {
|
|
118
|
+
export class FixElementSize extends BaseBehavior<FixElementSizeOptions> {
|
|
86
119
|
static defaultOptions: Partial<FixElementSizeOptions> = {
|
|
87
|
-
enable: (event) => event.data.scale! < 1,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
shape: (shapes: DisplayObject[]) =>
|
|
96
|
-
shapes.find((shape) => shape.parentElement?.className === 'label' && shape.className === 'text')!,
|
|
97
|
-
fields: ['fontSize', 'lineHeight'],
|
|
98
|
-
},
|
|
99
|
-
],
|
|
120
|
+
enable: (event: IViewportEvent) => event.data.scale! < 1,
|
|
121
|
+
nodeFilter: () => true,
|
|
122
|
+
edgeFilter: () => true,
|
|
123
|
+
comboFilter: () => true,
|
|
124
|
+
edge: [{ shape: 'key', fields: ['lineWidth'] }, { shape: 'halo', fields: ['lineWidth'] }, { shape: 'label' }],
|
|
125
|
+
reset: false,
|
|
100
126
|
};
|
|
101
127
|
|
|
102
|
-
private elementCache: Map<ID, Element> = new Map();
|
|
103
|
-
|
|
104
128
|
constructor(context: RuntimeContext, options: FixElementSizeOptions) {
|
|
105
129
|
super(context, Object.assign({}, FixElementSize.defaultOptions, options));
|
|
106
130
|
this.bindEvents();
|
|
107
131
|
}
|
|
108
132
|
|
|
109
|
-
private isZoomEvent = (event: IViewportEvent) => 'scale' in event.data;
|
|
133
|
+
private isZoomEvent = (event: IViewportEvent) => Boolean(event.data && 'scale' in event.data);
|
|
134
|
+
|
|
135
|
+
private relatedEdgeToUpdate: Set<ID> = new Set();
|
|
136
|
+
|
|
137
|
+
private zoom = this.context.graph.getZoom();
|
|
110
138
|
|
|
111
139
|
private fixElementSize = async (event: IViewportEvent) => {
|
|
112
|
-
if (!this.
|
|
113
|
-
|
|
114
|
-
const { graph
|
|
115
|
-
const { state } = this.options;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
140
|
+
if (!this.validate(event)) return;
|
|
141
|
+
|
|
142
|
+
const { graph } = this.context;
|
|
143
|
+
const { state, nodeFilter, edgeFilter, comboFilter } = this.options;
|
|
144
|
+
|
|
145
|
+
const nodeData = (state ? graph.getElementDataByState('node', state) : graph.getNodeData()).filter(nodeFilter);
|
|
146
|
+
const edgeData = (state ? graph.getElementDataByState('edge', state) : graph.getEdgeData()).filter(edgeFilter);
|
|
147
|
+
const comboData = (state ? graph.getElementDataByState('combo', state) : graph.getComboData()).filter(comboFilter);
|
|
148
|
+
|
|
149
|
+
// 设置阈值防止过大或过小时抖动 | Set the threshold to prevent jitter when too large or too small
|
|
150
|
+
const currentScale = this.isZoomEvent(event)
|
|
151
|
+
? (this.zoom = Math.max(0.01, Math.min(event.data.scale!, 10)))
|
|
152
|
+
: this.zoom;
|
|
153
|
+
|
|
154
|
+
const nodeLikeData = [...nodeData, ...comboData];
|
|
155
|
+
if (nodeLikeData.length > 0) {
|
|
156
|
+
nodeLikeData.forEach((datum) => this.fixNodeLike(datum, currentScale));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
this.updateRelatedEdges();
|
|
160
|
+
|
|
161
|
+
if (edgeData.length > 0) {
|
|
162
|
+
edgeData.forEach((datum) => this.fixEdge(datum, currentScale));
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
private cachedStyles: Map<ID, { shape: DisplayObject; [field: string]: any }[]> = new Map();
|
|
167
|
+
|
|
168
|
+
private getOriginalFieldValue = (id: ID, shape: DisplayObject, field: string) => {
|
|
169
|
+
const shapesStyle = this.cachedStyles.get(id) || [];
|
|
170
|
+
const shapeStyle = shapesStyle.find((style) => style.shape === shape)?.style || {};
|
|
171
|
+
if (!(field in shapeStyle)) {
|
|
172
|
+
shapeStyle[field] = shape.attributes[field];
|
|
173
|
+
this.cachedStyles.set(id, [
|
|
174
|
+
...shapesStyle.filter((style) => style.shape !== shape),
|
|
175
|
+
{ shape, style: shapeStyle },
|
|
176
|
+
]);
|
|
177
|
+
}
|
|
178
|
+
return shapeStyle[field];
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
private scaleEntireElement = (id: ID, el: DisplayObject, currentScale: number) => {
|
|
182
|
+
el.setLocalScale(1 / currentScale);
|
|
183
|
+
const shapesStyle = this.cachedStyles.get(id) || [];
|
|
184
|
+
shapesStyle.push({ shape: el });
|
|
185
|
+
this.cachedStyles.set(id, shapesStyle);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
private scaleSpecificShapes = (el: Element, currentScale: number, config: FixShapeConfig | FixShapeConfig[]) => {
|
|
189
|
+
const descendantShapes = getDescendantShapes(el);
|
|
190
|
+
const configs = Array.isArray(config) ? config : [config];
|
|
191
|
+
|
|
192
|
+
configs.forEach((config: FixShapeConfig) => {
|
|
193
|
+
const { shape: shapeFilter, fields } = config;
|
|
194
|
+
const shape = typeof shapeFilter === 'function' ? shapeFilter(descendantShapes) : el.getShape(shapeFilter);
|
|
195
|
+
|
|
196
|
+
if (!shape) return;
|
|
197
|
+
if (!fields) {
|
|
198
|
+
this.scaleEntireElement(el.id, shape, currentScale);
|
|
141
199
|
return;
|
|
142
200
|
}
|
|
143
201
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const shape = shapeFilter(descendantShapes);
|
|
149
|
-
|
|
150
|
-
fields.forEach((field) => {
|
|
151
|
-
if (!hasCachedStyle(shape, field)) cacheStyle(shape, field);
|
|
152
|
-
const oriFieldValue = getCachedStyle(shape, field);
|
|
153
|
-
if (!isNumber(oriFieldValue)) return;
|
|
154
|
-
shape.style[field] = oriFieldValue / currentScale;
|
|
155
|
-
});
|
|
202
|
+
fields.forEach((field) => {
|
|
203
|
+
const oriFieldValue = this.getOriginalFieldValue(el.id, shape, field);
|
|
204
|
+
if (!isNumber(oriFieldValue)) return;
|
|
205
|
+
shape.style[field] = oriFieldValue / currentScale;
|
|
156
206
|
});
|
|
157
207
|
});
|
|
158
208
|
};
|
|
159
209
|
|
|
210
|
+
private skipIfExceedViewport = (el: Element) => {
|
|
211
|
+
const { viewport } = this.context;
|
|
212
|
+
return !viewport?.isInViewport(el.getRenderBounds(), false, 30);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
private fixNodeLike = (datum: NodeLikeData, currentScale: number) => {
|
|
216
|
+
const id = idOf(datum);
|
|
217
|
+
const { element, model } = this.context;
|
|
218
|
+
const el = element!.getElement(id) as Node | Combo;
|
|
219
|
+
|
|
220
|
+
if (this.skipIfExceedViewport(el)) return;
|
|
221
|
+
|
|
222
|
+
const edges = model.getRelatedEdgesData(id);
|
|
223
|
+
edges.forEach((edge) => this.relatedEdgeToUpdate.add(idOf(edge)));
|
|
224
|
+
|
|
225
|
+
const config = this.options[(el as any).type];
|
|
226
|
+
if (!config) {
|
|
227
|
+
this.scaleEntireElement(id, el, currentScale);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
this.scaleSpecificShapes(el, currentScale, config);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
private fixEdge = (datum: EdgeData, currentScale: number) => {
|
|
234
|
+
const id = idOf(datum);
|
|
235
|
+
const el = this.context.element!.getElement(id) as Edge;
|
|
236
|
+
|
|
237
|
+
if (this.skipIfExceedViewport(el)) return;
|
|
238
|
+
|
|
239
|
+
const config = this.options.edge;
|
|
240
|
+
if (!config) {
|
|
241
|
+
el.style.transformOrigin = 'center';
|
|
242
|
+
this.scaleEntireElement(id, el, currentScale);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
this.scaleSpecificShapes(el, currentScale, config);
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
private updateRelatedEdges = () => {
|
|
249
|
+
const { element } = this.context;
|
|
250
|
+
if (this.relatedEdgeToUpdate.size > 0) {
|
|
251
|
+
this.relatedEdgeToUpdate.forEach((id) => {
|
|
252
|
+
const edge = element!.getElement(id) as Edge;
|
|
253
|
+
edge?.update({});
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
this.relatedEdgeToUpdate.clear();
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
private restoreCachedStyles() {
|
|
260
|
+
if (this.cachedStyles.size > 0) {
|
|
261
|
+
this.cachedStyles.forEach((shapesStyle) => {
|
|
262
|
+
shapesStyle.forEach(({ shape, style }) => {
|
|
263
|
+
if (isEmpty(style)) {
|
|
264
|
+
shape.setLocalScale(1);
|
|
265
|
+
} else {
|
|
266
|
+
if (this.options.state) return;
|
|
267
|
+
Object.entries(style).forEach(([field, value]) => (shape.style[field] = value));
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
const { graph, element } = this.context;
|
|
272
|
+
const nodeIds = Object.keys(Object.fromEntries(this.cachedStyles)).filter(
|
|
273
|
+
(id) => id && graph.getElementType(id) === 'node',
|
|
274
|
+
);
|
|
275
|
+
if (nodeIds.length > 0) {
|
|
276
|
+
const edgeIds = new Set<ID>();
|
|
277
|
+
nodeIds.forEach((id) => {
|
|
278
|
+
graph.getRelatedEdgesData(id).forEach((edge) => edgeIds.add(idOf(edge)));
|
|
279
|
+
});
|
|
280
|
+
edgeIds.forEach((id) => {
|
|
281
|
+
const edge = element?.getElement(id) as Edge;
|
|
282
|
+
edge?.update({});
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
// this.cachedStyles.clear();
|
|
287
|
+
}
|
|
288
|
+
|
|
160
289
|
private resetTransform = async () => {
|
|
161
|
-
if (this.
|
|
162
|
-
this.
|
|
163
|
-
|
|
290
|
+
if (this.options.reset) {
|
|
291
|
+
this.restoreCachedStyles();
|
|
292
|
+
} else {
|
|
293
|
+
this.fixElementSize({ data: { scale: this.zoom } } as IViewportEvent);
|
|
164
294
|
}
|
|
165
295
|
};
|
|
166
296
|
|
|
167
297
|
private bindEvents() {
|
|
168
298
|
const { graph } = this.context;
|
|
299
|
+
graph.on(GraphEvent.AFTER_DRAW, this.resetTransform);
|
|
169
300
|
graph.on(GraphEvent.AFTER_TRANSFORM, this.fixElementSize);
|
|
170
|
-
graph.on(GraphEvent.BEFORE_DRAW, this.resetTransform);
|
|
171
301
|
}
|
|
172
302
|
|
|
173
303
|
private unbindEvents() {
|
|
174
304
|
const { graph } = this.context;
|
|
305
|
+
graph.off(GraphEvent.AFTER_DRAW, this.resetTransform);
|
|
175
306
|
graph.off(GraphEvent.AFTER_TRANSFORM, this.fixElementSize);
|
|
176
|
-
graph.off(GraphEvent.BEFORE_DRAW, this.resetTransform);
|
|
177
307
|
}
|
|
178
308
|
|
|
179
309
|
private validate(event: IViewportEvent) {
|
|
@@ -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 { EdgeDirection, Element, ID, IDragEvent, IPointerEvent, State } from '../types';
|
|
5
|
+
import type { EdgeDirection, Element, ElementType, ID, IDragEvent, IPointerEvent, State } from '../types';
|
|
6
6
|
import { isToBeDestroyed } from '../utils/element';
|
|
7
7
|
import { idsOf } from '../utils/id';
|
|
8
8
|
import { getElementNthDegreeIds } from '../utils/relation';
|
|
@@ -138,12 +138,11 @@ export class HoverActivate extends BaseBehavior<HoverActivateOptions> {
|
|
|
138
138
|
const { graph } = this.context;
|
|
139
139
|
const { degree, direction } = this.options;
|
|
140
140
|
const elementId = event.target.id;
|
|
141
|
-
const elementType = graph.getElementType(elementId);
|
|
142
141
|
|
|
143
142
|
return degree
|
|
144
143
|
? getElementNthDegreeIds(
|
|
145
144
|
graph,
|
|
146
|
-
|
|
145
|
+
event.targetType as ElementType,
|
|
147
146
|
elementId,
|
|
148
147
|
typeof degree === 'function' ? degree(event) : degree,
|
|
149
148
|
direction,
|
package/src/behaviors/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { AutoAdaptLabel } from './auto-adapt-label';
|
|
1
2
|
export { BaseBehavior } from './base-behavior';
|
|
2
3
|
export { BrushSelect } from './brush-select';
|
|
3
4
|
export { ClickSelect } from './click-select';
|
|
@@ -14,6 +15,7 @@ export { OptimizeViewportTransform } from './optimize-viewport-transform';
|
|
|
14
15
|
export { ScrollCanvas } from './scroll-canvas';
|
|
15
16
|
export { ZoomCanvas } from './zoom-canvas';
|
|
16
17
|
|
|
18
|
+
export type { AutoAdaptLabelOptions } from './auto-adapt-label';
|
|
17
19
|
export type { BaseBehaviorOptions } from './base-behavior';
|
|
18
20
|
export type { BrushSelectOptions } from './brush-select';
|
|
19
21
|
export type { ClickSelectOptions } from './click-select';
|
|
@@ -21,10 +21,10 @@ export interface OptimizeViewportTransformOptions extends BaseBehaviorOptions {
|
|
|
21
21
|
*/
|
|
22
22
|
enable?: boolean | ((event: IViewportEvent) => boolean);
|
|
23
23
|
/**
|
|
24
|
-
* <zh/>
|
|
24
|
+
* <zh/> 在画布操作过程中,元素会被隐藏以提高性能。通过设置 `shapes` 配置项,可以保留指定类名的子图形不被隐藏,从而保留整个元素的部分可见性
|
|
25
25
|
*
|
|
26
|
-
* <en/>
|
|
27
|
-
* @defaultValue
|
|
26
|
+
* <en/> During canvas operations, elements are hidden to improve performance. By configuring the `shapes` option, specific sub-elements with designated class names can be retained, thereby maintaining partial visibility of the entire element.
|
|
27
|
+
* @defaultValue { node: ['key'] }
|
|
28
28
|
*/
|
|
29
29
|
shapes?: {
|
|
30
30
|
node?: string[];
|
package/src/exports.ts
CHANGED
|
@@ -78,6 +78,7 @@ export {
|
|
|
78
78
|
BubbleSets,
|
|
79
79
|
CameraSetting,
|
|
80
80
|
Contextmenu,
|
|
81
|
+
EdgeBundling,
|
|
81
82
|
EdgeFilterLens,
|
|
82
83
|
Fisheye,
|
|
83
84
|
Fullscreen,
|
|
@@ -184,6 +185,7 @@ export type {
|
|
|
184
185
|
BubbleSetsOptions,
|
|
185
186
|
CameraSettingOptions,
|
|
186
187
|
ContextmenuOptions,
|
|
188
|
+
EdgeBundlingOptions,
|
|
187
189
|
EdgeFilterLensOptions,
|
|
188
190
|
FisheyeOptions,
|
|
189
191
|
FullscreenOptions,
|
|
@@ -260,6 +262,7 @@ export type {
|
|
|
260
262
|
LoopStyleProps,
|
|
261
263
|
Node,
|
|
262
264
|
NodeBadgeStyleProps,
|
|
265
|
+
NodeCentralityOptions,
|
|
263
266
|
NodeLabelStyleProps,
|
|
264
267
|
NodeLikeData,
|
|
265
268
|
NodePortStyleProps,
|