@antv/g6 5.0.1 → 5.0.3
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/click-select.d.ts +4 -5
- package/dist/lib/behaviors/hover-activate.d.ts +0 -1
- package/dist/lib/elements/base-element.d.ts +1 -22
- package/dist/lib/elements/combos/base-combo.d.ts +4 -4
- package/dist/lib/elements/edges/base-edge.d.ts +4 -2
- package/dist/lib/elements/effect.d.ts +17 -0
- package/dist/lib/elements/nodes/base-node.d.ts +5 -4
- package/dist/lib/elements/nodes/diamond.d.ts +0 -1
- package/dist/lib/elements/shapes/badge.d.ts +17 -6
- package/dist/lib/elements/shapes/base-shape.d.ts +9 -3
- package/dist/lib/elements/shapes/icon.d.ts +15 -3
- package/dist/lib/elements/shapes/label.d.ts +18 -7
- package/dist/lib/exports.d.ts +3 -2
- package/dist/lib/index.d.ts +5 -1
- package/dist/lib/layouts/base-layout.d.ts +3 -1
- package/dist/lib/plugins/bubble-sets.d.ts +2 -2
- package/dist/lib/plugins/contextmenu/index.d.ts +4 -3
- package/dist/lib/plugins/hull/index.d.ts +2 -2
- package/dist/lib/runtime/canvas.d.ts +15 -2
- package/dist/lib/runtime/data.d.ts +9 -16
- package/dist/lib/runtime/element.d.ts +18 -2
- package/dist/lib/runtime/graph.d.ts +374 -109
- package/dist/lib/spec/element/edge.d.ts +1 -1
- package/dist/lib/spec/element/node.d.ts +1 -1
- package/dist/lib/transforms/process-parallel-edges.d.ts +2 -2
- package/dist/lib/types/callable.d.ts +0 -11
- package/dist/lib/types/data.d.ts +12 -0
- package/dist/lib/types/edge.d.ts +11 -0
- package/dist/lib/types/element.d.ts +100 -9
- package/dist/lib/types/index.d.ts +0 -1
- package/dist/lib/types/point.d.ts +0 -1
- package/dist/lib/utils/element.d.ts +2 -2
- package/dist/lib/utils/layout.d.ts +2 -2
- package/dist/lib/utils/path.d.ts +3 -3
- package/dist/lib/utils/position.d.ts +8 -8
- package/dist/lib/utils/style.d.ts +13 -8
- package/esm/behaviors/click-select.d.ts +4 -5
- package/esm/behaviors/click-select.js +62 -50
- package/esm/behaviors/click-select.js.map +1 -1
- package/esm/behaviors/drag-element.js +2 -9
- package/esm/behaviors/drag-element.js.map +1 -1
- package/esm/behaviors/hover-activate.d.ts +0 -1
- package/esm/behaviors/hover-activate.js +18 -16
- package/esm/behaviors/hover-activate.js.map +1 -1
- package/esm/behaviors/lasso-select.js.map +1 -1
- package/esm/elements/base-element.d.ts +1 -22
- package/esm/elements/base-element.js +0 -21
- package/esm/elements/base-element.js.map +1 -1
- package/esm/elements/combos/base-combo.d.ts +4 -4
- package/esm/elements/combos/base-combo.js +27 -4
- package/esm/elements/combos/base-combo.js.map +1 -1
- package/esm/elements/edges/base-edge.d.ts +4 -2
- package/esm/elements/edges/base-edge.js +41 -7
- package/esm/elements/edges/base-edge.js.map +1 -1
- package/esm/elements/effect.d.ts +17 -0
- package/esm/elements/effect.js +70 -0
- package/esm/elements/effect.js.map +1 -0
- package/esm/elements/nodes/base-node.d.ts +5 -4
- package/esm/elements/nodes/base-node.js +33 -14
- package/esm/elements/nodes/base-node.js.map +1 -1
- package/esm/elements/nodes/circle.js +1 -1
- package/esm/elements/nodes/circle.js.map +1 -1
- package/esm/elements/nodes/diamond.d.ts +0 -1
- package/esm/elements/nodes/diamond.js +0 -6
- package/esm/elements/nodes/diamond.js.map +1 -1
- package/esm/elements/nodes/ellipse.js +1 -1
- package/esm/elements/nodes/ellipse.js.map +1 -1
- package/esm/elements/nodes/image.js +2 -2
- package/esm/elements/nodes/image.js.map +1 -1
- package/esm/elements/nodes/rect.js +1 -1
- package/esm/elements/nodes/rect.js.map +1 -1
- package/esm/elements/shapes/badge.d.ts +17 -6
- package/esm/elements/shapes/badge.js +9 -0
- package/esm/elements/shapes/badge.js.map +1 -1
- package/esm/elements/shapes/base-shape.d.ts +9 -3
- package/esm/elements/shapes/base-shape.js +33 -15
- package/esm/elements/shapes/base-shape.js.map +1 -1
- package/esm/elements/shapes/icon.d.ts +15 -3
- package/esm/elements/shapes/icon.js +12 -4
- package/esm/elements/shapes/icon.js.map +1 -1
- package/esm/elements/shapes/label.d.ts +18 -7
- package/esm/elements/shapes/label.js +10 -0
- package/esm/elements/shapes/label.js.map +1 -1
- package/esm/elements/shapes/polygon.js +1 -1
- package/esm/elements/shapes/polygon.js.map +1 -1
- package/esm/exports.d.ts +3 -2
- package/esm/exports.js +1 -1
- package/esm/exports.js.map +1 -1
- package/esm/index.d.ts +5 -1
- package/esm/index.js +5 -1
- package/esm/index.js.map +1 -1
- package/esm/layouts/base-layout.d.ts +3 -1
- package/esm/layouts/base-layout.js +3 -1
- package/esm/layouts/base-layout.js.map +1 -1
- package/esm/plugins/bubble-sets.d.ts +2 -2
- package/esm/plugins/bubble-sets.js.map +1 -1
- package/esm/plugins/contextmenu/index.d.ts +4 -3
- package/esm/plugins/contextmenu/index.js +12 -10
- package/esm/plugins/contextmenu/index.js.map +1 -1
- package/esm/plugins/hull/index.d.ts +2 -2
- package/esm/plugins/hull/index.js.map +1 -1
- package/esm/runtime/canvas.d.ts +15 -2
- package/esm/runtime/canvas.js.map +1 -1
- package/esm/runtime/data.d.ts +9 -16
- package/esm/runtime/data.js +26 -34
- package/esm/runtime/data.js.map +1 -1
- package/esm/runtime/element.d.ts +18 -2
- package/esm/runtime/element.js +75 -24
- package/esm/runtime/element.js.map +1 -1
- package/esm/runtime/graph.d.ts +374 -109
- package/esm/runtime/graph.js +278 -82
- package/esm/runtime/graph.js.map +1 -1
- package/esm/runtime/layout.js +1 -1
- package/esm/runtime/layout.js.map +1 -1
- package/esm/spec/element/edge.d.ts +1 -1
- package/esm/spec/element/node.d.ts +1 -1
- package/esm/themes/base.js +5 -0
- package/esm/themes/base.js.map +1 -1
- package/esm/transforms/collapse-expand-node.js +14 -4
- package/esm/transforms/collapse-expand-node.js.map +1 -1
- package/esm/transforms/process-parallel-edges.d.ts +2 -2
- package/esm/types/callable.d.ts +0 -11
- package/esm/types/data.d.ts +12 -0
- package/esm/types/edge.d.ts +11 -0
- package/esm/types/element.d.ts +100 -9
- package/esm/types/index.d.ts +0 -1
- package/esm/types/point.d.ts +0 -1
- package/esm/utils/element.d.ts +2 -2
- package/esm/utils/element.js.map +1 -1
- package/esm/utils/layout.d.ts +2 -2
- package/esm/utils/layout.js +4 -4
- package/esm/utils/layout.js.map +1 -1
- package/esm/utils/path.d.ts +3 -3
- package/esm/utils/path.js +1 -1
- package/esm/utils/path.js.map +1 -1
- package/esm/utils/position.d.ts +8 -8
- package/esm/utils/position.js +2 -2
- package/esm/utils/position.js.map +1 -1
- package/esm/utils/style.d.ts +13 -8
- package/esm/utils/style.js +16 -11
- package/esm/utils/style.js.map +1 -1
- package/lib/behaviors/click-select.d.ts +4 -5
- package/lib/behaviors/click-select.js +62 -50
- package/lib/behaviors/click-select.js.map +1 -1
- package/lib/behaviors/drag-element.js +2 -9
- package/lib/behaviors/drag-element.js.map +1 -1
- package/lib/behaviors/hover-activate.d.ts +0 -1
- package/lib/behaviors/hover-activate.js +18 -16
- package/lib/behaviors/hover-activate.js.map +1 -1
- package/lib/behaviors/lasso-select.js.map +1 -1
- package/lib/elements/base-element.d.ts +1 -22
- package/lib/elements/base-element.js +0 -21
- package/lib/elements/base-element.js.map +1 -1
- package/lib/elements/combos/base-combo.d.ts +4 -4
- package/lib/elements/combos/base-combo.js +27 -4
- package/lib/elements/combos/base-combo.js.map +1 -1
- package/lib/elements/edges/base-edge.d.ts +4 -2
- package/lib/elements/edges/base-edge.js +41 -7
- package/lib/elements/edges/base-edge.js.map +1 -1
- package/lib/elements/effect.d.ts +17 -0
- package/lib/elements/effect.js +74 -0
- package/lib/elements/effect.js.map +1 -0
- package/lib/elements/nodes/base-node.d.ts +5 -4
- package/lib/elements/nodes/base-node.js +33 -14
- package/lib/elements/nodes/base-node.js.map +1 -1
- package/lib/elements/nodes/circle.js +1 -1
- package/lib/elements/nodes/circle.js.map +1 -1
- package/lib/elements/nodes/diamond.d.ts +0 -1
- package/lib/elements/nodes/diamond.js +0 -6
- package/lib/elements/nodes/diamond.js.map +1 -1
- package/lib/elements/nodes/ellipse.js +1 -1
- package/lib/elements/nodes/ellipse.js.map +1 -1
- package/lib/elements/nodes/image.js +2 -2
- package/lib/elements/nodes/image.js.map +1 -1
- package/lib/elements/nodes/rect.js +1 -1
- package/lib/elements/nodes/rect.js.map +1 -1
- package/lib/elements/shapes/badge.d.ts +17 -6
- package/lib/elements/shapes/badge.js +9 -0
- package/lib/elements/shapes/badge.js.map +1 -1
- package/lib/elements/shapes/base-shape.d.ts +9 -3
- package/lib/elements/shapes/base-shape.js +33 -15
- package/lib/elements/shapes/base-shape.js.map +1 -1
- package/lib/elements/shapes/icon.d.ts +15 -3
- package/lib/elements/shapes/icon.js +12 -4
- package/lib/elements/shapes/icon.js.map +1 -1
- package/lib/elements/shapes/label.d.ts +18 -7
- package/lib/elements/shapes/label.js +10 -0
- package/lib/elements/shapes/label.js.map +1 -1
- package/lib/elements/shapes/polygon.js +1 -1
- package/lib/elements/shapes/polygon.js.map +1 -1
- package/lib/exports.d.ts +3 -2
- package/lib/exports.js +5 -2
- package/lib/exports.js.map +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.js +6 -2
- package/lib/index.js.map +1 -1
- package/lib/layouts/base-layout.d.ts +3 -1
- package/lib/layouts/base-layout.js +3 -1
- package/lib/layouts/base-layout.js.map +1 -1
- package/lib/plugins/bubble-sets.d.ts +2 -2
- package/lib/plugins/bubble-sets.js.map +1 -1
- package/lib/plugins/contextmenu/index.d.ts +4 -3
- package/lib/plugins/contextmenu/index.js +12 -10
- package/lib/plugins/contextmenu/index.js.map +1 -1
- package/lib/plugins/hull/index.d.ts +2 -2
- package/lib/plugins/hull/index.js.map +1 -1
- package/lib/runtime/canvas.d.ts +15 -2
- package/lib/runtime/canvas.js.map +1 -1
- package/lib/runtime/data.d.ts +9 -16
- package/lib/runtime/data.js +26 -34
- package/lib/runtime/data.js.map +1 -1
- package/lib/runtime/element.d.ts +18 -2
- package/lib/runtime/element.js +75 -24
- package/lib/runtime/element.js.map +1 -1
- package/lib/runtime/graph.d.ts +374 -109
- package/lib/runtime/graph.js +278 -82
- package/lib/runtime/graph.js.map +1 -1
- package/lib/runtime/layout.js +1 -1
- package/lib/runtime/layout.js.map +1 -1
- package/lib/spec/element/edge.d.ts +1 -1
- package/lib/spec/element/node.d.ts +1 -1
- package/lib/themes/base.js +5 -0
- package/lib/themes/base.js.map +1 -1
- package/lib/transforms/collapse-expand-node.js +14 -4
- package/lib/transforms/collapse-expand-node.js.map +1 -1
- package/lib/transforms/process-parallel-edges.d.ts +2 -2
- package/lib/types/callable.d.ts +0 -11
- package/lib/types/data.d.ts +12 -0
- package/lib/types/edge.d.ts +11 -0
- package/lib/types/element.d.ts +100 -9
- package/lib/types/index.d.ts +0 -1
- package/lib/types/point.d.ts +0 -1
- package/lib/utils/element.d.ts +2 -2
- package/lib/utils/element.js.map +1 -1
- package/lib/utils/layout.d.ts +2 -2
- package/lib/utils/layout.js +4 -4
- package/lib/utils/layout.js.map +1 -1
- package/lib/utils/path.d.ts +3 -3
- package/lib/utils/path.js +1 -1
- package/lib/utils/path.js.map +1 -1
- package/lib/utils/position.d.ts +8 -8
- package/lib/utils/position.js +2 -2
- package/lib/utils/position.js.map +1 -1
- package/lib/utils/style.d.ts +13 -8
- package/lib/utils/style.js +18 -13
- package/lib/utils/style.js.map +1 -1
- package/package.json +10 -10
- package/src/behaviors/click-select.ts +61 -60
- package/src/behaviors/drag-element.ts +2 -7
- package/src/behaviors/hover-activate.ts +18 -22
- package/src/behaviors/lasso-select.ts +2 -2
- package/src/elements/base-element.ts +1 -25
- package/src/elements/combos/base-combo.ts +27 -11
- package/src/elements/edges/base-edge.ts +28 -8
- package/src/elements/effect.ts +74 -0
- package/src/elements/nodes/base-node.ts +23 -18
- package/src/elements/nodes/circle.ts +1 -1
- package/src/elements/nodes/diamond.ts +0 -7
- package/src/elements/nodes/ellipse.ts +1 -1
- package/src/elements/nodes/image.ts +2 -2
- package/src/elements/nodes/rect.ts +1 -1
- package/src/elements/shapes/badge.ts +17 -5
- package/src/elements/shapes/base-shape.ts +35 -15
- package/src/elements/shapes/icon.ts +18 -7
- package/src/elements/shapes/label.ts +19 -6
- package/src/elements/shapes/polygon.ts +1 -1
- package/src/exports.ts +6 -2
- package/src/index.ts +6 -2
- package/src/layouts/base-layout.ts +5 -1
- package/src/plugins/bubble-sets.ts +2 -2
- package/src/plugins/contextmenu/index.ts +16 -16
- package/src/plugins/hull/index.ts +2 -2
- package/src/runtime/canvas.ts +15 -10
- package/src/runtime/data.ts +32 -44
- package/src/runtime/element.ts +87 -30
- package/src/runtime/graph.ts +405 -132
- package/src/runtime/layout.ts +2 -2
- package/src/spec/element/edge.ts +1 -1
- package/src/spec/element/node.ts +1 -1
- package/src/themes/base.ts +5 -0
- package/src/transforms/collapse-expand-node.ts +13 -4
- package/src/transforms/process-parallel-edges.ts +2 -2
- package/src/types/callable.ts +0 -12
- package/src/types/data.ts +13 -0
- package/src/types/edge.ts +11 -0
- package/src/types/element.ts +106 -10
- package/src/types/index.ts +0 -1
- package/src/types/point.ts +0 -1
- package/src/utils/element.ts +3 -13
- package/src/utils/layout.ts +6 -6
- package/src/utils/path.ts +3 -3
- package/src/utils/position.ts +8 -8
- package/src/utils/style.ts +19 -12
- package/dist/lib/types/position.d.ts +0 -2
- package/esm/types/position.d.ts +0 -2
- package/esm/types/position.js +0 -2
- package/esm/types/position.js.map +0 -1
- package/lib/types/position.d.ts +0 -2
- package/lib/types/position.js +0 -3
- package/lib/types/position.js.map +0 -1
- package/src/types/position.ts +0 -3
package/src/runtime/graph.ts
CHANGED
|
@@ -23,12 +23,12 @@ import type { UpdateBehaviorOption } from '../spec/behavior';
|
|
|
23
23
|
import type { UpdatePluginOption } from '../spec/plugin';
|
|
24
24
|
import type { UpdateTransformOption } from '../spec/transform';
|
|
25
25
|
import type {
|
|
26
|
-
CallableValue,
|
|
27
26
|
DataID,
|
|
28
27
|
EdgeDirection,
|
|
29
28
|
ElementDatum,
|
|
30
29
|
ElementType,
|
|
31
30
|
FitViewOptions,
|
|
31
|
+
HierarchyKey,
|
|
32
32
|
ID,
|
|
33
33
|
IEvent,
|
|
34
34
|
NodeLikeData,
|
|
@@ -36,7 +36,6 @@ import type {
|
|
|
36
36
|
PartialGraphData,
|
|
37
37
|
PartialNodeLikeData,
|
|
38
38
|
Point,
|
|
39
|
-
Position,
|
|
40
39
|
State,
|
|
41
40
|
Vector2,
|
|
42
41
|
ViewportAnimationEffectTiming,
|
|
@@ -46,14 +45,12 @@ import { sizeOf } from '../utils/dom';
|
|
|
46
45
|
import { GraphLifeCycleEvent, emit } from '../utils/event';
|
|
47
46
|
import { idOf } from '../utils/id';
|
|
48
47
|
import { parsePoint, toPointObject } from '../utils/point';
|
|
49
|
-
import { zIndexOf } from '../utils/style';
|
|
50
48
|
import { subtract } from '../utils/vector';
|
|
51
49
|
import { Animation } from './animation';
|
|
52
50
|
import { BatchController } from './batch';
|
|
53
51
|
import { BehaviorController } from './behavior';
|
|
54
52
|
import type { DataURLOptions } from './canvas';
|
|
55
53
|
import { Canvas } from './canvas';
|
|
56
|
-
import type { HierarchyKey } from './data';
|
|
57
54
|
import { DataController } from './data';
|
|
58
55
|
import { ElementController } from './element';
|
|
59
56
|
import { LayoutController } from './layout';
|
|
@@ -164,7 +161,7 @@ export class Graph extends EventEmitter {
|
|
|
164
161
|
}
|
|
165
162
|
|
|
166
163
|
/**
|
|
167
|
-
* <zh/>
|
|
164
|
+
* <zh/> 获取当前画布容器的尺寸
|
|
168
165
|
*
|
|
169
166
|
* <en/> Get the size of the current canvas container
|
|
170
167
|
* @returns <zh/> 画布尺寸 | <en/> canvas size
|
|
@@ -176,7 +173,7 @@ export class Graph extends EventEmitter {
|
|
|
176
173
|
}
|
|
177
174
|
|
|
178
175
|
/**
|
|
179
|
-
* <zh/>
|
|
176
|
+
* <zh/> 获取当前画布容器的尺寸
|
|
180
177
|
*
|
|
181
178
|
* <en/> Get the size of the current canvas container
|
|
182
179
|
* @param width - <zh/> 画布宽度 | <en/> canvas width
|
|
@@ -189,7 +186,7 @@ export class Graph extends EventEmitter {
|
|
|
189
186
|
}
|
|
190
187
|
|
|
191
188
|
/**
|
|
192
|
-
* <zh/>
|
|
189
|
+
* <zh/> 设置当前图的缩放区间
|
|
193
190
|
*
|
|
194
191
|
* <en/> Get the zoom range of the current graph
|
|
195
192
|
* @param zoomRange - <zh/> 缩放区间 | <en/> zoom range
|
|
@@ -214,7 +211,11 @@ export class Graph extends EventEmitter {
|
|
|
214
211
|
* <zh/> 设置节点样式映射
|
|
215
212
|
*
|
|
216
213
|
* <en/> Set node mapper
|
|
217
|
-
* @param node - <zh/> 节点配置 | <en/> node
|
|
214
|
+
* @param node - <zh/> 节点配置 | <en/> node options
|
|
215
|
+
* @remarks
|
|
216
|
+
* <zh/> 即 `options.node` 的值
|
|
217
|
+
*
|
|
218
|
+
* <en/> The value of `options.node`
|
|
218
219
|
* @apiCategory element
|
|
219
220
|
*/
|
|
220
221
|
public setNode(node: NodeOptions): void {
|
|
@@ -226,7 +227,11 @@ export class Graph extends EventEmitter {
|
|
|
226
227
|
* <zh/> 设置边样式映射
|
|
227
228
|
*
|
|
228
229
|
* <en/> Set edge mapper
|
|
229
|
-
* @param edge - <zh/> 边配置 | <en/> edge
|
|
230
|
+
* @param edge - <zh/> 边配置 | <en/> edge options
|
|
231
|
+
* @remarks
|
|
232
|
+
* <zh/> 即 `options.edge` 的值
|
|
233
|
+
*
|
|
234
|
+
* <en/> The value of `options.edge`
|
|
230
235
|
* @apiCategory element
|
|
231
236
|
*/
|
|
232
237
|
public setEdge(edge: EdgeOptions): void {
|
|
@@ -238,7 +243,11 @@ export class Graph extends EventEmitter {
|
|
|
238
243
|
* <zh/> 设置组合样式映射
|
|
239
244
|
*
|
|
240
245
|
* <en/> Set combo mapper
|
|
241
|
-
* @param combo - <zh/> 组合配置 | <en/> combo
|
|
246
|
+
* @param combo - <zh/> 组合配置 | <en/> combo options
|
|
247
|
+
* @remarks
|
|
248
|
+
* <zh/> 即 `options.combo` 的值
|
|
249
|
+
*
|
|
250
|
+
* <en/> The value of `options.combo`
|
|
242
251
|
* @apiCategory element
|
|
243
252
|
*/
|
|
244
253
|
public setCombo(combo: ComboOptions): void {
|
|
@@ -250,7 +259,7 @@ export class Graph extends EventEmitter {
|
|
|
250
259
|
* <zh/> 获取主题
|
|
251
260
|
*
|
|
252
261
|
* <en/> Get theme
|
|
253
|
-
* @returns <zh/>
|
|
262
|
+
* @returns <zh/> 当前主题 | <en/> current theme
|
|
254
263
|
* @apiCategory theme
|
|
255
264
|
*/
|
|
256
265
|
public getTheme(): ThemeOptions {
|
|
@@ -261,10 +270,14 @@ export class Graph extends EventEmitter {
|
|
|
261
270
|
* <zh/> 设置主题
|
|
262
271
|
*
|
|
263
272
|
* <en/> Set theme
|
|
264
|
-
* @param theme - <zh/>
|
|
273
|
+
* @param theme - <zh/> 主题名 | <en/> theme name
|
|
274
|
+
* @example
|
|
275
|
+
* ```ts
|
|
276
|
+
* graph.setTheme('dark');
|
|
277
|
+
* ```
|
|
265
278
|
* @apiCategory theme
|
|
266
279
|
*/
|
|
267
|
-
public setTheme(theme:
|
|
280
|
+
public setTheme(theme: ThemeOptions | ((prev: ThemeOptions) => ThemeOptions)): void {
|
|
268
281
|
this.options.theme = isFunction(theme) ? theme(this.getTheme()) : theme;
|
|
269
282
|
|
|
270
283
|
const { background } = getExtension('theme', this.options.theme) || {};
|
|
@@ -277,18 +290,24 @@ export class Graph extends EventEmitter {
|
|
|
277
290
|
* <zh/> 设置布局
|
|
278
291
|
*
|
|
279
292
|
* <en/> Set layout
|
|
280
|
-
* @param layout - <zh/> 布局配置 | <en/> layout
|
|
293
|
+
* @param layout - <zh/> 布局配置 | <en/> layout options
|
|
294
|
+
* @example
|
|
295
|
+
* ```ts
|
|
296
|
+
* graph.setLayout({
|
|
297
|
+
* type: 'dagre',
|
|
298
|
+
* })
|
|
299
|
+
* ```
|
|
281
300
|
* @apiCategory layout
|
|
282
301
|
*/
|
|
283
|
-
public setLayout(layout:
|
|
302
|
+
public setLayout(layout: LayoutOptions | ((prev: LayoutOptions) => LayoutOptions)): void {
|
|
284
303
|
this.options.layout = isFunction(layout) ? layout(this.getLayout()) : layout;
|
|
285
304
|
}
|
|
286
305
|
|
|
287
306
|
/**
|
|
288
|
-
* <zh/>
|
|
307
|
+
* <zh/> 获取布局配置
|
|
289
308
|
*
|
|
290
|
-
* <en/> Get layout
|
|
291
|
-
* @returns <zh/> 布局配置 | <en/> layout
|
|
309
|
+
* <en/> Get layout options
|
|
310
|
+
* @returns <zh/> 布局配置 | <en/> layout options
|
|
292
311
|
* @apiCategory layout
|
|
293
312
|
*/
|
|
294
313
|
public getLayout(): LayoutOptions {
|
|
@@ -299,19 +318,38 @@ export class Graph extends EventEmitter {
|
|
|
299
318
|
* <zh/> 设置交互
|
|
300
319
|
*
|
|
301
320
|
* <en/> Set behaviors
|
|
302
|
-
* @param behaviors - <zh/> 交互配置 | <en/> behavior
|
|
321
|
+
* @param behaviors - <zh/> 交互配置 | <en/> behavior options
|
|
322
|
+
* @remarks
|
|
323
|
+
* <zh/> 设置的交互会全量替换原有的交互,如果需要新增交互可以使用如下方式:
|
|
324
|
+
*
|
|
325
|
+
* <en/> The set behavior will completely replace the original behavior. If you need to add behavior, you can use the following method:
|
|
326
|
+
*
|
|
327
|
+
* ```ts
|
|
328
|
+
* graph.setBehaviors((behaviors) => [...behaviors, { type: 'zoom-canvas' }])
|
|
329
|
+
* ```
|
|
303
330
|
* @apiCategory behavior
|
|
304
331
|
*/
|
|
305
|
-
public setBehaviors(behaviors:
|
|
332
|
+
public setBehaviors(behaviors: BehaviorOptions | ((prev: BehaviorOptions) => BehaviorOptions)): void {
|
|
306
333
|
this.options.behaviors = isFunction(behaviors) ? behaviors(this.getBehaviors()) : behaviors;
|
|
307
334
|
this.context.behavior?.setBehaviors(this.options.behaviors);
|
|
308
335
|
}
|
|
309
336
|
|
|
310
337
|
/**
|
|
311
|
-
* <zh/>
|
|
338
|
+
* <zh/> 更新指定的交互配置
|
|
339
|
+
*
|
|
340
|
+
* <en/> Update specified behavior options
|
|
341
|
+
* @param behavior - <zh/> 交互配置 | <en/> behavior options
|
|
342
|
+
* @remarks
|
|
343
|
+
* <zh/> 如果要更新一个交互,那么必须在交互配置中指定 key 字段,例如:
|
|
344
|
+
*
|
|
345
|
+
* <en/> If you want to update a behavior, you must specify the key field in the behavior options, for example:
|
|
346
|
+
* ```ts
|
|
347
|
+
* {
|
|
348
|
+
* behaviors: [{ type: 'zoom-canvas', key: 'zoom-canvas' }]
|
|
349
|
+
* }
|
|
312
350
|
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
351
|
+
* graph.updateBehavior({ key: 'zoom-canvas', enable: false })
|
|
352
|
+
* ```
|
|
315
353
|
* @apiCategory behavior
|
|
316
354
|
*/
|
|
317
355
|
public updateBehavior(behavior: UpdateBehaviorOption): void {
|
|
@@ -326,10 +364,10 @@ export class Graph extends EventEmitter {
|
|
|
326
364
|
}
|
|
327
365
|
|
|
328
366
|
/**
|
|
329
|
-
* <zh/>
|
|
367
|
+
* <zh/> 获取交互配置
|
|
330
368
|
*
|
|
331
|
-
* <en/> Get behaviors
|
|
332
|
-
* @returns <zh/> 交互配置 | <en/> behavior
|
|
369
|
+
* <en/> Get behaviors options
|
|
370
|
+
* @returns <zh/> 交互配置 | <en/> behavior options
|
|
333
371
|
* @apiCategory behavior
|
|
334
372
|
*/
|
|
335
373
|
public getBehaviors(): BehaviorOptions {
|
|
@@ -337,22 +375,40 @@ export class Graph extends EventEmitter {
|
|
|
337
375
|
}
|
|
338
376
|
|
|
339
377
|
/**
|
|
340
|
-
* <zh/>
|
|
378
|
+
* <zh/> 设置插件配置
|
|
379
|
+
*
|
|
380
|
+
* <en/> Set plugins options
|
|
381
|
+
* @param plugins - <zh/> 插件配置 | <en/> plugin options
|
|
382
|
+
* @remarks
|
|
383
|
+
* <zh/> 设置的插件会全量替换原有的插件配置,如果需要新增插件可以使用如下方式:
|
|
341
384
|
*
|
|
342
|
-
* <en/>
|
|
343
|
-
*
|
|
385
|
+
* <en/> The set plugin will completely replace the original plugin configuration. If you need to add a plugin, you can use the following method:
|
|
386
|
+
* ```ts
|
|
387
|
+
* graph.setPlugins((plugins) => [...plugins, { key: 'grid-line' }])
|
|
388
|
+
* ```
|
|
344
389
|
* @apiCategory plugin
|
|
345
390
|
*/
|
|
346
|
-
public setPlugins(plugins:
|
|
391
|
+
public setPlugins(plugins: PluginOptions | ((prev: PluginOptions) => PluginOptions)): void {
|
|
347
392
|
this.options.plugins = isFunction(plugins) ? plugins(this.getPlugins()) : plugins;
|
|
348
393
|
this.context.plugin?.setPlugins(this.options.plugins);
|
|
349
394
|
}
|
|
350
395
|
|
|
351
396
|
/**
|
|
352
|
-
* <zh/>
|
|
397
|
+
* <zh/> 更新插件配置
|
|
398
|
+
*
|
|
399
|
+
* <en/> Update plugin options
|
|
400
|
+
* @param plugin - <zh/> 插件配置 | <en/> plugin options
|
|
401
|
+
* @remarks
|
|
402
|
+
* <zh/> 如果要更新一个插件,那么必须在插件配置中指定 key 字段,例如:
|
|
353
403
|
*
|
|
354
|
-
* <en/>
|
|
355
|
-
*
|
|
404
|
+
* <en/> If you want to update a plugin, you must specify the key field in the plugin options, for example:
|
|
405
|
+
* ```ts
|
|
406
|
+
* {
|
|
407
|
+
* plugins: [{ key: 'grid-line' }]
|
|
408
|
+
* }
|
|
409
|
+
*
|
|
410
|
+
* graph.updatePlugin({ key: 'grid-line', follow: true })
|
|
411
|
+
* ```
|
|
356
412
|
* @apiCategory plugin
|
|
357
413
|
*/
|
|
358
414
|
public updatePlugin(plugin: UpdatePluginOption): void {
|
|
@@ -367,10 +423,10 @@ export class Graph extends EventEmitter {
|
|
|
367
423
|
}
|
|
368
424
|
|
|
369
425
|
/**
|
|
370
|
-
* <zh/>
|
|
426
|
+
* <zh/> 获取插件配置
|
|
371
427
|
*
|
|
372
|
-
* <en/> Get plugins
|
|
373
|
-
* @returns <zh/> 插件配置 | <en/> plugin
|
|
428
|
+
* <en/> Get plugins options
|
|
429
|
+
* @returns <zh/> 插件配置 | <en/> plugin options
|
|
374
430
|
* @apiCategory plugin
|
|
375
431
|
*/
|
|
376
432
|
public getPlugins(): PluginOptions {
|
|
@@ -383,6 +439,17 @@ export class Graph extends EventEmitter {
|
|
|
383
439
|
* <en/> Get plugin instance
|
|
384
440
|
* @param key - <zh/> 插件 key | <en/> plugin key
|
|
385
441
|
* @returns <zh/> 插件实例 | <en/> plugin instance
|
|
442
|
+
* @remarks
|
|
443
|
+
* <zh/> 一些插件提供了 API 方法可供调用,例如全屏插件可以调用 `request` 和 `exit` 方法来请求和退出全屏
|
|
444
|
+
*
|
|
445
|
+
* <en/> Some plugins provide API methods for calling, such as the full-screen plugin can call the `request` and `exit` methods to request and exit full-screen
|
|
446
|
+
* ```ts
|
|
447
|
+
* const fullscreen = graph.getPluginInstance('fullscreen');
|
|
448
|
+
*
|
|
449
|
+
* fullscreen.request();
|
|
450
|
+
*
|
|
451
|
+
* fullscreen.exit();
|
|
452
|
+
* ```
|
|
386
453
|
* @apiCategory plugin
|
|
387
454
|
*/
|
|
388
455
|
public getPluginInstance<T extends Plugin>(key: string) {
|
|
@@ -393,10 +460,14 @@ export class Graph extends EventEmitter {
|
|
|
393
460
|
* <zh/> 设置数据转换器
|
|
394
461
|
*
|
|
395
462
|
* <en/> Set data transforms
|
|
396
|
-
* @param transforms - <zh/> 数据转换配置 | <en/> data transform
|
|
463
|
+
* @param transforms - <zh/> 数据转换配置 | <en/> data transform options
|
|
464
|
+
* @remarks
|
|
465
|
+
* <zh/> 数据转换器能够在图渲染过程中执行数据转换,目前支持在渲染前对绘制数据进行转化。
|
|
466
|
+
*
|
|
467
|
+
* <en/> Data transforms can perform data transformation during the rendering process of the graph. Currently, it supports transforming the drawing data before rendering.
|
|
397
468
|
* @apiCategory transform
|
|
398
469
|
*/
|
|
399
|
-
public setTransforms(transforms:
|
|
470
|
+
public setTransforms(transforms: TransformOptions | ((prev: TransformOptions) => TransformOptions)): void {
|
|
400
471
|
this.options.transforms = isFunction(transforms) ? transforms(this.getTransforms()) : transforms;
|
|
401
472
|
this.context.transform?.setTransforms(this.options.transforms);
|
|
402
473
|
}
|
|
@@ -405,7 +476,7 @@ export class Graph extends EventEmitter {
|
|
|
405
476
|
* <zh/> 更新数据转换器
|
|
406
477
|
*
|
|
407
478
|
* <en/> Update data transform
|
|
408
|
-
* @param transform - <zh/>
|
|
479
|
+
* @param transform - <zh/> 数据转换器配置 | <en/> data transform options
|
|
409
480
|
* @apiCategory transform
|
|
410
481
|
*/
|
|
411
482
|
public updateTransform(transform: UpdateTransformOption): void {
|
|
@@ -421,10 +492,10 @@ export class Graph extends EventEmitter {
|
|
|
421
492
|
}
|
|
422
493
|
|
|
423
494
|
/**
|
|
424
|
-
* <zh/>
|
|
495
|
+
* <zh/> 获取数据转换器配置
|
|
425
496
|
*
|
|
426
|
-
* <en/> Get data transforms
|
|
427
|
-
* @returns <zh/>
|
|
497
|
+
* <en/> Get data transforms options
|
|
498
|
+
* @returns <zh/> 数据转换配置 | <en/> data transform options
|
|
428
499
|
* @apiCategory transform
|
|
429
500
|
*/
|
|
430
501
|
public getTransforms(): TransformOptions {
|
|
@@ -432,10 +503,13 @@ export class Graph extends EventEmitter {
|
|
|
432
503
|
}
|
|
433
504
|
|
|
434
505
|
/**
|
|
435
|
-
* <zh/>
|
|
506
|
+
* <zh/> 获取图数据
|
|
507
|
+
*
|
|
508
|
+
* <en/> Get graph data
|
|
509
|
+
* @returns <zh/> 图数据 | <en/> Graph data
|
|
510
|
+
* <zh/> 获取当前图的数据,包括节点、边、组合数据
|
|
436
511
|
*
|
|
437
|
-
* <en/> Get data
|
|
438
|
-
* @returns <zh/> 数据 | <en/> data
|
|
512
|
+
* <en/> Get the data of the current graph, including node, edge, and combo data
|
|
439
513
|
* @apiCategory data
|
|
440
514
|
*/
|
|
441
515
|
public getData(): GraphData {
|
|
@@ -448,6 +522,10 @@ export class Graph extends EventEmitter {
|
|
|
448
522
|
* <en/> Get element data by ID
|
|
449
523
|
* @param id - <zh/> 元素 ID | <en/> element ID
|
|
450
524
|
* @returns <zh/> 元素数据 | <en/> element data
|
|
525
|
+
* @remarks
|
|
526
|
+
* <zh/> 直接获取元素的数据而不必考虑元素类型
|
|
527
|
+
*
|
|
528
|
+
* <en/> Get element data directly without considering the element type
|
|
451
529
|
* @apiCategory data
|
|
452
530
|
*/
|
|
453
531
|
public getElementData(id: ID): ElementDatum;
|
|
@@ -456,6 +534,10 @@ export class Graph extends EventEmitter {
|
|
|
456
534
|
*
|
|
457
535
|
* <en/> Get multiple element data in batch
|
|
458
536
|
* @param ids - <zh/> 元素 ID 数组 | <en/> element ID array
|
|
537
|
+
* @remarks
|
|
538
|
+
* <zh/> 直接获取元素的数据而不必考虑元素类型
|
|
539
|
+
*
|
|
540
|
+
* <en/> Get element data directly without considering the element type
|
|
459
541
|
* @apiCategory data
|
|
460
542
|
*/
|
|
461
543
|
public getElementData(ids: ID[]): ElementDatum[];
|
|
@@ -478,6 +560,10 @@ export class Graph extends EventEmitter {
|
|
|
478
560
|
* <en/> Get single node data
|
|
479
561
|
* @param id - <zh/> 节点 ID | <en/> node ID
|
|
480
562
|
* @returns <zh/> 节点数据 | <en/> node data
|
|
563
|
+
* @example
|
|
564
|
+
* ```ts
|
|
565
|
+
* const node1 = graph.getNodeData('node-1');
|
|
566
|
+
* ```
|
|
481
567
|
* @apiCategory data
|
|
482
568
|
*/
|
|
483
569
|
public getNodeData(id: ID): NodeData;
|
|
@@ -487,6 +573,10 @@ export class Graph extends EventEmitter {
|
|
|
487
573
|
* <en/> Get multiple node data in batch
|
|
488
574
|
* @param ids - <zh/> 节点 ID 数组 | <en/> node ID array
|
|
489
575
|
* @returns <zh/> 节点数据 | <en/> node data
|
|
576
|
+
* @example
|
|
577
|
+
* ```ts
|
|
578
|
+
* const [node1, node2] = graph.getNodeData(['node-1', 'node-2']);
|
|
579
|
+
* ```
|
|
490
580
|
* @apiCategory data
|
|
491
581
|
*/
|
|
492
582
|
public getNodeData(ids: ID[]): NodeData[];
|
|
@@ -510,6 +600,10 @@ export class Graph extends EventEmitter {
|
|
|
510
600
|
* <en/> Get single edge data
|
|
511
601
|
* @param id - <zh/> 边 ID | <en/> edge ID
|
|
512
602
|
* @returns <zh/> 边数据 | <en/> edge data
|
|
603
|
+
* @example
|
|
604
|
+
* ```ts
|
|
605
|
+
* const edge1 = graph.getEdgeData('edge-1');
|
|
606
|
+
* ```
|
|
513
607
|
* @apiCategory data
|
|
514
608
|
*/
|
|
515
609
|
public getEdgeData(id: ID): EdgeData;
|
|
@@ -519,6 +613,10 @@ export class Graph extends EventEmitter {
|
|
|
519
613
|
* <en/> Get multiple edge data in batch
|
|
520
614
|
* @param ids - <zh/> 边 ID 数组 | <en/> edge ID array
|
|
521
615
|
* @returns <zh/> 边数据 | <en/> edge data
|
|
616
|
+
* @example
|
|
617
|
+
* ```ts
|
|
618
|
+
* const [edge1, edge2] = graph.getEdgeData(['edge-1', 'edge-2']);
|
|
619
|
+
* ```
|
|
522
620
|
* @apiCategory data
|
|
523
621
|
*/
|
|
524
622
|
public getEdgeData(ids: ID[]): EdgeData[];
|
|
@@ -542,6 +640,10 @@ export class Graph extends EventEmitter {
|
|
|
542
640
|
* <en/> Get single combo data
|
|
543
641
|
* @param id - <zh/> 组合ID | <en/> combo ID
|
|
544
642
|
* @returns <zh/> 组合数据 | <en/> combo data
|
|
643
|
+
* @example
|
|
644
|
+
* ```ts
|
|
645
|
+
* const combo1 = graph.getComboData('combo-1');
|
|
646
|
+
* ```
|
|
545
647
|
* @apiCategory data
|
|
546
648
|
*/
|
|
547
649
|
public getComboData(id: ID): ComboData;
|
|
@@ -551,6 +653,10 @@ export class Graph extends EventEmitter {
|
|
|
551
653
|
* <en/> Get multiple combo data in batch
|
|
552
654
|
* @param ids - <zh/> 组合ID 数组 | <en/> combo ID array
|
|
553
655
|
* @returns <zh/> 组合数据 | <en/> combo data
|
|
656
|
+
* @example
|
|
657
|
+
* ```ts
|
|
658
|
+
* const [combo1, combo2] = graph.getComboData(['combo-1', 'combo-2']);
|
|
659
|
+
* ```
|
|
554
660
|
* @apiCategory data
|
|
555
661
|
*/
|
|
556
662
|
public getComboData(ids: ID[]): ComboData[];
|
|
@@ -565,9 +671,13 @@ export class Graph extends EventEmitter {
|
|
|
565
671
|
*
|
|
566
672
|
* <en/> Set full data
|
|
567
673
|
* @param data - <zh/> 数据 | <en/> data
|
|
674
|
+
* @remarks
|
|
675
|
+
* <zh/> 设置全量数据会替换当前图中的所有数据,G6 会自动进行数据差异计算
|
|
676
|
+
*
|
|
677
|
+
* <en/> Setting full data will replace all data in the current graph, and G6 will automatically calculate the data difference
|
|
568
678
|
* @apiCategory data
|
|
569
679
|
*/
|
|
570
|
-
public setData(data:
|
|
680
|
+
public setData(data: GraphData | ((prev: GraphData) => GraphData)): void {
|
|
571
681
|
this.context.model.setData(isFunction(data) ? data(this.getData()) : data);
|
|
572
682
|
}
|
|
573
683
|
|
|
@@ -576,9 +686,16 @@ export class Graph extends EventEmitter {
|
|
|
576
686
|
*
|
|
577
687
|
* <en/> Add element data
|
|
578
688
|
* @param data - <zh/> 元素数据 | <en/> element data
|
|
689
|
+
* @example
|
|
690
|
+
* ```ts
|
|
691
|
+
* graph.addData({
|
|
692
|
+
* nodes: [{ id: 'node-1' }, { id: 'node-2' }],
|
|
693
|
+
* edges: [{ source: 'node-1', target: 'node-2' }],
|
|
694
|
+
* });
|
|
695
|
+
* ```
|
|
579
696
|
* @apiCategory data
|
|
580
697
|
*/
|
|
581
|
-
public addData(data:
|
|
698
|
+
public addData(data: GraphData | ((prev: GraphData) => GraphData)): void {
|
|
582
699
|
this.context.model.addData(isFunction(data) ? data(this.getData()) : data);
|
|
583
700
|
}
|
|
584
701
|
|
|
@@ -587,9 +704,13 @@ export class Graph extends EventEmitter {
|
|
|
587
704
|
*
|
|
588
705
|
* <en/> Add node data
|
|
589
706
|
* @param data - <zh/> 节点数据 | <en/> node data
|
|
707
|
+
* @example
|
|
708
|
+
* ```ts
|
|
709
|
+
* graph.addNodeData([{ id: 'node-1' }, { id: 'node-2' }]);
|
|
710
|
+
* ```
|
|
590
711
|
* @apiCategory data
|
|
591
712
|
*/
|
|
592
|
-
public addNodeData(data:
|
|
713
|
+
public addNodeData(data: NodeData[] | ((prev: NodeData[]) => NodeData[])): void {
|
|
593
714
|
this.context.model.addNodeData(isFunction(data) ? data(this.getNodeData()) : data);
|
|
594
715
|
}
|
|
595
716
|
|
|
@@ -598,9 +719,13 @@ export class Graph extends EventEmitter {
|
|
|
598
719
|
*
|
|
599
720
|
* <en/> Add edge data
|
|
600
721
|
* @param data - <zh/> 边数据 | <en/> edge data
|
|
722
|
+
* @example
|
|
723
|
+
* ```ts
|
|
724
|
+
* graph.addEdgeData([{ source: 'node-1', target: 'node-2' }]);
|
|
725
|
+
* ```
|
|
601
726
|
* @apiCategory data
|
|
602
727
|
*/
|
|
603
|
-
public addEdgeData(data:
|
|
728
|
+
public addEdgeData(data: EdgeData[] | ((prev: EdgeData[]) => EdgeData[])): void {
|
|
604
729
|
this.context.model.addEdgeData(isFunction(data) ? data(this.getEdgeData()) : data);
|
|
605
730
|
}
|
|
606
731
|
|
|
@@ -609,20 +734,51 @@ export class Graph extends EventEmitter {
|
|
|
609
734
|
*
|
|
610
735
|
* <en/> Add combo data
|
|
611
736
|
* @param data - <zh/> 组合数据 | <en/> combo data
|
|
737
|
+
* @example
|
|
738
|
+
* ```ts
|
|
739
|
+
* graph.addComboData([{ id: 'combo-1' }]);
|
|
740
|
+
* ```
|
|
612
741
|
* @apiCategory data
|
|
613
742
|
*/
|
|
614
|
-
public addComboData(data:
|
|
743
|
+
public addComboData(data: ComboData[] | ((prev: ComboData[]) => ComboData[])): void {
|
|
615
744
|
this.context.model.addComboData(isFunction(data) ? data(this.getComboData()) : data);
|
|
616
745
|
}
|
|
617
746
|
|
|
747
|
+
/**
|
|
748
|
+
* <zh/> 为树图节点添加子节点数据
|
|
749
|
+
*
|
|
750
|
+
* <en/> Add child node data to the tree node
|
|
751
|
+
* @param parentId - <zh/> 父节点 ID | <en/> parent node ID
|
|
752
|
+
* @param childrenData - <zh/> 子节点数据 | <en/> child node data
|
|
753
|
+
* @remarks
|
|
754
|
+
* <zh/> 为组合添加子节点使用 addNodeData / addComboData 方法
|
|
755
|
+
*
|
|
756
|
+
* <en/> Use addNodeData / addComboData method to add child nodes to the combo
|
|
757
|
+
* @apiCategory data
|
|
758
|
+
*/
|
|
759
|
+
public addChildrenData(parentId: ID, childrenData: NodeData[]) {
|
|
760
|
+
this.context.model.addChildrenData(parentId, childrenData);
|
|
761
|
+
}
|
|
762
|
+
|
|
618
763
|
/**
|
|
619
764
|
* <zh/> 更新元素数据
|
|
620
765
|
*
|
|
621
766
|
* <en/> Update element data
|
|
622
767
|
* @param data - <zh/> 元素数据 | <en/> element data
|
|
768
|
+
* @remarks
|
|
769
|
+
* <zh/> 只需要传入需要更新的数据即可,不必传入完整的数据
|
|
770
|
+
*
|
|
771
|
+
* <en/> Just pass in the data that needs to be updated, no need to pass in the complete data
|
|
772
|
+
* @example
|
|
773
|
+
* ```ts
|
|
774
|
+
* graph.updateData({
|
|
775
|
+
* nodes: [{ id: 'node-1', style: { x: 100, y: 100 } }],
|
|
776
|
+
* edges: [{ id: 'edge-1', style: { lineWidth: 2 } }]
|
|
777
|
+
* });
|
|
778
|
+
* ```
|
|
623
779
|
* @apiCategory data
|
|
624
780
|
*/
|
|
625
|
-
public updateData(data:
|
|
781
|
+
public updateData(data: PartialGraphData | ((prev: GraphData) => PartialGraphData)): void {
|
|
626
782
|
this.context.model.updateData(isFunction(data) ? data(this.getData()) : data);
|
|
627
783
|
}
|
|
628
784
|
|
|
@@ -631,9 +787,19 @@ export class Graph extends EventEmitter {
|
|
|
631
787
|
*
|
|
632
788
|
* <en/> Update node data
|
|
633
789
|
* @param data - <zh/> 节点数据 | <en/> node data
|
|
790
|
+
* @remarks
|
|
791
|
+
* <zh/> 只需要传入需要更新的数据即可,不必传入完整的数据
|
|
792
|
+
*
|
|
793
|
+
* <en/> Just pass in the data that needs to be updated, no need to pass in the complete data
|
|
794
|
+
* @example
|
|
795
|
+
* ```ts
|
|
796
|
+
* graph.updateNodeData([{ id: 'node-1', style: { x: 100, y: 100 } }]);
|
|
797
|
+
* ```
|
|
634
798
|
* @apiCategory data
|
|
635
799
|
*/
|
|
636
|
-
public updateNodeData(
|
|
800
|
+
public updateNodeData(
|
|
801
|
+
data: PartialNodeLikeData<NodeData>[] | ((prev: NodeData[]) => PartialNodeLikeData<NodeData>[]),
|
|
802
|
+
): void {
|
|
637
803
|
this.context.model.updateNodeData(isFunction(data) ? data(this.getNodeData()) : data);
|
|
638
804
|
}
|
|
639
805
|
|
|
@@ -642,9 +808,17 @@ export class Graph extends EventEmitter {
|
|
|
642
808
|
*
|
|
643
809
|
* <en/> Update edge data
|
|
644
810
|
* @param data - <zh/> 边数据 | <en/> edge data
|
|
811
|
+
* @remarks
|
|
812
|
+
* <zh/> 只需要传入需要更新的数据即可,不必传入完整的数据
|
|
813
|
+
*
|
|
814
|
+
* <en/> Just pass in the data that needs to be updated, no need to pass in the complete data
|
|
815
|
+
* @example
|
|
816
|
+
* ```ts
|
|
817
|
+
* graph.updateEdgeData([{ id: 'edge-1', style: { lineWidth: 2 } }]);
|
|
818
|
+
* ```
|
|
645
819
|
* @apiCategory data
|
|
646
820
|
*/
|
|
647
|
-
public updateEdgeData(data:
|
|
821
|
+
public updateEdgeData(data: PartialEdgeData<EdgeData>[] | ((prev: EdgeData[]) => PartialEdgeData<EdgeData>[])): void {
|
|
648
822
|
this.context.model.updateEdgeData(isFunction(data) ? data(this.getEdgeData()) : data);
|
|
649
823
|
}
|
|
650
824
|
|
|
@@ -653,17 +827,34 @@ export class Graph extends EventEmitter {
|
|
|
653
827
|
*
|
|
654
828
|
* <en/> Update combo data
|
|
655
829
|
* @param data - <zh/> 组合数据 | <en/> combo data
|
|
830
|
+
* @remarks
|
|
831
|
+
* <zh/> 只需要传入需要更新的数据即可,不必传入完整的数据
|
|
832
|
+
*
|
|
833
|
+
* <en/> Just pass in the data that needs to be updated, no need to pass in the complete data
|
|
834
|
+
* @example
|
|
835
|
+
* ```ts
|
|
836
|
+
* graph.updateComboData([{ id: 'combo-1', style: { x: 100, y: 100 } }]);
|
|
837
|
+
* ```
|
|
656
838
|
* @apiCategory data
|
|
657
839
|
*/
|
|
658
|
-
public updateComboData(
|
|
840
|
+
public updateComboData(
|
|
841
|
+
data: PartialNodeLikeData<ComboData>[] | ((prev: ComboData[]) => PartialNodeLikeData<ComboData>[]),
|
|
842
|
+
): void {
|
|
659
843
|
this.context.model.updateComboData(isFunction(data) ? data(this.getComboData()) : data);
|
|
660
844
|
}
|
|
661
845
|
|
|
662
846
|
/**
|
|
663
|
-
* <zh/>
|
|
847
|
+
* <zh/> 删除元素数据
|
|
664
848
|
*
|
|
665
|
-
* <en/> Remove
|
|
849
|
+
* <en/> Remove element data
|
|
666
850
|
* @param ids - <zh/> 元素 ID 数组 | <en/> element ID array
|
|
851
|
+
* @example
|
|
852
|
+
* ```ts
|
|
853
|
+
* graph.removeData({
|
|
854
|
+
* nodes: ['node-1', 'node-2'],
|
|
855
|
+
* edges: ['edge-1'],
|
|
856
|
+
* });
|
|
857
|
+
* ```
|
|
667
858
|
* @apiCategory data
|
|
668
859
|
*/
|
|
669
860
|
public removeData(ids: DataID | ((data: GraphData) => DataID)): void {
|
|
@@ -671,10 +862,14 @@ export class Graph extends EventEmitter {
|
|
|
671
862
|
}
|
|
672
863
|
|
|
673
864
|
/**
|
|
674
|
-
* <zh/>
|
|
865
|
+
* <zh/> 删除节点数据
|
|
675
866
|
*
|
|
676
|
-
* <en/> Remove
|
|
867
|
+
* <en/> Remove node data
|
|
677
868
|
* @param ids - <zh/> 节点 ID 数组 | <en/> node ID array
|
|
869
|
+
* @example
|
|
870
|
+
* ```ts
|
|
871
|
+
* graph.removeNodeData(['node-1', 'node-2']);
|
|
872
|
+
* ```
|
|
678
873
|
* @apiCategory data
|
|
679
874
|
*/
|
|
680
875
|
public removeNodeData(ids: ID[] | ((data: NodeData[]) => ID[])): void {
|
|
@@ -682,10 +877,18 @@ export class Graph extends EventEmitter {
|
|
|
682
877
|
}
|
|
683
878
|
|
|
684
879
|
/**
|
|
685
|
-
* <zh/>
|
|
880
|
+
* <zh/> 删除边数据
|
|
686
881
|
*
|
|
687
|
-
* <en/> Remove
|
|
882
|
+
* <en/> Remove edge data
|
|
688
883
|
* @param ids - <zh/> 边 ID 数组 | <en/> edge ID array
|
|
884
|
+
* @remarks
|
|
885
|
+
* <zh/> 如果传入边数据时仅提供了 source 和 target,那么需要通过 `idOf` 方法获取边的实际 ID
|
|
886
|
+
*
|
|
887
|
+
* <en/> If only the source and target are provided when passing in the edge data, you need to get the actual ID of the edge through the `idOf` method
|
|
888
|
+
* @example
|
|
889
|
+
* ```ts
|
|
890
|
+
* graph.removeEdgeData(['edge-1']);
|
|
891
|
+
* ```
|
|
689
892
|
* @apiCategory data
|
|
690
893
|
*/
|
|
691
894
|
public removeEdgeData(ids: ID[] | ((data: EdgeData[]) => ID[])): void {
|
|
@@ -693,10 +896,14 @@ export class Graph extends EventEmitter {
|
|
|
693
896
|
}
|
|
694
897
|
|
|
695
898
|
/**
|
|
696
|
-
* <zh/>
|
|
899
|
+
* <zh/> 删除组合数据
|
|
697
900
|
*
|
|
698
|
-
* <en/> Remove
|
|
901
|
+
* <en/> Remove combo data
|
|
699
902
|
* @param ids - <zh/> 组合 ID 数组 | <en/> 组合 ID array
|
|
903
|
+
* @example
|
|
904
|
+
* ```ts
|
|
905
|
+
* graph.removeComboData(['combo-1']);
|
|
906
|
+
* ```
|
|
700
907
|
* @apiCategory data
|
|
701
908
|
*/
|
|
702
909
|
public removeComboData(ids: ID[] | ((data: ComboData[]) => ID[])): void {
|
|
@@ -788,6 +995,10 @@ export class Graph extends EventEmitter {
|
|
|
788
995
|
* <en/> Get node data in a specific state
|
|
789
996
|
* @param state - <zh/> 状态 | <en/> state
|
|
790
997
|
* @returns <zh/> 节点数据 | <en/> node data
|
|
998
|
+
* @example
|
|
999
|
+
* ```ts
|
|
1000
|
+
* const nodes = graph.getElementDataByState('node', 'selected');
|
|
1001
|
+
* ```
|
|
791
1002
|
* @apiCategory data
|
|
792
1003
|
*/
|
|
793
1004
|
public getElementDataByState(elementType: 'node', state: State): NodeData[];
|
|
@@ -797,6 +1008,10 @@ export class Graph extends EventEmitter {
|
|
|
797
1008
|
* <en/> Get edge data in a specific state
|
|
798
1009
|
* @param state - <zh/> 状态 | <en/> state
|
|
799
1010
|
* @returns <zh/> 边数据 | <en/> edge data
|
|
1011
|
+
* @example
|
|
1012
|
+
* ```ts
|
|
1013
|
+
* const nodes = graph.getElementDataByState('edge', 'selected');
|
|
1014
|
+
* ```
|
|
800
1015
|
* @apiCategory data
|
|
801
1016
|
*/
|
|
802
1017
|
public getElementDataByState(elementType: 'edge', state: State): EdgeData[];
|
|
@@ -806,6 +1021,10 @@ export class Graph extends EventEmitter {
|
|
|
806
1021
|
* <en/> Get combo data in a specific state
|
|
807
1022
|
* @param state - <zh/> 状态 | <en/> state
|
|
808
1023
|
* @returns <zh/> 组合数据 | <en/> combo data
|
|
1024
|
+
* @example
|
|
1025
|
+
* ```ts
|
|
1026
|
+
* const nodes = graph.getElementDataByState('node', 'selected');
|
|
1027
|
+
* ```
|
|
809
1028
|
* @apiCategory data
|
|
810
1029
|
*/
|
|
811
1030
|
public getElementDataByState(elementType: 'combo', state: State): ComboData[];
|
|
@@ -872,7 +1091,11 @@ export class Graph extends EventEmitter {
|
|
|
872
1091
|
* @remarks
|
|
873
1092
|
* <zh/> 此过程会执行数据更新、绘制元素、执行布局
|
|
874
1093
|
*
|
|
1094
|
+
* > ⚠️ render 为异步方法,如果需要在 render 后执行一些操作,可以使用 `await graph.render()` 或者监听 GraphEvent.AFTER_RENDER 事件
|
|
1095
|
+
*
|
|
875
1096
|
* <en/> This process will execute data update, element rendering, and layout execution
|
|
1097
|
+
*
|
|
1098
|
+
* > ⚠️ render is an asynchronous method. If you need to perform some operations after render, you can use `await graph.render()` or listen to the GraphEvent.AFTER_RENDER event
|
|
876
1099
|
* @apiCategory render
|
|
877
1100
|
*/
|
|
878
1101
|
public async render(): Promise<void> {
|
|
@@ -889,7 +1112,15 @@ export class Graph extends EventEmitter {
|
|
|
889
1112
|
*
|
|
890
1113
|
* <en/> Draw elements
|
|
891
1114
|
* @returns <zh/> 渲染结果 | <en/> draw result
|
|
892
|
-
* @
|
|
1115
|
+
* @remarks
|
|
1116
|
+
* <zh/> 仅执行元素绘制,不会重新布局
|
|
1117
|
+
*
|
|
1118
|
+
* <zh/> ⚠️ draw 为异步方法,如果需要在 draw 后执行一些操作,可以使用 `await graph.draw()` 或者监听 GraphEvent.AFTER_DRAW 事件
|
|
1119
|
+
*
|
|
1120
|
+
* <en/> Only execute element drawing, no re-layout
|
|
1121
|
+
*
|
|
1122
|
+
* <en/> ⚠️ draw is an asynchronous method. If you need to perform some operations after draw, you can use `await graph.draw()` or listen to the GraphEvent.AFTER_DRAW event
|
|
1123
|
+
* @apiCategory render
|
|
893
1124
|
*/
|
|
894
1125
|
public async draw(): Promise<void> {
|
|
895
1126
|
await this.prepare();
|
|
@@ -936,6 +1167,10 @@ export class Graph extends EventEmitter {
|
|
|
936
1167
|
* <zh/> 销毁当前图实例
|
|
937
1168
|
*
|
|
938
1169
|
* <en/> Destroy the current graph instance
|
|
1170
|
+
* @remarks
|
|
1171
|
+
* <zh/> 销毁后无法进行任何操作,如果需要重新使用,需要重新创建一个新的图实例
|
|
1172
|
+
*
|
|
1173
|
+
* <en/> After destruction, no operations can be performed. If you need to reuse it, you need to create a new graph instance
|
|
939
1174
|
* @apiCategory instance
|
|
940
1175
|
*/
|
|
941
1176
|
public destroy(): void {
|
|
@@ -1001,7 +1236,7 @@ export class Graph extends EventEmitter {
|
|
|
1001
1236
|
*
|
|
1002
1237
|
* <en/> Zoom the graph to fit the viewport and move it to the center of the viewport
|
|
1003
1238
|
* @param options - <zh/> 适配配置 | <en/> fit options
|
|
1004
|
-
* @param animation - <zh/> 动画配置 | <en/> animation
|
|
1239
|
+
* @param animation - <zh/> 动画配置 | <en/> animation options
|
|
1005
1240
|
* @apiCategory viewport
|
|
1006
1241
|
*/
|
|
1007
1242
|
public async fitView(options?: FitViewOptions, animation?: ViewportAnimationEffectTiming): Promise<void> {
|
|
@@ -1012,7 +1247,7 @@ export class Graph extends EventEmitter {
|
|
|
1012
1247
|
* <zh/> 将图平移至视口中心
|
|
1013
1248
|
*
|
|
1014
1249
|
* <en/> Move the graph to the center of the viewport
|
|
1015
|
-
* @param animation - <zh/> 动画配置 | <en/> animation
|
|
1250
|
+
* @param animation - <zh/> 动画配置 | <en/> animation options
|
|
1016
1251
|
* @apiCategory viewport
|
|
1017
1252
|
*/
|
|
1018
1253
|
public async fitCenter(animation?: ViewportAnimationEffectTiming): Promise<void> {
|
|
@@ -1034,11 +1269,15 @@ export class Graph extends EventEmitter {
|
|
|
1034
1269
|
}
|
|
1035
1270
|
|
|
1036
1271
|
/**
|
|
1272
|
+
* <zh/> 聚焦元素
|
|
1273
|
+
*
|
|
1274
|
+
* <en/> Focus on element
|
|
1275
|
+
* @param id - <zh/> 元素 ID | <en/> element ID
|
|
1276
|
+
* @param animation - <zh/> 动画配置 | <en/> animation options
|
|
1277
|
+
* @remarks
|
|
1037
1278
|
* <zh/> 移动图,使得元素对齐到视口中心
|
|
1038
1279
|
*
|
|
1039
1280
|
* <en/> Move the graph so that the element is aligned to the center of the viewport
|
|
1040
|
-
* @param id - <zh/> 元素 ID | <en/> element ID
|
|
1041
|
-
* @param animation - <zh/> 动画配置 | <en/> animation configuration
|
|
1042
1281
|
* @apiCategory viewport
|
|
1043
1282
|
*/
|
|
1044
1283
|
public async focusElement(id: ID | ID[], animation?: ViewportAnimationEffectTiming): Promise<void> {
|
|
@@ -1046,11 +1285,11 @@ export class Graph extends EventEmitter {
|
|
|
1046
1285
|
}
|
|
1047
1286
|
|
|
1048
1287
|
/**
|
|
1049
|
-
* <zh/>
|
|
1288
|
+
* <zh/> 基于当前缩放比例进行缩放(相对缩放)
|
|
1050
1289
|
*
|
|
1051
|
-
* <en/> Zoom based on the current zoom ratio
|
|
1290
|
+
* <en/> Zoom based on the current zoom ratio (relative zoom)
|
|
1052
1291
|
* @param ratio - <zh/> 缩放比例 | <en/> zoom ratio
|
|
1053
|
-
* @param animation - <zh/> 动画配置 | <en/> animation
|
|
1292
|
+
* @param animation - <zh/> 动画配置 | <en/> animation options
|
|
1054
1293
|
* @param origin - <zh/> 缩放中心(视口坐标) | <en/> zoom center(viewport coordinates)
|
|
1055
1294
|
* @remarks
|
|
1056
1295
|
* <zh/>
|
|
@@ -1067,11 +1306,11 @@ export class Graph extends EventEmitter {
|
|
|
1067
1306
|
}
|
|
1068
1307
|
|
|
1069
1308
|
/**
|
|
1070
|
-
* <zh/>
|
|
1309
|
+
* <zh/> 缩放画布至指定比例(绝对缩放)
|
|
1071
1310
|
*
|
|
1072
|
-
* <en/> Zoom the canvas to the specified ratio
|
|
1311
|
+
* <en/> Zoom the canvas to the specified ratio (absolute zoom)
|
|
1073
1312
|
* @param zoom - <zh/> 指定缩放比例 | <en/> specified zoom ratio
|
|
1074
|
-
* @param animation - <zh/> 动画配置 | <en/> animation
|
|
1313
|
+
* @param animation - <zh/> 动画配置 | <en/> animation options
|
|
1075
1314
|
* @param origin - <zh/> 缩放中心(视口坐标) | <en/> zoom center(viewport coordinates)
|
|
1076
1315
|
* @remarks
|
|
1077
1316
|
* <zh/>
|
|
@@ -1101,11 +1340,11 @@ export class Graph extends EventEmitter {
|
|
|
1101
1340
|
}
|
|
1102
1341
|
|
|
1103
1342
|
/**
|
|
1104
|
-
* <zh/>
|
|
1343
|
+
* <zh/> 基于当前旋转角度进行旋转(相对旋转)
|
|
1105
1344
|
*
|
|
1106
|
-
* <en/> Rotate based on the current rotation angle
|
|
1345
|
+
* <en/> Rotate based on the current rotation angle (relative rotation)
|
|
1107
1346
|
* @param angle - <zh/> 旋转角度 | <en/> rotation angle
|
|
1108
|
-
* @param animation - <zh/> 动画配置 | <en/> animation
|
|
1347
|
+
* @param animation - <zh/> 动画配置 | <en/> animation options
|
|
1109
1348
|
* @param origin - <zh/> 旋转中心(视口坐标) | <en/> rotation center(viewport coordinates)
|
|
1110
1349
|
* @apiCategory viewport
|
|
1111
1350
|
*/
|
|
@@ -1114,11 +1353,11 @@ export class Graph extends EventEmitter {
|
|
|
1114
1353
|
}
|
|
1115
1354
|
|
|
1116
1355
|
/**
|
|
1117
|
-
* <zh/> 旋转画布至指定角度
|
|
1356
|
+
* <zh/> 旋转画布至指定角度 (绝对旋转)
|
|
1118
1357
|
*
|
|
1119
|
-
* <en/> Rotate the canvas to the specified angle
|
|
1358
|
+
* <en/> Rotate the canvas to the specified angle (absolute rotation)
|
|
1120
1359
|
* @param angle - <zh/> 目标角度 | <en/> target angle
|
|
1121
|
-
* @param animation - <zh/> 动画配置 | <en/> animation
|
|
1360
|
+
* @param animation - <zh/> 动画配置 | <en/> animation options
|
|
1122
1361
|
* @param origin - <zh/> 旋转中心(视口坐标) | <en/> rotation center(viewport coordinates)
|
|
1123
1362
|
* @apiCategory viewport
|
|
1124
1363
|
*/
|
|
@@ -1138,11 +1377,11 @@ export class Graph extends EventEmitter {
|
|
|
1138
1377
|
}
|
|
1139
1378
|
|
|
1140
1379
|
/**
|
|
1141
|
-
* <zh/> 将图平移指定距离
|
|
1380
|
+
* <zh/> 将图平移指定距离 (相对平移)
|
|
1142
1381
|
*
|
|
1143
|
-
* <en/> Translate the graph by the specified distance
|
|
1382
|
+
* <en/> Translate the graph by the specified distance (relative translation)
|
|
1144
1383
|
* @param offset - <zh/> 偏移量 | <en/> offset
|
|
1145
|
-
* @param animation - <zh/> 动画配置 | <en/> animation
|
|
1384
|
+
* @param animation - <zh/> 动画配置 | <en/> animation options
|
|
1146
1385
|
* @apiCategory viewport
|
|
1147
1386
|
*/
|
|
1148
1387
|
public async translateBy(offset: Point, animation?: ViewportAnimationEffectTiming): Promise<void> {
|
|
@@ -1150,11 +1389,11 @@ export class Graph extends EventEmitter {
|
|
|
1150
1389
|
}
|
|
1151
1390
|
|
|
1152
1391
|
/**
|
|
1153
|
-
* <zh/> 将图平移至指定位置
|
|
1392
|
+
* <zh/> 将图平移至指定位置 (绝对平移)
|
|
1154
1393
|
*
|
|
1155
|
-
* <en/> Translate the graph to the specified position
|
|
1394
|
+
* <en/> Translate the graph to the specified position (absolute translation)
|
|
1156
1395
|
* @param position - <zh/> 指定位置 | <en/> specified position
|
|
1157
|
-
* @param animation - <zh/> 动画配置 | <en/> animation
|
|
1396
|
+
* @param animation - <zh/> 动画配置 | <en/> animation options
|
|
1158
1397
|
* @apiCategory viewport
|
|
1159
1398
|
*/
|
|
1160
1399
|
public async translateTo(position: Point, animation?: ViewportAnimationEffectTiming): Promise<void> {
|
|
@@ -1177,67 +1416,67 @@ export class Graph extends EventEmitter {
|
|
|
1177
1416
|
}
|
|
1178
1417
|
|
|
1179
1418
|
/**
|
|
1180
|
-
* <zh/> 将元素平移指定距离
|
|
1419
|
+
* <zh/> 将元素平移指定距离 (相对平移)
|
|
1181
1420
|
*
|
|
1182
|
-
* <en/> Translate the element by the specified distance
|
|
1421
|
+
* <en/> Translate the element by the specified distance (relative translation)
|
|
1183
1422
|
* @param id - <zh/> 元素 ID | <en/> element ID
|
|
1184
1423
|
* @param offset - <zh/> 偏移量 | <en/> offset
|
|
1185
1424
|
* @param animation - <zh/> 是否启用动画 | <en/> whether to enable animation
|
|
1186
1425
|
* @apiCategory element
|
|
1187
1426
|
*/
|
|
1188
|
-
public async translateElementBy(id: ID, offset:
|
|
1427
|
+
public async translateElementBy(id: ID, offset: Point, animation?: boolean): Promise<void>;
|
|
1189
1428
|
/**
|
|
1190
|
-
* <zh/> 批量将元素平移指定距离
|
|
1429
|
+
* <zh/> 批量将元素平移指定距离 (相对平移)
|
|
1191
1430
|
*
|
|
1192
|
-
* <en/> Batch translate elements by the specified distance
|
|
1193
|
-
* @param offsets - <zh/> 偏移量配置 | <en/> offset
|
|
1431
|
+
* <en/> Batch translate elements by the specified distance (relative translation)
|
|
1432
|
+
* @param offsets - <zh/> 偏移量配置 | <en/> offset options
|
|
1194
1433
|
* @param animation - <zh/> 是否启用动画 | <en/> whether to enable animation
|
|
1195
1434
|
* @apiCategory element
|
|
1196
1435
|
*/
|
|
1197
|
-
public async translateElementBy(offsets: Record<ID,
|
|
1436
|
+
public async translateElementBy(offsets: Record<ID, Point>, animation?: boolean): Promise<void>;
|
|
1198
1437
|
public async translateElementBy(
|
|
1199
|
-
args1: ID | Record<ID,
|
|
1200
|
-
args2?:
|
|
1438
|
+
args1: ID | Record<ID, Point>,
|
|
1439
|
+
args2?: Point | boolean,
|
|
1201
1440
|
args3: boolean = true,
|
|
1202
1441
|
): Promise<void> {
|
|
1203
1442
|
const [config, animation] = isObject(args1)
|
|
1204
1443
|
? [args1, (args2 as boolean) ?? true]
|
|
1205
|
-
: [{ [args1 as ID]: args2 as
|
|
1444
|
+
: [{ [args1 as ID]: args2 as Point }, args3];
|
|
1206
1445
|
|
|
1207
|
-
Object.entries(config).forEach(([id, offset]) => this.context.model.
|
|
1208
|
-
await this.context.element!.draw({ animation })?.finished;
|
|
1446
|
+
Object.entries(config).forEach(([id, offset]) => this.context.model.translateNodeLikeBy(id, offset));
|
|
1447
|
+
await this.context.element!.draw({ animation, stage: 'translate' })?.finished;
|
|
1209
1448
|
}
|
|
1210
1449
|
|
|
1211
1450
|
/**
|
|
1212
|
-
* <zh/> 将元素平移至指定位置
|
|
1451
|
+
* <zh/> 将元素平移至指定位置 (绝对平移)
|
|
1213
1452
|
*
|
|
1214
|
-
* <en/> Translate the element to the specified position
|
|
1453
|
+
* <en/> Translate the element to the specified position (absolute translation)
|
|
1215
1454
|
* @param id - <zh/> 元素 ID | <en/> element ID
|
|
1216
1455
|
* @param position - <zh/> 指定位置 | <en/> specified position
|
|
1217
1456
|
* @param animation - <zh/> 是否启用动画 | <en/> whether to enable animation
|
|
1218
1457
|
* @apiCategory element
|
|
1219
1458
|
*/
|
|
1220
|
-
public async translateElementTo(id: ID, position:
|
|
1459
|
+
public async translateElementTo(id: ID, position: Point, animation?: boolean): Promise<void>;
|
|
1221
1460
|
/**
|
|
1222
|
-
* <zh/> 批量将元素平移至指定位置
|
|
1461
|
+
* <zh/> 批量将元素平移至指定位置 (绝对平移)
|
|
1223
1462
|
*
|
|
1224
|
-
* <en/> Batch translate elements to the specified position
|
|
1225
|
-
* @param positions - <zh/> 位置配置 | <en/> position
|
|
1463
|
+
* <en/> Batch translate elements to the specified position (absolute translation)
|
|
1464
|
+
* @param positions - <zh/> 位置配置 | <en/> position options
|
|
1226
1465
|
* @param animation - <zh/> 是否启用动画 | <en/> whether to enable animation
|
|
1227
1466
|
* @apiCategory element
|
|
1228
1467
|
*/
|
|
1229
|
-
public async translateElementTo(positions: Record<ID,
|
|
1468
|
+
public async translateElementTo(positions: Record<ID, Point>, animation?: boolean): Promise<void>;
|
|
1230
1469
|
public async translateElementTo(
|
|
1231
|
-
args1: ID | Record<ID,
|
|
1232
|
-
args2?: boolean |
|
|
1470
|
+
args1: ID | Record<ID, Point>,
|
|
1471
|
+
args2?: boolean | Point,
|
|
1233
1472
|
args3: boolean = true,
|
|
1234
1473
|
): Promise<void> {
|
|
1235
1474
|
const [config, animation] = isObject(args1)
|
|
1236
1475
|
? [args1, (args2 as boolean) ?? true]
|
|
1237
|
-
: [{ [args1 as ID]: args2 as
|
|
1476
|
+
: [{ [args1 as ID]: args2 as Point }, args3];
|
|
1238
1477
|
|
|
1239
|
-
Object.entries(config).forEach(([id, position]) => this.context.model.
|
|
1240
|
-
await this.context.element!.draw({ animation })?.finished;
|
|
1478
|
+
Object.entries(config).forEach(([id, position]) => this.context.model.translateNodeLikeTo(id, position));
|
|
1479
|
+
await this.context.element!.draw({ animation, stage: 'translate' })?.finished;
|
|
1241
1480
|
}
|
|
1242
1481
|
|
|
1243
1482
|
/**
|
|
@@ -1248,7 +1487,7 @@ export class Graph extends EventEmitter {
|
|
|
1248
1487
|
* @returns <zh/> 元素位置 | <en/> element position
|
|
1249
1488
|
* @apiCategory element
|
|
1250
1489
|
*/
|
|
1251
|
-
public getElementPosition(id: ID):
|
|
1490
|
+
public getElementPosition(id: ID): Point {
|
|
1252
1491
|
return this.context.model.getElementPosition(id);
|
|
1253
1492
|
}
|
|
1254
1493
|
|
|
@@ -1260,7 +1499,7 @@ export class Graph extends EventEmitter {
|
|
|
1260
1499
|
* @returns <zh/> 元素渲染样式 | <en/> element rendering style
|
|
1261
1500
|
* @apiCategory element
|
|
1262
1501
|
*/
|
|
1263
|
-
public getElementRenderStyle(id: ID) {
|
|
1502
|
+
public getElementRenderStyle(id: ID): Record<string, any> {
|
|
1264
1503
|
return omit(this.context.element!.getElement(id)!.attributes, ['context']);
|
|
1265
1504
|
}
|
|
1266
1505
|
|
|
@@ -1270,7 +1509,11 @@ export class Graph extends EventEmitter {
|
|
|
1270
1509
|
* <en/> Set element visibility
|
|
1271
1510
|
* @param id - <zh/> 元素 ID | <en/> element ID
|
|
1272
1511
|
* @param visibility - <zh/> 可见性 | <en/> visibility
|
|
1273
|
-
* @param animation - <zh/> 动画配置 | <en/> animation
|
|
1512
|
+
* @param animation - <zh/> 动画配置 | <en/> animation options
|
|
1513
|
+
* @remarks
|
|
1514
|
+
* <zh/> 可见性配置包括 `visible` 和 `hidden` 两种状态
|
|
1515
|
+
*
|
|
1516
|
+
* <en/> Visibility configuration includes two states: `visible` and `hidden`
|
|
1274
1517
|
* @apiCategory element
|
|
1275
1518
|
*/
|
|
1276
1519
|
public async setElementVisibility(
|
|
@@ -1282,8 +1525,8 @@ export class Graph extends EventEmitter {
|
|
|
1282
1525
|
* <zh/> 批量设置元素可见性
|
|
1283
1526
|
*
|
|
1284
1527
|
* <en/> Batch set element visibility
|
|
1285
|
-
* @param visibility - <zh/> 可见性配置 | <en/> visibility
|
|
1286
|
-
* @param animation - <zh/> 动画配置 | <en/> animation
|
|
1528
|
+
* @param visibility - <zh/> 可见性配置 | <en/> visibility options
|
|
1529
|
+
* @param animation - <zh/> 动画配置 | <en/> animation options
|
|
1287
1530
|
* @apiCategory element
|
|
1288
1531
|
*/
|
|
1289
1532
|
public async setElementVisibility(
|
|
@@ -1370,7 +1613,7 @@ export class Graph extends EventEmitter {
|
|
|
1370
1613
|
* <zh/> 批量设置元素层级
|
|
1371
1614
|
*
|
|
1372
1615
|
* <en/> Batch set element z-index
|
|
1373
|
-
* @param zIndex - <zh/> 层级配置 | <en/> z-index
|
|
1616
|
+
* @param zIndex - <zh/> 层级配置 | <en/> z-index options
|
|
1374
1617
|
* @apiCategory element
|
|
1375
1618
|
*/
|
|
1376
1619
|
public async setElementZIndex(zIndex: Record<ID, number>): Promise<void>;
|
|
@@ -1385,7 +1628,7 @@ export class Graph extends EventEmitter {
|
|
|
1385
1628
|
|
|
1386
1629
|
const { model, element } = this.context;
|
|
1387
1630
|
model.preventUpdateNodeLikeHierarchy(() => model.updateData(dataToUpdate));
|
|
1388
|
-
await element!.draw({ animation: false })?.finished;
|
|
1631
|
+
await element!.draw({ animation: false, stage: 'zIndex' })?.finished;
|
|
1389
1632
|
}
|
|
1390
1633
|
|
|
1391
1634
|
/**
|
|
@@ -1397,20 +1640,18 @@ export class Graph extends EventEmitter {
|
|
|
1397
1640
|
*/
|
|
1398
1641
|
public async frontElement(id: ID | ID[]): Promise<void> {
|
|
1399
1642
|
const ids = Array.isArray(id) ? id : [id];
|
|
1400
|
-
const { model } = this.context;
|
|
1643
|
+
const { model, element } = this.context;
|
|
1401
1644
|
const config: Record<ID, number> = {};
|
|
1402
1645
|
|
|
1403
1646
|
ids.map((_id) => {
|
|
1404
|
-
const zIndex =
|
|
1647
|
+
const zIndex = element!.getFrontZIndex(_id);
|
|
1405
1648
|
const elementType = model.getElementType(_id);
|
|
1406
1649
|
if (elementType === 'combo') {
|
|
1407
1650
|
const ancestor = model.getAncestorsData(_id, COMBO_KEY).at(-1) || this.getComboData(_id);
|
|
1408
|
-
const combos = [ancestor, ...model.getDescendantsData(idOf(ancestor))]
|
|
1409
|
-
|
|
1410
|
-
);
|
|
1411
|
-
const delta = zIndex - zIndexOf(ancestor);
|
|
1651
|
+
const combos = [ancestor, ...model.getDescendantsData(idOf(ancestor))];
|
|
1652
|
+
const delta = zIndex - element!.getElementZIndex(_id);
|
|
1412
1653
|
combos.forEach((combo) => {
|
|
1413
|
-
config[idOf(combo)] =
|
|
1654
|
+
config[idOf(combo)] = this.getElementZIndex(idOf(combo)) + delta;
|
|
1414
1655
|
});
|
|
1415
1656
|
} else config[_id] = zIndex;
|
|
1416
1657
|
});
|
|
@@ -1427,7 +1668,8 @@ export class Graph extends EventEmitter {
|
|
|
1427
1668
|
* @apiCategory element
|
|
1428
1669
|
*/
|
|
1429
1670
|
public getElementZIndex(id: ID): number {
|
|
1430
|
-
|
|
1671
|
+
const { model, element } = this.context;
|
|
1672
|
+
return model.getElementDataById(id)?.style?.zIndex ?? element!.getElementZIndex(id);
|
|
1431
1673
|
}
|
|
1432
1674
|
|
|
1433
1675
|
/**
|
|
@@ -1436,7 +1678,7 @@ export class Graph extends EventEmitter {
|
|
|
1436
1678
|
* <en/> Set element state
|
|
1437
1679
|
* @param id - <zh/> 元素 ID | <en/> element ID
|
|
1438
1680
|
* @param state - <zh/> 状态 | <en/> state
|
|
1439
|
-
* @param animation - <zh/> 动画配置 | <en/> animation
|
|
1681
|
+
* @param animation - <zh/> 动画配置 | <en/> animation options
|
|
1440
1682
|
* @apiCategory element
|
|
1441
1683
|
*/
|
|
1442
1684
|
public async setElementState(id: ID, state: State | State[], animation?: boolean): Promise<void>;
|
|
@@ -1444,8 +1686,8 @@ export class Graph extends EventEmitter {
|
|
|
1444
1686
|
* <zh/> 批量设置元素状态
|
|
1445
1687
|
*
|
|
1446
1688
|
* <en/> Batch set element state
|
|
1447
|
-
* @param state - <zh/> 状态配置 | <en/> state
|
|
1448
|
-
* @param animation - <zh/> 动画配置 | <en/> animation
|
|
1689
|
+
* @param state - <zh/> 状态配置 | <en/> state options
|
|
1690
|
+
* @param animation - <zh/> 动画配置 | <en/> animation options
|
|
1449
1691
|
* @apiCategory element
|
|
1450
1692
|
*/
|
|
1451
1693
|
public async setElementState(state: Record<ID, State | State[]>, animation?: boolean): Promise<void>;
|
|
@@ -1500,7 +1742,7 @@ export class Graph extends EventEmitter {
|
|
|
1500
1742
|
private isCollapsingExpanding = false;
|
|
1501
1743
|
|
|
1502
1744
|
/**
|
|
1503
|
-
* <zh/>
|
|
1745
|
+
* <zh/> 收起组合
|
|
1504
1746
|
*
|
|
1505
1747
|
* <en/> Collapse Combo
|
|
1506
1748
|
* @param id - <zh/> 元素 ID | <en/> element ID
|
|
@@ -1524,7 +1766,7 @@ export class Graph extends EventEmitter {
|
|
|
1524
1766
|
}
|
|
1525
1767
|
|
|
1526
1768
|
/**
|
|
1527
|
-
* <zh/>
|
|
1769
|
+
* <zh/> 展开组合
|
|
1528
1770
|
*
|
|
1529
1771
|
* <en/> Expand Combo
|
|
1530
1772
|
* @param id - <zh/> 元素 ID | <en/> element ID
|
|
@@ -1557,7 +1799,7 @@ export class Graph extends EventEmitter {
|
|
|
1557
1799
|
* <zh/> 导出画布内容为 DataURL
|
|
1558
1800
|
*
|
|
1559
1801
|
* <en/> Export canvas content as DataURL
|
|
1560
|
-
* @param options - <zh/> 导出配置 | <en/> export
|
|
1802
|
+
* @param options - <zh/> 导出配置 | <en/> export options
|
|
1561
1803
|
* @returns <zh/> DataURL | <en/> DataURL
|
|
1562
1804
|
* @apiCategory exportImage
|
|
1563
1805
|
*/
|
|
@@ -1650,7 +1892,7 @@ export class Graph extends EventEmitter {
|
|
|
1650
1892
|
* @returns <zh/> Graph 实例 | <en/> Graph instance
|
|
1651
1893
|
* @apiCategory event
|
|
1652
1894
|
*/
|
|
1653
|
-
public on<T extends IEvent = IEvent>(eventName: string, callback: (event: T) => void) {
|
|
1895
|
+
public on<T extends IEvent = IEvent>(eventName: string, callback: (event: T) => void): this {
|
|
1654
1896
|
return super.on(eventName, callback);
|
|
1655
1897
|
}
|
|
1656
1898
|
|
|
@@ -1663,7 +1905,38 @@ export class Graph extends EventEmitter {
|
|
|
1663
1905
|
* @returns <zh/> Graph 实例 | <en/> Graph instance
|
|
1664
1906
|
* @apiCategory event
|
|
1665
1907
|
*/
|
|
1666
|
-
public once<T extends IEvent = IEvent>(eventName: string, callback: (event: T) => void) {
|
|
1908
|
+
public once<T extends IEvent = IEvent>(eventName: string, callback: (event: T) => void): this {
|
|
1667
1909
|
return super.once(eventName, callback);
|
|
1668
1910
|
}
|
|
1911
|
+
|
|
1912
|
+
/**
|
|
1913
|
+
* <zh/> 移除全部事件监听
|
|
1914
|
+
*
|
|
1915
|
+
* <en/> Remove all event listeners
|
|
1916
|
+
* @returns <zh/> Graph 实例 | <en/> Graph instance
|
|
1917
|
+
* @apiCategory event
|
|
1918
|
+
*/
|
|
1919
|
+
public off(): this;
|
|
1920
|
+
/**
|
|
1921
|
+
* <zh/> 移除指定事件的全部监听
|
|
1922
|
+
*
|
|
1923
|
+
* <en/> Remove all listeners for the specified event
|
|
1924
|
+
* @param eventName - <zh/> 事件名称 | <en/> event name
|
|
1925
|
+
* @returns <zh/> Graph 实例 | <en/> Graph instance
|
|
1926
|
+
* @apiCategory event
|
|
1927
|
+
*/
|
|
1928
|
+
public off(eventName: string): this;
|
|
1929
|
+
/**
|
|
1930
|
+
* <zh/> 移除事件监听
|
|
1931
|
+
*
|
|
1932
|
+
* <en/> Remove event listener
|
|
1933
|
+
* @param eventName - <zh/> 事件名称 | <en/> event name
|
|
1934
|
+
* @param callback - <zh/> 回调函数 | <en/> callback function
|
|
1935
|
+
* @returns <zh/> Graph 实例 | <en/> Graph instance
|
|
1936
|
+
* @apiCategory event
|
|
1937
|
+
*/
|
|
1938
|
+
public off(eventName: string, callback: (...args: any[]) => void): this;
|
|
1939
|
+
public off(eventName?: string, callback?: (...args: any[]) => void) {
|
|
1940
|
+
return super.off(eventName, callback);
|
|
1941
|
+
}
|
|
1669
1942
|
}
|