@antv/g6 5.0.0-beta.20 → 5.0.0-beta.21

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.
Files changed (184) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/index.d.ts +16 -9
  3. package/esm/index.js +1 -1
  4. package/esm/runtime/controller/data.d.ts +27 -10
  5. package/esm/runtime/controller/data.js +240 -216
  6. package/esm/runtime/controller/data.js.map +1 -1
  7. package/esm/stdlib/behavior/activate-relations.d.ts +1 -1
  8. package/esm/stdlib/behavior/brush-select.d.ts +2 -2
  9. package/esm/stdlib/behavior/click-select.d.ts +1 -1
  10. package/esm/stdlib/behavior/collapse-expand-combo.d.ts +1 -1
  11. package/esm/stdlib/behavior/collapse-expand-tree.d.ts +1 -1
  12. package/esm/stdlib/behavior/drag-canvas.js +1 -1
  13. package/esm/stdlib/behavior/drag-combo.d.ts +1 -1
  14. package/esm/stdlib/behavior/drag-node.d.ts +1 -1
  15. package/esm/stdlib/behavior/shortcuts-call.d.ts +1 -1
  16. package/esm/stdlib/behavior/zoom-canvas.js +1 -1
  17. package/esm/stdlib/data/index.d.ts +1 -0
  18. package/esm/stdlib/data/index.js +1 -0
  19. package/esm/stdlib/data/index.js.map +1 -1
  20. package/esm/stdlib/data/mapNodeSize.d.ts +3 -4
  21. package/esm/stdlib/data/mapNodeSize.js +10 -0
  22. package/esm/stdlib/data/mapNodeSize.js.map +1 -1
  23. package/esm/stdlib/data/processParallelEdges.d.ts +21 -0
  24. package/esm/stdlib/data/processParallelEdges.js +127 -0
  25. package/esm/stdlib/data/processParallelEdges.js.map +1 -0
  26. package/esm/stdlib/data/transformV4Data.d.ts +2 -3
  27. package/esm/stdlib/data/transformV4Data.js +8 -0
  28. package/esm/stdlib/data/transformV4Data.js.map +1 -1
  29. package/esm/stdlib/data/validateData.d.ts +3 -4
  30. package/esm/stdlib/data/validateData.js +9 -1
  31. package/esm/stdlib/data/validateData.js.map +1 -1
  32. package/esm/stdlib/index.d.ts +15 -8
  33. package/esm/stdlib/index.js +2 -1
  34. package/esm/stdlib/index.js.map +1 -1
  35. package/esm/stdlib/item/node/donut.d.ts +3 -3
  36. package/esm/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  37. package/esm/stdlib/plugin/legend/index.d.ts +1 -1
  38. package/esm/stdlib/plugin/snapline/index.d.ts +2 -2
  39. package/esm/stdlib/plugin/snapline/index.js +239 -239
  40. package/esm/stdlib/plugin/snapline/index.js.map +1 -1
  41. package/esm/stdlib/plugin/timebar/index.d.ts +4 -4
  42. package/esm/stdlib/plugin/timebar/index.js +4 -4
  43. package/esm/stdlib/plugin/timebar/index.js.map +1 -1
  44. package/esm/stdlib/plugin/tooltip/index.d.ts +1 -1
  45. package/esm/stdlib/plugin/watermaker/index.d.ts +1 -1
  46. package/esm/types/animate.d.ts +2 -2
  47. package/esm/types/behavior.d.ts +1 -1
  48. package/esm/types/combo.d.ts +7 -7
  49. package/esm/types/common.d.ts +5 -5
  50. package/esm/types/data.d.ts +11 -6
  51. package/esm/types/edge.d.ts +9 -9
  52. package/esm/types/event.d.ts +1 -1
  53. package/esm/types/history.d.ts +2 -2
  54. package/esm/types/hook.d.ts +1 -1
  55. package/esm/types/item.d.ts +13 -13
  56. package/esm/types/item.js.map +1 -1
  57. package/esm/types/layout.d.ts +6 -6
  58. package/esm/types/loop.d.ts +2 -2
  59. package/esm/types/node.d.ts +7 -7
  60. package/esm/types/render.d.ts +1 -1
  61. package/esm/types/spec.d.ts +4 -3
  62. package/esm/types/stdlib.d.ts +1 -1
  63. package/esm/types/theme.d.ts +8 -8
  64. package/esm/types/view.d.ts +2 -2
  65. package/esm/util/array.d.ts +1 -0
  66. package/esm/util/array.js +3 -0
  67. package/esm/util/array.js.map +1 -1
  68. package/esm/util/data.d.ts +3 -0
  69. package/esm/util/data.js +15 -0
  70. package/esm/util/data.js.map +1 -1
  71. package/esm/util/event.d.ts +2 -2
  72. package/esm/util/layout.d.ts +1 -1
  73. package/esm/util/loop.d.ts +1 -0
  74. package/esm/util/loop.js +10 -0
  75. package/esm/util/loop.js.map +1 -1
  76. package/esm/util/shape.d.ts +2 -1
  77. package/esm/util/shape.js +2 -1
  78. package/esm/util/shape.js.map +1 -1
  79. package/esm/util/shape3d.d.ts +1 -1
  80. package/esm/util/warn.d.ts +1 -1
  81. package/lib/index.d.ts +16 -9
  82. package/lib/index.js +1 -1
  83. package/lib/runtime/controller/data.d.ts +27 -10
  84. package/lib/runtime/controller/data.js +238 -214
  85. package/lib/runtime/controller/data.js.map +1 -1
  86. package/lib/stdlib/behavior/activate-relations.d.ts +1 -1
  87. package/lib/stdlib/behavior/brush-select.d.ts +2 -2
  88. package/lib/stdlib/behavior/click-select.d.ts +1 -1
  89. package/lib/stdlib/behavior/collapse-expand-combo.d.ts +1 -1
  90. package/lib/stdlib/behavior/collapse-expand-tree.d.ts +1 -1
  91. package/lib/stdlib/behavior/drag-canvas.js +1 -1
  92. package/lib/stdlib/behavior/drag-combo.d.ts +1 -1
  93. package/lib/stdlib/behavior/drag-node.d.ts +1 -1
  94. package/lib/stdlib/behavior/shortcuts-call.d.ts +1 -1
  95. package/lib/stdlib/behavior/zoom-canvas.js +1 -1
  96. package/lib/stdlib/data/index.d.ts +1 -0
  97. package/lib/stdlib/data/index.js +1 -0
  98. package/lib/stdlib/data/index.js.map +1 -1
  99. package/lib/stdlib/data/mapNodeSize.d.ts +3 -4
  100. package/lib/stdlib/data/mapNodeSize.js +11 -1
  101. package/lib/stdlib/data/mapNodeSize.js.map +1 -1
  102. package/lib/stdlib/data/processParallelEdges.d.ts +21 -0
  103. package/lib/stdlib/data/processParallelEdges.js +131 -0
  104. package/lib/stdlib/data/processParallelEdges.js.map +1 -0
  105. package/lib/stdlib/data/transformV4Data.d.ts +2 -3
  106. package/lib/stdlib/data/transformV4Data.js +9 -1
  107. package/lib/stdlib/data/transformV4Data.js.map +1 -1
  108. package/lib/stdlib/data/validateData.d.ts +3 -4
  109. package/lib/stdlib/data/validateData.js +10 -2
  110. package/lib/stdlib/data/validateData.js.map +1 -1
  111. package/lib/stdlib/index.d.ts +15 -8
  112. package/lib/stdlib/index.js +2 -1
  113. package/lib/stdlib/index.js.map +1 -1
  114. package/lib/stdlib/item/node/donut.d.ts +3 -3
  115. package/lib/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  116. package/lib/stdlib/plugin/legend/index.d.ts +1 -1
  117. package/lib/stdlib/plugin/snapline/index.d.ts +2 -2
  118. package/lib/stdlib/plugin/snapline/index.js +239 -239
  119. package/lib/stdlib/plugin/snapline/index.js.map +1 -1
  120. package/lib/stdlib/plugin/timebar/index.d.ts +4 -4
  121. package/lib/stdlib/plugin/timebar/index.js +4 -4
  122. package/lib/stdlib/plugin/timebar/index.js.map +1 -1
  123. package/lib/stdlib/plugin/tooltip/index.d.ts +1 -1
  124. package/lib/stdlib/plugin/watermaker/index.d.ts +1 -1
  125. package/lib/types/animate.d.ts +2 -2
  126. package/lib/types/behavior.d.ts +1 -1
  127. package/lib/types/combo.d.ts +7 -7
  128. package/lib/types/common.d.ts +5 -5
  129. package/lib/types/data.d.ts +11 -6
  130. package/lib/types/edge.d.ts +9 -9
  131. package/lib/types/event.d.ts +1 -1
  132. package/lib/types/event.js +2 -2
  133. package/lib/types/event.js.map +1 -1
  134. package/lib/types/history.d.ts +2 -2
  135. package/lib/types/history.js +1 -1
  136. package/lib/types/history.js.map +1 -1
  137. package/lib/types/hook.d.ts +1 -1
  138. package/lib/types/item.d.ts +13 -13
  139. package/lib/types/item.js +1 -1
  140. package/lib/types/item.js.map +1 -1
  141. package/lib/types/layout.d.ts +6 -6
  142. package/lib/types/loop.d.ts +2 -2
  143. package/lib/types/loop.js +1 -1
  144. package/lib/types/loop.js.map +1 -1
  145. package/lib/types/node.d.ts +7 -7
  146. package/lib/types/render.d.ts +1 -1
  147. package/lib/types/spec.d.ts +4 -3
  148. package/lib/types/stdlib.d.ts +1 -1
  149. package/lib/types/theme.d.ts +8 -8
  150. package/lib/types/view.d.ts +2 -2
  151. package/lib/util/array.d.ts +1 -0
  152. package/lib/util/array.js +5 -1
  153. package/lib/util/array.js.map +1 -1
  154. package/lib/util/data.d.ts +3 -0
  155. package/lib/util/data.js +16 -1
  156. package/lib/util/data.js.map +1 -1
  157. package/lib/util/event.d.ts +2 -2
  158. package/lib/util/layout.d.ts +1 -1
  159. package/lib/util/loop.d.ts +1 -0
  160. package/lib/util/loop.js +11 -1
  161. package/lib/util/loop.js.map +1 -1
  162. package/lib/util/shape.d.ts +2 -1
  163. package/lib/util/shape.js +1 -0
  164. package/lib/util/shape.js.map +1 -1
  165. package/lib/util/shape3d.d.ts +1 -1
  166. package/lib/util/warn.d.ts +1 -1
  167. package/package.json +3 -3
  168. package/src/index.ts +1 -1
  169. package/src/runtime/controller/data.ts +309 -229
  170. package/src/stdlib/behavior/drag-canvas.ts +1 -1
  171. package/src/stdlib/behavior/zoom-canvas.ts +1 -1
  172. package/src/stdlib/data/index.ts +1 -0
  173. package/src/stdlib/data/mapNodeSize.ts +20 -1
  174. package/src/stdlib/data/processParallelEdges.ts +203 -0
  175. package/src/stdlib/data/transformV4Data.ts +14 -1
  176. package/src/stdlib/data/validateData.ts +16 -2
  177. package/src/stdlib/index.ts +3 -1
  178. package/src/types/data.ts +6 -0
  179. package/src/types/item.ts +2 -1
  180. package/src/types/spec.ts +1 -0
  181. package/src/util/array.ts +12 -0
  182. package/src/util/data.ts +24 -1
  183. package/src/util/loop.ts +11 -0
  184. package/src/util/shape.ts +1 -0
@@ -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,
@@ -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 } = Transforms;
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,
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/item.ts CHANGED
@@ -115,7 +115,8 @@ export type SHAPE_TYPE =
115
115
  | 'polyline'
116
116
  | 'line'
117
117
  | 'path'
118
- | 'text';
118
+ | 'text'
119
+ | 'group';
119
120
 
120
121
  export type SHAPE_TYPE_3D = 'sphere' | 'cube' | 'plane';
121
122
 
package/src/types/spec.ts CHANGED
@@ -93,6 +93,7 @@ export interface Specification<
93
93
  | string[]
94
94
  | {
95
95
  type: string;
96
+ activeLifecycle: string | string[];
96
97
  [param: string]: unknown; // TODO: generate by plugins
97
98
  }[]
98
99
  | TransformerFn[];
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 { GraphCore, GraphData } from '../types/data';
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,21 @@ 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
+ };
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 = {
package/src/util/shape.ts CHANGED
@@ -44,6 +44,7 @@ export const ShapeTagMap = {
44
44
  text: Text,
45
45
  image: Image,
46
46
  path: Path,
47
+ group: Group,
47
48
  };
48
49
 
49
50
  const LINE_TYPES = ['line', 'polyline', 'path'];