@antv/g6 5.0.0-beta.20 → 5.0.0-beta.22
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/esm/index.d.ts +16 -9
- package/esm/index.js +1 -1
- package/esm/runtime/controller/data.d.ts +27 -10
- package/esm/runtime/controller/data.js +240 -216
- package/esm/runtime/controller/data.js.map +1 -1
- package/esm/runtime/controller/item.js +2 -0
- package/esm/runtime/controller/item.js.map +1 -1
- package/esm/runtime/graph.d.ts +11 -4
- package/esm/runtime/graph.js +23 -5
- package/esm/runtime/graph.js.map +1 -1
- package/esm/stdlib/behavior/activate-relations.d.ts +1 -1
- package/esm/stdlib/behavior/brush-select.d.ts +2 -2
- package/esm/stdlib/behavior/click-select.d.ts +1 -1
- package/esm/stdlib/behavior/click-select.js +3 -1
- package/esm/stdlib/behavior/click-select.js.map +1 -1
- package/esm/stdlib/behavior/collapse-expand-combo.d.ts +1 -1
- package/esm/stdlib/behavior/collapse-expand-tree.d.ts +1 -1
- package/esm/stdlib/behavior/drag-canvas.js +1 -1
- package/esm/stdlib/behavior/drag-combo.d.ts +1 -1
- package/esm/stdlib/behavior/drag-node.d.ts +1 -1
- package/esm/stdlib/behavior/shortcuts-call.d.ts +1 -1
- package/esm/stdlib/behavior/zoom-canvas.js +1 -1
- package/esm/stdlib/data/index.d.ts +1 -0
- package/esm/stdlib/data/index.js +1 -0
- package/esm/stdlib/data/index.js.map +1 -1
- package/esm/stdlib/data/mapNodeSize.d.ts +3 -4
- package/esm/stdlib/data/mapNodeSize.js +10 -0
- package/esm/stdlib/data/mapNodeSize.js.map +1 -1
- package/esm/stdlib/data/processParallelEdges.d.ts +21 -0
- package/esm/stdlib/data/processParallelEdges.js +127 -0
- package/esm/stdlib/data/processParallelEdges.js.map +1 -0
- package/esm/stdlib/data/transformV4Data.d.ts +2 -3
- package/esm/stdlib/data/transformV4Data.js +8 -0
- package/esm/stdlib/data/transformV4Data.js.map +1 -1
- package/esm/stdlib/data/validateData.d.ts +3 -4
- package/esm/stdlib/data/validateData.js +9 -1
- package/esm/stdlib/data/validateData.js.map +1 -1
- package/esm/stdlib/index.d.ts +15 -8
- package/esm/stdlib/index.js +2 -1
- package/esm/stdlib/index.js.map +1 -1
- package/esm/stdlib/item/node/donut.d.ts +3 -3
- package/esm/stdlib/plugin/hull/hullComponent.d.ts +1 -1
- package/esm/stdlib/plugin/legend/index.d.ts +1 -1
- package/esm/stdlib/plugin/snapline/index.d.ts +2 -2
- package/esm/stdlib/plugin/snapline/index.js +239 -239
- package/esm/stdlib/plugin/snapline/index.js.map +1 -1
- package/esm/stdlib/plugin/timebar/index.d.ts +4 -4
- package/esm/stdlib/plugin/timebar/index.js +4 -4
- package/esm/stdlib/plugin/timebar/index.js.map +1 -1
- package/esm/stdlib/plugin/tooltip/index.d.ts +1 -1
- package/esm/stdlib/plugin/watermaker/index.d.ts +1 -1
- package/esm/stdlib/themeSolver/spec.js +21 -6
- package/esm/stdlib/themeSolver/spec.js.map +1 -1
- package/esm/types/animate.d.ts +2 -2
- package/esm/types/behavior.d.ts +1 -1
- package/esm/types/combo.d.ts +7 -7
- package/esm/types/common.d.ts +5 -5
- package/esm/types/data.d.ts +11 -6
- package/esm/types/edge.d.ts +9 -9
- package/esm/types/event.d.ts +1 -1
- package/esm/types/graph.d.ts +6 -0
- package/esm/types/history.d.ts +2 -2
- package/esm/types/hook.d.ts +1 -1
- package/esm/types/item.d.ts +13 -13
- package/esm/types/item.js.map +1 -1
- package/esm/types/layout.d.ts +6 -6
- package/esm/types/loop.d.ts +2 -2
- package/esm/types/node.d.ts +7 -7
- package/esm/types/render.d.ts +1 -1
- package/esm/types/spec.d.ts +4 -3
- package/esm/types/stdlib.d.ts +1 -1
- package/esm/types/theme.d.ts +8 -8
- package/esm/types/view.d.ts +2 -2
- package/esm/util/array.d.ts +1 -0
- package/esm/util/array.js +3 -0
- package/esm/util/array.js.map +1 -1
- package/esm/util/data.d.ts +10 -0
- package/esm/util/data.js +36 -0
- package/esm/util/data.js.map +1 -1
- package/esm/util/event.d.ts +2 -2
- package/esm/util/layout.d.ts +1 -1
- package/esm/util/loop.d.ts +1 -0
- package/esm/util/loop.js +10 -0
- package/esm/util/loop.js.map +1 -1
- package/esm/util/shape.d.ts +2 -1
- package/esm/util/shape.js +2 -1
- package/esm/util/shape.js.map +1 -1
- package/esm/util/shape3d.d.ts +1 -1
- package/esm/util/warn.d.ts +1 -1
- package/lib/index.d.ts +16 -9
- package/lib/index.js +1 -1
- package/lib/runtime/controller/data.d.ts +27 -10
- package/lib/runtime/controller/data.js +238 -214
- package/lib/runtime/controller/data.js.map +1 -1
- package/lib/runtime/controller/item.js +2 -0
- package/lib/runtime/controller/item.js.map +1 -1
- package/lib/runtime/graph.d.ts +11 -4
- package/lib/runtime/graph.js +23 -5
- package/lib/runtime/graph.js.map +1 -1
- package/lib/stdlib/behavior/activate-relations.d.ts +1 -1
- package/lib/stdlib/behavior/brush-select.d.ts +2 -2
- package/lib/stdlib/behavior/click-select.d.ts +1 -1
- package/lib/stdlib/behavior/click-select.js +3 -1
- package/lib/stdlib/behavior/click-select.js.map +1 -1
- package/lib/stdlib/behavior/collapse-expand-combo.d.ts +1 -1
- package/lib/stdlib/behavior/collapse-expand-tree.d.ts +1 -1
- package/lib/stdlib/behavior/drag-canvas.js +1 -1
- package/lib/stdlib/behavior/drag-combo.d.ts +1 -1
- package/lib/stdlib/behavior/drag-node.d.ts +1 -1
- package/lib/stdlib/behavior/shortcuts-call.d.ts +1 -1
- package/lib/stdlib/behavior/zoom-canvas.js +1 -1
- package/lib/stdlib/data/index.d.ts +1 -0
- package/lib/stdlib/data/index.js +1 -0
- package/lib/stdlib/data/index.js.map +1 -1
- package/lib/stdlib/data/mapNodeSize.d.ts +3 -4
- package/lib/stdlib/data/mapNodeSize.js +11 -1
- package/lib/stdlib/data/mapNodeSize.js.map +1 -1
- package/lib/stdlib/data/processParallelEdges.d.ts +21 -0
- package/lib/stdlib/data/processParallelEdges.js +131 -0
- package/lib/stdlib/data/processParallelEdges.js.map +1 -0
- package/lib/stdlib/data/transformV4Data.d.ts +2 -3
- package/lib/stdlib/data/transformV4Data.js +9 -1
- package/lib/stdlib/data/transformV4Data.js.map +1 -1
- package/lib/stdlib/data/validateData.d.ts +3 -4
- package/lib/stdlib/data/validateData.js +10 -2
- package/lib/stdlib/data/validateData.js.map +1 -1
- package/lib/stdlib/index.d.ts +15 -8
- package/lib/stdlib/index.js +2 -1
- package/lib/stdlib/index.js.map +1 -1
- package/lib/stdlib/item/node/donut.d.ts +3 -3
- package/lib/stdlib/plugin/hull/hullComponent.d.ts +1 -1
- package/lib/stdlib/plugin/legend/index.d.ts +1 -1
- package/lib/stdlib/plugin/snapline/index.d.ts +2 -2
- package/lib/stdlib/plugin/snapline/index.js +239 -239
- package/lib/stdlib/plugin/snapline/index.js.map +1 -1
- package/lib/stdlib/plugin/timebar/index.d.ts +4 -4
- package/lib/stdlib/plugin/timebar/index.js +4 -4
- package/lib/stdlib/plugin/timebar/index.js.map +1 -1
- package/lib/stdlib/plugin/tooltip/index.d.ts +1 -1
- package/lib/stdlib/plugin/watermaker/index.d.ts +1 -1
- package/lib/stdlib/themeSolver/spec.js +20 -5
- package/lib/stdlib/themeSolver/spec.js.map +1 -1
- package/lib/types/animate.d.ts +2 -2
- package/lib/types/behavior.d.ts +1 -1
- package/lib/types/combo.d.ts +7 -7
- package/lib/types/common.d.ts +5 -5
- package/lib/types/data.d.ts +11 -6
- package/lib/types/edge.d.ts +9 -9
- package/lib/types/event.d.ts +1 -1
- package/lib/types/event.js +2 -2
- package/lib/types/event.js.map +1 -1
- package/lib/types/graph.d.ts +6 -0
- package/lib/types/history.d.ts +2 -2
- package/lib/types/history.js +1 -1
- package/lib/types/history.js.map +1 -1
- package/lib/types/hook.d.ts +1 -1
- package/lib/types/item.d.ts +13 -13
- package/lib/types/item.js +1 -1
- package/lib/types/item.js.map +1 -1
- package/lib/types/layout.d.ts +6 -6
- package/lib/types/loop.d.ts +2 -2
- package/lib/types/loop.js +1 -1
- package/lib/types/loop.js.map +1 -1
- package/lib/types/node.d.ts +7 -7
- package/lib/types/render.d.ts +1 -1
- package/lib/types/spec.d.ts +4 -3
- package/lib/types/stdlib.d.ts +1 -1
- package/lib/types/theme.d.ts +8 -8
- package/lib/types/view.d.ts +2 -2
- package/lib/util/array.d.ts +1 -0
- package/lib/util/array.js +5 -1
- package/lib/util/array.js.map +1 -1
- package/lib/util/data.d.ts +10 -0
- package/lib/util/data.js +38 -1
- package/lib/util/data.js.map +1 -1
- package/lib/util/event.d.ts +2 -2
- package/lib/util/layout.d.ts +1 -1
- package/lib/util/loop.d.ts +1 -0
- package/lib/util/loop.js +11 -1
- package/lib/util/loop.js.map +1 -1
- package/lib/util/shape.d.ts +2 -1
- package/lib/util/shape.js +1 -0
- package/lib/util/shape.js.map +1 -1
- package/lib/util/shape3d.d.ts +1 -1
- package/lib/util/warn.d.ts +1 -1
- package/package.json +3 -3
- package/src/index.ts +1 -1
- package/src/runtime/controller/data.ts +309 -229
- package/src/runtime/controller/item.ts +2 -0
- package/src/runtime/graph.ts +26 -8
- package/src/stdlib/behavior/click-select.ts +3 -1
- package/src/stdlib/behavior/drag-canvas.ts +1 -1
- package/src/stdlib/behavior/zoom-canvas.ts +1 -1
- package/src/stdlib/data/index.ts +1 -0
- package/src/stdlib/data/mapNodeSize.ts +20 -1
- package/src/stdlib/data/processParallelEdges.ts +203 -0
- package/src/stdlib/data/transformV4Data.ts +14 -1
- package/src/stdlib/data/validateData.ts +16 -2
- package/src/stdlib/index.ts +3 -1
- package/src/stdlib/themeSolver/spec.ts +23 -7
- package/src/types/data.ts +6 -0
- package/src/types/graph.ts +6 -0
- package/src/types/item.ts +2 -1
- package/src/types/spec.ts +1 -0
- package/src/util/array.ts +12 -0
- package/src/util/data.ts +46 -1
- package/src/util/loop.ts +11 -0
- package/src/util/shape.ts +1 -0
package/src/runtime/graph.ts
CHANGED
|
@@ -2,11 +2,11 @@ import EventEmitter from '@antv/event-emitter';
|
|
|
2
2
|
import {
|
|
3
3
|
AABB,
|
|
4
4
|
Canvas,
|
|
5
|
+
Cursor,
|
|
5
6
|
DataURLType,
|
|
6
7
|
DisplayObject,
|
|
7
8
|
PointLike,
|
|
8
9
|
Rect,
|
|
9
|
-
Cursor,
|
|
10
10
|
} from '@antv/g';
|
|
11
11
|
import { GraphChange, ID } from '@antv/graphlib';
|
|
12
12
|
import {
|
|
@@ -46,7 +46,9 @@ import type {
|
|
|
46
46
|
StandardLayoutOptions,
|
|
47
47
|
} from '../types/layout';
|
|
48
48
|
import type { NodeDisplayModel, NodeModel, NodeModelData } from '../types/node';
|
|
49
|
+
import { Plugin as PluginBase } from '../types/plugin';
|
|
49
50
|
import type { RendererName } from '../types/render';
|
|
51
|
+
import { ComboMapper, EdgeMapper, NodeMapper } from '../types/spec';
|
|
50
52
|
import type {
|
|
51
53
|
ThemeOptionsOf,
|
|
52
54
|
ThemeRegistry,
|
|
@@ -54,11 +56,9 @@ import type {
|
|
|
54
56
|
} from '../types/theme';
|
|
55
57
|
import { FitViewRules, GraphTransformOptions } from '../types/view';
|
|
56
58
|
import { changeRenderer, createCanvas } from '../util/canvas';
|
|
57
|
-
import { formatPadding } from '../util/shape';
|
|
58
|
-
import { getLayoutBounds } from '../util/layout';
|
|
59
59
|
import { createDOM } from '../util/dom';
|
|
60
|
-
import {
|
|
61
|
-
import {
|
|
60
|
+
import { getLayoutBounds } from '../util/layout';
|
|
61
|
+
import { formatPadding } from '../util/shape';
|
|
62
62
|
import {
|
|
63
63
|
DataController,
|
|
64
64
|
ExtensionController,
|
|
@@ -70,6 +70,7 @@ import {
|
|
|
70
70
|
} from './controller';
|
|
71
71
|
import { PluginController } from './controller/plugin';
|
|
72
72
|
import Hook from './hooks';
|
|
73
|
+
import { isEmptyGraph } from '../util/data';
|
|
73
74
|
|
|
74
75
|
export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
75
76
|
extends EventEmitter
|
|
@@ -583,6 +584,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
583
584
|
options: GraphTransformOptions,
|
|
584
585
|
effectTiming?: CameraAnimationOptions,
|
|
585
586
|
): Promise<void> {
|
|
587
|
+
if (isEmptyGraph(this, true)) return;
|
|
586
588
|
const { tileLodSize } = this.specification.optimize || {};
|
|
587
589
|
await this.hooks.viewportchange.emitLinearAsync({
|
|
588
590
|
transform: options,
|
|
@@ -852,7 +854,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
852
854
|
}
|
|
853
855
|
|
|
854
856
|
/**
|
|
855
|
-
* Get item by id. We don't want
|
|
857
|
+
* Get item by id. We don't want users call this private API.
|
|
856
858
|
* @param id
|
|
857
859
|
* @returns Node | Edge | Combo
|
|
858
860
|
*/
|
|
@@ -1048,6 +1050,16 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1048
1050
|
return this.dataController.findChildren(comboId, 'combo');
|
|
1049
1051
|
}
|
|
1050
1052
|
|
|
1053
|
+
/**
|
|
1054
|
+
* Get item type by id.
|
|
1055
|
+
* @param id
|
|
1056
|
+
* @returns 'node' | 'edge' | 'combo'
|
|
1057
|
+
* @group Data
|
|
1058
|
+
*/
|
|
1059
|
+
public getTypeById(id: ID) {
|
|
1060
|
+
return this.itemController.getItemById(id)?.getType();
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1051
1063
|
/*
|
|
1052
1064
|
* Get the display model of a node / edge / combo.
|
|
1053
1065
|
* @param id item id
|
|
@@ -1594,6 +1606,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1594
1606
|
value: boolean,
|
|
1595
1607
|
) {
|
|
1596
1608
|
const idArr = isArray(ids) ? ids : [ids];
|
|
1609
|
+
if (ids === undefined || !idArr.length) return;
|
|
1597
1610
|
const stateArr = isArray(states) ? states : [states];
|
|
1598
1611
|
const stateOption = { ids: idArr, states: stateArr, value };
|
|
1599
1612
|
const changes = {
|
|
@@ -1607,6 +1620,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1607
1620
|
});
|
|
1608
1621
|
this.emit('afteritemstatechange', {
|
|
1609
1622
|
ids: idArr,
|
|
1623
|
+
itemTypes: idArr.map((id) => this.getTypeById(id)),
|
|
1610
1624
|
states,
|
|
1611
1625
|
value,
|
|
1612
1626
|
action: 'updateState',
|
|
@@ -1954,8 +1968,9 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1954
1968
|
});
|
|
1955
1969
|
// update the graph specification
|
|
1956
1970
|
modesArr.forEach((mode) => {
|
|
1957
|
-
this.specification.modes[mode] =
|
|
1958
|
-
this.specification.modes[mode]
|
|
1971
|
+
this.specification.modes[mode] = (
|
|
1972
|
+
this.specification.modes[mode] || []
|
|
1973
|
+
).concat(behaviorsArr);
|
|
1959
1974
|
});
|
|
1960
1975
|
}
|
|
1961
1976
|
/**
|
|
@@ -1975,6 +1990,9 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
|
|
|
1975
1990
|
// update the graph specification
|
|
1976
1991
|
modesArr.forEach((mode) => {
|
|
1977
1992
|
behaviorKeys.forEach((key) => {
|
|
1993
|
+
if (!this.specification.modes[mode]) {
|
|
1994
|
+
return;
|
|
1995
|
+
}
|
|
1978
1996
|
const oldBehavior = this.specification.modes[mode].find(
|
|
1979
1997
|
(behavior) => isObject(behavior) && behavior.key === key,
|
|
1980
1998
|
);
|
|
@@ -141,7 +141,9 @@ export class ClickSelect extends Behavior {
|
|
|
141
141
|
// Not multiple, clear all currently selected items
|
|
142
142
|
this.graph.setItemState(this.selectedIds, state, false);
|
|
143
143
|
}
|
|
144
|
-
this.
|
|
144
|
+
if (!this.selectedIds.includes(itemId)) {
|
|
145
|
+
this.graph.setItemState(itemId, state, isSelectAction);
|
|
146
|
+
}
|
|
145
147
|
});
|
|
146
148
|
|
|
147
149
|
if (isSelectAction) {
|
|
@@ -252,7 +252,7 @@ export class DragCanvas extends Behavior {
|
|
|
252
252
|
const shouldDebounce =
|
|
253
253
|
typeof graphBehaviorOptimize === 'boolean'
|
|
254
254
|
? graphBehaviorOptimize
|
|
255
|
-
: this.graph.getAllNodesData().length
|
|
255
|
+
: this.graph.getAllNodesData().length > graphBehaviorOptimize;
|
|
256
256
|
|
|
257
257
|
const now = Date.now();
|
|
258
258
|
if (
|
|
@@ -242,7 +242,7 @@ export class ZoomCanvas extends Behavior {
|
|
|
242
242
|
const shouldDebounce =
|
|
243
243
|
typeof graphBehaviorOptimize === 'boolean'
|
|
244
244
|
? graphBehaviorOptimize
|
|
245
|
-
: graph.getAllNodesData().length
|
|
245
|
+
: graph.getAllNodesData().length > graphBehaviorOptimize;
|
|
246
246
|
|
|
247
247
|
const now = Date.now();
|
|
248
248
|
if (
|
package/src/stdlib/data/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GraphCore } from '../../types/data';
|
|
1
|
+
import { GraphCore, GraphDataChanges } from '../../types/data';
|
|
2
2
|
import {
|
|
3
3
|
GraphData,
|
|
4
4
|
ComboUserModel,
|
|
@@ -12,7 +12,24 @@ import {
|
|
|
12
12
|
* @param graphCore the graph core stores the previous data.
|
|
13
13
|
* @returns formatted data.
|
|
14
14
|
*/
|
|
15
|
+
|
|
15
16
|
export const MapNodeSize = (
|
|
17
|
+
data: GraphDataChanges,
|
|
18
|
+
options: {
|
|
19
|
+
field?: string;
|
|
20
|
+
range?: [number, number];
|
|
21
|
+
} = {},
|
|
22
|
+
graphCore?: GraphCore,
|
|
23
|
+
): GraphDataChanges => {
|
|
24
|
+
const { dataAdded, dataUpdated, dataRemoved } = data;
|
|
25
|
+
return {
|
|
26
|
+
dataAdded: handler(dataAdded, options, graphCore),
|
|
27
|
+
dataUpdated: handler(dataUpdated, options, graphCore),
|
|
28
|
+
dataRemoved: handler(dataRemoved, options, graphCore),
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const handler = (
|
|
16
33
|
data: GraphData,
|
|
17
34
|
options: {
|
|
18
35
|
field?: string;
|
|
@@ -24,6 +41,8 @@ export const MapNodeSize = (
|
|
|
24
41
|
if (!field) return data;
|
|
25
42
|
const { nodes } = data;
|
|
26
43
|
|
|
44
|
+
if (!nodes) return data;
|
|
45
|
+
|
|
27
46
|
const nodeMap = new Map();
|
|
28
47
|
// map the value to node size
|
|
29
48
|
let maxValue = -Infinity,
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { Edge } from '@antv/graphlib';
|
|
2
|
+
import { loopPosition } from '../../util/loop';
|
|
3
|
+
import { EdgeUserModel, ID, GraphCore } from '../../types';
|
|
4
|
+
import { uniqBy } from '../../util/array';
|
|
5
|
+
import { EdgeUserModelData } from '../../types/edge';
|
|
6
|
+
import { GraphDataChanges } from '../../types/data';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Process edges which might overlap. For edges that share the same target and source nodes.
|
|
10
|
+
* @param data input user data.
|
|
11
|
+
* @param options.edgeIds The specific edge IDs to process, all edges by default.
|
|
12
|
+
* @param options.offsetDiff The offset between two parallel edges, 15 by default.
|
|
13
|
+
* @param options.multiEdgeType The edge type for the parallel edges, 'quadratic' by default. You can assign any custom edge type based on 'quadratic' to it.
|
|
14
|
+
* @param options.singleEdgeType The edge type for the single edge between two nodes, undefined by default, which means the type of the edge is kept unchanged as it is in the input data.
|
|
15
|
+
* @param options.loopEdgeType The edge type for a self-loop edge, undefined by default, which means the type of the edge is kept unchanged as it is in the input data.
|
|
16
|
+
* @returns formatted data.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
type ParallelEdgesOptions = {
|
|
20
|
+
edgeIds?: ID[];
|
|
21
|
+
offsetDiff?: number;
|
|
22
|
+
multiEdgeType?: string;
|
|
23
|
+
singleEdgeType?: string;
|
|
24
|
+
loopEdgeType?: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const ProcessParallelEdges = (
|
|
28
|
+
data: GraphDataChanges,
|
|
29
|
+
options: ParallelEdgesOptions = {},
|
|
30
|
+
graphCore?: GraphCore,
|
|
31
|
+
): GraphDataChanges => {
|
|
32
|
+
// Identify the edges to be processed and their associated edges
|
|
33
|
+
const { edgeIds = [] } = options;
|
|
34
|
+
const {
|
|
35
|
+
dataAdded: { edges: edgesAdded = [] } = {},
|
|
36
|
+
dataUpdated: { edges: edgesUpdated = [] } = {},
|
|
37
|
+
dataRemoved: { edges: edgesRemoved = [] } = {},
|
|
38
|
+
} = data;
|
|
39
|
+
|
|
40
|
+
const prevEdges = graphCore ? graphCore.getAllEdges() : [];
|
|
41
|
+
const edgeIdsToAdd = new Set(edgesAdded?.map((edge) => edge.id));
|
|
42
|
+
const edgeIdsToRemove = new Set(edgesRemoved?.map((edge) => edge.id));
|
|
43
|
+
const cacheEdges = uniqBy([...prevEdges, ...edgesUpdated], 'id');
|
|
44
|
+
|
|
45
|
+
let edges = [...edgesRemoved, ...edgesUpdated, ...edgesAdded];
|
|
46
|
+
|
|
47
|
+
// Recognize parallel edges prior to the update
|
|
48
|
+
edgesUpdated.forEach((newModel) => {
|
|
49
|
+
const oldModel = graphCore?.getEdge(newModel.id);
|
|
50
|
+
if (!oldModel) return;
|
|
51
|
+
const { id, source, target } = newModel;
|
|
52
|
+
if (
|
|
53
|
+
(source && oldModel.source !== source) ||
|
|
54
|
+
(target && oldModel.target !== target)
|
|
55
|
+
) {
|
|
56
|
+
const prevParallelEdges = getParallelEdges(
|
|
57
|
+
graphCore.getEdge(id),
|
|
58
|
+
cacheEdges,
|
|
59
|
+
);
|
|
60
|
+
edges = [...prevParallelEdges, ...edges];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Recognize parallel edges following the modification
|
|
65
|
+
edges.forEach((newModel) => {
|
|
66
|
+
const newParallelEdges = getParallelEdges(newModel, cacheEdges);
|
|
67
|
+
edges = [...newParallelEdges, ...edges];
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Remove deleted edges and filter edges based on edgeIds.
|
|
71
|
+
edges = uniqBy(
|
|
72
|
+
edges.filter((edge) => !edgeIdsToRemove.has(edge.id)),
|
|
73
|
+
'id',
|
|
74
|
+
);
|
|
75
|
+
if (edgeIds.length > 0) {
|
|
76
|
+
edges = edges.filter((edge) => edgeIds.includes(edge.id));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Calculate the offset for parallel edges
|
|
80
|
+
edges = calculateOffset(edges, options);
|
|
81
|
+
|
|
82
|
+
// Render based on the type of modification
|
|
83
|
+
return {
|
|
84
|
+
...data,
|
|
85
|
+
dataAdded: {
|
|
86
|
+
...data.dataAdded,
|
|
87
|
+
edges: edges.filter((edge) => edgeIdsToAdd.has(edge.id)),
|
|
88
|
+
},
|
|
89
|
+
dataUpdated: {
|
|
90
|
+
...data.dataUpdated,
|
|
91
|
+
edges: edges.filter((edge) => !edgeIdsToAdd.has(edge.id)),
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Get all edges parallel to a given edge
|
|
98
|
+
* @param edgeModel the data model of the edge currently under consideration
|
|
99
|
+
* @param allEdges the set of all edges in graph
|
|
100
|
+
*/
|
|
101
|
+
const getParallelEdges = (
|
|
102
|
+
edgeModel: EdgeUserModel,
|
|
103
|
+
allEdges: Edge<EdgeUserModelData>[],
|
|
104
|
+
) => {
|
|
105
|
+
const { id, source, target } = edgeModel;
|
|
106
|
+
return allEdges.filter((edge) => {
|
|
107
|
+
return (
|
|
108
|
+
(edge.id !== id && edge.source === source && edge.target === target) ||
|
|
109
|
+
(edge.source === target && edge.target === source)
|
|
110
|
+
);
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Calculate the offset for parallel edges.
|
|
116
|
+
* For each set of parallel edges, alternately assign positive and negative offsets to visually separate them.
|
|
117
|
+
* @param edges parallel edges affected by the modification
|
|
118
|
+
* @param options processing configuration
|
|
119
|
+
*/
|
|
120
|
+
const calculateOffset = (
|
|
121
|
+
edges: EdgeUserModel[],
|
|
122
|
+
options: ParallelEdgesOptions,
|
|
123
|
+
) => {
|
|
124
|
+
const {
|
|
125
|
+
offsetDiff = 15,
|
|
126
|
+
multiEdgeType = 'quadratic-edge',
|
|
127
|
+
singleEdgeType = undefined,
|
|
128
|
+
loopEdgeType = undefined,
|
|
129
|
+
} = options;
|
|
130
|
+
|
|
131
|
+
const len = edges.length;
|
|
132
|
+
const cod = offsetDiff * 2;
|
|
133
|
+
|
|
134
|
+
const edgeMap = new Map<string, EdgeUserModel[]>();
|
|
135
|
+
const processedEdgesSet = new Set<number>();
|
|
136
|
+
const reverses = {};
|
|
137
|
+
|
|
138
|
+
for (let i = 0; i < len; i++) {
|
|
139
|
+
if (processedEdgesSet.has(i)) continue;
|
|
140
|
+
|
|
141
|
+
const edge = edges[i];
|
|
142
|
+
const { source, target } = edge;
|
|
143
|
+
const sourceTarget = `${source}-${target}`;
|
|
144
|
+
|
|
145
|
+
if (!edgeMap.has(sourceTarget)) edgeMap.set(sourceTarget, []);
|
|
146
|
+
|
|
147
|
+
edgeMap.get(sourceTarget)!.push(edge);
|
|
148
|
+
processedEdgesSet.add(i);
|
|
149
|
+
|
|
150
|
+
for (let j = i + 1; j < len; j++) {
|
|
151
|
+
if (processedEdgesSet.has(j)) continue;
|
|
152
|
+
|
|
153
|
+
const sedge = edges[j];
|
|
154
|
+
const src = sedge.source;
|
|
155
|
+
const dst = sedge.target;
|
|
156
|
+
|
|
157
|
+
if (
|
|
158
|
+
(source === dst && target === src) ||
|
|
159
|
+
(source === src && target === dst)
|
|
160
|
+
) {
|
|
161
|
+
edgeMap.get(sourceTarget)!.push(sedge);
|
|
162
|
+
processedEdgesSet.add(j);
|
|
163
|
+
if (source === dst && target === src) {
|
|
164
|
+
reverses[`${src}|${dst}|${edgeMap.get(sourceTarget)?.length - 1}`] =
|
|
165
|
+
true;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
edgeMap.forEach((arcEdges, key) => {
|
|
172
|
+
const { length } = arcEdges;
|
|
173
|
+
for (let k = 0; k < length; k++) {
|
|
174
|
+
const current = arcEdges[k];
|
|
175
|
+
current.data ||= {};
|
|
176
|
+
|
|
177
|
+
if (current.source === current.target) {
|
|
178
|
+
if (loopEdgeType) current.data.type = loopEdgeType;
|
|
179
|
+
current.data.keyShape ||= {};
|
|
180
|
+
// @ts-ignore
|
|
181
|
+
current.data.keyShape.loopCfg = {
|
|
182
|
+
position: loopPosition[k % 8],
|
|
183
|
+
dist: Math.floor(k / 8) * 20 + 50,
|
|
184
|
+
};
|
|
185
|
+
} else if (length === 1) {
|
|
186
|
+
if (singleEdgeType) current.data.type = singleEdgeType;
|
|
187
|
+
} else {
|
|
188
|
+
current.data.type = multiEdgeType;
|
|
189
|
+
const sign =
|
|
190
|
+
(k % 2 === 0 ? 1 : -1) *
|
|
191
|
+
(reverses[`${current.source}|${current.target}|${k}`] ? -1 : 1);
|
|
192
|
+
current.data.keyShape ||= {};
|
|
193
|
+
// @ts-ignore
|
|
194
|
+
current.data.keyShape.curveOffset =
|
|
195
|
+
length % 2 === 1
|
|
196
|
+
? sign * Math.ceil(k / 2) * cod
|
|
197
|
+
: sign * (Math.floor(k / 2) * cod + offsetDiff);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
return edges;
|
|
203
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isArray, isNumber, uniqueId } from '@antv/util';
|
|
2
|
-
import { GraphCore } from '../../types/data';
|
|
2
|
+
import { GraphCore, GraphDataChanges } from '../../types/data';
|
|
3
3
|
import {
|
|
4
4
|
GraphData,
|
|
5
5
|
ComboUserModel,
|
|
@@ -14,6 +14,19 @@ import {
|
|
|
14
14
|
* @returns formatted data.
|
|
15
15
|
*/
|
|
16
16
|
export const TransformV4Data = (
|
|
17
|
+
data: GraphDataChanges,
|
|
18
|
+
options = {},
|
|
19
|
+
graphCore?: GraphCore,
|
|
20
|
+
): GraphDataChanges => {
|
|
21
|
+
const { dataAdded, dataUpdated, dataRemoved } = data;
|
|
22
|
+
return {
|
|
23
|
+
dataAdded: handler(dataAdded, options, graphCore),
|
|
24
|
+
dataUpdated: handler(dataUpdated, options, graphCore),
|
|
25
|
+
dataRemoved: handler(dataRemoved, options, graphCore),
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const handler = (
|
|
17
30
|
data: GraphData,
|
|
18
31
|
options = {},
|
|
19
32
|
graphCore?: GraphCore,
|
|
@@ -1,19 +1,33 @@
|
|
|
1
1
|
import { uniqueId } from '@antv/util';
|
|
2
|
-
import { GraphCore } from '../../types/data';
|
|
2
|
+
import { GraphCore, GraphDataChanges } from '../../types/data';
|
|
3
3
|
import {
|
|
4
4
|
GraphData,
|
|
5
5
|
ComboUserModel,
|
|
6
6
|
EdgeUserModel,
|
|
7
7
|
NodeUserModel,
|
|
8
8
|
} from '../../types';
|
|
9
|
+
import { deconstructData } from '../../util/data';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
|
-
* Validate and format the graph data.
|
|
12
|
+
* Validate and format the graph data which will be added.
|
|
12
13
|
* @param data input user data.
|
|
13
14
|
* @param graphCore the graph core stores the previous data.
|
|
14
15
|
* @returns formatted data.
|
|
15
16
|
*/
|
|
16
17
|
export const ValidateData = (
|
|
18
|
+
data: GraphDataChanges,
|
|
19
|
+
options = {},
|
|
20
|
+
graphCore?: GraphCore,
|
|
21
|
+
): GraphDataChanges => {
|
|
22
|
+
const { dataAdded, dataRemoved, dataUpdated } = data;
|
|
23
|
+
return {
|
|
24
|
+
dataAdded: handler(dataAdded, options, graphCore),
|
|
25
|
+
dataRemoved: handler(dataRemoved, options, graphCore),
|
|
26
|
+
dataUpdated: handler(dataUpdated, options, graphCore),
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const handler = (
|
|
17
31
|
data: GraphData,
|
|
18
32
|
options = {},
|
|
19
33
|
graphCore?: GraphCore,
|
package/src/stdlib/index.ts
CHANGED
|
@@ -13,7 +13,8 @@ import * as Themes from './theme';
|
|
|
13
13
|
import * as ThemeSolvers from './themeSolver';
|
|
14
14
|
import * as Plugins from './plugin';
|
|
15
15
|
|
|
16
|
-
const { ValidateData, TransformV4Data, MapNodeSize } =
|
|
16
|
+
const { ValidateData, TransformV4Data, MapNodeSize, ProcessParallelEdges } =
|
|
17
|
+
Transforms;
|
|
17
18
|
|
|
18
19
|
const { compactBox, dendrogram, indented, mindmap } = Hierarchy;
|
|
19
20
|
|
|
@@ -215,6 +216,7 @@ const Extensions = {
|
|
|
215
216
|
ValidateData,
|
|
216
217
|
TransformV4Data,
|
|
217
218
|
MapNodeSize,
|
|
219
|
+
ProcessParallelEdges,
|
|
218
220
|
// themes
|
|
219
221
|
LightTheme,
|
|
220
222
|
DarkTheme,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isArray } from '@antv/util';
|
|
1
|
+
import { isArray, isObject } from '@antv/util';
|
|
2
2
|
import {
|
|
3
3
|
NodeStyleSets,
|
|
4
4
|
EdgeStyleSets,
|
|
@@ -50,12 +50,28 @@ export class SpecThemeSolver extends BaseThemeSolver {
|
|
|
50
50
|
|
|
51
51
|
if (dataTypeField && !getStyleSets) {
|
|
52
52
|
getStyleSets = (paletteProps) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
if (isArray(paletteProps)) {
|
|
54
|
+
return paletteProps.map((color) => ({
|
|
55
|
+
default: {
|
|
56
|
+
keyShape:
|
|
57
|
+
itemType === 'edge' ? { stroke: color } : { fill: color },
|
|
58
|
+
},
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
if (isObject(paletteProps)) {
|
|
62
|
+
const res = {};
|
|
63
|
+
Object.keys(paletteProps).map((dataType) => {
|
|
64
|
+
res[dataType] = {
|
|
65
|
+
default: {
|
|
66
|
+
keyShape:
|
|
67
|
+
itemType === 'edge'
|
|
68
|
+
? { stroke: paletteProps[dataType] }
|
|
69
|
+
: { fill: paletteProps[dataType] },
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
return res;
|
|
74
|
+
}
|
|
59
75
|
};
|
|
60
76
|
}
|
|
61
77
|
|
package/src/types/data.ts
CHANGED
|
@@ -14,6 +14,12 @@ export interface GraphData {
|
|
|
14
14
|
combos?: ComboUserModel[];
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
export interface GraphDataChanges {
|
|
18
|
+
dataAdded: GraphData;
|
|
19
|
+
dataUpdated: GraphData;
|
|
20
|
+
dataRemoved: GraphData;
|
|
21
|
+
}
|
|
22
|
+
|
|
17
23
|
export type TreeData =
|
|
18
24
|
| ITreeData<NodeUserModelData>
|
|
19
25
|
| ITreeData<NodeUserModelData>[];
|
package/src/types/graph.ts
CHANGED
|
@@ -139,6 +139,12 @@ export interface IGraph<
|
|
|
139
139
|
* @group Data
|
|
140
140
|
*/
|
|
141
141
|
getComboChildrenData: (comboId: ID) => (ComboModel | NodeModel)[];
|
|
142
|
+
/**
|
|
143
|
+
* Get item type by id.
|
|
144
|
+
* @param id
|
|
145
|
+
* @returns 'node' | 'edge' | 'combo'
|
|
146
|
+
*/
|
|
147
|
+
getTypeById: (id: ID) => ITEM_TYPE;
|
|
142
148
|
/**
|
|
143
149
|
* Input data and render the graph.
|
|
144
150
|
* If there is old data, diffs and changes it.
|
package/src/types/item.ts
CHANGED
package/src/types/spec.ts
CHANGED
package/src/util/array.ts
CHANGED
|
@@ -66,3 +66,15 @@ export function replaceElements(arr, target, replaceWith) {
|
|
|
66
66
|
}
|
|
67
67
|
return arr;
|
|
68
68
|
}
|
|
69
|
+
|
|
70
|
+
export const uniqBy = <T>(arr: T[], key: keyof T): T[] => {
|
|
71
|
+
return Object.values(
|
|
72
|
+
arr.reduce(
|
|
73
|
+
(map, item) => ({
|
|
74
|
+
...map,
|
|
75
|
+
[`${item[key]}`]: item,
|
|
76
|
+
}),
|
|
77
|
+
{},
|
|
78
|
+
),
|
|
79
|
+
);
|
|
80
|
+
};
|
package/src/util/data.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { ID, TreeData } from '@antv/graphlib';
|
|
2
2
|
import { isArray } from '@antv/util';
|
|
3
3
|
import { depthFirstSearch, connectedComponent } from '@antv/algorithm';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
DataChangeType,
|
|
6
|
+
GraphCore,
|
|
7
|
+
GraphData,
|
|
8
|
+
GraphDataChanges,
|
|
9
|
+
} from '../types/data';
|
|
5
10
|
import { IGraph } from '../types/graph';
|
|
6
11
|
import { NodeModel, NodeUserModel } from '../types';
|
|
7
12
|
import { NodeUserModelData } from '../types/node';
|
|
@@ -304,3 +309,43 @@ export const traverse = (treeData, callback) => {
|
|
|
304
309
|
});
|
|
305
310
|
}
|
|
306
311
|
};
|
|
312
|
+
|
|
313
|
+
export const DEFAULT_ACTIVE_DATA_LIFECYCLE = ['read'];
|
|
314
|
+
|
|
315
|
+
export const AVAILABLE_DATA_LIFECYCLE = [
|
|
316
|
+
'read',
|
|
317
|
+
'changeData',
|
|
318
|
+
'updateData',
|
|
319
|
+
'addData',
|
|
320
|
+
'removeData',
|
|
321
|
+
];
|
|
322
|
+
|
|
323
|
+
export const dataLifecycleMap: Record<string, string> = {
|
|
324
|
+
replace: 'read',
|
|
325
|
+
mergeReplace: 'changeData',
|
|
326
|
+
union: 'addData',
|
|
327
|
+
remove: 'removeData',
|
|
328
|
+
update: 'updateData',
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Whether the graph is empty.
|
|
333
|
+
* @param graph graph instance.
|
|
334
|
+
* @param excludeInvisibles whether exclude invisibles. true means the function should test without visible items.
|
|
335
|
+
* @returns graph is empty or not.
|
|
336
|
+
*/
|
|
337
|
+
export const isEmptyGraph = (graph, excludeInvisibles = false): Boolean => {
|
|
338
|
+
const nodes = graph.getAllNodesData();
|
|
339
|
+
const combos = graph.getAllCombosData();
|
|
340
|
+
if (nodes.length === 0 && combos.length === 0) return true;
|
|
341
|
+
|
|
342
|
+
if (excludeInvisibles) {
|
|
343
|
+
const edges = graph.getAllEdgesData();
|
|
344
|
+
const hasVisibleItems =
|
|
345
|
+
nodes.filter((node) => graph.getItemVisible(node.id)).length +
|
|
346
|
+
edges.filter((edge) => graph.getItemVisible(edge.id)).length +
|
|
347
|
+
combos.filter((combo) => graph.getItemVisible(combo.id)).length;
|
|
348
|
+
if (!hasVisibleItems) return true;
|
|
349
|
+
}
|
|
350
|
+
return false;
|
|
351
|
+
};
|
package/src/util/loop.ts
CHANGED
|
@@ -2,6 +2,17 @@ import { Tuple3Number } from '@antv/g';
|
|
|
2
2
|
import { vec2 } from 'gl-matrix';
|
|
3
3
|
import { LOOP_POSITION, LoopPosition } from '../types/loop';
|
|
4
4
|
|
|
5
|
+
export const loopPosition = [
|
|
6
|
+
'top',
|
|
7
|
+
'top-right',
|
|
8
|
+
'right',
|
|
9
|
+
'bottom-right',
|
|
10
|
+
'bottom',
|
|
11
|
+
'bottom-left',
|
|
12
|
+
'left',
|
|
13
|
+
'top-left',
|
|
14
|
+
];
|
|
15
|
+
|
|
5
16
|
const PI_OVER_8 = Math.PI / 8;
|
|
6
17
|
|
|
7
18
|
const radiansMap = {
|