@antv/g6 5.0.29 → 5.0.31

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 (210) hide show
  1. package/dist/g6.min.js +29 -29
  2. package/dist/lib/animations/types.d.ts +7 -1
  3. package/dist/lib/elements/base-element.d.ts +3 -2
  4. package/dist/lib/elements/combos/base-combo.d.ts +0 -2
  5. package/dist/lib/elements/edges/base-edge.d.ts +3 -3
  6. package/dist/lib/elements/nodes/base-node.d.ts +3 -3
  7. package/dist/lib/elements/shapes/badge.d.ts +1 -1
  8. package/dist/lib/elements/shapes/base-shape.d.ts +1 -1
  9. package/dist/lib/exports.d.ts +3 -2
  10. package/dist/lib/layouts/fishbone.d.ts +72 -0
  11. package/dist/lib/layouts/index.d.ts +2 -0
  12. package/dist/lib/plugins/legend.d.ts +22 -14
  13. package/dist/lib/plugins/minimap/index.d.ts +2 -4
  14. package/dist/lib/plugins/timebar.d.ts +1 -2
  15. package/dist/lib/plugins/utils/canvas.d.ts +31 -0
  16. package/dist/lib/plugins/utils/dom.d.ts +22 -0
  17. package/dist/lib/runtime/data.d.ts +28 -0
  18. package/dist/lib/runtime/element.d.ts +0 -9
  19. package/dist/lib/types/element.d.ts +0 -8
  20. package/dist/lib/utils/dom.d.ts +0 -26
  21. package/dist/lib/utils/style.d.ts +1 -1
  22. package/dist/lib/utils/z-index.d.ts +8 -0
  23. package/dist/lib/version.d.ts +1 -1
  24. package/esm/animations/types.d.ts +7 -1
  25. package/esm/elements/base-element.d.ts +3 -2
  26. package/esm/elements/base-element.js +2 -1
  27. package/esm/elements/base-element.js.map +1 -1
  28. package/esm/elements/combos/base-combo.d.ts +0 -2
  29. package/esm/elements/combos/base-combo.js +7 -13
  30. package/esm/elements/combos/base-combo.js.map +1 -1
  31. package/esm/elements/edges/base-edge.d.ts +3 -3
  32. package/esm/elements/edges/base-edge.js +4 -4
  33. package/esm/elements/edges/base-edge.js.map +1 -1
  34. package/esm/elements/nodes/base-node.d.ts +3 -3
  35. package/esm/elements/nodes/base-node.js.map +1 -1
  36. package/esm/elements/shapes/badge.d.ts +1 -1
  37. package/esm/elements/shapes/base-shape.d.ts +1 -1
  38. package/esm/elements/shapes/base-shape.js.map +1 -1
  39. package/esm/exports.d.ts +3 -2
  40. package/esm/exports.js +1 -1
  41. package/esm/exports.js.map +1 -1
  42. package/esm/layouts/fishbone.d.ts +72 -0
  43. package/esm/layouts/fishbone.js +209 -0
  44. package/esm/layouts/fishbone.js.map +1 -0
  45. package/esm/layouts/index.d.ts +2 -0
  46. package/esm/layouts/index.js +1 -0
  47. package/esm/layouts/index.js.map +1 -1
  48. package/esm/plugins/background/index.js +2 -1
  49. package/esm/plugins/background/index.js.map +1 -1
  50. package/esm/plugins/contextmenu/index.js +1 -1
  51. package/esm/plugins/contextmenu/index.js.map +1 -1
  52. package/esm/plugins/edge-filter-lens/index.js +1 -0
  53. package/esm/plugins/edge-filter-lens/index.js.map +1 -1
  54. package/esm/plugins/grid-line.js +5 -3
  55. package/esm/plugins/grid-line.js.map +1 -1
  56. package/esm/plugins/legend.d.ts +22 -14
  57. package/esm/plugins/legend.js +39 -51
  58. package/esm/plugins/legend.js.map +1 -1
  59. package/esm/plugins/minimap/index.d.ts +2 -4
  60. package/esm/plugins/minimap/index.js +13 -30
  61. package/esm/plugins/minimap/index.js.map +1 -1
  62. package/esm/plugins/timebar.d.ts +1 -2
  63. package/esm/plugins/timebar.js +15 -47
  64. package/esm/plugins/timebar.js.map +1 -1
  65. package/esm/plugins/toolbar/index.js +1 -1
  66. package/esm/plugins/toolbar/index.js.map +1 -1
  67. package/esm/plugins/utils/canvas.d.ts +31 -0
  68. package/esm/plugins/utils/canvas.js +55 -0
  69. package/esm/plugins/utils/canvas.js.map +1 -0
  70. package/esm/plugins/utils/dom.d.ts +22 -0
  71. package/esm/plugins/utils/dom.js +52 -0
  72. package/esm/plugins/utils/dom.js.map +1 -0
  73. package/esm/plugins/watermark/index.js +1 -1
  74. package/esm/plugins/watermark/index.js.map +1 -1
  75. package/esm/preset.js +2 -0
  76. package/esm/preset.js.map +1 -1
  77. package/esm/registry/build-in.js +3 -2
  78. package/esm/registry/build-in.js.map +1 -1
  79. package/esm/runtime/animation.js +5 -2
  80. package/esm/runtime/animation.js.map +1 -1
  81. package/esm/runtime/data.d.ts +28 -0
  82. package/esm/runtime/data.js +131 -16
  83. package/esm/runtime/data.js.map +1 -1
  84. package/esm/runtime/element.d.ts +0 -9
  85. package/esm/runtime/element.js +7 -52
  86. package/esm/runtime/element.js.map +1 -1
  87. package/esm/runtime/graph.js +8 -9
  88. package/esm/runtime/graph.js.map +1 -1
  89. package/esm/types/element.d.ts +0 -8
  90. package/esm/utils/dom.d.ts +0 -26
  91. package/esm/utils/dom.js +0 -65
  92. package/esm/utils/dom.js.map +1 -1
  93. package/esm/utils/style.d.ts +1 -1
  94. package/esm/utils/style.js +2 -2
  95. package/esm/utils/style.js.map +1 -1
  96. package/esm/utils/z-index.d.ts +8 -0
  97. package/esm/utils/z-index.js +11 -0
  98. package/esm/utils/z-index.js.map +1 -0
  99. package/esm/version.d.ts +1 -1
  100. package/esm/version.js +1 -1
  101. package/lib/animations/types.d.ts +7 -1
  102. package/lib/elements/base-element.d.ts +3 -2
  103. package/lib/elements/base-element.js +2 -1
  104. package/lib/elements/base-element.js.map +1 -1
  105. package/lib/elements/combos/base-combo.d.ts +0 -2
  106. package/lib/elements/combos/base-combo.js +7 -13
  107. package/lib/elements/combos/base-combo.js.map +1 -1
  108. package/lib/elements/edges/base-edge.d.ts +3 -3
  109. package/lib/elements/edges/base-edge.js +4 -4
  110. package/lib/elements/edges/base-edge.js.map +1 -1
  111. package/lib/elements/nodes/base-node.d.ts +3 -3
  112. package/lib/elements/nodes/base-node.js.map +1 -1
  113. package/lib/elements/shapes/badge.d.ts +1 -1
  114. package/lib/elements/shapes/base-shape.d.ts +1 -1
  115. package/lib/elements/shapes/base-shape.js.map +1 -1
  116. package/lib/exports.d.ts +3 -2
  117. package/lib/exports.js +3 -2
  118. package/lib/exports.js.map +1 -1
  119. package/lib/layouts/fishbone.d.ts +72 -0
  120. package/lib/layouts/fishbone.js +213 -0
  121. package/lib/layouts/fishbone.js.map +1 -0
  122. package/lib/layouts/index.d.ts +2 -0
  123. package/lib/layouts/index.js +3 -1
  124. package/lib/layouts/index.js.map +1 -1
  125. package/lib/plugins/background/index.js +2 -1
  126. package/lib/plugins/background/index.js.map +1 -1
  127. package/lib/plugins/contextmenu/index.js +1 -1
  128. package/lib/plugins/contextmenu/index.js.map +1 -1
  129. package/lib/plugins/edge-filter-lens/index.js +1 -0
  130. package/lib/plugins/edge-filter-lens/index.js.map +1 -1
  131. package/lib/plugins/grid-line.js +5 -3
  132. package/lib/plugins/grid-line.js.map +1 -1
  133. package/lib/plugins/legend.d.ts +22 -14
  134. package/lib/plugins/legend.js +38 -50
  135. package/lib/plugins/legend.js.map +1 -1
  136. package/lib/plugins/minimap/index.d.ts +2 -4
  137. package/lib/plugins/minimap/index.js +13 -30
  138. package/lib/plugins/minimap/index.js.map +1 -1
  139. package/lib/plugins/timebar.d.ts +1 -2
  140. package/lib/plugins/timebar.js +15 -47
  141. package/lib/plugins/timebar.js.map +1 -1
  142. package/lib/plugins/toolbar/index.js +1 -1
  143. package/lib/plugins/toolbar/index.js.map +1 -1
  144. package/lib/plugins/utils/canvas.d.ts +31 -0
  145. package/lib/plugins/utils/canvas.js +58 -0
  146. package/lib/plugins/utils/canvas.js.map +1 -0
  147. package/lib/plugins/utils/dom.d.ts +22 -0
  148. package/lib/plugins/utils/dom.js +56 -0
  149. package/lib/plugins/utils/dom.js.map +1 -0
  150. package/lib/plugins/watermark/index.js +1 -1
  151. package/lib/plugins/watermark/index.js.map +1 -1
  152. package/lib/preset.js +2 -0
  153. package/lib/preset.js.map +1 -1
  154. package/lib/registry/build-in.js +2 -1
  155. package/lib/registry/build-in.js.map +1 -1
  156. package/lib/runtime/animation.js +5 -2
  157. package/lib/runtime/animation.js.map +1 -1
  158. package/lib/runtime/data.d.ts +28 -0
  159. package/lib/runtime/data.js +130 -15
  160. package/lib/runtime/data.js.map +1 -1
  161. package/lib/runtime/element.d.ts +0 -9
  162. package/lib/runtime/element.js +7 -52
  163. package/lib/runtime/element.js.map +1 -1
  164. package/lib/runtime/graph.js +8 -9
  165. package/lib/runtime/graph.js.map +1 -1
  166. package/lib/types/element.d.ts +0 -8
  167. package/lib/utils/dom.d.ts +0 -26
  168. package/lib/utils/dom.js +0 -68
  169. package/lib/utils/dom.js.map +1 -1
  170. package/lib/utils/style.d.ts +1 -1
  171. package/lib/utils/style.js +2 -2
  172. package/lib/utils/style.js.map +1 -1
  173. package/lib/utils/z-index.d.ts +8 -0
  174. package/lib/utils/z-index.js +14 -0
  175. package/lib/utils/z-index.js.map +1 -0
  176. package/lib/version.d.ts +1 -1
  177. package/lib/version.js +1 -1
  178. package/package.json +6 -6
  179. package/src/animations/types.ts +7 -1
  180. package/src/elements/base-element.ts +5 -3
  181. package/src/elements/combos/base-combo.ts +7 -14
  182. package/src/elements/edges/base-edge.ts +6 -7
  183. package/src/elements/nodes/base-node.ts +2 -3
  184. package/src/elements/shapes/base-shape.ts +1 -4
  185. package/src/exports.ts +2 -1
  186. package/src/global.d.ts +5 -0
  187. package/src/layouts/fishbone.ts +295 -0
  188. package/src/layouts/index.ts +2 -0
  189. package/src/plugins/background/index.ts +2 -1
  190. package/src/plugins/contextmenu/index.ts +1 -1
  191. package/src/plugins/edge-filter-lens/index.ts +1 -0
  192. package/src/plugins/grid-line.ts +5 -3
  193. package/src/plugins/legend.ts +67 -55
  194. package/src/plugins/minimap/index.ts +16 -52
  195. package/src/plugins/timebar.ts +16 -47
  196. package/src/plugins/toolbar/index.ts +1 -1
  197. package/src/plugins/utils/canvas.ts +89 -0
  198. package/src/plugins/utils/dom.ts +65 -0
  199. package/src/plugins/watermark/index.ts +1 -1
  200. package/src/preset.ts +3 -0
  201. package/src/registry/build-in.ts +3 -1
  202. package/src/runtime/animation.ts +5 -2
  203. package/src/runtime/data.ts +145 -16
  204. package/src/runtime/element.ts +4 -59
  205. package/src/runtime/graph.ts +8 -8
  206. package/src/types/element.ts +0 -9
  207. package/src/utils/dom.ts +0 -80
  208. package/src/utils/style.ts +3 -6
  209. package/src/utils/z-index.ts +11 -0
  210. package/src/version.ts +1 -1
@@ -1,5 +1,4 @@
1
1
  import { Canvas, DisplayObject, IRenderer, Landmark } from '@antv/g';
2
- import { Renderer } from '@antv/g-canvas';
3
2
  import { debounce, throttle } from '@antv/util';
4
3
  import { GraphEvent } from '../../constants';
5
4
  import type { RuntimeContext } from '../../runtime/types';
@@ -7,10 +6,10 @@ import { GraphData } from '../../spec';
7
6
  import type { ElementDatum, ElementType, ID, IGraphLifeCycleEvent, Padding, Placement, Vector3 } from '../../types';
8
7
  import { idOf } from '../../utils/id';
9
8
  import { parsePadding } from '../../utils/padding';
10
- import { parsePlacement } from '../../utils/placement';
11
9
  import { toPointObject } from '../../utils/point';
12
10
  import type { BasePluginOptions } from '../base-plugin';
13
11
  import { BasePlugin } from '../base-plugin';
12
+ import { createPluginCanvas } from '../utils/canvas';
14
13
 
15
14
  /**
16
15
  * <zh/> 缩略图插件配置项
@@ -64,9 +63,9 @@ export interface MinimapOptions extends BasePluginOptions {
64
63
  */
65
64
  shape?: 'key' | ((id: string, elementType: ElementType) => DisplayObject);
66
65
  /**
67
- * <zh/> 缩略图画布类名
66
+ * <zh/> 缩略图画布类名,传入外置容器时不生效
68
67
  *
69
- * <en/> The class name of the minimap canvas
68
+ * <en/> The class name of the minimap canvas, which does not take effect when an external container is passed in
70
69
  */
71
70
  className?: string;
72
71
  /**
@@ -269,46 +268,6 @@ export class Minimap extends BasePlugin<MinimapOptions> {
269
268
 
270
269
  private container!: HTMLElement;
271
270
 
272
- private calculatePosition(): [number, number] {
273
- const {
274
- position,
275
- size: [w, h],
276
- } = this.options;
277
-
278
- const { canvas } = this.context;
279
- const [width, height] = canvas.getSize();
280
- const [x, y] = parsePlacement(position);
281
- return [x * (width - w), y * (height - h)];
282
- }
283
-
284
- private createContainer(): HTMLElement {
285
- const {
286
- container,
287
- className,
288
- size: [width, height],
289
- containerStyle,
290
- } = this.options;
291
- if (container) {
292
- return typeof container === 'string' ? document.querySelector(container)! : container;
293
- }
294
-
295
- const $container = document.createElement('div');
296
- $container.classList.add('g6-minimap');
297
- if (className) $container.classList.add(className);
298
-
299
- const [x, y] = this.calculatePosition();
300
- Object.assign($container.style, {
301
- position: 'absolute',
302
- left: x + 'px',
303
- top: y + 'px',
304
- width: width + 'px',
305
- height: height + 'px',
306
- ...containerStyle,
307
- });
308
-
309
- return this.context.canvas.getContainer()!.appendChild($container);
310
- }
311
-
312
271
  private initCanvas() {
313
272
  const {
314
273
  renderer,
@@ -320,18 +279,23 @@ export class Minimap extends BasePlugin<MinimapOptions> {
320
279
  if (width !== w || height !== h) this.canvas.resize(width, height);
321
280
  if (renderer) this.canvas.setRenderer(renderer);
322
281
  } else {
323
- const dom = document.createElement('div');
282
+ const { className, position, container, containerStyle } = this.options;
324
283
 
325
- const container = this.createContainer();
326
- this.container = container;
327
- container.appendChild(dom);
328
-
329
- this.canvas = new Canvas({
284
+ const [$container, canvas] = createPluginCanvas({
285
+ renderer,
330
286
  width,
331
287
  height,
332
- container: dom,
333
- renderer: renderer || new Renderer(),
288
+ placement: position,
289
+ className: 'minimap',
290
+ container,
291
+ containerStyle,
292
+ graphCanvas: this.context.canvas,
334
293
  });
294
+
295
+ if (className) $container.classList.add(className);
296
+
297
+ this.container = $container;
298
+ this.canvas = canvas;
335
299
  }
336
300
 
337
301
  this.setCamera();
@@ -1,6 +1,5 @@
1
1
  import { Timebar as TimebarComponent } from '@antv/component';
2
2
  import { Canvas } from '@antv/g';
3
- import { Renderer as CanvasRenderer } from '@antv/g-canvas';
4
3
  import { isArray, isDate, isNumber } from '@antv/util';
5
4
  import { idOf } from '../utils/id';
6
5
  import { parsePadding } from '../utils/padding';
@@ -11,6 +10,7 @@ import type { RuntimeContext } from '../runtime/types';
11
10
  import type { GraphData } from '../spec';
12
11
  import type { ElementDatum, ElementType, ID, Padding } from '../types';
13
12
  import type { BasePluginOptions } from './base-plugin';
13
+ import { createPluginCanvas } from './utils/canvas';
14
14
 
15
15
  const prospectiveTimeKeys = ['timestamp', 'time', 'date', 'datetime'];
16
16
 
@@ -205,7 +205,7 @@ export class Timebar extends BasePlugin<TimebarOptions> {
205
205
 
206
206
  private canvas?: Canvas;
207
207
 
208
- private wrapper?: HTMLElement;
208
+ private container?: HTMLElement;
209
209
 
210
210
  private originalData?: GraphData;
211
211
 
@@ -275,16 +275,7 @@ export class Timebar extends BasePlugin<TimebarOptions> {
275
275
  super.update(options);
276
276
  this.backup();
277
277
 
278
- Object.keys(options).forEach((key) => {
279
- switch (key) {
280
- case 'position':
281
- this.upsertWrapper();
282
- break;
283
- default:
284
- this.upsertTimebar();
285
- break;
286
- }
287
- });
278
+ this.upsertTimebar();
288
279
  }
289
280
 
290
281
  /**
@@ -332,48 +323,26 @@ export class Timebar extends BasePlugin<TimebarOptions> {
332
323
  });
333
324
  }
334
325
 
335
- private upsertWrapper() {
336
- if (!this.wrapper) {
337
- const wrapper = document.createElement('div');
338
- wrapper.style.position = 'absolute';
339
- this.wrapper = wrapper;
340
- }
341
- const { x, y, className, position } = this.options;
342
- if (className) this.wrapper.className = className;
343
-
344
- if (isNumber(x) || isNumber(y)) {
345
- Object.assign(this.wrapper.style, {
346
- left: `${x ?? 0}px`,
347
- top: `${y ?? 0}px`,
348
- });
349
- } else {
350
- Object.assign(this.wrapper.style, {
351
- [position === 'top' ? 'bottom' : 'top']: 'unset',
352
- [position === 'top' ? 'top' : 'bottom']: '0px',
353
- });
354
- }
355
-
356
- this.context.canvas.getContainer()?.appendChild(this.wrapper);
357
-
358
- return this.wrapper;
359
- }
360
-
361
326
  private upsertCanvas() {
362
- const wrapper = this.upsertWrapper();
363
327
  if (this.canvas) return this.canvas;
364
328
 
365
- const { height } = this.options;
366
- const [width] = this.context.canvas.getSize();
329
+ const { className, height, position } = this.options;
330
+ const graphCanvas = this.context.canvas;
331
+ const [width] = graphCanvas.getSize();
367
332
  const [top, , bottom] = this.padding;
368
333
 
369
- this.canvas = new Canvas({
370
- container: wrapper,
334
+ const [$container, canvas] = createPluginCanvas({
371
335
  width,
372
336
  height: height + top + bottom,
373
- renderer: this.context.options.renderer?.('main') || new CanvasRenderer(),
374
- supportsMutipleCanvasesInOneContainer: true,
337
+ graphCanvas,
338
+ className: 'timebar',
339
+ placement: position,
375
340
  });
376
341
 
342
+ this.container = $container;
343
+ if (className) $container.classList.add(className);
344
+ this.canvas = canvas;
345
+
377
346
  return this.canvas;
378
347
  }
379
348
 
@@ -437,9 +406,9 @@ export class Timebar extends BasePlugin<TimebarOptions> {
437
406
  this.originalData && graph.setData({ ...this.originalData });
438
407
  this.timebar?.destroy();
439
408
  this.canvas?.destroy();
440
- this.wrapper?.remove();
409
+ this.container?.remove();
441
410
  this.originalData = undefined;
442
- this.wrapper = undefined;
411
+ this.container = undefined;
443
412
  this.timebar = undefined;
444
413
  this.canvas = undefined;
445
414
 
@@ -1,8 +1,8 @@
1
1
  import type { RuntimeContext } from '../../runtime/types';
2
2
  import type { CornerPlacement } from '../../types';
3
- import { createPluginContainer, insertDOM } from '../../utils/dom';
4
3
  import type { BasePluginOptions } from '../base-plugin';
5
4
  import { BasePlugin } from '../base-plugin';
5
+ import { createPluginContainer, insertDOM } from '../utils/dom';
6
6
  import type { ToolbarItem } from './util';
7
7
  import { BUILD_IN_SVG_ICON, TOOLBAR_CSS, parsePositionToStyle } from './util';
8
8
 
@@ -0,0 +1,89 @@
1
+ import type { IRenderer } from '@antv/g';
2
+ import { Canvas as GCanvas } from '@antv/g';
3
+ import { Renderer } from '@antv/g-canvas';
4
+ import { Canvas } from '../../runtime/canvas';
5
+ import type { Placement } from '../../types';
6
+ import { parsePlacement } from '../../utils/placement';
7
+ import { createPluginContainer } from './dom';
8
+
9
+ interface Options {
10
+ /** <zh/> 插件宽度 | <en/> Plugin width */
11
+ width: number;
12
+ /** <zh/> 插件高度 | <en/> Plugin height */
13
+ height: number;
14
+ /** <zh/> 渲染器 | <en/> Render */
15
+ renderer?: IRenderer;
16
+ /** <zh/> 插件放置位置 | <en/> Plugin placement */
17
+ placement: Placement;
18
+ /** <zh/> 插件类名 | <en/> Plugin class name */
19
+ className: string;
20
+ /** <zh/> 指定插件放置容器 | <en/> Specify the plugin placement container */
21
+ container?: string | HTMLElement;
22
+ /** <zh/> 容器样式 | <en/> Container style */
23
+ containerStyle?: Partial<CSSStyleDeclaration>;
24
+ /** <zh/> G6 画布 | <en/> G6 canvas */
25
+ graphCanvas: Canvas;
26
+ }
27
+
28
+ /**
29
+ * <zh/> 创建插件画布
30
+ *
31
+ * <en/> Create a plugin canvas
32
+ * @param options - <zh/> 配置项 | <en/> options
33
+ * @returns <zh/> [容器, 画布] | <en/> [container, canvas]
34
+ */
35
+ export function createPluginCanvas(options: Options): [HTMLElement, GCanvas] {
36
+ const { width, height, renderer, containerStyle } = options;
37
+ const $container = getContainer(options);
38
+ const [x, y] = computePosition(options);
39
+
40
+ Object.assign($container.style, {
41
+ position: 'absolute',
42
+ left: x + 'px',
43
+ top: y + 'px',
44
+ width: width + 'px',
45
+ height: height + 'px',
46
+ ...containerStyle,
47
+ });
48
+
49
+ const canvas = new GCanvas({
50
+ width,
51
+ height,
52
+ container: $container,
53
+ renderer: renderer || new Renderer(),
54
+ });
55
+
56
+ return [$container, canvas];
57
+ }
58
+
59
+ /**
60
+ * <zh/> 获取容器
61
+ *
62
+ * <en/> Get container
63
+ * @param options - <zh/> 配置项 | <en/> options
64
+ * @returns <zh/> 容器 | <en/> container
65
+ */
66
+ function getContainer(options: Options) {
67
+ const { container, className, graphCanvas } = options;
68
+ if (container) {
69
+ return typeof container === 'string' ? document.getElementById(container)! : container;
70
+ }
71
+
72
+ const $container = createPluginContainer(className, false);
73
+ graphCanvas.getContainer()?.appendChild($container);
74
+ return $container;
75
+ }
76
+
77
+ /**
78
+ * <zh/> 计算容器位置
79
+ *
80
+ * <en/> Compute the position of the container
81
+ * @param options - <zh/> 配置项 | <en/> options
82
+ * @returns <zh/> 位置 | <en/> position
83
+ */
84
+ function computePosition(options: Options) {
85
+ const { width, height, placement, graphCanvas } = options;
86
+ const [W, H] = graphCanvas.getSize();
87
+ const [xRatio, yRatio] = parsePlacement(placement);
88
+ return [xRatio * (W - width), yRatio * (H - height)];
89
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * <zh/> 创建插件容器
3
+ *
4
+ * <en/> Create a plugin container
5
+ * @param type - <zh/> 插件类型 | <en/> plugin type
6
+ * @param cover - <zh/> 容器是否覆盖整个画布 | <en/> Whether the container covers the entire canvas
7
+ * @param style - <zh/> 额外样式 | <en/> Additional style
8
+ * @returns <zh/> 插件容器 | <en/> plugin container
9
+ */
10
+ export function createPluginContainer(type: string, cover = true, style?: Partial<CSSStyleDeclaration>): HTMLElement {
11
+ const container = document.createElement('div');
12
+
13
+ container.setAttribute('class', `g6-${type}`);
14
+
15
+ Object.assign(container.style, {
16
+ position: 'absolute',
17
+ display: 'block',
18
+ });
19
+
20
+ if (cover) {
21
+ Object.assign(container.style, {
22
+ inset: '0px',
23
+ height: '100%',
24
+ width: '100%',
25
+ overflow: 'hidden',
26
+ pointerEvents: 'none',
27
+ });
28
+ }
29
+
30
+ if (style) Object.assign(container.style, style);
31
+
32
+ return container;
33
+ }
34
+
35
+ /**
36
+ * <zh/> 创建 DOM 元素,如果存在则删除,再创建一个新的
37
+ *
38
+ * <en/> Create a DOM element, if exists, remove it and create a new one.
39
+ * @param id - <zh/> id | <en/> id
40
+ * @param tag - <zh/> 标签 | <en/> tag
41
+ * @param style - <zh/> 样式 | <en/> style
42
+ * @param innerHTML - <zh/> 内容 | <en/> innerHTML
43
+ * @param container - <zh/> 容器 | <en/> container
44
+ * @returns <zh/> 创建的 DOM 元素 | <en/> created DOM element
45
+ */
46
+ export function insertDOM(
47
+ id: string,
48
+ tag = 'div',
49
+ style: Partial<CSSStyleDeclaration> = {},
50
+ innerHTML = '',
51
+ container: HTMLElement = document.body,
52
+ ) {
53
+ const dom = document.getElementById(id);
54
+ if (dom) dom.remove();
55
+
56
+ const div = document.createElement(tag);
57
+ div.innerHTML = innerHTML;
58
+ div.id = id;
59
+
60
+ Object.assign(div.style, style);
61
+
62
+ container.appendChild(div);
63
+
64
+ return div;
65
+ }
@@ -1,7 +1,7 @@
1
1
  import type { RuntimeContext } from '../../runtime/types';
2
- import { createPluginContainer } from '../../utils/dom';
3
2
  import type { BasePluginOptions } from '../base-plugin';
4
3
  import { BasePlugin } from '../base-plugin';
4
+ import { createPluginContainer } from '../utils/dom';
5
5
  import { getImageWatermark, getTextWatermark } from './util';
6
6
 
7
7
  /**
package/src/preset.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import { runtime } from '@antv/g';
1
2
  import { registerBuiltInExtensions } from './registry/build-in';
2
3
 
4
+ runtime.enableMassiveParsedStyleAssignOptimization = true;
5
+
3
6
  registerBuiltInExtensions();
@@ -57,6 +57,7 @@ import {
57
57
  ConcentricLayout,
58
58
  D3ForceLayout,
59
59
  DagreLayout,
60
+ FishboneLayout,
60
61
  ForceAtlas2Layout,
61
62
  ForceLayout,
62
63
  FruchtermanLayout,
@@ -151,12 +152,13 @@ const BUILT_IN_EXTENSIONS: ExtensionRegistry = {
151
152
  'antv-dagre': AntVDagreLayout,
152
153
  'combo-combined': ComboCombinedLayout,
153
154
  'compact-box': compactBox,
155
+ 'd3-force': D3ForceLayout,
154
156
  'force-atlas2': ForceAtlas2Layout,
155
157
  circular: CircularLayout,
156
158
  concentric: ConcentricLayout,
157
- 'd3-force': D3ForceLayout,
158
159
  dagre: DagreLayout,
159
160
  dendrogram,
161
+ fishbone: FishboneLayout,
160
162
  force: ForceLayout,
161
163
  fruchterman: FruchtermanLayout,
162
164
  grid: GridLayout,
@@ -39,7 +39,7 @@ export class Animation {
39
39
  const { element, elementType, stage } = context;
40
40
  const options = getElementAnimationOptions(this.context.options, elementType, stage, localAnimation);
41
41
  cb?.before?.();
42
- const animation = executor(element, this.inferStyle(context, extendOptions), options);
42
+ const animation = options.length ? executor(element, this.inferStyle(context, extendOptions), options) : null;
43
43
 
44
44
  if (animation) {
45
45
  cb?.beforeAnimate?.(animation);
@@ -83,7 +83,10 @@ export class Animation {
83
83
  context: AnimationContext,
84
84
  options?: ExtendOptions,
85
85
  ): [Record<string, unknown>, Record<string, unknown>] {
86
- const { element, elementType, stage, originalStyle, modifiedStyle } = context;
86
+ const { element, elementType, stage, originalStyle, updatedStyle = {} } = context;
87
+
88
+ if (!context.modifiedStyle) context.modifiedStyle = { ...originalStyle, ...updatedStyle };
89
+ const { modifiedStyle } = context;
87
90
 
88
91
  const fromStyle: Record<string, unknown> = {};
89
92
  const toStyle: Record<string, unknown> = {};