@antv/g6 5.0.0-alpha.8 → 5.0.0-alpha.9

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 (290) hide show
  1. package/dist/g6.min.js +6 -19
  2. package/esm/index.d.ts +26 -6
  3. package/esm/item/combo.d.ts +72 -2
  4. package/esm/item/combo.js +122 -2
  5. package/esm/item/combo.js.map +1 -1
  6. package/esm/item/edge.d.ts +3 -3
  7. package/esm/item/edge.js +4 -5
  8. package/esm/item/edge.js.map +1 -1
  9. package/esm/item/item.d.ts +4 -4
  10. package/esm/item/item.js +38 -9
  11. package/esm/item/item.js.map +1 -1
  12. package/esm/item/node.d.ts +20 -16
  13. package/esm/item/node.js +14 -8
  14. package/esm/item/node.js.map +1 -1
  15. package/esm/runtime/controller/data.d.ts +12 -4
  16. package/esm/runtime/controller/data.js +354 -62
  17. package/esm/runtime/controller/data.js.map +1 -1
  18. package/esm/runtime/controller/interaction.js +16 -4
  19. package/esm/runtime/controller/interaction.js.map +1 -1
  20. package/esm/runtime/controller/item.d.ts +11 -2
  21. package/esm/runtime/controller/item.js +344 -52
  22. package/esm/runtime/controller/item.js.map +1 -1
  23. package/esm/runtime/controller/layout.js +19 -5
  24. package/esm/runtime/controller/layout.js.map +1 -1
  25. package/esm/runtime/graph.d.ts +54 -17
  26. package/esm/runtime/graph.js +165 -34
  27. package/esm/runtime/graph.js.map +1 -1
  28. package/esm/stdlib/behavior/click-select.d.ts +3 -0
  29. package/esm/stdlib/behavior/click-select.js +13 -1
  30. package/esm/stdlib/behavior/click-select.js.map +1 -1
  31. package/esm/stdlib/behavior/collapse-expand-combo.d.ts +29 -0
  32. package/esm/stdlib/behavior/collapse-expand-combo.js +35 -0
  33. package/esm/stdlib/behavior/collapse-expand-combo.js.map +1 -0
  34. package/esm/stdlib/behavior/drag-combo.d.ts +99 -0
  35. package/esm/stdlib/behavior/drag-combo.js +341 -0
  36. package/esm/stdlib/behavior/drag-combo.js.map +1 -0
  37. package/esm/stdlib/behavior/drag-node.d.ts +14 -10
  38. package/esm/stdlib/behavior/drag-node.js +134 -37
  39. package/esm/stdlib/behavior/drag-node.js.map +1 -1
  40. package/esm/stdlib/behavior/hover-activate.d.ts +3 -1
  41. package/esm/stdlib/behavior/hover-activate.js +3 -1
  42. package/esm/stdlib/behavior/hover-activate.js.map +1 -1
  43. package/esm/stdlib/behavior/orbit-canvas-3d.js +1 -1
  44. package/esm/stdlib/behavior/orbit-canvas-3d.js.map +1 -1
  45. package/esm/stdlib/behavior/track-canvas-3d.js +1 -1
  46. package/esm/stdlib/behavior/track-canvas-3d.js.map +1 -1
  47. package/esm/stdlib/index.d.ts +25 -3
  48. package/esm/stdlib/index.js +25 -3
  49. package/esm/stdlib/index.js.map +1 -1
  50. package/esm/stdlib/item/combo/circle.d.ts +29 -0
  51. package/esm/stdlib/item/combo/circle.js +56 -0
  52. package/esm/stdlib/item/combo/circle.js.map +1 -0
  53. package/esm/stdlib/item/edge/base.d.ts +2 -2
  54. package/esm/stdlib/item/edge/base.js +3 -0
  55. package/esm/stdlib/item/edge/base.js.map +1 -1
  56. package/esm/stdlib/item/edge/cubic-horizon.d.ts +37 -0
  57. package/esm/stdlib/item/edge/cubic-horizon.js +71 -0
  58. package/esm/stdlib/item/edge/cubic-horizon.js.map +1 -0
  59. package/esm/stdlib/item/edge/cubic-vertical.d.ts +37 -0
  60. package/esm/stdlib/item/edge/cubic-vertical.js +71 -0
  61. package/esm/stdlib/item/edge/cubic-vertical.js.map +1 -0
  62. package/esm/stdlib/item/edge/cubic.d.ts +60 -0
  63. package/esm/stdlib/item/edge/cubic.js +99 -0
  64. package/esm/stdlib/item/edge/cubic.js.map +1 -0
  65. package/esm/stdlib/item/edge/index.d.ts +1 -0
  66. package/esm/stdlib/item/edge/index.js +1 -0
  67. package/esm/stdlib/item/edge/index.js.map +1 -1
  68. package/esm/stdlib/item/edge/line.d.ts +1 -1
  69. package/esm/stdlib/item/edge/quadratic.d.ts +41 -0
  70. package/esm/stdlib/item/edge/quadratic.js +66 -0
  71. package/esm/stdlib/item/edge/quadratic.js.map +1 -0
  72. package/esm/stdlib/item/node/base.d.ts +38 -37
  73. package/esm/stdlib/item/node/base.js +4 -4
  74. package/esm/stdlib/item/node/base.js.map +1 -1
  75. package/esm/stdlib/item/node/index.d.ts +1 -0
  76. package/esm/stdlib/item/node/index.js +1 -0
  77. package/esm/stdlib/item/node/index.js.map +1 -1
  78. package/esm/stdlib/item/node/rect.d.ts +31 -0
  79. package/esm/stdlib/item/node/rect.js +59 -0
  80. package/esm/stdlib/item/node/rect.js.map +1 -0
  81. package/esm/stdlib/plugin/fisheye/index.d.ts +102 -0
  82. package/esm/stdlib/plugin/fisheye/index.js +487 -0
  83. package/esm/stdlib/plugin/fisheye/index.js.map +1 -0
  84. package/esm/stdlib/plugin/menu/index.d.ts +42 -0
  85. package/esm/stdlib/plugin/menu/index.js +236 -0
  86. package/esm/stdlib/plugin/menu/index.js.map +1 -0
  87. package/esm/stdlib/plugin/tooltip/index.d.ts +75 -0
  88. package/esm/stdlib/plugin/tooltip/index.js +377 -0
  89. package/esm/stdlib/plugin/tooltip/index.js.map +1 -0
  90. package/esm/stdlib/theme/dark.js +4 -0
  91. package/esm/stdlib/theme/dark.js.map +1 -1
  92. package/esm/stdlib/theme/light.js +54 -9
  93. package/esm/stdlib/theme/light.js.map +1 -1
  94. package/esm/types/combo.d.ts +52 -3
  95. package/esm/types/data.d.ts +4 -4
  96. package/esm/types/edge.d.ts +2 -3
  97. package/esm/types/event.d.ts +9 -1
  98. package/esm/types/event.js +8 -8
  99. package/esm/types/event.js.map +1 -1
  100. package/esm/types/graph.d.ts +49 -13
  101. package/esm/types/hook.d.ts +8 -1
  102. package/esm/types/item.d.ts +4 -4
  103. package/esm/types/node.d.ts +4 -5
  104. package/esm/types/theme.d.ts +1 -1
  105. package/esm/util/animate.js.map +1 -1
  106. package/esm/util/canvas.js +8 -0
  107. package/esm/util/canvas.js.map +1 -1
  108. package/esm/util/data.d.ts +65 -0
  109. package/esm/util/data.js +150 -0
  110. package/esm/util/data.js.map +1 -0
  111. package/esm/util/event.d.ts +8 -0
  112. package/esm/util/event.js +16 -0
  113. package/esm/util/event.js.map +1 -1
  114. package/esm/util/item.d.ts +2 -1
  115. package/esm/util/item.js +36 -13
  116. package/esm/util/item.js.map +1 -1
  117. package/esm/util/shape.d.ts +39 -4
  118. package/esm/util/shape.js +101 -1
  119. package/esm/util/shape.js.map +1 -1
  120. package/esm/util/zoom.d.ts +2 -2
  121. package/lib/index.d.ts +26 -6
  122. package/lib/item/combo.d.ts +72 -2
  123. package/lib/item/combo.js +122 -2
  124. package/lib/item/combo.js.map +1 -1
  125. package/lib/item/edge.d.ts +3 -3
  126. package/lib/item/edge.js +4 -5
  127. package/lib/item/edge.js.map +1 -1
  128. package/lib/item/item.d.ts +4 -4
  129. package/lib/item/item.js +37 -8
  130. package/lib/item/item.js.map +1 -1
  131. package/lib/item/node.d.ts +20 -16
  132. package/lib/item/node.js +14 -8
  133. package/lib/item/node.js.map +1 -1
  134. package/lib/runtime/controller/data.d.ts +12 -4
  135. package/lib/runtime/controller/data.js +353 -61
  136. package/lib/runtime/controller/data.js.map +1 -1
  137. package/lib/runtime/controller/interaction.js +15 -3
  138. package/lib/runtime/controller/interaction.js.map +1 -1
  139. package/lib/runtime/controller/item.d.ts +11 -2
  140. package/lib/runtime/controller/item.js +342 -50
  141. package/lib/runtime/controller/item.js.map +1 -1
  142. package/lib/runtime/controller/layout.js +19 -5
  143. package/lib/runtime/controller/layout.js.map +1 -1
  144. package/lib/runtime/graph.d.ts +54 -17
  145. package/lib/runtime/graph.js +165 -34
  146. package/lib/runtime/graph.js.map +1 -1
  147. package/lib/stdlib/behavior/click-select.d.ts +3 -0
  148. package/lib/stdlib/behavior/click-select.js +13 -1
  149. package/lib/stdlib/behavior/click-select.js.map +1 -1
  150. package/lib/stdlib/behavior/collapse-expand-combo.d.ts +29 -0
  151. package/lib/stdlib/behavior/collapse-expand-combo.js +38 -0
  152. package/lib/stdlib/behavior/collapse-expand-combo.js.map +1 -0
  153. package/lib/stdlib/behavior/drag-combo.d.ts +99 -0
  154. package/lib/stdlib/behavior/drag-combo.js +344 -0
  155. package/lib/stdlib/behavior/drag-combo.js.map +1 -0
  156. package/lib/stdlib/behavior/drag-node.d.ts +14 -10
  157. package/lib/stdlib/behavior/drag-node.js +134 -37
  158. package/lib/stdlib/behavior/drag-node.js.map +1 -1
  159. package/lib/stdlib/behavior/hover-activate.d.ts +3 -1
  160. package/lib/stdlib/behavior/hover-activate.js +3 -2
  161. package/lib/stdlib/behavior/hover-activate.js.map +1 -1
  162. package/lib/stdlib/behavior/orbit-canvas-3d.js +1 -1
  163. package/lib/stdlib/behavior/orbit-canvas-3d.js.map +1 -1
  164. package/lib/stdlib/behavior/track-canvas-3d.js +1 -1
  165. package/lib/stdlib/behavior/track-canvas-3d.js.map +1 -1
  166. package/lib/stdlib/index.d.ts +25 -3
  167. package/lib/stdlib/index.js +25 -3
  168. package/lib/stdlib/index.js.map +1 -1
  169. package/lib/stdlib/item/combo/circle.d.ts +29 -0
  170. package/lib/stdlib/item/combo/circle.js +60 -0
  171. package/lib/stdlib/item/combo/circle.js.map +1 -0
  172. package/lib/stdlib/item/edge/base.d.ts +2 -2
  173. package/lib/stdlib/item/edge/base.js +3 -0
  174. package/lib/stdlib/item/edge/base.js.map +1 -1
  175. package/lib/stdlib/item/edge/cubic-horizon.d.ts +37 -0
  176. package/lib/stdlib/item/edge/cubic-horizon.js +75 -0
  177. package/lib/stdlib/item/edge/cubic-horizon.js.map +1 -0
  178. package/lib/stdlib/item/edge/cubic-vertical.d.ts +37 -0
  179. package/lib/stdlib/item/edge/cubic-vertical.js +75 -0
  180. package/lib/stdlib/item/edge/cubic-vertical.js.map +1 -0
  181. package/lib/stdlib/item/edge/cubic.d.ts +60 -0
  182. package/lib/stdlib/item/edge/cubic.js +103 -0
  183. package/lib/stdlib/item/edge/cubic.js.map +1 -0
  184. package/lib/stdlib/item/edge/index.d.ts +1 -0
  185. package/lib/stdlib/item/edge/index.js +1 -0
  186. package/lib/stdlib/item/edge/index.js.map +1 -1
  187. package/lib/stdlib/item/edge/line.d.ts +1 -1
  188. package/lib/stdlib/item/edge/quadratic.d.ts +41 -0
  189. package/lib/stdlib/item/edge/quadratic.js +70 -0
  190. package/lib/stdlib/item/edge/quadratic.js.map +1 -0
  191. package/lib/stdlib/item/node/base.d.ts +38 -37
  192. package/lib/stdlib/item/node/base.js +4 -4
  193. package/lib/stdlib/item/node/base.js.map +1 -1
  194. package/lib/stdlib/item/node/index.d.ts +1 -0
  195. package/lib/stdlib/item/node/index.js +1 -0
  196. package/lib/stdlib/item/node/index.js.map +1 -1
  197. package/lib/stdlib/item/node/rect.d.ts +31 -0
  198. package/lib/stdlib/item/node/rect.js +63 -0
  199. package/lib/stdlib/item/node/rect.js.map +1 -0
  200. package/lib/stdlib/plugin/fisheye/index.d.ts +102 -0
  201. package/lib/stdlib/plugin/fisheye/index.js +490 -0
  202. package/lib/stdlib/plugin/fisheye/index.js.map +1 -0
  203. package/lib/stdlib/plugin/menu/index.d.ts +42 -0
  204. package/lib/stdlib/plugin/menu/index.js +242 -0
  205. package/lib/stdlib/plugin/menu/index.js.map +1 -0
  206. package/lib/stdlib/plugin/tooltip/index.d.ts +75 -0
  207. package/lib/stdlib/plugin/tooltip/index.js +383 -0
  208. package/lib/stdlib/plugin/tooltip/index.js.map +1 -0
  209. package/lib/stdlib/theme/dark.js +4 -0
  210. package/lib/stdlib/theme/dark.js.map +1 -1
  211. package/lib/stdlib/theme/light.js +54 -9
  212. package/lib/stdlib/theme/light.js.map +1 -1
  213. package/lib/types/combo.d.ts +52 -3
  214. package/lib/types/data.d.ts +4 -4
  215. package/lib/types/edge.d.ts +2 -3
  216. package/lib/types/event.d.ts +9 -1
  217. package/lib/types/event.js +10 -10
  218. package/lib/types/event.js.map +1 -1
  219. package/lib/types/graph.d.ts +49 -13
  220. package/lib/types/hook.d.ts +8 -1
  221. package/lib/types/item.d.ts +4 -4
  222. package/lib/types/item.js +1 -1
  223. package/lib/types/item.js.map +1 -1
  224. package/lib/types/node.d.ts +4 -5
  225. package/lib/types/theme.d.ts +1 -1
  226. package/lib/util/animate.js.map +1 -1
  227. package/lib/util/canvas.js +8 -0
  228. package/lib/util/canvas.js.map +1 -1
  229. package/lib/util/data.d.ts +65 -0
  230. package/lib/util/data.js +161 -0
  231. package/lib/util/data.js.map +1 -0
  232. package/lib/util/event.d.ts +8 -0
  233. package/lib/util/event.js +18 -1
  234. package/lib/util/event.js.map +1 -1
  235. package/lib/util/item.d.ts +2 -1
  236. package/lib/util/item.js +36 -13
  237. package/lib/util/item.js.map +1 -1
  238. package/lib/util/shape.d.ts +39 -4
  239. package/lib/util/shape.js +105 -2
  240. package/lib/util/shape.js.map +1 -1
  241. package/lib/util/zoom.d.ts +2 -2
  242. package/package.json +13 -13
  243. package/src/item/combo.ts +220 -2
  244. package/src/item/edge.ts +7 -8
  245. package/src/item/item.ts +58 -15
  246. package/src/item/node.ts +47 -24
  247. package/src/runtime/controller/data.ts +390 -68
  248. package/src/runtime/controller/interaction.ts +23 -3
  249. package/src/runtime/controller/item.ts +444 -64
  250. package/src/runtime/controller/layout.ts +24 -5
  251. package/src/runtime/graph.ts +225 -38
  252. package/src/stdlib/behavior/click-select.ts +15 -2
  253. package/src/stdlib/behavior/collapse-expand-combo.ts +59 -0
  254. package/src/stdlib/behavior/drag-combo.ts +533 -0
  255. package/src/stdlib/behavior/drag-node.ts +195 -62
  256. package/src/stdlib/behavior/hover-activate.ts +4 -5
  257. package/src/stdlib/behavior/orbit-canvas-3d.ts +1 -1
  258. package/src/stdlib/behavior/track-canvas-3d.ts +1 -1
  259. package/src/stdlib/index.ts +25 -3
  260. package/src/stdlib/item/combo/circle.ts +113 -0
  261. package/src/stdlib/item/edge/base.ts +5 -2
  262. package/src/stdlib/item/edge/cubic-horizon.ts +114 -0
  263. package/src/stdlib/item/edge/cubic-vertical.ts +116 -0
  264. package/src/stdlib/item/edge/cubic.ts +198 -0
  265. package/src/stdlib/item/edge/index.ts +1 -0
  266. package/src/stdlib/item/edge/quadratic.ts +136 -0
  267. package/src/stdlib/item/node/base.ts +79 -41
  268. package/src/stdlib/item/node/index.ts +1 -0
  269. package/src/stdlib/item/node/rect.ts +124 -0
  270. package/src/stdlib/plugin/fisheye/index.ts +578 -0
  271. package/src/stdlib/plugin/menu/index.ts +260 -0
  272. package/src/stdlib/plugin/tooltip/index.ts +424 -0
  273. package/src/stdlib/theme/dark.ts +4 -0
  274. package/src/stdlib/theme/light.ts +77 -9
  275. package/src/types/combo.ts +61 -3
  276. package/src/types/data.ts +6 -4
  277. package/src/types/edge.ts +2 -2
  278. package/src/types/event.ts +8 -8
  279. package/src/types/graph.ts +73 -16
  280. package/src/types/hook.ts +8 -1
  281. package/src/types/item.ts +10 -9
  282. package/src/types/node.ts +4 -4
  283. package/src/types/theme.ts +1 -1
  284. package/src/util/animate.ts +2 -3
  285. package/src/util/canvas.ts +10 -0
  286. package/src/util/data.ts +178 -0
  287. package/src/util/event.ts +29 -0
  288. package/src/util/item.ts +75 -12
  289. package/src/util/shape.ts +142 -5
  290. package/src/util/zoom.ts +2 -2
@@ -1,4 +1,5 @@
1
1
  import { Animation, DisplayObject, IAnimationEffectTiming } from '@antv/g';
2
+ import { Graph as GraphLib } from '@antv/graphlib';
2
3
  import {
3
4
  isLayoutWithIterations,
4
5
  Layout,
@@ -12,8 +13,10 @@ import {
12
13
  isImmediatelyInvokedLayoutOptions,
13
14
  isLayoutWorkerized,
14
15
  LayoutOptions,
16
+ NodeModelData,
15
17
  } from '../../types';
16
18
  import { GraphCore } from '../../types/data';
19
+ import { EdgeModelData } from '../../types/edge';
17
20
 
18
21
  /**
19
22
  * Manages layout extensions and graph layout.
@@ -54,6 +57,20 @@ export class LayoutController {
54
57
  this.stopLayout();
55
58
 
56
59
  const { graphCore, options } = params;
60
+ const layoutNodes = graphCore
61
+ .getAllNodes()
62
+ .filter((node) => node.data.visible !== false && !node.data._isCombo);
63
+ const layoutNodesIdMap = {};
64
+ layoutNodes.forEach((node) => (layoutNodesIdMap[node.id] = true));
65
+ const layoutGraphCore = new GraphLib<NodeModelData, EdgeModelData>({
66
+ nodes: layoutNodes,
67
+ edges: graphCore
68
+ .getAllEdges()
69
+ .filter(
70
+ (edge) =>
71
+ layoutNodesIdMap[edge.source] && layoutNodesIdMap[edge.target],
72
+ ),
73
+ });
57
74
 
58
75
  this.graph.emit('startlayout');
59
76
 
@@ -68,7 +85,7 @@ export class LayoutController {
68
85
  } = options;
69
86
 
70
87
  // It will ignore some layout options such as `type` and `workerEnabled`.
71
- positions = await execute(graphCore, rest);
88
+ positions = await execute(layoutGraphCore, rest);
72
89
 
73
90
  if (animated) {
74
91
  await this.animateLayoutWithoutIterations(
@@ -108,7 +125,9 @@ export class LayoutController {
108
125
  /**
109
126
  * Run algorithm in WebWorker, `animated` option will be ignored.
110
127
  */
111
- const supervisor = new Supervisor(graphCore, layout, { iterations });
128
+ const supervisor = new Supervisor(layoutGraphCore, layout, {
129
+ iterations,
130
+ });
112
131
  this.currentSupervisor = supervisor;
113
132
  positions = await supervisor.execute();
114
133
  } else {
@@ -118,7 +137,7 @@ export class LayoutController {
118
137
  /**
119
138
  * `onTick` will get triggered in this case.
120
139
  */
121
- positions = await layout.execute(graphCore, {
140
+ positions = await layout.execute(layoutGraphCore, {
122
141
  onTick: (positionsOnTick: LayoutMapping) => {
123
142
  // Display the animated process of layout.
124
143
  this.updateNodesPosition(positionsOnTick);
@@ -130,12 +149,12 @@ export class LayoutController {
130
149
  * Manually step simulation in a sync way. `onTick` won't get triggered in this case,
131
150
  * there will be no animation either.
132
151
  */
133
- layout.execute(graphCore);
152
+ layout.execute(layoutGraphCore);
134
153
  layout.stop();
135
154
  positions = layout.tick(iterations);
136
155
  }
137
156
  } else {
138
- positions = await layout.execute(graphCore);
157
+ positions = await layout.execute(layoutGraphCore);
139
158
 
140
159
  if (animated) {
141
160
  await this.animateLayoutWithoutIterations(
@@ -44,6 +44,7 @@ import {
44
44
  } from './controller';
45
45
  import { PluginController } from './controller/plugin';
46
46
  import Hook from './hooks';
47
+ import { graphComboTreeDfs } from '../util/data';
47
48
 
48
49
  /**
49
50
  * Disable CSS parsing for better performance.
@@ -88,7 +89,6 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
88
89
 
89
90
  constructor(spec: Specification<B, T>) {
90
91
  super();
91
- // TODO: analyse cfg
92
92
 
93
93
  this.specification = Object.assign({}, this.defaultSpecification, spec);
94
94
  this.initHooks();
@@ -217,6 +217,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
217
217
  changes: GraphChange<NodeModelData, EdgeModelData>[];
218
218
  graphCore: GraphCore;
219
219
  theme: ThemeSpecification;
220
+ upsertAncestors?: boolean;
220
221
  }>({ name: 'itemchange' }),
221
222
  render: new Hook<{
222
223
  graphCore: GraphCore;
@@ -243,6 +244,9 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
243
244
  itemvisibilitychange: new Hook<{ ids: ID[]; value: boolean }>({
244
245
  name: 'itemvisibilitychange',
245
246
  }),
247
+ itemzindexchange: new Hook<{ ids: ID[]; action: 'front' | 'back' }>({
248
+ name: 'itemzindexchange',
249
+ }),
246
250
  transientupdate: new Hook<{
247
251
  type: ITEM_TYPE | SHAPE_TYPE;
248
252
  id: ID;
@@ -251,6 +255,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
251
255
  action: 'remove' | 'add' | 'update' | undefined;
252
256
  };
253
257
  canvas: Canvas;
258
+ graphCore: GraphCore;
254
259
  }>({ name: 'transientupdate' }),
255
260
  pluginchange: new Hook<{
256
261
  action: 'update' | 'add' | 'remove';
@@ -364,7 +369,18 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
364
369
  * @returns
365
370
  */
366
371
  public clear() {
367
- // TODO
372
+ this.removeData(
373
+ 'edge',
374
+ this.getAllEdgesData().map((edge) => edge.id),
375
+ );
376
+ this.removeData(
377
+ 'node',
378
+ this.getAllNodesData().map((node) => node.id),
379
+ );
380
+ this.removeData(
381
+ 'combo',
382
+ this.getAllCombosData().map((combo) => combo.id),
383
+ );
368
384
  }
369
385
 
370
386
  public getViewportCenter(): PointLike {
@@ -737,7 +753,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
737
753
  * @group Data
738
754
  */
739
755
  public getAllNodesData(): NodeModel[] {
740
- return this.dataController.findAllData('node');
756
+ return this.dataController.findAllData('node') as NodeModel[];
741
757
  }
742
758
  /**
743
759
  * Get all the edges' inner data
@@ -758,26 +774,35 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
758
774
  /**
759
775
  * Get one-hop edge ids from a start node.
760
776
  * @param nodeId id of the start node
761
- * @returns one-hop edge ids
777
+ * @returns one-hop edges' data array
762
778
  * @group Data
763
779
  */
764
780
  public getRelatedEdgesData(
765
781
  nodeId: ID,
766
782
  direction: 'in' | 'out' | 'both' = 'both',
767
783
  ): EdgeModel[] {
768
- return this.dataController.findRelatedEdgeIds(nodeId, direction);
784
+ return this.dataController.findRelatedEdges(nodeId, direction);
769
785
  }
770
786
  /**
771
787
  * Get one-hop node ids from a start node.
772
788
  * @param nodeId id of the start node
773
- * @returns one-hop node ids
789
+ * @returns one-hop nodes' data array
774
790
  * @group Data
775
791
  */
776
792
  public getNeighborNodesData(
777
793
  nodeId: ID,
778
794
  direction: 'in' | 'out' | 'both' = 'both',
779
795
  ): NodeModel[] {
780
- return this.dataController.findNeighborNodeIds(nodeId, direction);
796
+ return this.dataController.findNeighborNodes(nodeId, direction);
797
+ }
798
+ /**
799
+ * Get the children's data of a combo.
800
+ * @param comboId combo id
801
+ * @returns children's data array
802
+ * @group Data
803
+ */
804
+ public getComboChildrenData(comboId: ID): (ComboModel | NodeModel)[] {
805
+ return this.dataController.findChildren(comboId, 'combo');
781
806
  }
782
807
 
783
808
  /**
@@ -796,8 +821,9 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
796
821
  ): ID[] {
797
822
  let ids = this.itemController.findIdByState(itemType, state, value);
798
823
  if (additionalFilter) {
799
- const getDataFunc =
800
- itemType === 'node' ? this.getNodeData : this.getEdgeData; // TODO: combo
824
+ let getDataFunc: any = this.getEdgeData;
825
+ if (itemType === 'node') getDataFunc = this.getNodeData;
826
+ else if (itemType === 'combo') getDataFunc = this.getComboData;
801
827
  ids = ids.filter((id) => additionalFilter(getDataFunc(id)));
802
828
  }
803
829
  return ids;
@@ -868,7 +894,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
868
894
  const { userGraphCore, graphCore } = this.dataController;
869
895
  const { specification } = this.themeController;
870
896
  const getItem =
871
- itemType === 'edge' ? userGraphCore.getEdge : userGraphCore.getNode; // TODO: combo
897
+ itemType === 'edge' ? userGraphCore.getEdge : userGraphCore.getNode;
872
898
  data[`${itemType}s`] = idArr.map((id) => getItem.bind(userGraphCore)(id));
873
899
  graphCore.once('changed', (event) => {
874
900
  if (!event.changes.length) return;
@@ -955,6 +981,40 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
955
981
  | Partial<
956
982
  ComboUserModel | Partial<NodeUserModel>[] | Partial<ComboUserModel>[]
957
983
  >,
984
+ upsertAncestors?: boolean,
985
+ stack?: boolean,
986
+ ) {
987
+ return this.updatePosition('node', models, upsertAncestors, stack);
988
+ }
989
+
990
+ /**
991
+ * Update one or more combos' positions,
992
+ * do not update other styles which leads to better performance than updating positions by updateData.
993
+ * In fact, it changes the succeed nodes positions to affect the combo's position, but not modify the combo's position directly.
994
+ * @param models new configurations with x and y for every combo, which has id field to indicate the specific item
995
+ * @param {boolean} stack whether push this operation into graph's stack, true by default
996
+ * @group Data
997
+ */
998
+ public updateComboPosition(
999
+ models:
1000
+ | Partial<NodeUserModel>
1001
+ | Partial<
1002
+ ComboUserModel | Partial<NodeUserModel>[] | Partial<ComboUserModel>[]
1003
+ >,
1004
+ upsertAncestors?: boolean,
1005
+ stack?: boolean,
1006
+ ) {
1007
+ return this.updatePosition('combo', models, upsertAncestors, stack);
1008
+ }
1009
+
1010
+ private updatePosition(
1011
+ type: 'node' | 'combo',
1012
+ models:
1013
+ | Partial<NodeUserModel>
1014
+ | Partial<
1015
+ ComboUserModel | Partial<NodeUserModel>[] | Partial<ComboUserModel>[]
1016
+ >,
1017
+ upsertAncestors?: boolean,
958
1018
  stack?: boolean,
959
1019
  ) {
960
1020
  const modelArr = isArray(models) ? models : [models];
@@ -963,32 +1023,36 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
963
1023
  graphCore.once('changed', (event) => {
964
1024
  if (!event.changes.length) return;
965
1025
  this.hooks.itemchange.emit({
966
- type: 'node',
1026
+ type,
967
1027
  changes: event.changes,
968
1028
  graphCore,
969
1029
  theme: specification,
970
- action: 'updateNodePosition',
1030
+ upsertAncestors,
1031
+ action: 'updatePosition',
971
1032
  });
972
1033
  this.emit('afteritemchange', {
973
- type: 'node',
974
- action: 'updateNodePosition',
1034
+ type,
1035
+ action: 'updatePosition',
1036
+ upsertAncestors,
975
1037
  models,
976
1038
  });
977
1039
  });
978
1040
 
979
1041
  this.hooks.datachange.emit({
980
1042
  data: {
981
- nodes: modelArr as NodeUserModel[],
1043
+ nodes: type === 'node' ? (modelArr as NodeUserModel[]) : [],
982
1044
  edges: [],
1045
+ combos: type === 'combo' ? (modelArr as ComboUserModel[]) : [],
983
1046
  },
984
1047
  type: 'update',
985
1048
  });
986
1049
  const dataList = this.dataController.findData(
987
- 'node',
1050
+ type,
988
1051
  modelArr.map((model) => model.id),
989
1052
  );
990
1053
  return isArray(models) ? dataList : dataList[0];
991
1054
  }
1055
+
992
1056
  /**
993
1057
  * Show the item(s).
994
1058
  * @param item the item to be shown
@@ -1000,6 +1064,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1000
1064
  this.hooks.itemvisibilitychange.emit({
1001
1065
  ids: idArr as ID[],
1002
1066
  value: true,
1067
+ graphCore: this.dataController.graphCore,
1003
1068
  animate: !disableAniamte,
1004
1069
  });
1005
1070
  }
@@ -1014,9 +1079,37 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1014
1079
  this.hooks.itemvisibilitychange.emit({
1015
1080
  ids: idArr as ID[],
1016
1081
  value: false,
1082
+ graphCore: this.dataController.graphCore,
1017
1083
  animate: !disableAniamte,
1018
1084
  });
1019
1085
  }
1086
+
1087
+ /**
1088
+ * Make the item(s) to the front.
1089
+ * @param ids
1090
+ * @returns
1091
+ * @group Item
1092
+ */
1093
+ public frontItem(ids: ID | ID[]) {
1094
+ const idArr = isArray(ids) ? ids : [ids];
1095
+ this.hooks.itemzindexchange.emit({
1096
+ ids: idArr as ID[],
1097
+ action: 'front',
1098
+ });
1099
+ }
1100
+ /**
1101
+ * Make the item(s) to the back.
1102
+ * @param ids
1103
+ * @returns
1104
+ * @group Item
1105
+ */
1106
+ public backItem(ids: ID | ID[]) {
1107
+ const idArr = isArray(ids) ? ids : [ids];
1108
+ this.hooks.itemzindexchange.emit({
1109
+ ids: idArr as ID[],
1110
+ action: 'back',
1111
+ });
1112
+ }
1020
1113
  /**
1021
1114
  * Set state for the item.
1022
1115
  * @param item the item to be set
@@ -1073,9 +1166,13 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1073
1166
  * @returns rendering bounding box. returns false if the item is not exist
1074
1167
  * @group Item
1075
1168
  */
1076
- public getRenderBBox(id: ID | undefined): AABB | false {
1169
+ public getRenderBBox(
1170
+ id: ID | undefined,
1171
+ onlyKeyShape = false,
1172
+ isTransient = false,
1173
+ ): AABB | false {
1077
1174
  if (!id) return this.canvas.getRoot().getRenderBounds();
1078
- return this.itemController.getItemBBox(id);
1175
+ return this.itemController.getItemBBox(id, onlyKeyShape, isTransient);
1079
1176
  }
1080
1177
 
1081
1178
  /**
@@ -1089,42 +1186,130 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1089
1186
  }
1090
1187
 
1091
1188
  // ===== combo operations =====
1189
+
1092
1190
  /**
1093
- * Create a new combo with existing child nodes and combos.
1094
- * @param combo combo ID or Combo model
1095
- * @param childrenIds id array of children of the new combo
1191
+ * Add a new combo to the graph, and update the structure of the existed child in childrenIds to be the children of the new combo.
1192
+ * Different from addData with combo type, this API update the succeeds' combo tree strucutres in the same time.
1193
+ * @param model combo user data
1194
+ * @param stack whether push this operation to stack
1195
+ * @returns whether success
1096
1196
  * @group Combo
1097
1197
  */
1098
- public createCombo(
1099
- combo: string | ComboUserModel,
1100
- childrenIds: string[],
1198
+ public addCombo(
1199
+ model: ComboUserModel,
1200
+ childrenIds: ID[],
1101
1201
  stack?: boolean,
1102
- ) {
1103
- // TODO
1202
+ ): ComboModel {
1203
+ const { graphCore } = this.dataController;
1204
+ const { specification } = this.themeController;
1205
+ graphCore.once('changed', (event) => {
1206
+ if (!event.changes.length) return;
1207
+ this.hooks.itemchange.emit({
1208
+ type: 'combo',
1209
+ changes: graphCore.reduceChanges(event.changes),
1210
+ graphCore,
1211
+ theme: specification,
1212
+ });
1213
+ this.emit('afteritemchange', {
1214
+ type: 'combo',
1215
+ action: 'add',
1216
+ models: [model],
1217
+ });
1218
+ });
1219
+
1220
+ const data = {
1221
+ nodes: [],
1222
+ edges: [],
1223
+ combos: [
1224
+ {
1225
+ ...model,
1226
+ data: {
1227
+ ...model.data,
1228
+ _children: childrenIds,
1229
+ },
1230
+ },
1231
+ ],
1232
+ };
1233
+ this.hooks.datachange.emit({
1234
+ data,
1235
+ type: 'addCombo',
1236
+ });
1237
+ return this.dataController.findData('combo', [model.id])[0] as ComboModel;
1104
1238
  }
1105
1239
  /**
1106
- * dissolve combo
1107
- * @param {String | ICombo} item combo item or id to be dissolve
1240
+ * Collapse a combo.
1241
+ * @param comboId combo ids
1108
1242
  * @group Combo
1109
1243
  */
1110
- public uncombo(comboId: ID, stack?: boolean) {
1111
- // TODO
1244
+ public collapseCombo(comboIds: ID | ID[], stack?: boolean) {
1245
+ const ids = isArray(comboIds) ? comboIds : [comboIds];
1246
+ this.updateData(
1247
+ 'combo',
1248
+ ids.map((id) => ({ id, data: { collapsed: true } })),
1249
+ );
1250
+ // emit collapse event?
1112
1251
  }
1113
1252
  /**
1114
- * Collapse a combo.
1115
- * @param comboId combo id or item
1253
+ * Expand a combo.
1254
+ * @param combo combo ids
1116
1255
  * @group Combo
1117
1256
  */
1118
- public collapseCombo(comboId: ID, stack?: boolean) {
1119
- // TODO
1257
+ public expandCombo(comboIds: ID | ID[], stack?: boolean) {
1258
+ const ids = isArray(comboIds) ? comboIds : [comboIds];
1259
+ this.updateData(
1260
+ 'combo',
1261
+ ids.map((id) => ({ id, data: { collapsed: false } })),
1262
+ );
1263
+ // emit expand event?
1120
1264
  }
1265
+
1121
1266
  /**
1122
- * Expand a combo.
1123
- * @param combo combo ID 或 combo 实例
1267
+ * Move one or more combos a distance (dx, dy) relatively,
1268
+ * do not update other styles which leads to better performance than updating positions by updateData.
1269
+ * In fact, it changes the succeed nodes positions to affect the combo's position, but not modify the combo's position directly.
1270
+ * @param models new configurations with x and y for every combo, which has id field to indicate the specific item
1271
+ * @param {boolean} stack whether push this operation into graph's stack, true by default
1124
1272
  * @group Combo
1125
1273
  */
1126
- public expandCombo(comboId: ID, stack?: boolean) {
1127
- // TODO
1274
+ public moveCombo(
1275
+ ids: ID | ID[],
1276
+ dx: number,
1277
+ dy: number,
1278
+ upsertAncestors?: boolean,
1279
+ stack?: boolean,
1280
+ ): ComboModel[] {
1281
+ const idArr = isArray(ids) ? ids : [ids];
1282
+ const { graphCore } = this.dataController;
1283
+ const { specification } = this.themeController;
1284
+ graphCore.once('changed', (event) => {
1285
+ if (!event.changes.length) return;
1286
+ this.hooks.itemchange.emit({
1287
+ type: 'combo',
1288
+ changes: event.changes,
1289
+ graphCore,
1290
+ theme: specification,
1291
+ upsertAncestors,
1292
+ action: 'updatePosition',
1293
+ });
1294
+ this.emit('afteritemchange', {
1295
+ type: 'combo',
1296
+ ids: idArr,
1297
+ dx,
1298
+ dy,
1299
+ action: 'updatePosition',
1300
+ upsertAncestors,
1301
+ });
1302
+ });
1303
+
1304
+ this.hooks.datachange.emit({
1305
+ data: {
1306
+ nodes: [],
1307
+ edges: [],
1308
+ combos: idArr.map((id) => ({ id, data: { dx, dy } })),
1309
+ },
1310
+ type: 'moveCombo',
1311
+ });
1312
+ return this.dataController.findData('combo', idArr) as ComboModel[];
1128
1313
  }
1129
1314
 
1130
1315
  // ===== layout =====
@@ -1399,6 +1584,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1399
1584
  action: 'remove' | 'add' | 'update' | undefined;
1400
1585
  style: ShapeStyle;
1401
1586
  onlyDrawKeyShape?: boolean;
1587
+ upsertAncestors?: boolean;
1402
1588
  },
1403
1589
  ): DisplayObject {
1404
1590
  this.hooks.transientupdate.emit({
@@ -1406,6 +1592,7 @@ export default class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1406
1592
  id,
1407
1593
  config,
1408
1594
  canvas: this.transientCanvas,
1595
+ graphCore: this.dataController.graphCore,
1409
1596
  });
1410
1597
  return this.itemController.getTransient(String(id));
1411
1598
  }
@@ -67,7 +67,8 @@ export default class ClickSelect extends Behavior {
67
67
  * Two flag to avoid onCanvasClick triggered while dragging canvas
68
68
  */
69
69
  private canvasPointerDown: Point | undefined = undefined;
70
- private canvasPointerMove: Boolean = false;
70
+ private canvasPointerMove = false;
71
+ private timeout: NodeJS.Timeout = undefined;
71
72
 
72
73
  constructor(options: Partial<ClickSelectOptions>) {
73
74
  super(Object.assign({}, DEFAULT_OPTIONS, options));
@@ -84,6 +85,7 @@ export default class ClickSelect extends Behavior {
84
85
  return {
85
86
  'node:click': this.onClick,
86
87
  'edge:click': this.onClick,
88
+ 'combo:click': this.onClickBesideDblClick,
87
89
  'canvas:pointerdown': this.onCanvasPointerDown,
88
90
  'canvas:pointermove': this.onCanvasPointerMove,
89
91
  'canvas:pointerup': this.onCanvasPointerUp,
@@ -92,7 +94,6 @@ export default class ClickSelect extends Behavior {
92
94
 
93
95
  private isMultipleSelect(event: MouseEvent) {
94
96
  if (!this.options.multiple) return false;
95
- const key = this.options.trigger;
96
97
  const keyMap: Record<Trigger, boolean> = {
97
98
  shift: event.shiftKey,
98
99
  ctrl: event.ctrlKey,
@@ -102,6 +103,18 @@ export default class ClickSelect extends Behavior {
102
103
  return keyMap[this.options.trigger];
103
104
  }
104
105
 
106
+ public onClickBesideDblClick(event: IG6GraphEvent) {
107
+ if (this.timeout) {
108
+ clearTimeout(this.timeout);
109
+ this.timeout = undefined;
110
+ return;
111
+ }
112
+ this.timeout = setTimeout(() => {
113
+ this.timeout = undefined;
114
+ this.onClick(event);
115
+ }, 200);
116
+ }
117
+
105
118
  public onClick(event: IG6GraphEvent) {
106
119
  if (!this.options.shouldBegin(event)) return;
107
120
 
@@ -0,0 +1,59 @@
1
+ import { ID } from '@antv/graphlib';
2
+ import { throttle, uniq } from '@antv/util';
3
+ import { ComboModel, EdgeModel, NodeModel } from '../../types';
4
+ import { Behavior } from '../../types/behavior';
5
+ import { IG6GraphEvent } from '../../types/event';
6
+ import { Point } from '../../types/common';
7
+ import { graphComboTreeDfs } from '../../util/data';
8
+
9
+ const ALLOWED_TRIGGERS = ['dblclick', 'click'] as const;
10
+ type Trigger = (typeof ALLOWED_TRIGGERS)[number];
11
+
12
+ export interface CollapseExpandComboOptions {
13
+ /**
14
+ * The key to pressed with mouse click to apply multiple selection.
15
+ * Defaults to `"dblclick"`.
16
+ * Could be "dblclick", "click".
17
+ */
18
+ trigger: Trigger;
19
+ /**
20
+ * Whether allow the behavior happen on the current item.
21
+ */
22
+ shouldBegin?: (event: IG6GraphEvent) => boolean;
23
+ }
24
+
25
+ const DEFAULT_OPTIONS: Required<CollapseExpandComboOptions> = {
26
+ trigger: 'dblclick',
27
+ shouldBegin: () => true,
28
+ };
29
+
30
+ export default class CollapseExpandCombo extends Behavior {
31
+ options: CollapseExpandComboOptions;
32
+
33
+ constructor(options: Partial<CollapseExpandComboOptions>) {
34
+ const finalOptions = Object.assign({}, DEFAULT_OPTIONS, options);
35
+ super(finalOptions);
36
+ }
37
+
38
+ getEvents = () => {
39
+ if (this.options.trigger === 'dblclick') {
40
+ return {
41
+ 'combo:dblclick': this.collapseExpandCombo,
42
+ };
43
+ }
44
+ return {
45
+ 'combo:click': this.collapseExpandCombo,
46
+ };
47
+ };
48
+
49
+ public collapseExpandCombo(event: IG6GraphEvent) {
50
+ if (!this.options.shouldBegin(event)) return;
51
+ const { itemId } = event;
52
+ const model = this.graph.getComboData(itemId);
53
+ if (model.data.collapsed) {
54
+ this.graph.expandCombo(itemId);
55
+ } else {
56
+ this.graph.collapseCombo(itemId);
57
+ }
58
+ }
59
+ }