@antv/g6 5.0.0-beta.3 → 5.0.0-beta.5

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 (201) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/constant/shape.d.ts +2 -0
  3. package/esm/index.d.ts +4 -1
  4. package/esm/index.js +1 -1
  5. package/esm/item/edge.d.ts +1 -0
  6. package/esm/item/edge.js +3 -1
  7. package/esm/item/edge.js.map +1 -1
  8. package/esm/item/item.d.ts +3 -2
  9. package/esm/item/item.js +12 -6
  10. package/esm/item/item.js.map +1 -1
  11. package/esm/item/node.d.ts +1 -0
  12. package/esm/item/node.js +11 -4
  13. package/esm/item/node.js.map +1 -1
  14. package/esm/runtime/controller/item.js +252 -148
  15. package/esm/runtime/controller/item.js.map +1 -1
  16. package/esm/runtime/graph.d.ts +16 -14
  17. package/esm/runtime/graph.js +66 -28
  18. package/esm/runtime/graph.js.map +1 -1
  19. package/esm/stdlib/behavior/activate-relations.js +2 -2
  20. package/esm/stdlib/behavior/activate-relations.js.map +1 -1
  21. package/esm/stdlib/behavior/click-select.js +1 -1
  22. package/esm/stdlib/behavior/click-select.js.map +1 -1
  23. package/esm/stdlib/behavior/drag-canvas.js +50 -27
  24. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  25. package/esm/stdlib/behavior/drag-combo.js +8 -8
  26. package/esm/stdlib/behavior/drag-combo.js.map +1 -1
  27. package/esm/stdlib/behavior/drag-node.js +10 -10
  28. package/esm/stdlib/behavior/drag-node.js.map +1 -1
  29. package/esm/stdlib/behavior/zoom-canvas.js +47 -24
  30. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
  31. package/esm/stdlib/index.d.ts +3 -0
  32. package/esm/stdlib/index.js +12 -9
  33. package/esm/stdlib/index.js.map +1 -1
  34. package/esm/stdlib/item/edge/base.d.ts +1 -1
  35. package/esm/stdlib/item/edge/base.js +13 -4
  36. package/esm/stdlib/item/edge/base.js.map +1 -1
  37. package/esm/stdlib/item/node/base.d.ts +1 -1
  38. package/esm/stdlib/item/node/base.js +18 -26
  39. package/esm/stdlib/item/node/base.js.map +1 -1
  40. package/esm/stdlib/item/node/diamond.js +1 -1
  41. package/esm/stdlib/item/node/ellipse.js +2 -2
  42. package/esm/stdlib/item/node/hexagon.js +6 -2
  43. package/esm/stdlib/item/node/hexagon.js.map +1 -1
  44. package/esm/stdlib/item/node/image.d.ts +40 -0
  45. package/esm/stdlib/item/node/image.js +110 -0
  46. package/esm/stdlib/item/node/image.js.map +1 -0
  47. package/esm/stdlib/item/node/index.d.ts +1 -0
  48. package/esm/stdlib/item/node/index.js +1 -0
  49. package/esm/stdlib/item/node/index.js.map +1 -1
  50. package/esm/stdlib/plugin/history/combo-command.js +2 -2
  51. package/esm/stdlib/plugin/history/combo-command.js.map +1 -1
  52. package/esm/stdlib/plugin/history/index.d.ts +10 -10
  53. package/esm/stdlib/plugin/history/index.js +14 -14
  54. package/esm/stdlib/plugin/history/index.js.map +1 -1
  55. package/esm/stdlib/plugin/history/item-data-command.js +4 -4
  56. package/esm/stdlib/plugin/history/item-data-command.js.map +1 -1
  57. package/esm/stdlib/plugin/history/layer-updated-command.js +2 -2
  58. package/esm/stdlib/plugin/history/layer-updated-command.js.map +1 -1
  59. package/esm/stdlib/plugin/history/state-updated-command.js +1 -1
  60. package/esm/stdlib/plugin/history/state-updated-command.js.map +1 -1
  61. package/esm/stdlib/plugin/history/visibility-updated-command.js +2 -2
  62. package/esm/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  63. package/esm/stdlib/plugin/index.d.ts +1 -0
  64. package/esm/stdlib/plugin/index.js +1 -0
  65. package/esm/stdlib/plugin/index.js.map +1 -1
  66. package/esm/stdlib/plugin/snapline/index.d.ts +163 -0
  67. package/esm/stdlib/plugin/snapline/index.js +1052 -0
  68. package/esm/stdlib/plugin/snapline/index.js.map +1 -0
  69. package/esm/stdlib/plugin/types.d.ts +1 -0
  70. package/esm/stdlib/theme/dark.js +42 -2
  71. package/esm/stdlib/theme/dark.js.map +1 -1
  72. package/esm/stdlib/theme/light.js +4 -4
  73. package/esm/types/graph.d.ts +14 -14
  74. package/esm/types/hook.d.ts +6 -0
  75. package/esm/types/item.d.ts +6 -0
  76. package/esm/types/item.js.map +1 -1
  77. package/esm/types/spec.d.ts +13 -0
  78. package/esm/util/bbox.d.ts +16 -1
  79. package/esm/util/bbox.js +29 -0
  80. package/esm/util/bbox.js.map +1 -1
  81. package/esm/util/shape.js +2 -2
  82. package/esm/util/shape.js.map +1 -1
  83. package/lib/constant/shape.d.ts +2 -0
  84. package/lib/index.d.ts +4 -1
  85. package/lib/index.js +1 -1
  86. package/lib/item/edge.d.ts +1 -0
  87. package/lib/item/edge.js +3 -1
  88. package/lib/item/edge.js.map +1 -1
  89. package/lib/item/item.d.ts +3 -2
  90. package/lib/item/item.js +12 -6
  91. package/lib/item/item.js.map +1 -1
  92. package/lib/item/node.d.ts +1 -0
  93. package/lib/item/node.js +11 -4
  94. package/lib/item/node.js.map +1 -1
  95. package/lib/runtime/controller/item.js +251 -147
  96. package/lib/runtime/controller/item.js.map +1 -1
  97. package/lib/runtime/graph.d.ts +16 -14
  98. package/lib/runtime/graph.js +66 -28
  99. package/lib/runtime/graph.js.map +1 -1
  100. package/lib/stdlib/behavior/activate-relations.js +2 -2
  101. package/lib/stdlib/behavior/activate-relations.js.map +1 -1
  102. package/lib/stdlib/behavior/click-select.js +1 -1
  103. package/lib/stdlib/behavior/click-select.js.map +1 -1
  104. package/lib/stdlib/behavior/drag-canvas.js +50 -27
  105. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  106. package/lib/stdlib/behavior/drag-combo.js +8 -8
  107. package/lib/stdlib/behavior/drag-combo.js.map +1 -1
  108. package/lib/stdlib/behavior/drag-node.js +10 -10
  109. package/lib/stdlib/behavior/drag-node.js.map +1 -1
  110. package/lib/stdlib/behavior/zoom-canvas.js +47 -24
  111. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  112. package/lib/stdlib/index.d.ts +3 -0
  113. package/lib/stdlib/index.js +12 -9
  114. package/lib/stdlib/index.js.map +1 -1
  115. package/lib/stdlib/item/edge/base.d.ts +1 -1
  116. package/lib/stdlib/item/edge/base.js +13 -4
  117. package/lib/stdlib/item/edge/base.js.map +1 -1
  118. package/lib/stdlib/item/node/base.d.ts +1 -1
  119. package/lib/stdlib/item/node/base.js +18 -26
  120. package/lib/stdlib/item/node/base.js.map +1 -1
  121. package/lib/stdlib/item/node/diamond.js +1 -1
  122. package/lib/stdlib/item/node/ellipse.js +2 -2
  123. package/lib/stdlib/item/node/hexagon.js +6 -2
  124. package/lib/stdlib/item/node/hexagon.js.map +1 -1
  125. package/lib/stdlib/item/node/image.d.ts +40 -0
  126. package/lib/stdlib/item/node/image.js +114 -0
  127. package/lib/stdlib/item/node/image.js.map +1 -0
  128. package/lib/stdlib/item/node/index.d.ts +1 -0
  129. package/lib/stdlib/item/node/index.js +1 -0
  130. package/lib/stdlib/item/node/index.js.map +1 -1
  131. package/lib/stdlib/plugin/history/combo-command.js +2 -2
  132. package/lib/stdlib/plugin/history/combo-command.js.map +1 -1
  133. package/lib/stdlib/plugin/history/index.d.ts +10 -10
  134. package/lib/stdlib/plugin/history/index.js +14 -14
  135. package/lib/stdlib/plugin/history/index.js.map +1 -1
  136. package/lib/stdlib/plugin/history/item-data-command.js +4 -4
  137. package/lib/stdlib/plugin/history/item-data-command.js.map +1 -1
  138. package/lib/stdlib/plugin/history/layer-updated-command.js +2 -2
  139. package/lib/stdlib/plugin/history/layer-updated-command.js.map +1 -1
  140. package/lib/stdlib/plugin/history/state-updated-command.js +1 -1
  141. package/lib/stdlib/plugin/history/state-updated-command.js.map +1 -1
  142. package/lib/stdlib/plugin/history/visibility-updated-command.js +2 -2
  143. package/lib/stdlib/plugin/history/visibility-updated-command.js.map +1 -1
  144. package/lib/stdlib/plugin/index.d.ts +1 -0
  145. package/lib/stdlib/plugin/index.js +1 -0
  146. package/lib/stdlib/plugin/index.js.map +1 -1
  147. package/lib/stdlib/plugin/snapline/index.d.ts +163 -0
  148. package/lib/stdlib/plugin/snapline/index.js +1056 -0
  149. package/lib/stdlib/plugin/snapline/index.js.map +1 -0
  150. package/lib/stdlib/plugin/types.d.ts +1 -0
  151. package/lib/stdlib/theme/dark.js +42 -2
  152. package/lib/stdlib/theme/dark.js.map +1 -1
  153. package/lib/stdlib/theme/light.js +4 -4
  154. package/lib/types/graph.d.ts +14 -14
  155. package/lib/types/hook.d.ts +6 -0
  156. package/lib/types/item.d.ts +6 -0
  157. package/lib/types/item.js.map +1 -1
  158. package/lib/types/spec.d.ts +13 -0
  159. package/lib/util/bbox.d.ts +16 -1
  160. package/lib/util/bbox.js +32 -1
  161. package/lib/util/bbox.js.map +1 -1
  162. package/lib/util/shape.js +2 -2
  163. package/lib/util/shape.js.map +1 -1
  164. package/package.json +2 -2
  165. package/src/index.ts +1 -1
  166. package/src/item/edge.ts +4 -1
  167. package/src/item/item.ts +11 -6
  168. package/src/item/node.ts +18 -10
  169. package/src/runtime/controller/item.ts +212 -66
  170. package/src/runtime/graph.ts +91 -29
  171. package/src/stdlib/behavior/activate-relations.ts +2 -2
  172. package/src/stdlib/behavior/click-select.ts +1 -1
  173. package/src/stdlib/behavior/drag-canvas.ts +65 -27
  174. package/src/stdlib/behavior/drag-combo.ts +8 -8
  175. package/src/stdlib/behavior/drag-node.ts +10 -10
  176. package/src/stdlib/behavior/zoom-canvas.ts +60 -24
  177. package/src/stdlib/index.ts +12 -7
  178. package/src/stdlib/item/edge/base.ts +13 -5
  179. package/src/stdlib/item/node/base.ts +24 -29
  180. package/src/stdlib/item/node/diamond.ts +1 -1
  181. package/src/stdlib/item/node/ellipse.ts +2 -2
  182. package/src/stdlib/item/node/hexagon.ts +6 -2
  183. package/src/stdlib/item/node/image.ts +190 -0
  184. package/src/stdlib/item/node/index.ts +1 -0
  185. package/src/stdlib/plugin/history/combo-command.ts +2 -2
  186. package/src/stdlib/plugin/history/index.ts +14 -14
  187. package/src/stdlib/plugin/history/item-data-command.ts +4 -4
  188. package/src/stdlib/plugin/history/layer-updated-command.ts +2 -2
  189. package/src/stdlib/plugin/history/state-updated-command.ts +1 -1
  190. package/src/stdlib/plugin/history/visibility-updated-command.ts +2 -2
  191. package/src/stdlib/plugin/index.ts +1 -0
  192. package/src/stdlib/plugin/snapline/index.ts +1277 -0
  193. package/src/stdlib/plugin/types.ts +1 -0
  194. package/src/stdlib/theme/dark.ts +66 -2
  195. package/src/stdlib/theme/light.ts +4 -4
  196. package/src/types/graph.ts +22 -17
  197. package/src/types/hook.ts +6 -0
  198. package/src/types/item.ts +10 -0
  199. package/src/types/spec.ts +13 -0
  200. package/src/util/bbox.ts +38 -1
  201. package/src/util/shape.ts +2 -2
@@ -1,5 +1,6 @@
1
1
  import { ID, IG6GraphEvent } from 'types';
2
2
  import { Behavior } from '../../types/behavior';
3
+ import { isNumber } from '@antv/util';
3
4
 
4
5
  const VALID_TRIGGERS = ['wheel', 'upDownKeys'];
5
6
  export interface ZoomCanvasOptions {
@@ -56,7 +57,7 @@ export interface ZoomCanvasOptions {
56
57
  }
57
58
 
58
59
  const DEFAULT_OPTIONS: Required<ZoomCanvasOptions> = {
59
- enableOptimize: false,
60
+ enableOptimize: undefined,
60
61
  triggerOnItems: true,
61
62
  sensitivity: 2,
62
63
  trigger: 'wheel',
@@ -114,43 +115,78 @@ export class ZoomCanvas extends Behavior {
114
115
 
115
116
  private hideShapes() {
116
117
  const { graph } = this;
117
- if (this.options.enableOptimize) {
118
+ const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
119
+ graph.getSpecification().optimize || {};
120
+ const optimize = this.options.enableOptimize || graphBehaviorOptimize;
121
+ const shouldOptimzie = isNumber(optimize)
122
+ ? graph.getAllNodesData().length > optimize
123
+ : optimize;
124
+ if (shouldOptimzie) {
118
125
  this.hiddenEdgeIds = graph
119
126
  .getAllEdgesData()
120
127
  .map((edge) => edge.id)
121
128
  .filter((id) => graph.getItemVisible(id) === true);
122
- // TODO
123
- graph.hideItem(this.hiddenEdgeIds, false);
124
129
  this.hiddenNodeIds = graph
125
130
  .getAllNodesData()
126
131
  .map((node) => node.id)
127
132
  .filter((id) => graph.getItemVisible(id) === true);
128
- // draw node's keyShapes on transient, and then hidden the real nodes;
129
- // this.hiddenNodeIds.forEach((id) => {
130
- // graph.drawTransient('node', id, {
131
- // onlyDrawKeyShape: true,
132
- // });
133
- // });
134
- // graph.hideItem(this.hiddenNodeIds, false);
133
+
134
+ let requestId;
135
+ const hiddenIds = [...this.hiddenNodeIds];
136
+ const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
137
+ const sections = Array.from({ length: sectionNum }, (v, i) =>
138
+ hiddenIds.slice(
139
+ i * tileBehaviorSize,
140
+ i * tileBehaviorSize + tileBehaviorSize,
141
+ ),
142
+ );
143
+ const update = () => {
144
+ if (!sections.length) {
145
+ cancelAnimationFrame(requestId);
146
+ return;
147
+ }
148
+ const section = sections.shift();
149
+ graph.hideItem(section, false, true);
150
+ requestId = requestAnimationFrame(update);
151
+ };
152
+ graph.startHistoryBatch();
153
+ requestId = requestAnimationFrame(update);
154
+ graph.stopHistoryBatch();
135
155
  }
136
156
  }
137
157
 
138
158
  private endZoom() {
139
- const { graph, hiddenEdgeIds, hiddenNodeIds } = this;
140
- const { enableOptimize } = this.options;
159
+ const { graph, hiddenEdgeIds = [], hiddenNodeIds } = this;
160
+ const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
161
+ graph.getSpecification().optimize || {};
162
+ const optimize = this.options.enableOptimize || graphBehaviorOptimize;
163
+ const shouldOptimzie = isNumber(optimize)
164
+ ? graph.getAllNodesData().length > optimize
165
+ : optimize;
141
166
  this.zooming = false;
142
- if (enableOptimize) {
143
- // restore hidden items
144
- if (hiddenEdgeIds) {
145
- graph.showItem(hiddenEdgeIds, false);
167
+ if (shouldOptimzie) {
168
+ if (hiddenNodeIds) {
169
+ let requestId;
170
+ const hiddenIds = [...hiddenNodeIds, ...hiddenEdgeIds];
171
+ const sectionNum = Math.ceil(hiddenIds.length / tileBehaviorSize);
172
+ const sections = Array.from({ length: sectionNum }, (v, i) =>
173
+ hiddenIds.slice(
174
+ i * tileBehaviorSize,
175
+ i * tileBehaviorSize + tileBehaviorSize,
176
+ ),
177
+ );
178
+ const update = () => {
179
+ if (!sections.length) {
180
+ cancelAnimationFrame(requestId);
181
+ return;
182
+ }
183
+ graph.showItem(sections.shift(), false);
184
+ requestId = requestAnimationFrame(update);
185
+ };
186
+ graph.executeWithNoStack(() => {
187
+ requestId = requestAnimationFrame(update);
188
+ });
146
189
  }
147
- // TODO
148
- // if (hiddenNodeIds) {
149
- // hiddenNodeIds.forEach((id) => {
150
- // graph.drawTransient('node', id, { action: 'remove' });
151
- // });
152
- // graph.showItem(hiddenNodeIds, false);
153
- // }
154
190
  }
155
191
  this.hiddenEdgeIds = [];
156
192
  this.hiddenNodeIds = [];
@@ -31,6 +31,7 @@ const {
31
31
  TriangleNode,
32
32
  EllipseNode,
33
33
  ModelRectNode,
34
+ ImageNode,
34
35
  } = Nodes;
35
36
 
36
37
  const {
@@ -72,6 +73,7 @@ const {
72
73
  Legend,
73
74
  Toolbar,
74
75
  Timebar,
76
+ Snapline,
75
77
  } = Plugins;
76
78
 
77
79
  const {
@@ -129,6 +131,7 @@ const stdLib = {
129
131
  nodes: {
130
132
  'circle-node': CircleNode,
131
133
  'rect-node': RectNode,
134
+ 'image-node': ImageNode,
132
135
  },
133
136
  edges: {
134
137
  'line-edge': LineEdge,
@@ -204,13 +207,13 @@ const Extensions = {
204
207
  ValidateData,
205
208
  TransformV4Data,
206
209
  MapNodeSize,
207
- //themes
210
+ // themes
208
211
  LightTheme,
209
212
  DarkTheme,
210
- //themeSolvers
213
+ // themeSolvers
211
214
  SpecThemeSolver,
212
215
  SubjectThemeSolver,
213
- //layout
216
+ // layout
214
217
  ForceLayout,
215
218
  GridLayout,
216
219
  CircularLayout,
@@ -223,12 +226,12 @@ const Extensions = {
223
226
  ForceAtlas2Layout,
224
227
  DagreLayout,
225
228
  ComboCombinedLayout,
226
- //Hierarchy
229
+ // Hierarchy
227
230
  compactBox,
228
231
  dendrogram,
229
232
  indented,
230
233
  mindmap,
231
- //nodes
234
+ // nodes
232
235
  CircleNode,
233
236
  RectNode,
234
237
  DiamondNode,
@@ -250,7 +253,7 @@ const Extensions = {
250
253
  // combos
251
254
  CircleCombo,
252
255
  RectCombo,
253
- //behaviors
256
+ // behaviors
254
257
  BaseBehavior,
255
258
  ActivateRelations,
256
259
  BrushSelect,
@@ -266,7 +269,8 @@ const Extensions = {
266
269
  CollapseExpandCombo,
267
270
  DragNode,
268
271
  DragCombo,
269
- //plugins
272
+ ShortcutsCall,
273
+ // plugins
270
274
  BasePlugin,
271
275
  History,
272
276
  Toolbar,
@@ -278,6 +282,7 @@ const Extensions = {
278
282
  Legend,
279
283
  Timebar,
280
284
  Hull,
285
+ Snapline,
281
286
  };
282
287
 
283
288
  export default registery;
@@ -550,7 +550,11 @@ export abstract class BaseEdge {
550
550
  * @param shapeMap The shape map that contains all of the elements to show on the edge.
551
551
  * @param zoom The zoom level of the graph.
552
552
  */
553
- public onZoom = (shapeMap: EdgeShapeMap, zoom: number) => {
553
+ public onZoom = (
554
+ shapeMap: EdgeShapeMap,
555
+ zoom: number,
556
+ cacheHiddenShape = {},
557
+ ) => {
554
558
  // balance the size for label, badges
555
559
  this.balanceShapeSize(shapeMap, zoom);
556
560
 
@@ -574,7 +578,10 @@ export abstract class BaseEdge {
574
578
  // zoomLevel changed, from higher to lower, hide something
575
579
  if (firstRender) {
576
580
  for (let i = currentLevel + 1; i <= maxLevel; i++) {
577
- levelShapes[String(i)]?.forEach((id) => shapeMap[id]?.hide());
581
+ levelShapes[String(i)]?.forEach((id) => {
582
+ if (!shapeMap[id] || cacheHiddenShape[id]) return;
583
+ shapeMap[id]?.hide();
584
+ });
578
585
  }
579
586
  } else {
580
587
  for (let i = currentLevel + 1; i <= maxLevel; i++) {
@@ -586,7 +593,8 @@ export abstract class BaseEdge {
586
593
  } else if (currentLevel > previousLevel) {
587
594
  // zoomLevel changed, from lower to higher, show something
588
595
  for (let i = currentLevel; i >= minLevel; i--) {
589
- levelShapes[String(i)]?.forEach((id) =>
596
+ levelShapes[String(i)]?.forEach((id) => {
597
+ if (hiddenShape[id]) return;
590
598
  fadeIn(
591
599
  id,
592
600
  shapeMap[id],
@@ -594,8 +602,8 @@ export abstract class BaseEdge {
594
602
  this.mergedStyles[id.replace('Background', '')],
595
603
  hiddenShape,
596
604
  animateConfig,
597
- ),
598
- );
605
+ );
606
+ });
599
607
  }
600
608
  }
601
609
 
@@ -186,10 +186,10 @@ export abstract class BaseNode {
186
186
  });
187
187
  this.zoomCache.levelShapes = levelShapes;
188
188
 
189
- if (shapeMap.labelShape && this.boundsCache.keyShapeLocal) {
189
+ if (shapeMap.labelShape) {
190
190
  const { maxWidth = '200%' } = this.mergedStyles.labelShape || {};
191
191
  this.zoomCache.wordWrapWidth = getWordWrapWidthByBox(
192
- this.boundsCache.keyShapeLocal,
192
+ shapeMap.keyShape.getLocalBounds(),
193
193
  maxWidth,
194
194
  1,
195
195
  );
@@ -286,12 +286,10 @@ export abstract class BaseNode {
286
286
  const { labelShape: shapeStyle } = this.mergedStyles;
287
287
  if (!shapeStyle || !shapeStyle.text || !model.data.labelShape) return;
288
288
  const { keyShape } = shapeMap;
289
- this.boundsCache.keyShapeLocal =
290
- this.boundsCache.keyShapeLocal || keyShape.getLocalBounds();
291
289
  const keyShapeBox = getShapeLocalBoundsByStyle(
292
290
  keyShape,
293
291
  this.mergedStyles.keyShape,
294
- this.boundsCache.keyShapeLocal,
292
+ keyShape.getLocalBounds(),
295
293
  );
296
294
  const {
297
295
  position,
@@ -577,12 +575,12 @@ export abstract class BaseNode {
577
575
  position: string | [number, number],
578
576
  anchorPositionMap: IAnchorPositionMap,
579
577
  ): [number, number] {
580
- const keyShapeBBox = this.boundsCache.keyShapeLocal;
578
+ const keyShapeBBox = this.boundsCache.keyShapeLocal!;
581
579
  const keyShapeWidth = keyShapeBBox.max[0] - keyShapeBBox.min[0];
582
580
  const keyShapeHeight = keyShapeBBox.max[1] - keyShapeBBox.min[1];
583
581
  const defaultPosition: [number, number] = [
584
- keyShapeBBox.max[0],
585
- keyShapeBBox.min[1],
582
+ keyShapeBBox.max[0] - keyShapeBBox.center[0],
583
+ keyShapeBBox.min[1] - keyShapeBBox.center[1],
586
584
  ]; //topRight
587
585
  if (position instanceof Array) {
588
586
  return [
@@ -645,12 +643,10 @@ export abstract class BaseNode {
645
643
  (style) => style.tag === 'badgeShape',
646
644
  );
647
645
  if (!individualConfigs.length) return {};
648
- this.boundsCache.keyShapeLocal =
649
- this.boundsCache.keyShapeLocal || shapeMap.keyShape.getLocalBounds();
650
646
  const keyShapeBBox = getShapeLocalBoundsByStyle(
651
647
  shapeMap.keyShape,
652
648
  keyShapeStyle,
653
- this.boundsCache.keyShapeLocal,
649
+ shapeMap.keyShape.getLocalBounds(),
654
650
  );
655
651
  const keyShapeSize = Math.min(
656
652
  keyShapeBBox.max[0] - keyShapeBBox.min[0],
@@ -759,8 +755,6 @@ export abstract class BaseNode {
759
755
  (text as string).length <= 1
760
756
  ? bgHeight
761
757
  : Math.max(bgHeight, bbox.max[0] - bbox.min[0]) + 8;
762
- let bgX = isLeft ? pos.x - bgWidth : pos.x;
763
- if (isCenter) bgX = pos.x - bgWidth / 2;
764
758
  shapes[bgShapeId] = this.upsertShape(
765
759
  'rect',
766
760
  bgShapeId,
@@ -771,8 +765,8 @@ export abstract class BaseNode {
771
765
  width: bgWidth,
772
766
  radius: bgHeight / 2,
773
767
  zIndex,
774
- x: bgX,
775
- y: pos.y,
768
+ x: bbox.center[0] - bgWidth / 2,
769
+ y: bbox.center[1] - bgHeight / 2,
776
770
  ...otherStyles,
777
771
  } as GShapeStyle,
778
772
  shapeMap,
@@ -810,7 +804,11 @@ export abstract class BaseNode {
810
804
  * @param shapeMap The shape map that contains all of the elements to show on the node.
811
805
  * @param zoom The zoom level of the graph.
812
806
  */
813
- public onZoom = (shapeMap: NodeShapeMap | ComboShapeMap, zoom: number) => {
807
+ public onZoom = (
808
+ shapeMap: NodeShapeMap | ComboShapeMap,
809
+ zoom: number,
810
+ cacheHiddenShape = {},
811
+ ) => {
814
812
  // zoomLevel changed
815
813
  if (this.lodStrategy) {
816
814
  const { levels } = this.lodStrategy;
@@ -831,7 +829,7 @@ export abstract class BaseNode {
831
829
  // zoomLevel changed, from higher to lower, hide something
832
830
  for (let i = currentLevel + 1; i <= maxLevel; i++) {
833
831
  levelShapes[String(i)]?.forEach((id) => {
834
- if (!shapeMap[id]) return;
832
+ if (!shapeMap[id] || cacheHiddenShape[id]) return;
835
833
  shapeMap[id].hide();
836
834
  hiddenShape[id] = true;
837
835
  });
@@ -880,8 +878,7 @@ export abstract class BaseNode {
880
878
  const balanceRatio = 1 / zoom || 1;
881
879
  this.zoomCache.balanceRatio = balanceRatio;
882
880
  if (!labelShape || !labelShape.isVisible()) return;
883
- const { labelShape: labelStyle } = this.mergedStyles;
884
- const { position = 'bottom' } = labelStyle;
881
+ const { position = 'bottom' } = this.mergedStyles.labelShape;
885
882
 
886
883
  const keyShapeLocal = keyShape.getLocalBounds();
887
884
  if (zoom < 1) {
@@ -923,21 +920,20 @@ export abstract class BaseNode {
923
920
  const scaleTransform = `scale(${balanceRatio}, ${balanceRatio})`;
924
921
  labelShape.style.transform = `${oriTransform} ${scaleTransform}`;
925
922
  this.scaleTransformCache = scaleTransform;
926
- const wordWrapWidth = this.zoomCache.wordWrapWidth * zoom;
927
- labelShape.style.wordWrapWidth = wordWrapWidth;
923
+ labelShape.style.wordWrapWidth = this.zoomCache.wordWrapWidth * zoom;
928
924
 
929
925
  if (!labelBackgroundShape || !labelBackgroundShape.isVisible()) return;
930
926
 
931
- const { padding } = this.mergedStyles.labelBackgroundShape;
927
+ const [paddingTop, paddingRight, paddingBottom, paddingLeft] = this
928
+ .mergedStyles.labelBackgroundShape.padding as number[];
929
+ const sidePadding = paddingRight + paddingLeft;
932
930
  const { width, height, x, y } = labelBackgroundShape.attributes;
933
- const [paddingTop, paddingRight, paddingBottom, paddingLeft] =
934
- padding as number[];
935
931
 
936
932
  switch (position) {
937
933
  case 'top':
938
934
  // if it is zoom-out, do not scale the gap between keyShape and labelShape, differentiate from zoom-in by adjusting transformOrigin
939
935
  labelBackgroundShape.style.transformOrigin = `${
940
- paddingLeft + (width - paddingLeft - paddingRight) / 2
936
+ paddingLeft + (width - sidePadding) / 2
941
937
  } ${zoom < 1 ? height - paddingBottom : keyShapeLocal.min[1] - y}`;
942
938
  break;
943
939
  case 'left':
@@ -952,7 +948,7 @@ export abstract class BaseNode {
952
948
  break;
953
949
  case 'bottom':
954
950
  labelBackgroundShape.style.transformOrigin = `${
955
- paddingLeft + (width - paddingLeft - paddingRight) / 2
951
+ paddingLeft + (width - sidePadding) / 2
956
952
  } ${
957
953
  zoom < 1
958
954
  ? paddingTop + (height - paddingTop - paddingBottom) / 2
@@ -962,14 +958,13 @@ export abstract class BaseNode {
962
958
  default:
963
959
  // center
964
960
  labelBackgroundShape.style.transformOrigin = `${
965
- paddingLeft + (width - paddingLeft - paddingRight) / 2
961
+ paddingLeft + (width - sidePadding) / 2
966
962
  } ${paddingTop + (height - paddingTop - paddingBottom) / 2}`;
967
963
  }
968
964
 
969
965
  const { labelShapeGeometry: labelBBox } = this.boundsCache;
970
966
  const labelWidth = labelBBox.max[0] - labelBBox.min[0];
971
- const xAxistRatio =
972
- (labelWidth * balanceRatio + paddingLeft + paddingRight) / width;
967
+ const xAxistRatio = (labelWidth * balanceRatio + sidePadding) / width;
973
968
 
974
969
  labelBackgroundShape.style.transform = `scale(${xAxistRatio}, ${balanceRatio})`;
975
970
  }
@@ -12,7 +12,7 @@ type PathArray = any; //TODO: cannot import type PathArray
12
12
  export class DiamondNode extends BaseNode {
13
13
  override defaultStyles = {
14
14
  keyShape: {
15
- size: [50, 30],
15
+ size: [32, 32],
16
16
  x: 0,
17
17
  y: 0,
18
18
  },
@@ -11,8 +11,8 @@ import { BaseNode } from './base';
11
11
  export class EllipseNode extends BaseNode {
12
12
  override defaultStyles = {
13
13
  keyShape: {
14
- rx: 30,
15
- ry: 20,
14
+ rx: 16,
15
+ ry: 12,
16
16
  x: 0,
17
17
  y: 0,
18
18
  },
@@ -17,10 +17,10 @@ const offsetAngleMap = {
17
17
  export class HexagonNode extends BaseNode {
18
18
  override defaultStyles = {
19
19
  keyShape: {
20
- r: 20,
20
+ r: 16,
21
21
  x: 0,
22
22
  y: 0,
23
- direction: 'horizontal',
23
+ direction: 'vertical',
24
24
  },
25
25
  };
26
26
  mergedStyles: NodeShapeStyles;
@@ -167,6 +167,10 @@ export class HexagonNode extends BaseNode {
167
167
  const vy = r * Math.sin(angle);
168
168
  anchorPositionMap[anchorPositionDirection[i]] = [vx, vy];
169
169
  }
170
+ if (!anchorPositionMap.hasOwnProperty('default')) {
171
+ anchorPositionMap['default'] =
172
+ anchorPositionMap[anchorPositionDirection[0]];
173
+ }
170
174
  return anchorPositionMap;
171
175
  }
172
176
  }
@@ -0,0 +1,190 @@
1
+ import { DisplayObject } from '@antv/g';
2
+ import { ComboDisplayModel, NodeDisplayModel } from '../../../types';
3
+ import { State } from '../../../types/item';
4
+ import {
5
+ NodeModelData,
6
+ NodeShapeMap,
7
+ NodeShapeStyles,
8
+ } from '../../../types/node';
9
+ import { convertToNumber } from '../../../util/type';
10
+ import { ComboModelData, ComboShapeMap } from '../../../types/combo';
11
+ import { ShapeTagMap } from '../../../util/shape';
12
+ import { BaseNode } from './base';
13
+
14
+ export class ImageNode extends BaseNode {
15
+ override defaultStyles = {
16
+ keyShape: {
17
+ x: 0,
18
+ y: 0,
19
+ width: 32,
20
+ height: 32,
21
+ },
22
+ };
23
+ mergedStyles: NodeShapeStyles;
24
+ constructor(props) {
25
+ super(props);
26
+ // suggest to merge default styles like this to avoid style value missing
27
+ // this.defaultStyles = mergeStyles([this.baseDefaultStyles, this.defaultStyles]);
28
+ }
29
+
30
+ public override drawKeyShape(
31
+ model: NodeDisplayModel,
32
+ shapeMap: NodeShapeMap,
33
+ diffData?: { previous: NodeModelData; current: NodeModelData },
34
+ diffState?: { previous: State[]; current: State[] },
35
+ ): DisplayObject {
36
+ const clipCfg = this.mergedStyles.keyShape?.clipCfg;
37
+ let clipPath: DisplayObject | undefined;
38
+ if (clipCfg) {
39
+ const { type, ...rest } = clipCfg;
40
+ clipPath = new ShapeTagMap[type]();
41
+ clipPath.attr(rest);
42
+ }
43
+
44
+ const shape = this.upsertShape(
45
+ 'image',
46
+ 'keyShape',
47
+ {
48
+ ...this.mergedStyles.keyShape,
49
+ x: this.mergedStyles.keyShape!.x,
50
+ y: this.mergedStyles.keyShape!.y,
51
+ anchor: '0.5 0.5',
52
+ },
53
+ shapeMap,
54
+ model,
55
+ );
56
+
57
+ if (clipPath) {
58
+ shape.appendChild(clipPath);
59
+ shape.attr('clipPath', clipPath);
60
+ }
61
+
62
+ return shape;
63
+ }
64
+
65
+ public override calculateAnchorPosition(keyShapeStyle) {
66
+ const x = convertToNumber(keyShapeStyle.x);
67
+ const y = convertToNumber(keyShapeStyle.y);
68
+ const height = keyShapeStyle.height;
69
+ const width = keyShapeStyle.width;
70
+ const anchorPositionMap = {};
71
+ anchorPositionMap['top'] = [x, y - height / 2];
72
+ anchorPositionMap['left'] = [x - width / 2, y];
73
+ anchorPositionMap['right'] = anchorPositionMap['default'] = [
74
+ x + width / 2,
75
+ y,
76
+ ];
77
+ anchorPositionMap['bottom'] = [x, y + height / 2];
78
+ return anchorPositionMap;
79
+ }
80
+
81
+ public draw(
82
+ model: NodeDisplayModel,
83
+ shapeMap: NodeShapeMap,
84
+ diffData?: { previous: NodeModelData; current: NodeModelData },
85
+ diffState?: { previous: State[]; current: State[] },
86
+ ): NodeShapeMap {
87
+ const { data = {} } = model;
88
+ let shapes: NodeShapeMap = { keyShape: undefined };
89
+
90
+ // keyShape
91
+ shapes.keyShape = this.drawKeyShape(model, shapeMap, diffData);
92
+
93
+ // labelShape
94
+ if (data.labelShape) {
95
+ shapes.labelShape = this.drawLabelShape(model, shapeMap, diffData);
96
+ }
97
+
98
+ // haloShape
99
+ if (data.haloShape && this.drawHaloShape) {
100
+ shapes.haloShape = this.drawHaloShape(model, shapeMap, diffData);
101
+ }
102
+
103
+ // labelBackgroundShape
104
+ if (data.labelBackgroundShape) {
105
+ shapes.labelBackgroundShape = this.drawLabelBackgroundShape(
106
+ model,
107
+ shapeMap,
108
+ diffData,
109
+ );
110
+ }
111
+
112
+ // anchor shapes
113
+ if (data.anchorShapes) {
114
+ const anchorShapes = this.drawAnchorShapes(
115
+ model,
116
+ shapeMap,
117
+ diffData,
118
+ diffState,
119
+ );
120
+ shapes = {
121
+ ...shapes,
122
+ ...anchorShapes,
123
+ };
124
+ }
125
+
126
+ // iconShape
127
+ if (data.iconShape) {
128
+ shapes.iconShape = this.drawIconShape(model, shapeMap, diffData);
129
+ }
130
+
131
+ // badgeShape
132
+ if (data.badgeShapes) {
133
+ const badgeShapes = this.drawBadgeShapes(
134
+ model,
135
+ shapeMap,
136
+ diffData,
137
+ diffState,
138
+ );
139
+ shapes = {
140
+ ...shapes,
141
+ ...badgeShapes,
142
+ };
143
+ }
144
+
145
+ // otherShapes
146
+ if (data.otherShapes && this.drawOtherShapes) {
147
+ shapes = {
148
+ ...shapes,
149
+ ...this.drawOtherShapes(model, shapeMap, diffData),
150
+ };
151
+ }
152
+ return shapes;
153
+ }
154
+
155
+ public drawHaloShape(
156
+ model: NodeDisplayModel | ComboDisplayModel,
157
+ shapeMap: NodeShapeMap | ComboShapeMap,
158
+ diffData?: {
159
+ previous: NodeModelData | ComboModelData;
160
+ current: NodeModelData | ComboModelData;
161
+ },
162
+ diffState?: { previous: State[]; current: State[] },
163
+ ): DisplayObject {
164
+ const { keyShape } = shapeMap;
165
+ const { haloShape: haloShapeStyle, keyShape: keyShapeStyle } =
166
+ this.mergedStyles;
167
+ if (haloShapeStyle?.visible === false) return;
168
+
169
+ const clipShape = haloShapeStyle?.clipCfg?.type || 'rect';
170
+ const { attributes } = keyShape;
171
+ const { x, y, fill } = attributes;
172
+
173
+ return this.upsertShape(
174
+ clipShape,
175
+ 'haloShape',
176
+ {
177
+ ...attributes,
178
+ ...keyShapeStyle,
179
+ x,
180
+ y,
181
+ stroke: fill,
182
+ ...haloShapeStyle,
183
+ fill: 'transparent',
184
+ batchKey: 'halo',
185
+ },
186
+ shapeMap,
187
+ model,
188
+ );
189
+ }
190
+ }
@@ -8,3 +8,4 @@ export * from './ellipse';
8
8
  export * from './donut';
9
9
  export * from './diamond';
10
10
  export * from './modelRect';
11
+ export * from './image';
@@ -11,7 +11,7 @@ export class ComboCommand implements Command {
11
11
  }
12
12
 
13
13
  undo(graph: IGraph) {
14
- graph.executeWithoutStacking(() => {
14
+ graph.executeWithNoStack(() => {
15
15
  this.action === 'expandCombo'
16
16
  ? graph.collapseCombo(this.ids)
17
17
  : graph.expandCombo(this.ids);
@@ -19,7 +19,7 @@ export class ComboCommand implements Command {
19
19
  }
20
20
 
21
21
  redo(graph: IGraph) {
22
- graph.executeWithoutStacking(() => {
22
+ graph.executeWithNoStack(() => {
23
23
  this.action === 'collapseCombo'
24
24
  ? graph.collapseCombo(this.ids)
25
25
  : graph.expandCombo(this.ids);