@antv/g6 5.0.33 → 5.0.35-beta.1
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 +11 -11
- package/dist/lib/behaviors/optimize-viewport-transform.d.ts +1 -1
- package/dist/lib/elements/edges/base-edge.d.ts +5 -5
- package/dist/lib/elements/nodes/base-node.d.ts +2 -0
- package/dist/lib/elements/shapes/base-shape.d.ts +2 -9
- package/dist/lib/exports.d.ts +2 -2
- package/dist/lib/layouts/fishbone.d.ts +2 -1
- package/dist/lib/layouts/index.d.ts +2 -0
- package/dist/lib/layouts/snake.d.ts +80 -0
- package/dist/lib/layouts/types.d.ts +23 -1
- package/dist/lib/plugins/minimap/index.d.ts +1 -1
- package/dist/lib/plugins/tooltip.d.ts +6 -0
- package/dist/lib/runtime/data.d.ts +2 -8
- package/dist/lib/runtime/element.d.ts +5 -2
- package/dist/lib/runtime/layout.d.ts +18 -1
- package/dist/lib/runtime/options.d.ts +9 -0
- package/dist/lib/runtime/transform.d.ts +2 -1
- package/dist/lib/spec/canvas.d.ts +26 -2
- package/dist/lib/spec/data.d.ts +0 -14
- package/dist/lib/spec/graph.d.ts +60 -12
- package/dist/lib/spec/viewport.d.ts +4 -0
- package/dist/lib/transforms/base-transform.d.ts +2 -1
- package/dist/lib/utils/cache.d.ts +5 -5
- package/dist/lib/utils/element.d.ts +9 -1
- package/dist/lib/utils/layout.d.ts +13 -1
- package/dist/lib/utils/style.d.ts +5 -5
- package/dist/lib/utils/transform.d.ts +2 -2
- package/dist/lib/version.d.ts +1 -1
- package/esm/animations/executor.js +3 -2
- package/esm/animations/executor.js.map +1 -1
- package/esm/behaviors/drag-element.js +9 -2
- package/esm/behaviors/drag-element.js.map +1 -1
- package/esm/behaviors/optimize-viewport-transform.d.ts +1 -1
- package/esm/elements/combos/base-combo.js +1 -1
- package/esm/elements/combos/base-combo.js.map +1 -1
- package/esm/elements/edges/base-edge.d.ts +5 -5
- package/esm/elements/edges/base-edge.js +8 -2
- package/esm/elements/edges/base-edge.js.map +1 -1
- package/esm/elements/nodes/base-node.d.ts +2 -0
- package/esm/elements/nodes/base-node.js +2 -2
- package/esm/elements/nodes/base-node.js.map +1 -1
- package/esm/elements/shapes/base-shape.d.ts +2 -9
- package/esm/elements/shapes/base-shape.js +24 -21
- package/esm/elements/shapes/base-shape.js.map +1 -1
- package/esm/exports.d.ts +2 -2
- package/esm/exports.js +1 -1
- package/esm/exports.js.map +1 -1
- package/esm/layouts/fishbone.d.ts +2 -1
- package/esm/layouts/fishbone.js +1 -1
- package/esm/layouts/fishbone.js.map +1 -1
- package/esm/layouts/index.d.ts +2 -0
- package/esm/layouts/index.js +1 -0
- package/esm/layouts/index.js.map +1 -1
- package/esm/layouts/snake.d.ts +80 -0
- package/esm/layouts/snake.js +162 -0
- package/esm/layouts/snake.js.map +1 -0
- package/esm/layouts/types.d.ts +23 -1
- package/esm/plugins/background/index.js +1 -0
- package/esm/plugins/background/index.js.map +1 -1
- package/esm/plugins/grid-line.js +1 -0
- package/esm/plugins/grid-line.js.map +1 -1
- package/esm/plugins/minimap/index.d.ts +1 -1
- package/esm/plugins/tooltip.d.ts +6 -0
- package/esm/plugins/tooltip.js +8 -6
- package/esm/plugins/tooltip.js.map +1 -1
- package/esm/registry/build-in.js +2 -1
- package/esm/registry/build-in.js.map +1 -1
- package/esm/runtime/data.d.ts +2 -8
- package/esm/runtime/data.js +14 -18
- package/esm/runtime/data.js.map +1 -1
- package/esm/runtime/element.d.ts +5 -2
- package/esm/runtime/element.js +39 -15
- package/esm/runtime/element.js.map +1 -1
- package/esm/runtime/graph.js +19 -7
- package/esm/runtime/graph.js.map +1 -1
- package/esm/runtime/layout.d.ts +18 -1
- package/esm/runtime/layout.js +85 -20
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/options.d.ts +9 -0
- package/esm/runtime/options.js +49 -0
- package/esm/runtime/options.js.map +1 -0
- package/esm/runtime/transform.d.ts +2 -1
- package/esm/runtime/transform.js.map +1 -1
- package/esm/spec/canvas.d.ts +26 -2
- package/esm/spec/data.d.ts +0 -14
- package/esm/spec/graph.d.ts +60 -12
- package/esm/spec/viewport.d.ts +4 -0
- package/esm/transforms/base-transform.d.ts +2 -1
- package/esm/transforms/base-transform.js +1 -1
- package/esm/transforms/base-transform.js.map +1 -1
- package/esm/utils/cache.d.ts +5 -5
- package/esm/utils/cache.js +5 -5
- package/esm/utils/element.d.ts +9 -1
- package/esm/utils/element.js +35 -1
- package/esm/utils/element.js.map +1 -1
- package/esm/utils/layout.d.ts +13 -1
- package/esm/utils/layout.js +14 -0
- package/esm/utils/layout.js.map +1 -1
- package/esm/utils/style.d.ts +5 -5
- package/esm/utils/style.js +5 -5
- package/esm/utils/transform.d.ts +2 -2
- package/esm/utils/transform.js +13 -8
- package/esm/utils/transform.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/esm/version.js.map +1 -1
- package/lib/animations/executor.js +3 -2
- package/lib/animations/executor.js.map +1 -1
- package/lib/behaviors/drag-element.js +9 -2
- package/lib/behaviors/drag-element.js.map +1 -1
- package/lib/behaviors/optimize-viewport-transform.d.ts +1 -1
- package/lib/elements/combos/base-combo.js +1 -1
- package/lib/elements/combos/base-combo.js.map +1 -1
- package/lib/elements/edges/base-edge.d.ts +5 -5
- package/lib/elements/edges/base-edge.js +7 -1
- package/lib/elements/edges/base-edge.js.map +1 -1
- package/lib/elements/nodes/base-node.d.ts +2 -0
- package/lib/elements/nodes/base-node.js +2 -2
- package/lib/elements/nodes/base-node.js.map +1 -1
- package/lib/elements/shapes/base-shape.d.ts +2 -9
- package/lib/elements/shapes/base-shape.js +23 -20
- package/lib/elements/shapes/base-shape.js.map +1 -1
- package/lib/exports.d.ts +2 -2
- package/lib/exports.js +3 -2
- package/lib/exports.js.map +1 -1
- package/lib/layouts/fishbone.d.ts +2 -1
- package/lib/layouts/fishbone.js +2 -2
- package/lib/layouts/fishbone.js.map +1 -1
- package/lib/layouts/index.d.ts +2 -0
- package/lib/layouts/index.js +3 -1
- package/lib/layouts/index.js.map +1 -1
- package/lib/layouts/snake.d.ts +80 -0
- package/lib/layouts/snake.js +166 -0
- package/lib/layouts/snake.js.map +1 -0
- package/lib/layouts/types.d.ts +23 -1
- package/lib/plugins/background/index.js +1 -0
- package/lib/plugins/background/index.js.map +1 -1
- package/lib/plugins/grid-line.js +1 -0
- package/lib/plugins/grid-line.js.map +1 -1
- package/lib/plugins/minimap/index.d.ts +1 -1
- package/lib/plugins/tooltip.d.ts +6 -0
- package/lib/plugins/tooltip.js +8 -6
- package/lib/plugins/tooltip.js.map +1 -1
- package/lib/registry/build-in.js +1 -0
- package/lib/registry/build-in.js.map +1 -1
- package/lib/runtime/data.d.ts +2 -8
- package/lib/runtime/data.js +14 -18
- package/lib/runtime/data.js.map +1 -1
- package/lib/runtime/element.d.ts +5 -2
- package/lib/runtime/element.js +39 -15
- package/lib/runtime/element.js.map +1 -1
- package/lib/runtime/graph.js +21 -9
- package/lib/runtime/graph.js.map +1 -1
- package/lib/runtime/layout.d.ts +18 -1
- package/lib/runtime/layout.js +84 -19
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/options.d.ts +9 -0
- package/lib/runtime/options.js +52 -0
- package/lib/runtime/options.js.map +1 -0
- package/lib/runtime/transform.d.ts +2 -1
- package/lib/runtime/transform.js.map +1 -1
- package/lib/spec/canvas.d.ts +26 -2
- package/lib/spec/data.d.ts +0 -14
- package/lib/spec/graph.d.ts +60 -12
- package/lib/spec/viewport.d.ts +4 -0
- package/lib/transforms/base-transform.d.ts +2 -1
- package/lib/transforms/base-transform.js +1 -1
- package/lib/transforms/base-transform.js.map +1 -1
- package/lib/utils/cache.d.ts +5 -5
- package/lib/utils/cache.js +5 -5
- package/lib/utils/element.d.ts +9 -1
- package/lib/utils/element.js +35 -0
- package/lib/utils/element.js.map +1 -1
- package/lib/utils/layout.d.ts +13 -1
- package/lib/utils/layout.js +15 -0
- package/lib/utils/layout.js.map +1 -1
- package/lib/utils/style.d.ts +5 -5
- package/lib/utils/style.js +5 -5
- package/lib/utils/transform.d.ts +2 -2
- package/lib/utils/transform.js +13 -8
- package/lib/utils/transform.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/version.js.map +1 -1
- package/package.json +2 -2
- package/src/animations/executor.ts +4 -4
- package/src/behaviors/drag-element.ts +9 -2
- package/src/behaviors/optimize-viewport-transform.ts +1 -1
- package/src/elements/combos/base-combo.ts +1 -1
- package/src/elements/edges/base-edge.ts +14 -10
- package/src/elements/nodes/base-node.ts +4 -2
- package/src/elements/shapes/base-shape.ts +23 -21
- package/src/exports.ts +2 -1
- package/src/layouts/fishbone.ts +3 -2
- package/src/layouts/index.ts +3 -0
- package/src/layouts/snake.ts +235 -0
- package/src/layouts/types.ts +25 -1
- package/src/plugins/background/index.ts +1 -0
- package/src/plugins/grid-line.ts +1 -0
- package/src/plugins/minimap/index.ts +1 -1
- package/src/plugins/tooltip.ts +11 -4
- package/src/registry/build-in.ts +2 -0
- package/src/runtime/data.ts +14 -19
- package/src/runtime/element.ts +62 -13
- package/src/runtime/graph.ts +19 -8
- package/src/runtime/layout.ts +79 -23
- package/src/runtime/options.ts +52 -0
- package/src/runtime/transform.ts +2 -0
- package/src/spec/canvas.ts +26 -2
- package/src/spec/data.ts +0 -14
- package/src/spec/graph.ts +60 -12
- package/src/spec/viewport.ts +4 -0
- package/src/transforms/base-transform.ts +3 -1
- package/src/utils/cache.ts +5 -5
- package/src/utils/element.ts +21 -2
- package/src/utils/layout.ts +16 -1
- package/src/utils/style.ts +5 -5
- package/src/utils/transform.ts +13 -9
- package/src/version.ts +1 -1
package/src/runtime/element.ts
CHANGED
|
@@ -262,28 +262,68 @@ export class ElementController {
|
|
|
262
262
|
return style;
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
+
private getDrawData(context: DrawContext): DrawPayload | null {
|
|
266
|
+
this.init();
|
|
267
|
+
|
|
268
|
+
const data = this.computeChangesAndDrawData(context);
|
|
269
|
+
if (!data) return null;
|
|
270
|
+
|
|
271
|
+
const { type = 'draw', stage = type } = context;
|
|
272
|
+
this.markDestroyElement(data.drawData);
|
|
273
|
+
// 计算样式 / Calculate style
|
|
274
|
+
this.computeStyle(stage);
|
|
275
|
+
|
|
276
|
+
return { type, stage, data };
|
|
277
|
+
}
|
|
278
|
+
|
|
265
279
|
/**
|
|
266
280
|
* <zh/> 开始绘制流程
|
|
267
281
|
*
|
|
268
282
|
* <en/> start render process
|
|
269
283
|
*/
|
|
270
284
|
public draw(context: DrawContext = { animation: true }) {
|
|
271
|
-
this.
|
|
285
|
+
const drawData = this.getDrawData(context);
|
|
286
|
+
if (!drawData) return;
|
|
272
287
|
|
|
273
|
-
const
|
|
274
|
-
|
|
288
|
+
const {
|
|
289
|
+
data: {
|
|
290
|
+
drawData: { add, update, remove },
|
|
291
|
+
},
|
|
292
|
+
} = drawData;
|
|
293
|
+
|
|
294
|
+
this.destroyElements(remove, context);
|
|
295
|
+
this.createElements(add, context);
|
|
296
|
+
this.updateElements(update, context);
|
|
297
|
+
|
|
298
|
+
return this.setAnimationTask(context, drawData);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
public async preLayoutDraw(context: DrawContext = { animation: true }) {
|
|
302
|
+
const preResult = this.getDrawData(context);
|
|
303
|
+
if (!preResult) return;
|
|
304
|
+
|
|
305
|
+
const {
|
|
306
|
+
data: { drawData },
|
|
307
|
+
} = preResult;
|
|
308
|
+
|
|
309
|
+
await this.context.layout?.preLayout?.(drawData);
|
|
275
310
|
|
|
276
|
-
const { type = 'draw', stage = type, animation, silence } = context;
|
|
277
|
-
const { dataChanges, drawData } = data;
|
|
278
|
-
this.markDestroyElement(drawData);
|
|
279
|
-
// 计算样式 / Calculate style
|
|
280
|
-
this.computeStyle(stage);
|
|
281
|
-
// 创建渲染任务 / Create render task
|
|
282
311
|
const { add, update, remove } = drawData;
|
|
283
312
|
this.destroyElements(remove, context);
|
|
284
313
|
this.createElements(add, context);
|
|
285
314
|
this.updateElements(update, context);
|
|
286
315
|
|
|
316
|
+
return this.setAnimationTask(context, preResult);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
private setAnimationTask(context: DrawContext, data: DrawPayload) {
|
|
320
|
+
const { animation, silence } = context;
|
|
321
|
+
const {
|
|
322
|
+
data: { dataChanges, drawData },
|
|
323
|
+
stage,
|
|
324
|
+
type,
|
|
325
|
+
} = data;
|
|
326
|
+
|
|
287
327
|
return this.context.animation!.animate(
|
|
288
328
|
animation,
|
|
289
329
|
silence
|
|
@@ -618,17 +658,17 @@ export class ElementController {
|
|
|
618
658
|
*
|
|
619
659
|
* <en/> collapse node
|
|
620
660
|
* @param id - <zh/> 元素 ID | <en/> element ID
|
|
621
|
-
* @param
|
|
661
|
+
* @param options - <zh/> 选项 | <en/> options
|
|
622
662
|
*/
|
|
623
663
|
public async collapseNode(id: ID, options: CollapseExpandNodeOptions): Promise<void> {
|
|
624
664
|
const { animation, align } = options;
|
|
625
665
|
|
|
626
666
|
const { model, layout } = this.context;
|
|
627
667
|
|
|
628
|
-
const
|
|
629
|
-
if (!
|
|
668
|
+
const simulateLayoutData = this.computeChangesAndDrawData({ stage: 'collapse', animation });
|
|
669
|
+
if (!simulateLayoutData) return;
|
|
630
670
|
|
|
631
|
-
this.markDestroyElement(
|
|
671
|
+
this.markDestroyElement(simulateLayoutData.drawData);
|
|
632
672
|
|
|
633
673
|
// 进行预布局,计算出所有元素的位置
|
|
634
674
|
// Perform pre-layout to calculate the position of all elements
|
|
@@ -837,6 +877,15 @@ export interface DrawContext {
|
|
|
837
877
|
target?: ID;
|
|
838
878
|
}
|
|
839
879
|
|
|
880
|
+
interface DrawPayload {
|
|
881
|
+
data: {
|
|
882
|
+
dataChanges: DataChange[];
|
|
883
|
+
drawData: DrawData;
|
|
884
|
+
};
|
|
885
|
+
stage: AnimationStage;
|
|
886
|
+
type: 'render' | 'draw';
|
|
887
|
+
}
|
|
888
|
+
|
|
840
889
|
/**
|
|
841
890
|
* <zh/> 展开/收起节点选项
|
|
842
891
|
*
|
package/src/runtime/graph.ts
CHANGED
|
@@ -44,6 +44,7 @@ import { sizeOf } from '../utils/dom';
|
|
|
44
44
|
import { getSubgraphRelatedEdges } from '../utils/edge';
|
|
45
45
|
import { GraphLifeCycleEvent, emit } from '../utils/event';
|
|
46
46
|
import { idOf } from '../utils/id';
|
|
47
|
+
import { isPreLayout } from '../utils/layout';
|
|
47
48
|
import { format } from '../utils/print';
|
|
48
49
|
import { subtract } from '../utils/vector';
|
|
49
50
|
import { getZIndexOf } from '../utils/z-index';
|
|
@@ -56,13 +57,14 @@ import { DataController } from './data';
|
|
|
56
57
|
import type { CollapseExpandNodeOptions } from './element';
|
|
57
58
|
import { ElementController } from './element';
|
|
58
59
|
import { LayoutController } from './layout';
|
|
60
|
+
import { inferOptions } from './options';
|
|
59
61
|
import { PluginController } from './plugin';
|
|
60
62
|
import { TransformController } from './transform';
|
|
61
63
|
import { RuntimeContext } from './types';
|
|
62
64
|
import { ViewportController } from './viewport';
|
|
63
65
|
|
|
64
66
|
export class Graph extends EventEmitter {
|
|
65
|
-
private options: GraphOptions;
|
|
67
|
+
private options: GraphOptions = {};
|
|
66
68
|
|
|
67
69
|
/**
|
|
68
70
|
* @internal
|
|
@@ -96,8 +98,7 @@ export class Graph extends EventEmitter {
|
|
|
96
98
|
|
|
97
99
|
constructor(options: GraphOptions) {
|
|
98
100
|
super();
|
|
99
|
-
this.
|
|
100
|
-
this._setOptions(this.options, true);
|
|
101
|
+
this._setOptions(Object.assign({}, Graph.defaultOptions, options), true);
|
|
101
102
|
this.context.graph = this;
|
|
102
103
|
|
|
103
104
|
// Listening resize to autoResize.
|
|
@@ -132,13 +133,13 @@ export class Graph extends EventEmitter {
|
|
|
132
133
|
|
|
133
134
|
private _setOptions(options: GraphOptions, isInit: boolean) {
|
|
134
135
|
this.updateCanvas(options);
|
|
136
|
+
Object.assign(this.options, inferOptions(options));
|
|
135
137
|
|
|
136
138
|
if (isInit) {
|
|
137
139
|
const { data } = options;
|
|
138
140
|
if (data) this.addData(data);
|
|
139
141
|
return;
|
|
140
142
|
}
|
|
141
|
-
Object.assign(this.options, options);
|
|
142
143
|
const { behaviors, combo, data, edge, layout, node, plugins, theme, transforms } = options;
|
|
143
144
|
if (behaviors) this.setBehaviors(behaviors);
|
|
144
145
|
if (data) this.setData(data);
|
|
@@ -1131,9 +1132,19 @@ export class Graph extends EventEmitter {
|
|
|
1131
1132
|
public async render(): Promise<void> {
|
|
1132
1133
|
await this.prepare();
|
|
1133
1134
|
emit(this, new GraphLifeCycleEvent(GraphEvent.BEFORE_RENDER));
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1135
|
+
|
|
1136
|
+
if (!this.options.layout) {
|
|
1137
|
+
const animation = this.context.element!.draw({ type: 'render' });
|
|
1138
|
+
await Promise.all([animation?.finished, this.autoFit()]);
|
|
1139
|
+
} else if (!this.rendered && isPreLayout(this.options.layout)) {
|
|
1140
|
+
const animation = await this.context.element!.preLayoutDraw({ type: 'render' });
|
|
1141
|
+
await Promise.all([animation?.finished, this.autoFit()]);
|
|
1142
|
+
} else {
|
|
1143
|
+
const animation = this.context.element!.draw({ type: 'render' });
|
|
1144
|
+
await Promise.all([animation?.finished, this.context.layout!.postLayout()]);
|
|
1145
|
+
await this.autoFit();
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1137
1148
|
this.rendered = true;
|
|
1138
1149
|
emit(this, new GraphLifeCycleEvent(GraphEvent.AFTER_RENDER));
|
|
1139
1150
|
}
|
|
@@ -1165,7 +1176,7 @@ export class Graph extends EventEmitter {
|
|
|
1165
1176
|
* @apiCategory layout
|
|
1166
1177
|
*/
|
|
1167
1178
|
public async layout() {
|
|
1168
|
-
await this.context.layout!.
|
|
1179
|
+
await this.context.layout!.postLayout();
|
|
1169
1180
|
}
|
|
1170
1181
|
|
|
1171
1182
|
/**
|
package/src/runtime/layout.ts
CHANGED
|
@@ -2,14 +2,16 @@ import type { IAnimation } from '@antv/g';
|
|
|
2
2
|
import { Graph as Graphlib } from '@antv/graphlib';
|
|
3
3
|
import { Supervisor, isLayoutWithIterations } from '@antv/layout';
|
|
4
4
|
import { deepMix } from '@antv/util';
|
|
5
|
-
import { GraphEvent, TREE_KEY } from '../constants';
|
|
5
|
+
import { COMBO_KEY, GraphEvent, TREE_KEY } from '../constants';
|
|
6
6
|
import { BaseLayout } from '../layouts';
|
|
7
7
|
import type { AntVLayout } from '../layouts/types';
|
|
8
8
|
import { getExtension } from '../registry/get';
|
|
9
9
|
import type { GraphData, NodeData } from '../spec';
|
|
10
10
|
import type { STDLayoutOptions } from '../spec/layout';
|
|
11
|
-
import type {
|
|
11
|
+
import type { DrawData } from '../transforms/types';
|
|
12
|
+
import type { AdaptiveLayout, ID, TreeData } from '../types';
|
|
12
13
|
import { getAnimationOptions } from '../utils/animation';
|
|
14
|
+
import { isCollapsed } from '../utils/collapsibility';
|
|
13
15
|
import { isToBeDestroyed } from '../utils/element';
|
|
14
16
|
import { GraphLifeCycleEvent, emit } from '../utils/event';
|
|
15
17
|
import { createTreeStructure } from '../utils/graphlib';
|
|
@@ -49,11 +51,54 @@ export class LayoutController {
|
|
|
49
51
|
return this.instances;
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
/**
|
|
55
|
+
* <zh/> 前布局,即在绘制前执行布局
|
|
56
|
+
*
|
|
57
|
+
* <en/> Pre-layout, that is, perform layout before drawing
|
|
58
|
+
* @param data - <zh/> 绘制数据 | <en/> Draw data
|
|
59
|
+
* @remarks
|
|
60
|
+
* <zh/> 前布局应该只在首次绘制前执行,后续更新不会触发
|
|
61
|
+
*
|
|
62
|
+
* <en/> Pre-layout should only be executed before the first drawing, and subsequent updates will not trigger
|
|
63
|
+
*/
|
|
64
|
+
public async preLayout(data: DrawData) {
|
|
65
|
+
const { graph, model } = this.context;
|
|
66
|
+
|
|
67
|
+
const { add } = data;
|
|
68
|
+
emit(graph, new GraphLifeCycleEvent(GraphEvent.BEFORE_LAYOUT, { type: 'pre' }));
|
|
69
|
+
const simulate = await this.context.layout?.simulate();
|
|
70
|
+
simulate?.nodes?.forEach((l) => {
|
|
71
|
+
const id = idOf(l);
|
|
72
|
+
const node = add.nodes.get(id);
|
|
73
|
+
model.syncNodeLikeDatum(l);
|
|
74
|
+
if (node) Object.assign(node.style!, l.style);
|
|
75
|
+
});
|
|
76
|
+
simulate?.edges?.forEach((l) => {
|
|
77
|
+
const id = idOf(l);
|
|
78
|
+
const edge = add.edges.get(id);
|
|
79
|
+
model.syncEdgeDatum(l);
|
|
80
|
+
if (edge) Object.assign(edge.style!, l.style);
|
|
81
|
+
});
|
|
82
|
+
simulate?.combos?.forEach((l) => {
|
|
83
|
+
const id = idOf(l);
|
|
84
|
+
const combo = add.combos.get(id);
|
|
85
|
+
model.syncNodeLikeDatum(l);
|
|
86
|
+
if (combo) Object.assign(combo.style!, l.style);
|
|
87
|
+
});
|
|
88
|
+
emit(graph, new GraphLifeCycleEvent(GraphEvent.AFTER_LAYOUT, { type: 'pre' }));
|
|
89
|
+
this.transformDataAfterLayout('pre', data);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* <zh/> 后布局,即在完成绘制后执行布局
|
|
94
|
+
*
|
|
95
|
+
* <en/> Post layout, that is, perform layout after drawing
|
|
96
|
+
*/
|
|
97
|
+
public async postLayout() {
|
|
53
98
|
if (!this.options) return;
|
|
54
99
|
const pipeline = Array.isArray(this.options) ? this.options : [this.options];
|
|
55
100
|
const { graph } = this.context;
|
|
56
|
-
emit(graph, new GraphLifeCycleEvent(GraphEvent.BEFORE_LAYOUT));
|
|
101
|
+
emit(graph, new GraphLifeCycleEvent(GraphEvent.BEFORE_LAYOUT, { type: 'post' }));
|
|
57
102
|
for (const options of pipeline) {
|
|
58
103
|
const index = pipeline.indexOf(options);
|
|
59
104
|
const data = this.getLayoutData(options);
|
|
@@ -67,14 +112,14 @@ export class LayoutController {
|
|
|
67
112
|
this.updateElementPosition(result, false);
|
|
68
113
|
}
|
|
69
114
|
}
|
|
70
|
-
emit(graph, new GraphLifeCycleEvent(GraphEvent.AFTER_LAYOUT));
|
|
71
|
-
this.transformDataAfterLayout();
|
|
115
|
+
emit(graph, new GraphLifeCycleEvent(GraphEvent.AFTER_LAYOUT, { type: 'post' }));
|
|
116
|
+
this.transformDataAfterLayout('post');
|
|
72
117
|
}
|
|
73
118
|
|
|
74
|
-
private transformDataAfterLayout() {
|
|
119
|
+
private transformDataAfterLayout(type: 'pre' | 'post', data?: DrawData) {
|
|
75
120
|
const transforms = this.context.transform.getTransformInstance();
|
|
76
|
-
|
|
77
|
-
Object.values(transforms).forEach((transform) => transform.afterLayout());
|
|
121
|
+
// @ts-expect-error skip type check
|
|
122
|
+
Object.values(transforms).forEach((transform) => transform.afterLayout(type, data));
|
|
78
123
|
}
|
|
79
124
|
|
|
80
125
|
/**
|
|
@@ -250,18 +295,30 @@ export class LayoutController {
|
|
|
250
295
|
}
|
|
251
296
|
|
|
252
297
|
public getLayoutData(options: STDLayoutOptions): GraphData {
|
|
253
|
-
const { nodeFilter = () => true } = options;
|
|
298
|
+
const { nodeFilter = () => true, preLayout = false, isLayoutInvisibleNodes = false } = options;
|
|
254
299
|
const { nodes, edges, combos } = this.context.model.getData();
|
|
255
300
|
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
301
|
+
const { element, model } = this.context;
|
|
302
|
+
const getElement = (id: ID) => element!.getElement(id);
|
|
303
|
+
|
|
304
|
+
const filterFn = preLayout
|
|
305
|
+
? (node: NodeData) => {
|
|
306
|
+
if (!isLayoutInvisibleNodes) {
|
|
307
|
+
if (node.style?.visibility === 'hidden') return false;
|
|
308
|
+
if (model.getAncestorsData(node.id, TREE_KEY).some(isCollapsed)) return false;
|
|
309
|
+
if (model.getAncestorsData(node.id, COMBO_KEY).some(isCollapsed)) return false;
|
|
310
|
+
}
|
|
311
|
+
return nodeFilter(node);
|
|
312
|
+
}
|
|
313
|
+
: (node: NodeData) => {
|
|
314
|
+
const id = idOf(node);
|
|
315
|
+
const element = getElement(id);
|
|
316
|
+
if (!element) return false;
|
|
317
|
+
if (isToBeDestroyed(element)) return false;
|
|
318
|
+
return nodeFilter(node);
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
const nodesToLayout = nodes.filter(filterFn);
|
|
265
322
|
|
|
266
323
|
const nodesIdMap = new Map<ID, NodeData>(nodesToLayout.map((node) => [idOf(node), node]));
|
|
267
324
|
|
|
@@ -295,10 +352,9 @@ export class LayoutController {
|
|
|
295
352
|
const nodeSize: number | ((node: NodeData) => number) =
|
|
296
353
|
(options?.nodeSize as number) ??
|
|
297
354
|
((node) => {
|
|
298
|
-
const nodeElement = element?.getElement
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
return size;
|
|
355
|
+
const nodeElement = element?.getElement(node.id);
|
|
356
|
+
if (nodeElement) return nodeElement.attributes.size;
|
|
357
|
+
return element?.getElementComputedStyle('node', node).size;
|
|
302
358
|
});
|
|
303
359
|
|
|
304
360
|
const Ctor = getExtension('layout', type);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { GraphOptions } from '../spec';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* <zh/> 基于用户传入的配置,推断出最终的配置
|
|
5
|
+
*
|
|
6
|
+
* <en/> Infer the final configuration based on the configuration passed by the user
|
|
7
|
+
* @param options - <zh/> 用户传入的配置 | <en/> Configuration passed by the user
|
|
8
|
+
* @returns <zh/> 最终的配置 | <en/> Final configuration
|
|
9
|
+
*/
|
|
10
|
+
export function inferOptions(options: GraphOptions): GraphOptions {
|
|
11
|
+
const flow = [inferLayoutOptions];
|
|
12
|
+
return flow.reduce((acc, infer) => infer(acc), options);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* <zh/> 推断布局配置
|
|
17
|
+
*
|
|
18
|
+
* <en/> Infer layout configuration
|
|
19
|
+
* @param options - <zh/> 用户传入的配置 | <en/> Configuration passed by the user
|
|
20
|
+
* @returns <zh/> 最终的配置 | <en/> Final configuration
|
|
21
|
+
*/
|
|
22
|
+
function inferLayoutOptions(options: GraphOptions): GraphOptions {
|
|
23
|
+
if (!options.layout) return options;
|
|
24
|
+
if (Array.isArray(options.layout)) return options;
|
|
25
|
+
if ('preLayout' in options.layout) return options;
|
|
26
|
+
|
|
27
|
+
if (
|
|
28
|
+
[
|
|
29
|
+
'antv-dagre',
|
|
30
|
+
'combo-combined',
|
|
31
|
+
'compact-box',
|
|
32
|
+
'circular',
|
|
33
|
+
'concentric',
|
|
34
|
+
'dagre',
|
|
35
|
+
'fishbone',
|
|
36
|
+
'grid',
|
|
37
|
+
'indented',
|
|
38
|
+
'mds',
|
|
39
|
+
'radial',
|
|
40
|
+
'random',
|
|
41
|
+
'snake',
|
|
42
|
+
// <zh/> 下列布局的标签位置待适配,需要手动配置 preLayout false
|
|
43
|
+
// <en/> The label position of the following layouts needs to be adapted, and preLayout needs to be manually configured as false
|
|
44
|
+
'dendrogram',
|
|
45
|
+
'mindmap',
|
|
46
|
+
].includes(options.layout.type)
|
|
47
|
+
) {
|
|
48
|
+
options.layout.preLayout = true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return options;
|
|
52
|
+
}
|
package/src/runtime/transform.ts
CHANGED
|
@@ -29,6 +29,8 @@ export class TransformController extends ExtensionController<BaseTransform<Custo
|
|
|
29
29
|
]);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
public getTransformInstance(): Record<string, BaseTransform>;
|
|
33
|
+
public getTransformInstance(key: string): BaseTransform;
|
|
32
34
|
public getTransformInstance(key?: string) {
|
|
33
35
|
return key ? this.extensionMap[key] : this.extensionMap;
|
|
34
36
|
}
|
package/src/spec/canvas.ts
CHANGED
|
@@ -18,18 +18,30 @@ export interface CanvasOptions {
|
|
|
18
18
|
* <zh/> 画布宽度
|
|
19
19
|
*
|
|
20
20
|
* <en/> canvas width
|
|
21
|
+
* @remarks
|
|
22
|
+
* <zh/> 如果未设置,则会自动获取容器宽度
|
|
23
|
+
*
|
|
24
|
+
* <en/> If not set, the container width will be automatically obtained
|
|
21
25
|
*/
|
|
22
26
|
width?: number;
|
|
23
27
|
/**
|
|
24
28
|
* <zh/> 画布高度
|
|
25
29
|
*
|
|
26
30
|
* <en/> canvas height
|
|
31
|
+
* @remarks
|
|
32
|
+
* <zh/> 如果未设置,则会自动获取容器高度
|
|
33
|
+
*
|
|
34
|
+
* <en/> If not set, the container height will be automatically obtained
|
|
27
35
|
*/
|
|
28
36
|
height?: number;
|
|
29
37
|
/**
|
|
30
|
-
* <zh/>
|
|
38
|
+
* <zh/> 手动置顶渲染器
|
|
39
|
+
*
|
|
40
|
+
* <en/> manually set renderer
|
|
41
|
+
* @remarks
|
|
42
|
+
* <zh/> G6 采用了分层渲染的方式,分为 background、main、label、transient 四层,用户可以通过该配置项分别设置每层画布的渲染器
|
|
31
43
|
*
|
|
32
|
-
* <en/>
|
|
44
|
+
* <en/> G6 adopts a layered rendering method, divided into four layers: background, main, label, transient. Users can set the renderer of each layer canvas separately through this configuration item
|
|
33
45
|
*/
|
|
34
46
|
renderer?: (layer: 'background' | 'main' | 'label' | 'transient') => IRenderer;
|
|
35
47
|
/**
|
|
@@ -37,18 +49,30 @@ export interface CanvasOptions {
|
|
|
37
49
|
*
|
|
38
50
|
* <en/> whether to auto resize canvas
|
|
39
51
|
* @defaultValue false
|
|
52
|
+
* @remarks
|
|
53
|
+
* <zh/> 基于 window.onresize 事件自动调整画布大小
|
|
54
|
+
*
|
|
55
|
+
* <en/> Automatically adjust the canvas size based on the window.onresize event
|
|
40
56
|
*/
|
|
41
57
|
autoResize?: boolean;
|
|
42
58
|
/**
|
|
43
59
|
* <zh/> 画布背景色
|
|
44
60
|
*
|
|
45
61
|
* <en/> canvas background color
|
|
62
|
+
* @remarks
|
|
63
|
+
* <zh/> 该颜色作为导出图片时的背景色
|
|
64
|
+
*
|
|
65
|
+
* <en/> This color is used as the background color when exporting images
|
|
46
66
|
*/
|
|
47
67
|
background?: string;
|
|
48
68
|
/**
|
|
49
69
|
* <zh/> 设备像素比
|
|
50
70
|
*
|
|
51
71
|
* <en/> device pixel ratio
|
|
72
|
+
* @remarks
|
|
73
|
+
* <zh/> 用于高清屏的设备像素比,默认为 [window.devicePixelRatio](https://developer.mozilla.org/zh-CN/docs/Web/API/Window/devicePixelRatio)
|
|
74
|
+
*
|
|
75
|
+
* <en/> Device pixel ratio for high-definition screens, default is [window.devicePixelRatio](https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio)
|
|
52
76
|
*/
|
|
53
77
|
devicePixelRatio?: number;
|
|
54
78
|
/**
|
package/src/spec/data.ts
CHANGED
|
@@ -189,20 +189,6 @@ export interface EdgeData {
|
|
|
189
189
|
* <en/> Target node ID
|
|
190
190
|
*/
|
|
191
191
|
target: ID;
|
|
192
|
-
/**
|
|
193
|
-
* <zh/> 边的起点 shape
|
|
194
|
-
*
|
|
195
|
-
* <en/> The source shape. Represents the start of the edge
|
|
196
|
-
* @internal
|
|
197
|
-
*/
|
|
198
|
-
sourceNode?: ID;
|
|
199
|
-
/**
|
|
200
|
-
* <zh/> 边的终点 shape
|
|
201
|
-
*
|
|
202
|
-
* <en/> The source shape. Represents the start of the edge
|
|
203
|
-
* @internal
|
|
204
|
-
*/
|
|
205
|
-
targetNode?: ID;
|
|
206
192
|
/**
|
|
207
193
|
* <zh/> 边类型
|
|
208
194
|
*
|
package/src/spec/graph.ts
CHANGED
|
@@ -40,30 +40,50 @@ export interface GraphOptions extends CanvasOptions, ViewportOptions {
|
|
|
40
40
|
* <zh/> 数据
|
|
41
41
|
*
|
|
42
42
|
* <en/> Data
|
|
43
|
+
* @remarks
|
|
44
|
+
* <zh/> 详见 [Data](/api/data/graph-data)
|
|
45
|
+
*
|
|
46
|
+
* <en/> See [Data](/en/api/data/graph-data)
|
|
43
47
|
*/
|
|
44
48
|
data?: GraphData;
|
|
45
49
|
/**
|
|
46
|
-
* <zh/>
|
|
50
|
+
* <zh/> 布局配置项
|
|
51
|
+
*
|
|
52
|
+
* <en/> Layout options
|
|
53
|
+
* @remarks
|
|
54
|
+
* <zh/> 详见 [Layout](/api/layouts/antv-dagre-layout)
|
|
47
55
|
*
|
|
48
|
-
* <en/> Layout
|
|
56
|
+
* <en/> See [Layout](/en/api/layouts/antv-dagre-layout)
|
|
49
57
|
*/
|
|
50
58
|
layout?: LayoutOptions;
|
|
51
59
|
/**
|
|
52
|
-
* <zh/>
|
|
60
|
+
* <zh/> 节点配置项
|
|
61
|
+
*
|
|
62
|
+
* <en/> Node options
|
|
63
|
+
* @remarks
|
|
64
|
+
* <zh/> 详见 [Node](/api/elements/nodes/base-node)
|
|
53
65
|
*
|
|
54
|
-
* <en/> Node
|
|
66
|
+
* <en/> See [Node](/en/api/elements/nodes/base-node)
|
|
55
67
|
*/
|
|
56
68
|
node?: NodeOptions;
|
|
57
69
|
/**
|
|
58
|
-
* <zh/>
|
|
70
|
+
* <zh/> 边配置项
|
|
59
71
|
*
|
|
60
|
-
* <en/> Edge
|
|
72
|
+
* <en/> Edge options
|
|
73
|
+
* @remarks
|
|
74
|
+
* <zh/> 详见 [Edge](/api/elements/edges/base-edge)
|
|
75
|
+
*
|
|
76
|
+
* <en/> See [Edge](/en/api/elements/edges/base-edge)
|
|
61
77
|
*/
|
|
62
78
|
edge?: EdgeOptions;
|
|
63
79
|
/**
|
|
64
|
-
* <zh/>
|
|
80
|
+
* <zh/> 组合配置项
|
|
65
81
|
*
|
|
66
|
-
* <en/> Combo
|
|
82
|
+
* <en/> Combo options
|
|
83
|
+
* @remarks
|
|
84
|
+
* <zh/> 详见 [Combo](/api/elements/combos/base-combo)
|
|
85
|
+
*
|
|
86
|
+
* <en/> See [Combo](/en/api/elements/combos/base-combo)
|
|
67
87
|
*/
|
|
68
88
|
combo?: ComboOptions;
|
|
69
89
|
/**
|
|
@@ -73,15 +93,43 @@ export interface GraphOptions extends CanvasOptions, ViewportOptions {
|
|
|
73
93
|
*/
|
|
74
94
|
theme?: ThemeOptions;
|
|
75
95
|
/**
|
|
76
|
-
* <zh/>
|
|
96
|
+
* <zh/> 启用交互
|
|
97
|
+
*
|
|
98
|
+
* <en/> Enable interactions
|
|
99
|
+
* @remarks
|
|
100
|
+
* <zh/>
|
|
101
|
+
* - 概念:[核心概念 - 交互](/manual/core-concept/behavior)
|
|
102
|
+
*
|
|
103
|
+
* - 内置交互: [交互](/api/behaviors/auto-adapt-label)
|
|
104
|
+
*
|
|
105
|
+
* - 自定义交互: [自定义扩展 - 自定义交互](/manual/advanced/custom-behavior)
|
|
77
106
|
*
|
|
78
|
-
* <en/>
|
|
107
|
+
* <en/>
|
|
108
|
+
* - Concept: [Concepts - Behavior](/en/manual/core-concept/behavior)
|
|
109
|
+
*
|
|
110
|
+
* - Built-in behaviors: [Behavior](/en/api/behaviors/auto-adapt-label)
|
|
111
|
+
*
|
|
112
|
+
* - Custom behaviors: [Custom Extension - Custom Behavior](/en/manual/advanced/custom-behavior)
|
|
79
113
|
*/
|
|
80
114
|
behaviors?: BehaviorOptions;
|
|
81
115
|
/**
|
|
82
|
-
* <zh/>
|
|
116
|
+
* <zh/> 启用插件
|
|
117
|
+
*
|
|
118
|
+
* <en/> Enable plugins
|
|
119
|
+
* @remarks
|
|
120
|
+
* <zh/>
|
|
121
|
+
* - 概念:[核心概念 - 插件](/manual/core-concept/plugin)
|
|
122
|
+
*
|
|
123
|
+
* - 内置插件: [插件](/en/api/plugins/background)
|
|
124
|
+
*
|
|
125
|
+
* - 自定义插件: [自定义扩展 - 自定义插件](/manual/advanced/custom-plugin)
|
|
126
|
+
*
|
|
127
|
+
* <en/>
|
|
128
|
+
* - Concept: [Concepts - Plugin](/en/manual/core-concept/plugin)
|
|
129
|
+
*
|
|
130
|
+
* - Built-in plugins: [Plugin](/en/api/plugins/background)
|
|
83
131
|
*
|
|
84
|
-
*
|
|
132
|
+
* - Custom plugins: [Custom Extension - Custom Plugin](/en/manual/advanced/custom-plugin)
|
|
85
133
|
*/
|
|
86
134
|
plugins?: PluginOptions;
|
|
87
135
|
/**
|
package/src/spec/viewport.ts
CHANGED
|
@@ -24,6 +24,10 @@ export interface ViewportOptions {
|
|
|
24
24
|
* <zh/> 是否自动适应
|
|
25
25
|
*
|
|
26
26
|
* <en/> whether to auto fit
|
|
27
|
+
* @remarks
|
|
28
|
+
* <zh/> 每次执行 `render` 时,都会根据 `autoFit` 进行自适应
|
|
29
|
+
*
|
|
30
|
+
* <en/> Every time `render` is executed, it will be adapted according to `autoFit`
|
|
27
31
|
*/
|
|
28
32
|
autoFit?:
|
|
29
33
|
| { type: 'view'; options?: FitViewOptions; animation?: ViewportAnimationEffectTiming }
|
|
@@ -15,5 +15,7 @@ export abstract class BaseTransform<T extends BaseTransformOptions = BaseTransfo
|
|
|
15
15
|
return data;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
public afterLayout()
|
|
18
|
+
public afterLayout(type: 'pre', data: DrawData): void;
|
|
19
|
+
public afterLayout(type: 'post', data?: undefined): void;
|
|
20
|
+
public afterLayout(type: 'pre' | 'post', data?: DrawData) {}
|
|
19
21
|
}
|
package/src/utils/cache.ts
CHANGED
|
@@ -8,8 +8,8 @@ const getStyleCacheKey = (name: string) => `__${name}__`;
|
|
|
8
8
|
/**
|
|
9
9
|
* <zh/> 缓存图形样式
|
|
10
10
|
*
|
|
11
|
-
* <en/> Cache
|
|
12
|
-
* @param element - <zh/> 图形元素 | <en/>
|
|
11
|
+
* <en/> Cache shape style
|
|
12
|
+
* @param element - <zh/> 图形元素 | <en/> shape element
|
|
13
13
|
* @param name - <zh/> 样式名 | <en/> style name
|
|
14
14
|
*/
|
|
15
15
|
export function cacheStyle(element: DisplayObject, name: string | string[]) {
|
|
@@ -24,7 +24,7 @@ export function cacheStyle(element: DisplayObject, name: string | string[]) {
|
|
|
24
24
|
* <zh/> 获取缓存的样式
|
|
25
25
|
*
|
|
26
26
|
* <en/> Get cached style
|
|
27
|
-
* @param element - <zh/> 图形元素 | <en/>
|
|
27
|
+
* @param element - <zh/> 图形元素 | <en/> shape element
|
|
28
28
|
* @param name - <zh/> 样式名 | <en/> style name
|
|
29
29
|
* @returns <zh/> 样式值 | <en/> style value
|
|
30
30
|
*/
|
|
@@ -36,7 +36,7 @@ export function getCachedStyle(element: DisplayObject, name: string) {
|
|
|
36
36
|
* <zh/> 是否有缓存的样式
|
|
37
37
|
*
|
|
38
38
|
* <en/> Whether there is a cached style
|
|
39
|
-
* @param element - <zh/> 图形元素 | <en/>
|
|
39
|
+
* @param element - <zh/> 图形元素 | <en/> shape element
|
|
40
40
|
* @param name - <zh/> 样式名 | <en/> style name
|
|
41
41
|
* @returns <zh/> 是否有缓存的样式 | <en/> Whether there is a cached style
|
|
42
42
|
*/
|
|
@@ -48,7 +48,7 @@ export function hasCachedStyle(element: DisplayObject, name: string) {
|
|
|
48
48
|
* <zh/> 设置缓存的样式
|
|
49
49
|
*
|
|
50
50
|
* <en/> Set cached style
|
|
51
|
-
* @param element - <zh/> 图形元素 | <en/>
|
|
51
|
+
* @param element - <zh/> 图形元素 | <en/> shape element
|
|
52
52
|
* @param name - <zh/> 样式名 | <en/> style name
|
|
53
53
|
* @param value - <zh/> 样式值 | <en/> style value
|
|
54
54
|
*/
|