@antv/g6 5.0.50 → 5.1.0-beta.0
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/README.md +1 -0
- package/README.zh-CN.md +1 -0
- package/dist/g6.min.js +38 -59
- package/dist/lib/behaviors/brush-select.d.ts +1 -2
- package/dist/lib/behaviors/click-select.d.ts +2 -2
- package/dist/lib/behaviors/drag-element.d.ts +18 -0
- package/dist/lib/behaviors/focus-element.d.ts +18 -0
- package/dist/lib/layouts/types.d.ts +14 -2
- package/dist/lib/plugins/bubble-sets.d.ts +1 -1
- package/dist/lib/plugins/legend.d.ts +10 -2
- package/dist/lib/runtime/element.d.ts +8 -0
- package/dist/lib/runtime/layout.d.ts +2 -2
- package/dist/lib/types/layout.d.ts +2 -4
- package/dist/lib/utils/data.d.ts +9 -0
- package/dist/lib/utils/layout.d.ts +20 -4
- package/dist/lib/version.d.ts +1 -1
- package/esm/behaviors/brush-select.d.ts +1 -2
- package/esm/behaviors/brush-select.js +2 -2
- package/esm/behaviors/brush-select.js.map +1 -1
- package/esm/behaviors/click-select.d.ts +2 -2
- package/esm/behaviors/click-select.js.map +1 -1
- package/esm/behaviors/create-edge.js +5 -1
- package/esm/behaviors/create-edge.js.map +1 -1
- package/esm/behaviors/drag-element.d.ts +18 -0
- package/esm/behaviors/drag-element.js +18 -1
- package/esm/behaviors/drag-element.js.map +1 -1
- package/esm/behaviors/focus-element.d.ts +18 -0
- package/esm/behaviors/focus-element.js +18 -1
- package/esm/behaviors/focus-element.js.map +1 -1
- package/esm/elements/combos/base-combo.js.map +1 -1
- package/esm/elements/edges/base-edge.js.map +1 -1
- package/esm/elements/nodes/base-node.js.map +1 -1
- package/esm/layouts/types.d.ts +14 -2
- package/esm/plugins/bubble-sets.d.ts +1 -1
- package/esm/plugins/bubble-sets.js +30 -7
- package/esm/plugins/bubble-sets.js.map +1 -1
- package/esm/plugins/legend.d.ts +10 -2
- package/esm/plugins/legend.js.map +1 -1
- package/esm/plugins/tooltip.js +6 -1
- package/esm/plugins/tooltip.js.map +1 -1
- package/esm/registry/build-in.js +3 -3
- package/esm/registry/build-in.js.map +1 -1
- package/esm/runtime/canvas.js.map +1 -1
- package/esm/runtime/element.d.ts +8 -0
- package/esm/runtime/element.js +53 -8
- package/esm/runtime/element.js.map +1 -1
- package/esm/runtime/graph.js +2 -2
- package/esm/runtime/graph.js.map +1 -1
- package/esm/runtime/layout.d.ts +2 -2
- package/esm/runtime/layout.js +15 -25
- package/esm/runtime/layout.js.map +1 -1
- package/esm/types/layout.d.ts +2 -4
- package/esm/utils/data.d.ts +9 -0
- package/esm/utils/data.js +11 -0
- package/esm/utils/data.js.map +1 -1
- package/esm/utils/layout.d.ts +20 -4
- package/esm/utils/layout.js +99 -5
- package/esm/utils/layout.js.map +1 -1
- package/esm/utils/shortcut.js +1 -1
- package/esm/utils/shortcut.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/behaviors/brush-select.d.ts +1 -2
- package/lib/behaviors/brush-select.js +2 -2
- package/lib/behaviors/brush-select.js.map +1 -1
- package/lib/behaviors/click-select.d.ts +2 -2
- package/lib/behaviors/click-select.js.map +1 -1
- package/lib/behaviors/create-edge.js +5 -1
- package/lib/behaviors/create-edge.js.map +1 -1
- package/lib/behaviors/drag-element.d.ts +18 -0
- package/lib/behaviors/drag-element.js +18 -1
- package/lib/behaviors/drag-element.js.map +1 -1
- package/lib/behaviors/focus-element.d.ts +18 -0
- package/lib/behaviors/focus-element.js +18 -1
- package/lib/behaviors/focus-element.js.map +1 -1
- package/lib/elements/combos/base-combo.js.map +1 -1
- package/lib/elements/edges/base-edge.js.map +1 -1
- package/lib/elements/nodes/base-node.js.map +1 -1
- package/lib/layouts/types.d.ts +14 -2
- package/lib/plugins/bubble-sets.d.ts +1 -1
- package/lib/plugins/bubble-sets.js +30 -7
- package/lib/plugins/bubble-sets.js.map +1 -1
- package/lib/plugins/legend.d.ts +10 -2
- package/lib/plugins/legend.js.map +1 -1
- package/lib/plugins/tooltip.js +6 -1
- package/lib/plugins/tooltip.js.map +1 -1
- package/lib/registry/build-in.js.map +1 -1
- package/lib/runtime/canvas.js.map +1 -1
- package/lib/runtime/element.d.ts +8 -0
- package/lib/runtime/element.js +53 -8
- package/lib/runtime/element.js.map +1 -1
- package/lib/runtime/graph.js +2 -2
- package/lib/runtime/graph.js.map +1 -1
- package/lib/runtime/layout.d.ts +2 -2
- package/lib/runtime/layout.js +12 -22
- package/lib/runtime/layout.js.map +1 -1
- package/lib/types/layout.d.ts +2 -4
- package/lib/utils/data.d.ts +9 -0
- package/lib/utils/data.js +13 -0
- package/lib/utils/data.js.map +1 -1
- package/lib/utils/layout.d.ts +20 -4
- package/lib/utils/layout.js +102 -6
- package/lib/utils/layout.js.map +1 -1
- package/lib/utils/shortcut.js +1 -1
- package/lib/utils/shortcut.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 +34 -32
- package/src/behaviors/brush-select.ts +3 -4
- package/src/behaviors/click-select.ts +1 -1
- package/src/behaviors/create-edge.ts +5 -3
- package/src/behaviors/drag-element.ts +29 -1
- package/src/behaviors/focus-element.ts +28 -1
- package/src/elements/combos/base-combo.ts +2 -1
- package/src/elements/edges/base-edge.ts +2 -1
- package/src/elements/nodes/base-node.ts +2 -1
- package/src/layouts/types.ts +16 -1
- package/src/plugins/bubble-sets.ts +37 -9
- package/src/plugins/legend.ts +1 -1
- package/src/plugins/tooltip.ts +8 -2
- package/src/registry/build-in.ts +4 -4
- package/src/runtime/canvas.ts +4 -2
- package/src/runtime/element.ts +54 -9
- package/src/runtime/graph.ts +2 -2
- package/src/runtime/layout.ts +20 -30
- package/src/types/edge.ts +1 -3
- package/src/types/layout.ts +2 -5
- package/src/utils/data.ts +12 -0
- package/src/utils/layout.ts +146 -18
- package/src/utils/shortcut.ts +1 -1
- package/src/version.ts +1 -1
- package/LICENSE +0 -21
- package/src/layouts/hierarchy.d.ts +0 -10
package/src/runtime/element.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { groupBy } from '@antv/util';
|
|
|
6
6
|
import { AnimationType, COMBO_KEY, ChangeType, GraphEvent } from '../constants';
|
|
7
7
|
import { ELEMENT_TYPES } from '../constants/element';
|
|
8
8
|
import { getExtension } from '../registry/get';
|
|
9
|
-
import type { ComboData, EdgeData, GraphData, NodeData } from '../spec';
|
|
9
|
+
import type { ComboData, EdgeData, GraphData, LayoutOptions, NodeData } from '../spec';
|
|
10
10
|
import type { AnimationStage } from '../spec/element/animation';
|
|
11
11
|
import type { DrawData, ProcedureData } from '../transforms/types';
|
|
12
12
|
import type {
|
|
@@ -26,6 +26,7 @@ import type {
|
|
|
26
26
|
import { cacheStyle, hasCachedStyle } from '../utils/cache';
|
|
27
27
|
import { reduceDataChanges } from '../utils/change';
|
|
28
28
|
import { isCollapsed } from '../utils/collapsibility';
|
|
29
|
+
import { isOverridable } from '../utils/data';
|
|
29
30
|
import { markToBeDestroyed, updateStyle } from '../utils/element';
|
|
30
31
|
import type { BaseEvent } from '../utils/event';
|
|
31
32
|
import { AnimateEvent, ElementLifeCycleEvent, GraphLifeCycleEvent, emit } from '../utils/event';
|
|
@@ -77,7 +78,7 @@ export class ElementController {
|
|
|
77
78
|
|
|
78
79
|
public getElementType(elementType: ElementType, datum: ElementDatum) {
|
|
79
80
|
const { options, graph } = this.context;
|
|
80
|
-
const userDefinedType = options[elementType]?.type || datum.type;
|
|
81
|
+
const userDefinedType = isOverridable(datum) ? options[elementType]?.type || datum.type : datum.type;
|
|
81
82
|
|
|
82
83
|
if (!userDefinedType) {
|
|
83
84
|
if (elementType === 'edge') return 'line';
|
|
@@ -255,7 +256,9 @@ export class ElementController {
|
|
|
255
256
|
const themeStateStyle = this.getThemeStateStyle(elementType, this.getElementState(id));
|
|
256
257
|
const stateStyle = this.getStateStyle(id);
|
|
257
258
|
|
|
258
|
-
const style =
|
|
259
|
+
const style = isOverridable(datum)
|
|
260
|
+
? Object.assign({}, themeStyle, paletteStyle, dataStyle, defaultStyle, themeStateStyle, stateStyle)
|
|
261
|
+
: Object.assign({}, dataStyle);
|
|
259
262
|
|
|
260
263
|
if (elementType === 'combo') {
|
|
261
264
|
const childrenData = this.context.model.getChildrenData(id);
|
|
@@ -380,6 +383,23 @@ export class ElementController {
|
|
|
380
383
|
ComboRemoved = [],
|
|
381
384
|
} = groupBy(tasks, (change) => change.type) as unknown as Record<`${ChangeType}`, DataChange[]>;
|
|
382
385
|
|
|
386
|
+
const moveToAddedIfUnrendered = (updated: DataChange[], added: DataChange[]) => {
|
|
387
|
+
const keptUpdates: DataChange[] = [];
|
|
388
|
+
updated.forEach((change) => {
|
|
389
|
+
const id = idOf(change.value);
|
|
390
|
+
if (!this.getElement(id)) {
|
|
391
|
+
added.push(change);
|
|
392
|
+
} else {
|
|
393
|
+
keptUpdates.push(change);
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
return keptUpdates;
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
const finalNodeUpdated = moveToAddedIfUnrendered(NodeUpdated, NodeAdded);
|
|
400
|
+
const finalEdgeUpdated = moveToAddedIfUnrendered(EdgeUpdated, EdgeAdded);
|
|
401
|
+
const finalComboUpdated = moveToAddedIfUnrendered(ComboUpdated, ComboAdded);
|
|
402
|
+
|
|
383
403
|
const dataOf = <T extends DataChange['value']>(data: DataChange[]) =>
|
|
384
404
|
new Map(
|
|
385
405
|
data.map((datum) => {
|
|
@@ -395,9 +415,9 @@ export class ElementController {
|
|
|
395
415
|
combos: dataOf<ComboData>(ComboAdded),
|
|
396
416
|
},
|
|
397
417
|
update: {
|
|
398
|
-
nodes: dataOf<NodeData>(
|
|
399
|
-
edges: dataOf<EdgeData>(
|
|
400
|
-
combos: dataOf<ComboData>(
|
|
418
|
+
nodes: dataOf<NodeData>(finalNodeUpdated),
|
|
419
|
+
edges: dataOf<EdgeData>(finalEdgeUpdated),
|
|
420
|
+
combos: dataOf<ComboData>(finalComboUpdated),
|
|
401
421
|
},
|
|
402
422
|
remove: {
|
|
403
423
|
nodes: dataOf<NodeData>(NodeRemoved),
|
|
@@ -655,6 +675,29 @@ export class ElementController {
|
|
|
655
675
|
}
|
|
656
676
|
}
|
|
657
677
|
|
|
678
|
+
/**
|
|
679
|
+
* <zh/> 同步布局结果
|
|
680
|
+
*
|
|
681
|
+
* <en/> Sync layout result
|
|
682
|
+
* @param id - <zh/> 元素 ID | <en/> element ID
|
|
683
|
+
* @param align - <zh/> 是否对齐 | <en/> whether to align
|
|
684
|
+
*/
|
|
685
|
+
private async syncLayoutResult(id: ID, align?: boolean) {
|
|
686
|
+
const { layout, model } = this.context;
|
|
687
|
+
if (!layout) return;
|
|
688
|
+
|
|
689
|
+
const layoutOptions = this.context.options.layout;
|
|
690
|
+
const forcePreLayout = (opts: LayoutOptions): LayoutOptions => {
|
|
691
|
+
if (Array.isArray(opts)) {
|
|
692
|
+
return opts.map((o) => ({ ...o, preLayout: true }));
|
|
693
|
+
}
|
|
694
|
+
return { ...opts, preLayout: true };
|
|
695
|
+
};
|
|
696
|
+
const layoutResult = await layout.simulate(layoutOptions ? forcePreLayout(layoutOptions) : undefined);
|
|
697
|
+
if (align) this.alignLayoutResultToElement(layoutResult, id);
|
|
698
|
+
model.updateData(layoutResult);
|
|
699
|
+
}
|
|
700
|
+
|
|
658
701
|
/**
|
|
659
702
|
* <zh/> 收起节点
|
|
660
703
|
*
|
|
@@ -663,8 +706,8 @@ export class ElementController {
|
|
|
663
706
|
* @param options - <zh/> 选项 | <en/> options
|
|
664
707
|
*/
|
|
665
708
|
public async collapseNode(id: ID, options: CollapseExpandNodeOptions): Promise<void> {
|
|
666
|
-
const { animation } = options;
|
|
667
|
-
|
|
709
|
+
const { animation, align } = options;
|
|
710
|
+
await this.syncLayoutResult(id, align);
|
|
668
711
|
|
|
669
712
|
// 重新计算数据 / Recalculate data
|
|
670
713
|
const data = this.computeChangesAndDrawData({ stage: 'collapse', animation });
|
|
@@ -704,10 +747,12 @@ export class ElementController {
|
|
|
704
747
|
* @param animation - <zh/> 是否使用动画,默认为 true | <en/> Whether to use animation, default is true
|
|
705
748
|
*/
|
|
706
749
|
public async expandNode(id: ID, options: CollapseExpandNodeOptions): Promise<void> {
|
|
707
|
-
const { model
|
|
750
|
+
const { model } = this.context;
|
|
708
751
|
const { animation, align } = options;
|
|
709
752
|
const position = positionOf(model.getNodeData([id])[0]);
|
|
710
753
|
|
|
754
|
+
await this.syncLayoutResult(id, align);
|
|
755
|
+
|
|
711
756
|
// 重新计算数据 / Recalculate data
|
|
712
757
|
const data = this.computeChangesAndDrawData({ stage: 'expand', animation });
|
|
713
758
|
this.createElements(data!.drawData.add, { animation: false, stage: 'expand', target: id });
|
package/src/runtime/graph.ts
CHANGED
|
@@ -1873,7 +1873,7 @@ export class Graph extends EventEmitter {
|
|
|
1873
1873
|
if (isCollapsed(model.getNodeLikeData([id])[0])) return;
|
|
1874
1874
|
if (this.isCollapsingExpanding) return;
|
|
1875
1875
|
|
|
1876
|
-
if (typeof options === 'boolean') options = { animation: options, align:
|
|
1876
|
+
if (typeof options === 'boolean') options = { animation: options, align: false };
|
|
1877
1877
|
|
|
1878
1878
|
const elementType = model.getElementType(id);
|
|
1879
1879
|
|
|
@@ -1911,7 +1911,7 @@ export class Graph extends EventEmitter {
|
|
|
1911
1911
|
if (!isCollapsed(model.getNodeLikeData([id])[0])) return;
|
|
1912
1912
|
if (this.isCollapsingExpanding) return;
|
|
1913
1913
|
|
|
1914
|
-
if (typeof options === 'boolean') options = { animation: options, align:
|
|
1914
|
+
if (typeof options === 'boolean') options = { animation: options, align: false };
|
|
1915
1915
|
|
|
1916
1916
|
const elementType = model.getElementType(id);
|
|
1917
1917
|
|
package/src/runtime/layout.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import type { IAnimation } from '@antv/g';
|
|
2
2
|
import { Graph as Graphlib } from '@antv/graphlib';
|
|
3
|
-
import {
|
|
3
|
+
import { isLayoutWithIterations } from '@antv/layout';
|
|
4
4
|
import { deepMix } from '@antv/util';
|
|
5
5
|
import { COMBO_KEY, GraphEvent, TREE_KEY } from '../constants';
|
|
6
6
|
import { BaseLayout } from '../layouts';
|
|
7
|
-
import
|
|
7
|
+
import { AntVLayout } from '../layouts/types';
|
|
8
8
|
import { getExtension } from '../registry/get';
|
|
9
9
|
import type { GraphData, LayoutOptions, NodeData } from '../spec';
|
|
10
10
|
import type { STDLayoutOptions } from '../spec/layout';
|
|
11
11
|
import type { DrawData } from '../transforms/types';
|
|
12
|
-
import type {
|
|
12
|
+
import type { ID, TreeData } from '../types';
|
|
13
13
|
import { getAnimationOptions } from '../utils/animation';
|
|
14
14
|
import { isCollapsed } from '../utils/collapsibility';
|
|
15
15
|
import { isToBeDestroyed } from '../utils/element';
|
|
16
|
-
import {
|
|
16
|
+
import { emit, GraphLifeCycleEvent } from '../utils/event';
|
|
17
17
|
import { createTreeStructure } from '../utils/graphlib';
|
|
18
18
|
import { idOf } from '../utils/id';
|
|
19
|
-
import { isTreeLayout, layoutAdapter,
|
|
19
|
+
import { isLegacyAntVLayout, isTreeLayout, layoutAdapter, legacyLayoutAdapter } from '../utils/layout';
|
|
20
20
|
import { print } from '../utils/print';
|
|
21
21
|
import { dfs } from '../utils/traverse';
|
|
22
22
|
import type { RuntimeContext } from './types';
|
|
@@ -24,8 +24,6 @@ import type { RuntimeContext } from './types';
|
|
|
24
24
|
export class LayoutController {
|
|
25
25
|
private context: RuntimeContext;
|
|
26
26
|
|
|
27
|
-
private supervisor?: Supervisor;
|
|
28
|
-
|
|
29
27
|
private instance?: BaseLayout;
|
|
30
28
|
|
|
31
29
|
private instances: BaseLayout[] = [];
|
|
@@ -100,6 +98,7 @@ export class LayoutController {
|
|
|
100
98
|
const pipeline = Array.isArray(layoutOptions) ? layoutOptions : [layoutOptions];
|
|
101
99
|
const { graph } = this.context;
|
|
102
100
|
emit(graph, new GraphLifeCycleEvent(GraphEvent.BEFORE_LAYOUT, { type: 'post' }));
|
|
101
|
+
|
|
103
102
|
for (let index = 0; index < pipeline.length; index++) {
|
|
104
103
|
const options = pipeline[index];
|
|
105
104
|
const data = this.getLayoutData(options);
|
|
@@ -127,11 +126,12 @@ export class LayoutController {
|
|
|
127
126
|
* <zh/> 模拟布局
|
|
128
127
|
*
|
|
129
128
|
* <en/> Simulate layout
|
|
129
|
+
* @param options - <zh/> 布局配置项 | <en/> Layout options
|
|
130
130
|
* @returns <zh/> 模拟布局结果 | <en/> Simulated layout result
|
|
131
131
|
*/
|
|
132
|
-
public async simulate(): Promise<GraphData> {
|
|
133
|
-
if (!
|
|
134
|
-
const pipeline = Array.isArray(
|
|
132
|
+
public async simulate(options: LayoutOptions | undefined = this.options): Promise<GraphData> {
|
|
133
|
+
if (!options) return {};
|
|
134
|
+
const pipeline = Array.isArray(options) ? options : [options];
|
|
135
135
|
|
|
136
136
|
let simulation: GraphData = {};
|
|
137
137
|
|
|
@@ -153,7 +153,7 @@ export class LayoutController {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
private async graphLayout(data: GraphData, options: STDLayoutOptions, index: number): Promise<GraphData> {
|
|
156
|
-
const { animation,
|
|
156
|
+
const { animation, iterations = 300 } = options;
|
|
157
157
|
|
|
158
158
|
const layout = this.initGraphLayout(options);
|
|
159
159
|
if (!layout) return {};
|
|
@@ -161,20 +161,13 @@ export class LayoutController {
|
|
|
161
161
|
this.instances[index] = layout;
|
|
162
162
|
this.instance = layout;
|
|
163
163
|
|
|
164
|
-
// 使用 web worker 执行布局 / Use web worker to execute layout
|
|
165
|
-
if (enableWorker) {
|
|
166
|
-
const rawLayout = layout as unknown as AdaptiveLayout;
|
|
167
|
-
this.supervisor = new Supervisor(rawLayout.graphData2LayoutModel(data), rawLayout.instance, { iterations });
|
|
168
|
-
return layoutMapping2GraphData(await this.supervisor.execute());
|
|
169
|
-
}
|
|
170
|
-
|
|
171
164
|
if (isLayoutWithIterations(layout)) {
|
|
172
165
|
// 有动画,基于布局迭代 tick 更新位置 / Update position based on layout iteration tick
|
|
173
166
|
if (animation) {
|
|
174
167
|
return await layout.execute(data, {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
168
|
+
animate: true,
|
|
169
|
+
maxIteration: iterations,
|
|
170
|
+
onTick: (tickData: GraphData) => this.updateElementPosition(tickData, false),
|
|
178
171
|
});
|
|
179
172
|
}
|
|
180
173
|
|
|
@@ -186,6 +179,7 @@ export class LayoutController {
|
|
|
186
179
|
|
|
187
180
|
// 无迭代的布局,直接返回终态位置 / Layout without iteration, return final position directly
|
|
188
181
|
const layoutResult = await layout.execute(data);
|
|
182
|
+
|
|
189
183
|
if (animation) {
|
|
190
184
|
const animationResult = this.updateElementPosition(layoutResult, animation);
|
|
191
185
|
await animationResult?.finished;
|
|
@@ -284,11 +278,6 @@ export class LayoutController {
|
|
|
284
278
|
this.instance = undefined;
|
|
285
279
|
}
|
|
286
280
|
|
|
287
|
-
if (this.supervisor) {
|
|
288
|
-
this.supervisor.stop();
|
|
289
|
-
this.supervisor = undefined;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
281
|
if (this.animationResult) {
|
|
293
282
|
this.animationResult.finish();
|
|
294
283
|
this.animationResult = undefined;
|
|
@@ -350,7 +339,7 @@ export class LayoutController {
|
|
|
350
339
|
*/
|
|
351
340
|
private initGraphLayout(options: STDLayoutOptions) {
|
|
352
341
|
const { element, viewport } = this.context;
|
|
353
|
-
const { type,
|
|
342
|
+
const { type, animation, iterations, ...restOptions } = options;
|
|
354
343
|
|
|
355
344
|
const [width, height] = viewport!.getCanvasSize();
|
|
356
345
|
const center = [width / 2, height / 2];
|
|
@@ -369,9 +358,12 @@ export class LayoutController {
|
|
|
369
358
|
const STDCtor =
|
|
370
359
|
Object.getPrototypeOf(Ctor.prototype) === BaseLayout.prototype
|
|
371
360
|
? Ctor
|
|
372
|
-
:
|
|
361
|
+
: isLegacyAntVLayout(Ctor)
|
|
362
|
+
? legacyLayoutAdapter(Ctor, this.context)
|
|
363
|
+
: layoutAdapter(Ctor as new (options?: Record<string, unknown>) => AntVLayout, this.context);
|
|
373
364
|
|
|
374
365
|
const layout = new STDCtor(this.context);
|
|
366
|
+
|
|
375
367
|
const config = { nodeSize, width, height, center };
|
|
376
368
|
|
|
377
369
|
switch (layout.id) {
|
|
@@ -401,8 +393,6 @@ export class LayoutController {
|
|
|
401
393
|
this.stopLayout();
|
|
402
394
|
// @ts-expect-error force delete
|
|
403
395
|
this.context = {};
|
|
404
|
-
this.supervisor?.kill();
|
|
405
|
-
this.supervisor = undefined;
|
|
406
396
|
this.instance = undefined;
|
|
407
397
|
this.instances = [];
|
|
408
398
|
this.animationResult = undefined;
|
package/src/types/edge.ts
CHANGED
|
@@ -102,9 +102,7 @@ export interface EdgeBadgeStyleProps extends BadgeStyleProps {
|
|
|
102
102
|
* <en/> Edge arrow style properties
|
|
103
103
|
*/
|
|
104
104
|
export interface EdgeArrowStyleProps
|
|
105
|
-
extends PathStyleProps,
|
|
106
|
-
Omit<ImageStyleProps, 'width' | 'height'>,
|
|
107
|
-
Record<string, unknown> {
|
|
105
|
+
extends PathStyleProps, Omit<ImageStyleProps, 'width' | 'height'>, Record<string, unknown> {
|
|
108
106
|
/**
|
|
109
107
|
* <zh/> 箭头大小
|
|
110
108
|
*
|
package/src/types/layout.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { AntVLayout } from '../layouts/types';
|
|
1
|
+
import type { AntVLayout, LegacyAntVLayout } from '../layouts/types';
|
|
3
2
|
import type { GraphData } from '../spec/data';
|
|
4
3
|
import type { STDLayoutOptions } from '../spec/layout';
|
|
5
4
|
|
|
6
5
|
export interface AdaptiveLayout {
|
|
7
|
-
instance: AntVLayout;
|
|
6
|
+
instance: AntVLayout | LegacyAntVLayout;
|
|
8
7
|
|
|
9
8
|
execute(model: GraphData, options?: STDLayoutOptions): Promise<GraphData>;
|
|
10
|
-
|
|
11
|
-
graphData2LayoutModel(data: GraphData): LayoutModel;
|
|
12
9
|
}
|
package/src/utils/data.ts
CHANGED
|
@@ -111,3 +111,15 @@ export function isElementDataEqual(original: Partial<ElementDatum> = {}, modifie
|
|
|
111
111
|
|
|
112
112
|
return true;
|
|
113
113
|
}
|
|
114
|
+
|
|
115
|
+
export const OVERRIDE_KEY = '__internal_override__';
|
|
116
|
+
/**
|
|
117
|
+
* <zh/> 判断元素数据是否允许被覆盖
|
|
118
|
+
*
|
|
119
|
+
* <en/> Determine whether the element data can be overridden
|
|
120
|
+
* @param datum - <zh/> 元素数据 | <en/> element data
|
|
121
|
+
* @returns <zh/> 是否允许被覆盖 | <en/> is overridable
|
|
122
|
+
*/
|
|
123
|
+
export function isOverridable(datum: ElementDatum): boolean {
|
|
124
|
+
return datum[OVERRIDE_KEY] !== false;
|
|
125
|
+
}
|
package/src/utils/layout.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Graph as Graphlib } from '@antv/graphlib';
|
|
1
|
+
import { Edge, Graph as Graphlib, Node } from '@antv/graphlib';
|
|
2
2
|
import { deepMix, isNumber } from '@antv/util';
|
|
3
3
|
import { COMBO_KEY } from '../constants';
|
|
4
4
|
import { BaseLayout } from '../layouts/base-layout';
|
|
5
5
|
import { idOf } from './id';
|
|
6
|
-
import { parsePoint } from './point';
|
|
7
6
|
|
|
8
|
-
import type {
|
|
9
|
-
import type { AntVLayout } from '../layouts/types';
|
|
7
|
+
import type { AntVGraphData, AntVLayout, LegacyAntVLayout, LegacyGraph } from '../layouts/types';
|
|
10
8
|
import type { RuntimeContext } from '../runtime/types';
|
|
11
|
-
import type { GraphData } from '../spec/data';
|
|
9
|
+
import type { EdgeData, GraphData, NodeData } from '../spec/data';
|
|
10
|
+
import type { NodeStyle } from '../spec/element/node';
|
|
12
11
|
import type { LayoutOptions, STDLayoutOptions } from '../spec/layout';
|
|
13
12
|
import type { AdaptiveLayout, ID } from '../types';
|
|
13
|
+
import { parsePoint } from './point';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* <zh/> 判断是否是 combo 布局
|
|
@@ -64,6 +64,111 @@ export function isPreLayout(options?: LayoutOptions) {
|
|
|
64
64
|
return !Array.isArray(options) && options?.preLayout;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* <zh/> 将 @antv/layout 布局适配为 G6 布局
|
|
69
|
+
*
|
|
70
|
+
* <en/> Adapt @antv/layout layout to G6 layout
|
|
71
|
+
* @param Ctor - <zh/> 布局类 | <en/> Layout class
|
|
72
|
+
* @param context - <zh/> 运行时上下文 | <en/> Runtime context
|
|
73
|
+
* @returns <zh/> G6 布局类 | <en/> G6 layout class
|
|
74
|
+
*/
|
|
75
|
+
export function layoutAdapter(
|
|
76
|
+
Ctor: new (options: Record<string, unknown>) => AntVLayout,
|
|
77
|
+
context: RuntimeContext,
|
|
78
|
+
): new (context: RuntimeContext, options?: Record<string, unknown>) => BaseLayout {
|
|
79
|
+
class AdaptLayout extends BaseLayout implements AdaptiveLayout {
|
|
80
|
+
public instance: AntVLayout;
|
|
81
|
+
|
|
82
|
+
public id: string;
|
|
83
|
+
|
|
84
|
+
constructor(context: RuntimeContext, options?: Record<string, unknown>) {
|
|
85
|
+
super(context, options);
|
|
86
|
+
this.instance = new Ctor({});
|
|
87
|
+
this.id = this.instance.id;
|
|
88
|
+
|
|
89
|
+
if ('stop' in this.instance && 'tick' in this.instance) {
|
|
90
|
+
const instance = this.instance;
|
|
91
|
+
this.stop = instance.stop.bind(instance);
|
|
92
|
+
this.tick = (iterations?: number) => {
|
|
93
|
+
instance.tick(iterations);
|
|
94
|
+
return this.getLayoutResult(instance);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public async execute(model: GraphData, options?: STDLayoutOptions): Promise<GraphData> {
|
|
100
|
+
await this.instance.execute(
|
|
101
|
+
this.graphData2LayoutModel(model),
|
|
102
|
+
this.transformOptions(deepMix({}, this.options, options)),
|
|
103
|
+
);
|
|
104
|
+
return this.getLayoutResult(this.instance);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private graphData2LayoutModel(data: GraphData): AntVGraphData {
|
|
108
|
+
const { nodes = [], edges = [], combos = [] } = data;
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
nodes: [...nodes, ...combos],
|
|
112
|
+
edges,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private transformOptions(options: STDLayoutOptions) {
|
|
117
|
+
const isCombo = (id: string) => context.model.isCombo(id);
|
|
118
|
+
|
|
119
|
+
const defaultNode = (datum: NodeData) => {
|
|
120
|
+
const { style } = datum || {};
|
|
121
|
+
const parentId = 'combo' in (datum || {}) ? (datum.combo ?? null) : null;
|
|
122
|
+
const id = idOf(datum);
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
id,
|
|
126
|
+
...(isNumber(style?.x) ? { x: style.x } : {}),
|
|
127
|
+
...(isNumber(style?.y) ? { y: style.y } : {}),
|
|
128
|
+
...(isNumber(style?.z) ? { z: style.z } : {}),
|
|
129
|
+
parentId,
|
|
130
|
+
...(isCombo(id) ? { isCombo: true } : {}),
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const defaultEdge = (datum: EdgeData) => ({ id: idOf(datum), source: datum.source, target: datum.target });
|
|
135
|
+
|
|
136
|
+
options.node = defaultNode;
|
|
137
|
+
options.edge = defaultEdge;
|
|
138
|
+
|
|
139
|
+
if (!('onTick' in options)) return options;
|
|
140
|
+
|
|
141
|
+
const onTick = options.onTick as (data: GraphData) => void;
|
|
142
|
+
options.onTick = (layout: AntVLayout) => onTick(this.getLayoutResult(layout));
|
|
143
|
+
return options;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private getLayoutResult(layout: AntVLayout): GraphData {
|
|
147
|
+
const { model } = this.context;
|
|
148
|
+
|
|
149
|
+
const result: GraphData = { nodes: [], edges: [], combos: [] };
|
|
150
|
+
|
|
151
|
+
layout.forEachNode((node) => {
|
|
152
|
+
const nodeId = String(node.id);
|
|
153
|
+
const target = model.isCombo(nodeId) ? result.combos : result.nodes;
|
|
154
|
+
|
|
155
|
+
const style = { x: node.x, y: node.y, z: node.z ?? 0, ...(node.size ? { size: node.size } : {}) } as NodeStyle;
|
|
156
|
+
|
|
157
|
+
target?.push({ id: nodeId, style });
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
layout.forEachEdge((edge) => {
|
|
161
|
+
const style = { controlPoints: edge.points || [] };
|
|
162
|
+
result.edges!.push({ id: String(edge.id), source: String(edge.source), target: String(edge.target), style });
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return AdaptLayout;
|
|
170
|
+
}
|
|
171
|
+
|
|
67
172
|
/**
|
|
68
173
|
* <zh/> 将图布局结果转换为 G6 数据
|
|
69
174
|
*
|
|
@@ -71,8 +176,8 @@ export function isPreLayout(options?: LayoutOptions) {
|
|
|
71
176
|
* @param layoutMapping - <zh/> 布局映射 | <en/> Layout mapping
|
|
72
177
|
* @returns <zh/> G6 数据 | <en/> G6 data
|
|
73
178
|
*/
|
|
74
|
-
export function layoutMapping2GraphData(layoutMapping:
|
|
75
|
-
const { nodes, edges } = layoutMapping;
|
|
179
|
+
export function layoutMapping2GraphData(layoutMapping: AntVGraphData): GraphData {
|
|
180
|
+
const { nodes, edges = [] } = layoutMapping;
|
|
76
181
|
const data: GraphData = { nodes: [], edges: [], combos: [] };
|
|
77
182
|
|
|
78
183
|
nodes.forEach((nodeLike) => {
|
|
@@ -109,6 +214,19 @@ export function layoutMapping2GraphData(layoutMapping: LayoutMapping): GraphData
|
|
|
109
214
|
return data;
|
|
110
215
|
}
|
|
111
216
|
|
|
217
|
+
/**
|
|
218
|
+
* <zh/> 判断是否为 AntV Layout 1.x
|
|
219
|
+
*
|
|
220
|
+
* <en/> Determine if it is AntV Layout 1.x
|
|
221
|
+
* @param Ctor - <zh/> 布局类 | <en/> Layout class
|
|
222
|
+
* @returns <zh/> 是否为 AntV Layout 1.x | <en/> Whether it is AntV Layout 1.x
|
|
223
|
+
*/
|
|
224
|
+
export function isLegacyAntVLayout(
|
|
225
|
+
Ctor: new (options: Record<string, unknown>) => unknown,
|
|
226
|
+
): Ctor is new (options: Record<string, unknown>) => LegacyAntVLayout {
|
|
227
|
+
return !('forEachNode' in Ctor.prototype) && !('forEachEdge' in Ctor.prototype);
|
|
228
|
+
}
|
|
229
|
+
|
|
112
230
|
/**
|
|
113
231
|
* <zh/> 将 @antv/layout 布局适配为 G6 布局
|
|
114
232
|
*
|
|
@@ -117,12 +235,12 @@ export function layoutMapping2GraphData(layoutMapping: LayoutMapping): GraphData
|
|
|
117
235
|
* @param context - <zh/> 运行时上下文 | <en/> Runtime context
|
|
118
236
|
* @returns <zh/> G6 布局类 | <en/> G6 layout class
|
|
119
237
|
*/
|
|
120
|
-
export function
|
|
121
|
-
Ctor: new (options: Record<string, unknown>) =>
|
|
238
|
+
export function legacyLayoutAdapter(
|
|
239
|
+
Ctor: new (options: Record<string, unknown>) => LegacyAntVLayout,
|
|
122
240
|
context: RuntimeContext,
|
|
123
241
|
): new (context: RuntimeContext, options?: Record<string, unknown>) => BaseLayout {
|
|
124
242
|
class AdaptLayout extends BaseLayout implements AdaptiveLayout {
|
|
125
|
-
public instance:
|
|
243
|
+
public instance: LegacyAntVLayout;
|
|
126
244
|
|
|
127
245
|
public id: string;
|
|
128
246
|
|
|
@@ -135,7 +253,7 @@ export function layoutAdapter(
|
|
|
135
253
|
const instance = this.instance;
|
|
136
254
|
this.stop = instance.stop.bind(instance);
|
|
137
255
|
this.tick = (iterations?: number) => {
|
|
138
|
-
const tickResult = instance.tick(iterations);
|
|
256
|
+
const tickResult = instance.tick?.(iterations);
|
|
139
257
|
return layoutMapping2GraphData(tickResult);
|
|
140
258
|
};
|
|
141
259
|
}
|
|
@@ -153,13 +271,13 @@ export function layoutAdapter(
|
|
|
153
271
|
private transformOptions(options: STDLayoutOptions) {
|
|
154
272
|
if (!('onTick' in options)) return options;
|
|
155
273
|
const onTick = options.onTick as (data: GraphData) => void;
|
|
156
|
-
options.onTick = (data:
|
|
274
|
+
options.onTick = (data: AntVGraphData) => onTick(layoutMapping2GraphData(data));
|
|
157
275
|
return options;
|
|
158
276
|
}
|
|
159
277
|
|
|
160
|
-
|
|
278
|
+
private graphData2LayoutModel(data: GraphData): LegacyGraph {
|
|
161
279
|
const { nodes = [], edges = [], combos = [] } = data;
|
|
162
|
-
const nodesToLayout:
|
|
280
|
+
const nodesToLayout: Node<NodeData>[] = nodes.map((datum) => {
|
|
163
281
|
const id = idOf(datum);
|
|
164
282
|
const { data, style, combo, ...rest } = datum;
|
|
165
283
|
|
|
@@ -193,14 +311,24 @@ export function layoutAdapter(
|
|
|
193
311
|
})
|
|
194
312
|
.map((edge) => {
|
|
195
313
|
const { source, target, data, style } = edge;
|
|
196
|
-
return {
|
|
314
|
+
return {
|
|
315
|
+
id: idOf(edge),
|
|
316
|
+
source,
|
|
317
|
+
target,
|
|
318
|
+
data: { ...data },
|
|
319
|
+
style: { ...style },
|
|
320
|
+
} as unknown as Edge<EdgeData>;
|
|
197
321
|
});
|
|
198
322
|
|
|
199
|
-
const combosToLayout:
|
|
200
|
-
return {
|
|
323
|
+
const combosToLayout: Node<NodeData>[] = combos.map((combo) => {
|
|
324
|
+
return {
|
|
325
|
+
id: idOf(combo),
|
|
326
|
+
data: { _isCombo: true, ...combo.data },
|
|
327
|
+
style: { ...combo.style },
|
|
328
|
+
} as unknown as Node<NodeData>;
|
|
201
329
|
});
|
|
202
330
|
|
|
203
|
-
const layoutModel = new Graphlib({
|
|
331
|
+
const layoutModel = new Graphlib<NodeData, EdgeData>({
|
|
204
332
|
nodes: [...nodesToLayout, ...combosToLayout],
|
|
205
333
|
edges: edgesToLayout,
|
|
206
334
|
});
|
package/src/utils/shortcut.ts
CHANGED
|
@@ -130,6 +130,6 @@ export class Shortcut {
|
|
|
130
130
|
this.emitter.off(CommonEvent.WHEEL, this.onWheel);
|
|
131
131
|
this.emitter.off(CommonEvent.DRAG, this.onDrag);
|
|
132
132
|
this.pinchHandler?.off('pinchmove', this.boundHandlePinch);
|
|
133
|
-
globalThis.removeEventListener?.('
|
|
133
|
+
globalThis.removeEventListener?.('focus', this.onFocus);
|
|
134
134
|
}
|
|
135
135
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.0.
|
|
1
|
+
export const version = '5.1.0-beta.0';
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2018 Alipay.inc
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|