@antv/g6 5.0.0-beta.14 → 5.0.0-beta.16

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 (186) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/api-doc/types.d.ts +1 -0
  3. package/esm/api-doc/types.js +1 -2
  4. package/esm/api-doc/types.js.map +1 -1
  5. package/esm/index.d.ts +1 -1
  6. package/esm/index.js +1 -1
  7. package/esm/item/combo.js +2 -5
  8. package/esm/item/combo.js.map +1 -1
  9. package/esm/item/node.js +0 -1
  10. package/esm/item/node.js.map +1 -1
  11. package/esm/runtime/controller/item.js +2 -1
  12. package/esm/runtime/controller/item.js.map +1 -1
  13. package/esm/runtime/graph.js +2 -2
  14. package/esm/runtime/graph.js.map +1 -1
  15. package/esm/stdlib/behavior/activate-relations.d.ts +1 -1
  16. package/esm/stdlib/behavior/brush-select.d.ts +9 -3
  17. package/esm/stdlib/behavior/brush-select.js +9 -10
  18. package/esm/stdlib/behavior/brush-select.js.map +1 -1
  19. package/esm/stdlib/behavior/click-select.d.ts +1 -1
  20. package/esm/stdlib/behavior/collapse-expand-combo.d.ts +1 -1
  21. package/esm/stdlib/behavior/collapse-expand-tree.d.ts +1 -1
  22. package/esm/stdlib/behavior/create-edge.js +4 -1
  23. package/esm/stdlib/behavior/create-edge.js.map +1 -1
  24. package/esm/stdlib/behavior/drag-canvas.js +8 -1
  25. package/esm/stdlib/behavior/drag-canvas.js.map +1 -1
  26. package/esm/stdlib/behavior/drag-combo.d.ts +1 -1
  27. package/esm/stdlib/behavior/drag-node.d.ts +1 -1
  28. package/esm/stdlib/behavior/drag-node.js +3 -0
  29. package/esm/stdlib/behavior/drag-node.js.map +1 -1
  30. package/esm/stdlib/behavior/lasso-select.js +2 -2
  31. package/esm/stdlib/behavior/lasso-select.js.map +1 -1
  32. package/esm/stdlib/behavior/shortcuts-call.d.ts +1 -1
  33. package/esm/stdlib/behavior/zoom-canvas.js +10 -7
  34. package/esm/stdlib/behavior/zoom-canvas.js.map +1 -1
  35. package/esm/stdlib/item/edge/base.d.ts +2 -4
  36. package/esm/stdlib/item/edge/base.js +11 -18
  37. package/esm/stdlib/item/edge/base.js.map +1 -1
  38. package/esm/stdlib/item/node/base.d.ts +1 -5
  39. package/esm/stdlib/item/node/base.js +7 -32
  40. package/esm/stdlib/item/node/base.js.map +1 -1
  41. package/esm/stdlib/item/node/donut.d.ts +3 -3
  42. package/esm/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  43. package/esm/stdlib/plugin/legend/index.d.ts +1 -1
  44. package/esm/stdlib/plugin/snapline/index.d.ts +2 -2
  45. package/esm/stdlib/plugin/snapline/index.js +239 -239
  46. package/esm/stdlib/plugin/snapline/index.js.map +1 -1
  47. package/esm/stdlib/plugin/timebar/index.d.ts +4 -4
  48. package/esm/stdlib/plugin/timebar/index.js +4 -4
  49. package/esm/stdlib/plugin/timebar/index.js.map +1 -1
  50. package/esm/stdlib/plugin/tooltip/index.d.ts +1 -1
  51. package/esm/stdlib/plugin/watermaker/index.d.ts +1 -1
  52. package/esm/types/animate.d.ts +2 -2
  53. package/esm/types/behavior.d.ts +1 -1
  54. package/esm/types/combo.d.ts +7 -7
  55. package/esm/types/common.d.ts +5 -5
  56. package/esm/types/data.d.ts +6 -6
  57. package/esm/types/edge.d.ts +9 -9
  58. package/esm/types/event.d.ts +1 -1
  59. package/esm/types/graph.d.ts +1 -1
  60. package/esm/types/history.d.ts +2 -2
  61. package/esm/types/hook.d.ts +1 -1
  62. package/esm/types/item.d.ts +13 -13
  63. package/esm/types/layout.d.ts +6 -6
  64. package/esm/types/loop.d.ts +2 -2
  65. package/esm/types/node.d.ts +7 -7
  66. package/esm/types/render.d.ts +1 -1
  67. package/esm/types/spec.d.ts +3 -3
  68. package/esm/types/stdlib.d.ts +1 -1
  69. package/esm/types/theme.d.ts +8 -8
  70. package/esm/types/view.d.ts +2 -2
  71. package/esm/util/event.d.ts +2 -2
  72. package/esm/util/layout.d.ts +1 -1
  73. package/esm/util/loop.js +4 -0
  74. package/esm/util/loop.js.map +1 -1
  75. package/esm/util/shape.d.ts +0 -1
  76. package/esm/util/shape.js +0 -6
  77. package/esm/util/shape.js.map +1 -1
  78. package/esm/util/shape3d.js +1 -6
  79. package/esm/util/shape3d.js.map +1 -1
  80. package/esm/util/warn.d.ts +1 -1
  81. package/lib/api-doc/types.d.ts +1 -0
  82. package/lib/api-doc/types.js +2 -2
  83. package/lib/api-doc/types.js.map +1 -1
  84. package/lib/index.d.ts +1 -1
  85. package/lib/index.js +1 -1
  86. package/lib/item/combo.js +2 -5
  87. package/lib/item/combo.js.map +1 -1
  88. package/lib/item/node.js +0 -1
  89. package/lib/item/node.js.map +1 -1
  90. package/lib/runtime/controller/item.js +2 -1
  91. package/lib/runtime/controller/item.js.map +1 -1
  92. package/lib/runtime/graph.js +2 -2
  93. package/lib/runtime/graph.js.map +1 -1
  94. package/lib/stdlib/behavior/activate-relations.d.ts +1 -1
  95. package/lib/stdlib/behavior/brush-select.d.ts +9 -3
  96. package/lib/stdlib/behavior/brush-select.js +12 -10
  97. package/lib/stdlib/behavior/brush-select.js.map +1 -1
  98. package/lib/stdlib/behavior/click-select.d.ts +1 -1
  99. package/lib/stdlib/behavior/collapse-expand-combo.d.ts +1 -1
  100. package/lib/stdlib/behavior/collapse-expand-tree.d.ts +1 -1
  101. package/lib/stdlib/behavior/create-edge.js +4 -1
  102. package/lib/stdlib/behavior/create-edge.js.map +1 -1
  103. package/lib/stdlib/behavior/drag-canvas.js +8 -1
  104. package/lib/stdlib/behavior/drag-canvas.js.map +1 -1
  105. package/lib/stdlib/behavior/drag-combo.d.ts +1 -1
  106. package/lib/stdlib/behavior/drag-node.d.ts +1 -1
  107. package/lib/stdlib/behavior/drag-node.js +3 -0
  108. package/lib/stdlib/behavior/drag-node.js.map +1 -1
  109. package/lib/stdlib/behavior/lasso-select.js +5 -2
  110. package/lib/stdlib/behavior/lasso-select.js.map +1 -1
  111. package/lib/stdlib/behavior/shortcuts-call.d.ts +1 -1
  112. package/lib/stdlib/behavior/zoom-canvas.js +10 -7
  113. package/lib/stdlib/behavior/zoom-canvas.js.map +1 -1
  114. package/lib/stdlib/item/edge/base.d.ts +2 -4
  115. package/lib/stdlib/item/edge/base.js +9 -16
  116. package/lib/stdlib/item/edge/base.js.map +1 -1
  117. package/lib/stdlib/item/node/base.d.ts +1 -5
  118. package/lib/stdlib/item/node/base.js +6 -31
  119. package/lib/stdlib/item/node/base.js.map +1 -1
  120. package/lib/stdlib/item/node/donut.d.ts +3 -3
  121. package/lib/stdlib/plugin/hull/hullComponent.d.ts +1 -1
  122. package/lib/stdlib/plugin/legend/index.d.ts +1 -1
  123. package/lib/stdlib/plugin/snapline/index.d.ts +2 -2
  124. package/lib/stdlib/plugin/snapline/index.js +239 -239
  125. package/lib/stdlib/plugin/snapline/index.js.map +1 -1
  126. package/lib/stdlib/plugin/timebar/index.d.ts +4 -4
  127. package/lib/stdlib/plugin/timebar/index.js +4 -4
  128. package/lib/stdlib/plugin/timebar/index.js.map +1 -1
  129. package/lib/stdlib/plugin/tooltip/index.d.ts +1 -1
  130. package/lib/stdlib/plugin/watermaker/index.d.ts +1 -1
  131. package/lib/types/animate.d.ts +2 -2
  132. package/lib/types/behavior.d.ts +1 -1
  133. package/lib/types/combo.d.ts +7 -7
  134. package/lib/types/common.d.ts +5 -5
  135. package/lib/types/data.d.ts +6 -6
  136. package/lib/types/edge.d.ts +9 -9
  137. package/lib/types/event.d.ts +1 -1
  138. package/lib/types/event.js +2 -2
  139. package/lib/types/event.js.map +1 -1
  140. package/lib/types/graph.d.ts +1 -1
  141. package/lib/types/history.d.ts +2 -2
  142. package/lib/types/history.js +1 -1
  143. package/lib/types/history.js.map +1 -1
  144. package/lib/types/hook.d.ts +1 -1
  145. package/lib/types/item.d.ts +13 -13
  146. package/lib/types/item.js +1 -1
  147. package/lib/types/item.js.map +1 -1
  148. package/lib/types/layout.d.ts +6 -6
  149. package/lib/types/loop.d.ts +2 -2
  150. package/lib/types/loop.js +1 -1
  151. package/lib/types/loop.js.map +1 -1
  152. package/lib/types/node.d.ts +7 -7
  153. package/lib/types/render.d.ts +1 -1
  154. package/lib/types/spec.d.ts +3 -3
  155. package/lib/types/stdlib.d.ts +1 -1
  156. package/lib/types/theme.d.ts +8 -8
  157. package/lib/types/view.d.ts +2 -2
  158. package/lib/util/event.d.ts +2 -2
  159. package/lib/util/layout.d.ts +1 -1
  160. package/lib/util/loop.js +4 -0
  161. package/lib/util/loop.js.map +1 -1
  162. package/lib/util/shape.d.ts +0 -1
  163. package/lib/util/shape.js +1 -7
  164. package/lib/util/shape.js.map +1 -1
  165. package/lib/util/shape3d.js +0 -5
  166. package/lib/util/shape3d.js.map +1 -1
  167. package/lib/util/warn.d.ts +1 -1
  168. package/package.json +13 -13
  169. package/src/api-doc/types.ts +1 -0
  170. package/src/index.ts +1 -1
  171. package/src/item/combo.ts +2 -6
  172. package/src/item/node.ts +0 -1
  173. package/src/runtime/controller/item.ts +1 -1
  174. package/src/runtime/graph.ts +2 -2
  175. package/src/stdlib/behavior/brush-select.ts +10 -11
  176. package/src/stdlib/behavior/create-edge.ts +5 -1
  177. package/src/stdlib/behavior/drag-canvas.ts +11 -0
  178. package/src/stdlib/behavior/drag-node.ts +8 -0
  179. package/src/stdlib/behavior/lasso-select.ts +2 -2
  180. package/src/stdlib/behavior/zoom-canvas.ts +13 -14
  181. package/src/stdlib/item/edge/base.ts +11 -27
  182. package/src/stdlib/item/node/base.ts +10 -36
  183. package/src/types/graph.ts +4 -1
  184. package/src/util/loop.ts +4 -0
  185. package/src/util/shape.ts +0 -7
  186. package/src/util/shape3d.ts +1 -10
@@ -1044,7 +1044,7 @@ export class ItemController {
1044
1044
  );
1045
1045
  transientObjectMap.set(idStr, shape);
1046
1046
  shape.style.pointerEvents = capture ? 'auto' : 'none';
1047
- canvas.getRoot().appendChild(shape);
1047
+ if (shape.parentNode === null) canvas.getRoot().appendChild(shape);
1048
1048
  }
1049
1049
  public getTransient(id: string) {
1050
1050
  return this.transientObjectMap.get(id);
@@ -241,7 +241,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
241
241
  $domElement.style.outline = 'none';
242
242
  $domElement.tabIndex = 1; // Enable keyboard events
243
243
  // Transient canvas should let interactive events go through.
244
- if (i === 2) {
244
+ if (i !== 1) {
245
245
  $domElement.style.pointerEvents = 'none';
246
246
  }
247
247
  }
@@ -1405,7 +1405,7 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
1405
1405
  const modelArr = isArray(models) ? models : [models];
1406
1406
  const { graphCore } = this.dataController;
1407
1407
  const { specification } = this.themeController;
1408
- graphCore.once('changed', (event) => {
1408
+ graphCore?.once('changed', (event) => {
1409
1409
  if (!event.changes.length) return;
1410
1410
  const changes = event.changes.filter(
1411
1411
  (change) => !isEqual(change.newValue, change.oldValue),
@@ -1,6 +1,6 @@
1
1
  import { DisplayObject } from '@antv/g';
2
2
  import { ID } from '@antv/graphlib';
3
- import { utils } from '../../stdlib';
3
+ import rectSelector from '../selector/rect';
4
4
  import { Behavior } from '../../types/behavior';
5
5
  import { Point } from '../../types/common';
6
6
  import { IG6GraphEvent } from '../../types/event';
@@ -125,6 +125,7 @@ export class BrushSelect extends Behavior {
125
125
  pointerdown: this.onMouseDown,
126
126
  pointermove: this.onMouseMove,
127
127
  pointerup: this.onMouseUp,
128
+ 'canvas:click': this.onCanvasClick,
128
129
  };
129
130
  };
130
131
 
@@ -140,6 +141,10 @@ export class BrushSelect extends Behavior {
140
141
  return keyMap[trigger];
141
142
  }
142
143
 
144
+ public onCanvasClick(event: IG6GraphEvent) {
145
+ this.clearStates();
146
+ }
147
+
143
148
  public onMouseDown(event: IG6GraphEvent) {
144
149
  if (!this.options.shouldBegin(event)) return;
145
150
  const { itemId, itemType, canvas } = event;
@@ -151,11 +156,6 @@ export class BrushSelect extends Behavior {
151
156
  y: canvas.y,
152
157
  };
153
158
 
154
- if (!this.isKeydown(event as any)) {
155
- this.clearStates();
156
- return;
157
- }
158
-
159
159
  const { brush } = this;
160
160
  if (!brush) {
161
161
  this.brush = this.createBrush();
@@ -180,13 +180,12 @@ export class BrushSelect extends Behavior {
180
180
 
181
181
  public onMouseUp(event: IG6GraphEvent) {
182
182
  if (!this.mousedown) return;
183
- if (!this.isKeydown(event as any)) {
184
- this.clearStates();
185
- }
186
183
 
187
184
  this.removeBrush();
188
185
  this.brush = undefined;
189
- this.selectedIds = this.selectItems(event);
186
+ if (this.isKeydown(event as any)) {
187
+ this.selectedIds = this.selectItems(event);
188
+ }
190
189
  this.dragging = false;
191
190
  this.mousedown = false;
192
191
  }
@@ -373,7 +372,7 @@ export class BrushSelect extends Behavior {
373
372
  }
374
373
 
375
374
  public getSelector() {
376
- return utils.rectSelector;
375
+ return rectSelector;
377
376
  }
378
377
 
379
378
  public getPoints(event: IG6GraphEvent) {
@@ -132,7 +132,7 @@ export class CreateEdge extends Behavior {
132
132
  return;
133
133
  }
134
134
 
135
- if (this.options.shouldEnd(e)) {
135
+ if (this.options.shouldBegin(e)) {
136
136
  return;
137
137
  }
138
138
 
@@ -202,6 +202,10 @@ export class CreateEdge extends Behavior {
202
202
  return;
203
203
  }
204
204
 
205
+ if (this.options.shouldEnd(e)) {
206
+ return;
207
+ }
208
+
205
209
  const elements = await this.graph.canvas.document.elementsFromPoint(
206
210
  e.canvas.x,
207
211
  e.canvas.y,
@@ -243,10 +243,20 @@ export class DragCanvas extends Behavior {
243
243
  if (!this.dragging) {
244
244
  this.hideShapes();
245
245
  this.dragging = true;
246
+ this.graph.canvas.getConfig().disableHitTesting = true;
246
247
  }
247
248
 
249
+ const { tileBehavior: graphBehaviorOptimize } =
250
+ this.graph.getSpecification().optimize || {};
251
+
252
+ const shouldDebounce =
253
+ typeof graphBehaviorOptimize === 'boolean'
254
+ ? graphBehaviorOptimize
255
+ : this.graph.getAllNodesData().length < graphBehaviorOptimize;
256
+
248
257
  const now = Date.now();
249
258
  if (
259
+ shouldDebounce &&
250
260
  this.lastDragTriggerTime &&
251
261
  now - this.lastDragTriggerTime < DRAG_DURATION / 5
252
262
  ) {
@@ -276,6 +286,7 @@ export class DragCanvas extends Behavior {
276
286
  public onPointerUp() {
277
287
  this.pointerDownAt = undefined;
278
288
  this.dragging = false;
289
+ this.graph.canvas.getConfig().disableHitTesting = false;
279
290
 
280
291
  const { graph, hiddenNodeIds, hiddenEdgeIds = [] } = this;
281
292
  const { tileBehavior: graphBehaviorOptimize, tileBehaviorSize = 1000 } =
@@ -199,6 +199,14 @@ export class DragNode extends Behavior {
199
199
  if (!this.options.shouldBegin(event)) return;
200
200
  this.pointerDown = { x: event.canvas.x, y: event.canvas.y };
201
201
  this.dragging = false;
202
+
203
+ document.addEventListener(
204
+ 'mouseup',
205
+ (evt) => {
206
+ this.onPointerUp(event);
207
+ },
208
+ { once: true },
209
+ );
202
210
  }
203
211
 
204
212
  public onPointerMove(event: IG6GraphEvent) {
@@ -1,7 +1,7 @@
1
1
  import { DisplayObject } from '@antv/g';
2
2
  import { ID } from '@antv/graphlib';
3
3
  import { IG6GraphEvent } from '../../types/event';
4
- import { utils } from '..';
4
+ import lassoSelector from '../selector/lasso';
5
5
  import { Point } from '../../types/common';
6
6
  import { IGraph } from '../../types';
7
7
  import { BrushSelect } from './brush-select';
@@ -50,7 +50,7 @@ export class LassoSelect extends BrushSelect {
50
50
  };
51
51
 
52
52
  public getSelector() {
53
- return utils.lassoSelector;
53
+ return lassoSelector;
54
54
  }
55
55
 
56
56
  public getPoints() {
@@ -60,7 +60,7 @@ export interface ZoomCanvasOptions {
60
60
  const DEFAULT_OPTIONS: Required<ZoomCanvasOptions> = {
61
61
  enableOptimize: undefined,
62
62
  triggerOnItems: true,
63
- sensitivity: 10,
63
+ sensitivity: 6,
64
64
  trigger: 'wheel',
65
65
  secondaryKey: '',
66
66
  speedUpKey: 'shift',
@@ -231,12 +231,22 @@ export class ZoomCanvas extends Behavior {
231
231
 
232
232
  // begin zooming
233
233
  if (!this.zooming) {
234
+ this.graph.canvas.getConfig().disableHitTesting = true;
234
235
  this.hideShapes();
235
236
  this.zooming = true;
236
237
  }
237
238
 
239
+ const { tileBehavior: graphBehaviorOptimize } =
240
+ graph.getSpecification().optimize || {};
241
+
242
+ const shouldDebounce =
243
+ typeof graphBehaviorOptimize === 'boolean'
244
+ ? graphBehaviorOptimize
245
+ : graph.getAllNodesData().length < graphBehaviorOptimize;
246
+
238
247
  const now = Date.now();
239
248
  if (
249
+ shouldDebounce &&
240
250
  this.lastWheelTriggerTime &&
241
251
  now - this.lastWheelTriggerTime < WHEEL_DURATION / 5
242
252
  ) {
@@ -250,25 +260,14 @@ export class ZoomCanvas extends Behavior {
250
260
  if (minZoom && zoomTo < minZoom) return;
251
261
  if (maxZoom && zoomTo > maxZoom) return;
252
262
 
253
- const { tileBehavior: graphBehaviorOptimize } =
254
- graph.getSpecification().optimize || {};
255
-
256
- const shouldAnimate =
257
- typeof graphBehaviorOptimize === 'boolean'
258
- ? graphBehaviorOptimize
259
- : graph.getAllNodesData().length < graphBehaviorOptimize;
260
-
261
- graph.zoom(
262
- zoomRatio,
263
- { x: client.x, y: client.y },
264
- shouldAnimate ? { duration: WHEEL_DURATION / 5 } : undefined,
265
- );
263
+ graph.zoom(zoomRatio, { x: client.x, y: client.y });
266
264
 
267
265
  this.lastWheelTriggerTime = now;
268
266
 
269
267
  clearTimeout(this.zoomTimer);
270
268
  this.zoomTimer = setTimeout(() => {
271
269
  this.endZoom();
270
+ this.graph.canvas.getConfig().disableHitTesting = false;
272
271
  }, 300);
273
272
 
274
273
  // Emit event.
@@ -21,12 +21,7 @@ import {
21
21
  State,
22
22
  LodStrategyObj,
23
23
  } from '../../../types/item';
24
- import {
25
- LOCAL_BOUNDS_DIRTY_FLAG_KEY,
26
- formatPadding,
27
- mergeStyles,
28
- upsertShape,
29
- } from '../../../util/shape';
24
+ import { formatPadding, mergeStyles, upsertShape } from '../../../util/shape';
30
25
  import { DEFAULT_ANIMATE_CFG, fadeIn, fadeOut } from '../../../util/animate';
31
26
  import { getWordWrapWidthByEnds } from '../../../util/text';
32
27
  import { AnimateCfg } from '../../../types/animate';
@@ -49,9 +44,7 @@ export abstract class BaseEdge {
49
44
  transform: string;
50
45
  isRevert: boolean;
51
46
  };
52
- boundsCache: {
53
- labelShapeGeometry?: AABB;
54
- labelBackgroundShapeGeometry?: AABB;
47
+ transformCache: {
55
48
  labelShapeTransform?: string;
56
49
  labelBackgroundShapeTransform?: string;
57
50
  };
@@ -89,7 +82,7 @@ export abstract class BaseEdge {
89
82
  const { themeStyles, lodStrategy, zoom } = props;
90
83
  if (themeStyles) this.themeStyles = themeStyles;
91
84
  this.lodStrategy = lodStrategy;
92
- this.boundsCache = {};
85
+ this.transformCache = {};
93
86
  this.zoomCache.zoom = zoom;
94
87
  this.zoomCache.balanceRatio = 1 / zoom;
95
88
  this.zoomCache.animateConfig = {
@@ -147,10 +140,8 @@ export abstract class BaseEdge {
147
140
  public updateCache(shapeMap) {
148
141
  ['labelShape', 'labelBackgroundShape'].forEach((id) => {
149
142
  const shape = shapeMap[id];
150
- if (shape?.getAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY)) {
151
- this.boundsCache[`${id}Geometry`] = shape.getGeometryBounds();
152
- this.boundsCache[`${id}Transform`] = shape.style.transform;
153
- shape.setAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY, false);
143
+ if (shape) {
144
+ this.transformCache[`${id}Transform`] = shape.style.transform;
154
145
  }
155
146
  });
156
147
 
@@ -262,7 +253,7 @@ export abstract class BaseEdge {
262
253
  offsetY: 0,
263
254
  pointRatio: [0.5, 0.501],
264
255
  };
265
- if (isNumber(position)) {
256
+ if (typeof position === 'number') {
266
257
  positionPreset.pointRatio = [position, position + 0.01];
267
258
  }
268
259
  switch (position) {
@@ -341,7 +332,7 @@ export abstract class BaseEdge {
341
332
  ...positionStyle,
342
333
  ...otherStyle,
343
334
  };
344
- this.boundsCache.labelShapeTransform = style.transform;
335
+ this.transformCache.labelShapeTransform = style.transform;
345
336
  return this.upsertShape('text', 'labelShape', style, shapeMap, model);
346
337
  }
347
338
 
@@ -365,8 +356,7 @@ export abstract class BaseEdge {
365
356
  const { labelBackgroundShape, labelShape: labelShapeStyle } =
366
357
  this.mergedStyles;
367
358
 
368
- const textBBox =
369
- this.boundsCache.labelShapeGeometry || labelShape.getGeometryBounds();
359
+ const textBBox = labelShape.getGeometryBounds();
370
360
  const { x, y, transform, isRevert } = this.labelPosition;
371
361
  const { padding, ...backgroundStyle } = labelBackgroundShape;
372
362
  const { balanceRatio = 1 } = this.zoomCache;
@@ -451,15 +441,9 @@ export abstract class BaseEdge {
451
441
  shapeStyle.height = h;
452
442
  }
453
443
 
454
- if (labelShape) {
455
- const referShape = labelBackgroundShape || labelShape;
456
- }
457
444
  if (labelShapeProps) {
458
445
  const referShape = labelBackgroundShape || labelShape;
459
- const referBounds =
460
- this.boundsCache.labelBackgroundShapeGeometry ||
461
- this.boundsCache.labelShapeGeometry ||
462
- referShape.getGeometryBounds();
446
+ const referBounds = referShape.getGeometryBounds();
463
447
  const {
464
448
  min: referMin,
465
449
  max: referMax,
@@ -632,7 +616,7 @@ export abstract class BaseEdge {
632
616
  if (position === 'bottom') labelShape.style.transformOrigin = '0';
633
617
  else labelShape.style.transformOrigin = '';
634
618
 
635
- const oriTransform = this.boundsCache.labelShapeTransform;
619
+ const oriTransform = this.transformCache.labelShapeTransform;
636
620
  labelShape.style.transform = `${oriTransform} scale(${balanceRatio}, ${balanceRatio})`;
637
621
 
638
622
  const wordWrapWidth = this.zoomCache.wordWrapWidth * zoom;
@@ -640,7 +624,7 @@ export abstract class BaseEdge {
640
624
 
641
625
  if (!labelBackgroundShape) return;
642
626
 
643
- const oriBgTransform = this.boundsCache.labelBackgroundShapeTransform;
627
+ const oriBgTransform = this.transformCache.labelBackgroundShapeTransform;
644
628
  labelBackgroundShape.style.transform = `${oriBgTransform} scale(${balanceRatio}, ${balanceRatio})`;
645
629
  }
646
630
 
@@ -23,7 +23,6 @@ import {
23
23
  ComboShapeMap,
24
24
  } from '../../../types/combo';
25
25
  import {
26
- LOCAL_BOUNDS_DIRTY_FLAG_KEY,
27
26
  formatPadding,
28
27
  getShapeLocalBoundsByStyle,
29
28
  mergeStyles,
@@ -42,10 +41,6 @@ export abstract class BaseNode {
42
41
  mergedStyles: NodeShapeStyles | ComboShapeStyles;
43
42
  lodStrategy?: LodStrategyObj;
44
43
  enableBalanceShape?: boolean;
45
- boundsCache: {
46
- keyShapeLocal?: AABB;
47
- labelShapeGeometry?: AABB;
48
- };
49
44
  //vertex coordinate
50
45
 
51
46
  /**
@@ -89,7 +84,6 @@ export abstract class BaseNode {
89
84
  if (themeStyles) this.themeStyles = themeStyles;
90
85
  this.lodStrategy = lodStrategy;
91
86
  this.enableBalanceShape = enableBalanceShape;
92
- this.boundsCache = {};
93
87
  this.zoomCache.zoom = zoom;
94
88
  this.zoomCache.balanceRatio = 1 / zoom;
95
89
  this.zoomCache.animateConfig = {
@@ -163,21 +157,6 @@ export abstract class BaseNode {
163
157
  * @param shapeMap The shape map that contains all of the elements to show on the node.
164
158
  */
165
159
  public updateCache(shapeMap) {
166
- ['keyShape', 'labelShape']
167
- .concat(Object.keys(BadgePosition))
168
- .map((pos) => `${pos}BadgeShape`)
169
- .forEach((id) => {
170
- const shape = shapeMap[id];
171
- if (shape?.getAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY)) {
172
- if (id === 'labelShape') {
173
- this.boundsCache[`${id}Geometry`] = shape.getGeometryBounds();
174
- } else {
175
- this.boundsCache[`${id}Local`] = shape.getLocalBounds();
176
- }
177
- shape.setAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY, false);
178
- }
179
- });
180
-
181
160
  const levelShapes = {};
182
161
  Object.keys(shapeMap).forEach((shapeId) => {
183
162
  const { lod } = shapeMap[shapeId].attributes;
@@ -394,15 +373,8 @@ export abstract class BaseNode {
394
373
  ): DisplayObject {
395
374
  const { labelShape } = shapeMap;
396
375
  if (!labelShape || !labelShape.style.text || !model.data.labelShape) return;
397
- if (
398
- !this.boundsCache.labelShapeGeometry ||
399
- labelShape.getAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY)
400
- ) {
401
- this.boundsCache.labelShapeGeometry = labelShape.getGeometryBounds();
402
- labelShape.setAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY, false);
403
- }
404
376
  // label's local bounds, will take scale into acount
405
- const { labelShapeGeometry: textBBoxGeo } = this.boundsCache;
377
+ const textBBoxGeo = labelShape.getGeometryBounds();
406
378
  const height = textBBoxGeo.max[1] - textBBoxGeo.min[1];
407
379
  const width = Math.min(
408
380
  textBBoxGeo.max[0] - textBBoxGeo.min[0] + 2,
@@ -549,13 +521,15 @@ export abstract class BaseNode {
549
521
  (style) => style.tag === 'anchorShape',
550
522
  );
551
523
  if (!individualConfigs.length) return;
552
- this.boundsCache.keyShapeLocal =
553
- this.boundsCache.keyShapeLocal || shapeMap.keyShape.getLocalBounds();
554
524
  const shapes = {};
555
525
  const anchorPositionMap = this.calculateAnchorPosition(keyShapeStyle);
556
526
  individualConfigs.forEach((config, i) => {
557
527
  const { position, fill = keyShapeStyle.fill, ...style } = config;
558
- const [cx, cy] = this.getAnchorPosition(position, anchorPositionMap);
528
+ const [cx, cy] = this.getAnchorPosition(
529
+ position,
530
+ anchorPositionMap,
531
+ shapeMap,
532
+ );
559
533
  const id = `anchorShape${i}`;
560
534
  shapes[id] = this.upsertShape(
561
535
  'circle',
@@ -577,8 +551,9 @@ export abstract class BaseNode {
577
551
  private getAnchorPosition(
578
552
  position: string | [number, number],
579
553
  anchorPositionMap: IAnchorPositionMap,
554
+ shapeMap: NodeShapeMap | ComboShapeMap,
580
555
  ): [number, number] {
581
- const keyShapeBBox = this.boundsCache.keyShapeLocal!;
556
+ const keyShapeBBox = shapeMap.keyShape.getLocalBounds();
582
557
  const keyShapeWidth = keyShapeBBox.max[0] - keyShapeBBox.min[0];
583
558
  const keyShapeHeight = keyShapeBBox.max[1] - keyShapeBBox.min[1];
584
559
  const defaultPosition: [number, number] = [
@@ -750,8 +725,7 @@ export abstract class BaseNode {
750
725
  shapeMap,
751
726
  model,
752
727
  );
753
- this.boundsCache[`${id}Local`] = shapes[id].getLocalBounds();
754
- const bbox = this.boundsCache[`${id}Local`];
728
+ const bbox = shapes[id].getLocalBounds();
755
729
 
756
730
  const bgShapeId = `${position}BadgeBackgroundShape`;
757
731
  const bgWidth =
@@ -966,7 +940,7 @@ export abstract class BaseNode {
966
940
  } ${paddingTop + (height - paddingTop - paddingBottom) / 2}`;
967
941
  }
968
942
 
969
- const { labelShapeGeometry: labelBBox } = this.boundsCache;
943
+ const labelBBox = labelShape.getGeometryBounds();
970
944
  const labelWidth = labelBBox.max[0] - labelBBox.min[0];
971
945
  const xAxistRatio = (labelWidth * balanceRatio + sidePadding) / width;
972
946
 
@@ -50,7 +50,10 @@ export interface IGraph<
50
50
  * @param {ITEM_TYPE} type - The type of item (node, edge, or combo).
51
51
  * @param {NodeMapper | EdgeMapper | ComboMapper} mapper - The mapper to be updated.
52
52
  * */
53
- updateMapper(type: ITEM_TYPE, mapper: NodeMapper | EdgeMapper | ComboMapper);
53
+ updateMapper: (
54
+ type: ITEM_TYPE,
55
+ mapper: NodeMapper | EdgeMapper | ComboMapper,
56
+ ) => void;
54
57
  /**
55
58
  * Get the copy of specs(configurations).
56
59
  * @returns graph specs
package/src/util/loop.ts CHANGED
@@ -69,6 +69,7 @@ export const calculatePointForOtherShapes = (
69
69
  [center[0] - pointPadding, center[1] - halfOfHeight],
70
70
  [center[0] + pointPadding, center[1] - halfOfHeight],
71
71
  ],
72
+ // @ts-ignore
72
73
  [LOOP_POSITION['top-right']]: [
73
74
  [center[0] + halfOfWidth - pointPadding, center[1] - halfOfHeight],
74
75
  [center[0] + halfOfWidth, center[1] - halfOfHeight + pointPadding],
@@ -77,6 +78,7 @@ export const calculatePointForOtherShapes = (
77
78
  [center[0] + halfOfWidth, center[1] - pointPadding],
78
79
  [center[0] + halfOfWidth, center[1] + pointPadding],
79
80
  ],
81
+ // @ts-ignore
80
82
  [LOOP_POSITION['bottom-right']]: [
81
83
  [center[0] + halfOfWidth, center[1] + halfOfHeight - pointPadding],
82
84
  [center[0] + halfOfWidth - pointPadding, center[1] + halfOfHeight],
@@ -85,6 +87,7 @@ export const calculatePointForOtherShapes = (
85
87
  [center[0] + pointPadding, center[1] + halfOfHeight],
86
88
  [center[0] - pointPadding, center[1] + halfOfHeight],
87
89
  ],
90
+ // @ts-ignore
88
91
  [LOOP_POSITION['bottom-left']]: [
89
92
  [center[0] - halfOfWidth + pointPadding, center[1] + halfOfHeight],
90
93
  [center[0] - halfOfWidth, center[1] + halfOfHeight - pointPadding],
@@ -93,6 +96,7 @@ export const calculatePointForOtherShapes = (
93
96
  [center[0] - halfOfWidth, center[1] + pointPadding],
94
97
  [center[0] - halfOfWidth, center[1] - pointPadding],
95
98
  ],
99
+ // @ts-ignore
96
100
  [LOOP_POSITION['top-left']]: [
97
101
  [center[0] - halfOfWidth, center[1] - halfOfHeight + pointPadding],
98
102
  [center[0] - halfOfWidth + pointPadding, center[1] - halfOfHeight],
package/src/util/shape.ts CHANGED
@@ -48,8 +48,6 @@ export const ShapeTagMap = {
48
48
 
49
49
  const LINE_TYPES = ['line', 'polyline', 'path'];
50
50
 
51
- export const LOCAL_BOUNDS_DIRTY_FLAG_KEY = 'data-item-local-bounds-dirty';
52
-
53
51
  export const createShape = (
54
52
  type: SHAPE_TYPE,
55
53
  style: GShapeStyle,
@@ -132,12 +130,10 @@ export const upsertShape = (
132
130
  shape.style[key] = initShapeStyles[key];
133
131
  });
134
132
  }
135
- shape.setAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY, true);
136
133
  } else if (shape.nodeName !== type) {
137
134
  // remove and create for the shape changed type
138
135
  shape.remove();
139
136
  shape = createShape(type, style, id);
140
- shape.setAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY, true);
141
137
  } else {
142
138
  const updateStyles = {};
143
139
  const oldStyles = shape.attributes;
@@ -162,9 +158,6 @@ export const upsertShape = (
162
158
  }
163
159
  });
164
160
  }
165
- if (isStyleAffectBBox(type, updateStyles)) {
166
- shape.setAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY, true);
167
- }
168
161
  if (style.interactive === false) shape.interactive = false;
169
162
  else shape.interactive = true;
170
163
  }
@@ -11,11 +11,7 @@ import {
11
11
  import { EdgeShapeMap } from '../types/edge';
12
12
  import { NodeShapeMap } from '../types/node';
13
13
  import { GShapeStyle, SHAPE_TYPE, SHAPE_TYPE_3D } from '../types/item';
14
- import {
15
- LOCAL_BOUNDS_DIRTY_FLAG_KEY,
16
- createShape,
17
- isStyleAffectBBox,
18
- } from './shape';
14
+ import { createShape } from './shape';
19
15
 
20
16
  const GeometryTagMap = {
21
17
  sphere: SphereGeometry,
@@ -132,12 +128,10 @@ export const upsertShape3D = (
132
128
  if (!shape) {
133
129
  // @ts-ignore
134
130
  shape = createShape3D(type, style, id, device);
135
- shape.setAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY, true);
136
131
  } else if (shape.nodeName !== type) {
137
132
  shape.remove();
138
133
  // @ts-ignore
139
134
  shape = createShape3D(type, style, id, device);
140
- shape.setAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY, true);
141
135
  } else {
142
136
  const updateStyles = {};
143
137
  const oldStyles = shape.attributes;
@@ -147,9 +141,6 @@ export const upsertShape3D = (
147
141
  shape.style[key] = style[key];
148
142
  }
149
143
  });
150
- if (isStyleAffectBBox(type, updateStyles)) {
151
- shape.setAttribute(LOCAL_BOUNDS_DIRTY_FLAG_KEY, true);
152
- }
153
144
  }
154
145
  shapeMap[id] = shape;
155
146
  return shape;