@antv/g6 5.0.30 → 5.0.32

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 (148) 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/edges/base-edge.d.ts +3 -3
  5. package/dist/lib/elements/nodes/base-node.d.ts +3 -3
  6. package/dist/lib/elements/shapes/badge.d.ts +1 -1
  7. package/dist/lib/elements/shapes/base-shape.d.ts +1 -1
  8. package/dist/lib/exports.d.ts +1 -1
  9. package/dist/lib/plugins/legend.d.ts +22 -14
  10. package/dist/lib/plugins/minimap/index.d.ts +2 -4
  11. package/dist/lib/plugins/timebar.d.ts +1 -2
  12. package/dist/lib/plugins/utils/canvas.d.ts +31 -0
  13. package/dist/lib/plugins/utils/dom.d.ts +22 -0
  14. package/dist/lib/types/element.d.ts +0 -8
  15. package/dist/lib/utils/dom.d.ts +0 -26
  16. package/dist/lib/utils/style.d.ts +1 -1
  17. package/dist/lib/version.d.ts +1 -1
  18. package/esm/animations/types.d.ts +7 -1
  19. package/esm/elements/base-element.d.ts +3 -2
  20. package/esm/elements/base-element.js +2 -1
  21. package/esm/elements/base-element.js.map +1 -1
  22. package/esm/elements/combos/base-combo.js +6 -6
  23. package/esm/elements/combos/base-combo.js.map +1 -1
  24. package/esm/elements/edges/base-edge.d.ts +3 -3
  25. package/esm/elements/edges/base-edge.js +4 -4
  26. package/esm/elements/edges/base-edge.js.map +1 -1
  27. package/esm/elements/nodes/base-node.d.ts +3 -3
  28. package/esm/elements/nodes/base-node.js.map +1 -1
  29. package/esm/elements/shapes/badge.d.ts +1 -1
  30. package/esm/elements/shapes/base-shape.d.ts +1 -1
  31. package/esm/elements/shapes/base-shape.js.map +1 -1
  32. package/esm/exports.d.ts +1 -1
  33. package/esm/plugins/background/index.js +1 -2
  34. package/esm/plugins/background/index.js.map +1 -1
  35. package/esm/plugins/contextmenu/index.js +1 -1
  36. package/esm/plugins/contextmenu/index.js.map +1 -1
  37. package/esm/plugins/grid-line.js +3 -3
  38. package/esm/plugins/grid-line.js.map +1 -1
  39. package/esm/plugins/legend.d.ts +22 -14
  40. package/esm/plugins/legend.js +39 -51
  41. package/esm/plugins/legend.js.map +1 -1
  42. package/esm/plugins/minimap/index.d.ts +2 -4
  43. package/esm/plugins/minimap/index.js +13 -30
  44. package/esm/plugins/minimap/index.js.map +1 -1
  45. package/esm/plugins/timebar.d.ts +1 -2
  46. package/esm/plugins/timebar.js +15 -47
  47. package/esm/plugins/timebar.js.map +1 -1
  48. package/esm/plugins/toolbar/index.js +1 -1
  49. package/esm/plugins/toolbar/index.js.map +1 -1
  50. package/esm/plugins/utils/canvas.d.ts +31 -0
  51. package/esm/plugins/utils/canvas.js +55 -0
  52. package/esm/plugins/utils/canvas.js.map +1 -0
  53. package/esm/plugins/utils/dom.d.ts +22 -0
  54. package/esm/plugins/utils/dom.js +54 -0
  55. package/esm/plugins/utils/dom.js.map +1 -0
  56. package/esm/plugins/watermark/index.js +1 -1
  57. package/esm/plugins/watermark/index.js.map +1 -1
  58. package/esm/runtime/animation.js +5 -2
  59. package/esm/runtime/animation.js.map +1 -1
  60. package/esm/runtime/element.js +5 -9
  61. package/esm/runtime/element.js.map +1 -1
  62. package/esm/types/element.d.ts +0 -8
  63. package/esm/utils/dom.d.ts +0 -26
  64. package/esm/utils/dom.js +0 -65
  65. package/esm/utils/dom.js.map +1 -1
  66. package/esm/utils/style.d.ts +1 -1
  67. package/esm/utils/style.js +2 -2
  68. package/esm/utils/style.js.map +1 -1
  69. package/esm/version.d.ts +1 -1
  70. package/esm/version.js +1 -1
  71. package/lib/animations/types.d.ts +7 -1
  72. package/lib/elements/base-element.d.ts +3 -2
  73. package/lib/elements/base-element.js +2 -1
  74. package/lib/elements/base-element.js.map +1 -1
  75. package/lib/elements/combos/base-combo.js +6 -6
  76. package/lib/elements/combos/base-combo.js.map +1 -1
  77. package/lib/elements/edges/base-edge.d.ts +3 -3
  78. package/lib/elements/edges/base-edge.js +4 -4
  79. package/lib/elements/edges/base-edge.js.map +1 -1
  80. package/lib/elements/nodes/base-node.d.ts +3 -3
  81. package/lib/elements/nodes/base-node.js.map +1 -1
  82. package/lib/elements/shapes/badge.d.ts +1 -1
  83. package/lib/elements/shapes/base-shape.d.ts +1 -1
  84. package/lib/elements/shapes/base-shape.js.map +1 -1
  85. package/lib/exports.d.ts +1 -1
  86. package/lib/plugins/background/index.js +1 -2
  87. package/lib/plugins/background/index.js.map +1 -1
  88. package/lib/plugins/contextmenu/index.js +1 -1
  89. package/lib/plugins/contextmenu/index.js.map +1 -1
  90. package/lib/plugins/grid-line.js +3 -3
  91. package/lib/plugins/grid-line.js.map +1 -1
  92. package/lib/plugins/legend.d.ts +22 -14
  93. package/lib/plugins/legend.js +38 -50
  94. package/lib/plugins/legend.js.map +1 -1
  95. package/lib/plugins/minimap/index.d.ts +2 -4
  96. package/lib/plugins/minimap/index.js +13 -30
  97. package/lib/plugins/minimap/index.js.map +1 -1
  98. package/lib/plugins/timebar.d.ts +1 -2
  99. package/lib/plugins/timebar.js +15 -47
  100. package/lib/plugins/timebar.js.map +1 -1
  101. package/lib/plugins/toolbar/index.js +1 -1
  102. package/lib/plugins/toolbar/index.js.map +1 -1
  103. package/lib/plugins/utils/canvas.d.ts +31 -0
  104. package/lib/plugins/utils/canvas.js +58 -0
  105. package/lib/plugins/utils/canvas.js.map +1 -0
  106. package/lib/plugins/utils/dom.d.ts +22 -0
  107. package/lib/plugins/utils/dom.js +58 -0
  108. package/lib/plugins/utils/dom.js.map +1 -0
  109. package/lib/plugins/watermark/index.js +1 -1
  110. package/lib/plugins/watermark/index.js.map +1 -1
  111. package/lib/runtime/animation.js +5 -2
  112. package/lib/runtime/animation.js.map +1 -1
  113. package/lib/runtime/element.js +5 -9
  114. package/lib/runtime/element.js.map +1 -1
  115. package/lib/types/element.d.ts +0 -8
  116. package/lib/utils/dom.d.ts +0 -26
  117. package/lib/utils/dom.js +0 -68
  118. package/lib/utils/dom.js.map +1 -1
  119. package/lib/utils/style.d.ts +1 -1
  120. package/lib/utils/style.js +2 -2
  121. package/lib/utils/style.js.map +1 -1
  122. package/lib/version.d.ts +1 -1
  123. package/lib/version.js +1 -1
  124. package/package.json +1 -1
  125. package/src/animations/types.ts +7 -1
  126. package/src/elements/base-element.ts +5 -3
  127. package/src/elements/combos/base-combo.ts +6 -6
  128. package/src/elements/edges/base-edge.ts +6 -7
  129. package/src/elements/nodes/base-node.ts +2 -3
  130. package/src/elements/shapes/base-shape.ts +1 -4
  131. package/src/exports.ts +0 -1
  132. package/src/global.d.ts +5 -0
  133. package/src/plugins/background/index.ts +1 -2
  134. package/src/plugins/contextmenu/index.ts +1 -1
  135. package/src/plugins/grid-line.ts +3 -3
  136. package/src/plugins/legend.ts +67 -55
  137. package/src/plugins/minimap/index.ts +16 -52
  138. package/src/plugins/timebar.ts +16 -47
  139. package/src/plugins/toolbar/index.ts +1 -1
  140. package/src/plugins/utils/canvas.ts +89 -0
  141. package/src/plugins/utils/dom.ts +67 -0
  142. package/src/plugins/watermark/index.ts +1 -1
  143. package/src/runtime/animation.ts +5 -2
  144. package/src/runtime/element.ts +4 -9
  145. package/src/types/element.ts +0 -9
  146. package/src/utils/dom.ts +0 -80
  147. package/src/utils/style.ts +3 -6
  148. package/src/version.ts +1 -1
@@ -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,67 @@
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
+ position: 'unset',
23
+ gridArea: '1 / 1 / 2 / 2',
24
+ inset: '0px',
25
+ height: '100%',
26
+ width: '100%',
27
+ overflow: 'hidden',
28
+ pointerEvents: 'none',
29
+ });
30
+ }
31
+
32
+ if (style) Object.assign(container.style, style);
33
+
34
+ return container;
35
+ }
36
+
37
+ /**
38
+ * <zh/> 创建 DOM 元素,如果存在则删除,再创建一个新的
39
+ *
40
+ * <en/> Create a DOM element, if exists, remove it and create a new one.
41
+ * @param id - <zh/> id | <en/> id
42
+ * @param tag - <zh/> 标签 | <en/> tag
43
+ * @param style - <zh/> 样式 | <en/> style
44
+ * @param innerHTML - <zh/> 内容 | <en/> innerHTML
45
+ * @param container - <zh/> 容器 | <en/> container
46
+ * @returns <zh/> 创建的 DOM 元素 | <en/> created DOM element
47
+ */
48
+ export function insertDOM(
49
+ id: string,
50
+ tag = 'div',
51
+ style: Partial<CSSStyleDeclaration> = {},
52
+ innerHTML = '',
53
+ container: HTMLElement = document.body,
54
+ ) {
55
+ const dom = document.getElementById(id);
56
+ if (dom) dom.remove();
57
+
58
+ const div = document.createElement(tag);
59
+ div.innerHTML = innerHTML;
60
+ div.id = id;
61
+
62
+ Object.assign(div.style, style);
63
+
64
+ container.appendChild(div);
65
+
66
+ return div;
67
+ }
@@ -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
  /**
@@ -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> = {};
@@ -387,16 +387,11 @@ export class ElementController {
387
387
 
388
388
  this.emit(new ElementLifeCycleEvent(GraphEvent.BEFORE_ELEMENT_CREATE, elementType, datum), context);
389
389
 
390
- // if (context.stage === 'expand') {
391
- // // 如果是展开的元素,需要将其 zIndex 提升至目标元素的上层
392
- // const targetZIndex = this.getElementZIndex(context.target!);
393
- // if (!style.zIndex || style.zIndex < targetZIndex) style.zIndex = targetZIndex + (style.zIndex ?? 0);
394
- // }
395
390
  const element = this.container.appendChild(
396
391
  new Ctor({
397
392
  id,
393
+ context: this.context,
398
394
  style: {
399
- context: this.context,
400
395
  ...style,
401
396
  },
402
397
  }),
@@ -413,7 +408,7 @@ export class ElementController {
413
408
  elementType,
414
409
  stage,
415
410
  originalStyle: { ...element.attributes },
416
- modifiedStyle: { ...element.attributes, ...style },
411
+ updatedStyle: style,
417
412
  },
418
413
  {
419
414
  after: () => {
@@ -486,7 +481,7 @@ export class ElementController {
486
481
  elementType,
487
482
  stage: exactStage,
488
483
  originalStyle: { ...element.attributes },
489
- modifiedStyle: { ...element.attributes, ...style },
484
+ updatedStyle: style,
490
485
  },
491
486
  {
492
487
  before: () => {
@@ -559,7 +554,7 @@ export class ElementController {
559
554
  elementType,
560
555
  stage,
561
556
  originalStyle: { ...element.attributes },
562
- modifiedStyle: { ...element.attributes },
557
+ updatedStyle: {},
563
558
  },
564
559
  {
565
560
  after: () => {
@@ -1,6 +1,4 @@
1
1
  import type { DisplayObject } from '@antv/g';
2
- import { BaseShapeStyleProps } from '../elements/shapes';
3
- import type { RuntimeContext } from '../runtime/types';
4
2
  import type { ComboOptions, EdgeOptions, NodeOptions } from '../spec';
5
3
  import type { Point, Port } from '../types';
6
4
 
@@ -67,13 +65,6 @@ export type ElementType = 'node' | 'edge' | 'combo';
67
65
 
68
66
  export type ElementOptions = NodeOptions | EdgeOptions | ComboOptions;
69
67
 
70
- export interface BaseElementStyleProps extends BaseShapeStyleProps {
71
- /**
72
- * @internal
73
- */
74
- context?: RuntimeContext;
75
- }
76
-
77
68
  /**
78
69
  * <zh/> 元素方法
79
70
  *
package/src/utils/dom.ts CHANGED
@@ -44,83 +44,3 @@ export function sizeOf(container: HTMLElement | null): [number, number] {
44
44
  Math.max(isNumber(effectiveHeight) ? effectiveHeight : MIN_CHART_HEIGHT, MIN_CHART_HEIGHT),
45
45
  ];
46
46
  }
47
-
48
- /**
49
- * <zh/> 创建插件容器
50
- *
51
- * <en/> Create a plugin container
52
- * @param type - <zh/> 插件类型 | <en/> plugin type
53
- * @param cover - <zh/> 容器是否覆盖整个画布 | <en/> Whether the container covers the entire canvas
54
- * @param style - <zh/> 额外样式 | <en/> Additional style
55
- * @returns <zh/> 插件容器 | <en/> plugin container
56
- */
57
- export function createPluginContainer(type: string, cover = true, style?: Partial<CSSStyleDeclaration>): HTMLElement {
58
- const container = document.createElement('div');
59
-
60
- container.setAttribute('class', `g6-${type}`);
61
-
62
- Object.assign(container.style, {
63
- position: 'absolute',
64
- display: 'block',
65
- });
66
-
67
- if (cover) {
68
- Object.assign(container.style, {
69
- inset: '0px',
70
- height: '100%',
71
- width: '100%',
72
- overflow: 'hidden',
73
- pointerEvents: 'none',
74
- });
75
- }
76
-
77
- if (style) Object.assign(container.style, style);
78
-
79
- return container;
80
- }
81
-
82
- /**
83
- * Create a DOM element, if exists, remove it and create a new one.
84
- * @param id - id
85
- * @param tag - tag
86
- * @param style - style
87
- * @param innerHTML - innerHTML
88
- * @param container - container
89
- * @returns new DOM element
90
- */
91
- export function insertDOM(
92
- id: string,
93
- tag = 'div',
94
- style: Partial<CSSStyleDeclaration> = {},
95
- innerHTML = '',
96
- container: HTMLElement = document.body,
97
- ) {
98
- // 如果存在则删除
99
- const dom = document.getElementById(id);
100
- if (dom) dom.remove();
101
-
102
- // 重新创建
103
- const div = document.createElement(tag);
104
- div.innerHTML = innerHTML;
105
- div.id = id;
106
-
107
- Object.assign(div.style, style);
108
-
109
- container.appendChild(div);
110
-
111
- return div;
112
- }
113
-
114
- /**
115
- * Insert a DOM element before the first child of the container.
116
- * @param container - container
117
- * @param element - element
118
- */
119
- export function insertBefore(container: HTMLElement, element: HTMLElement) {
120
- const firstChild = container.firstChild;
121
- if (firstChild) {
122
- container.insertBefore(element, firstChild);
123
- } else {
124
- container.appendChild(element);
125
- }
126
- }
@@ -43,7 +43,7 @@ export function mergeOptions(opt1: DisplayObjectConfig<any>, opt2: DisplayObject
43
43
  const s1 = opt1?.style || {};
44
44
  const s2 = opt2?.style || {};
45
45
  return Object.assign({}, opt1, opt2, {
46
- style: Object.assign({}, s1, s2),
46
+ style: opt1?.style ? Object.assign({}, s1, s2) : s2,
47
47
  });
48
48
  }
49
49
 
@@ -61,10 +61,7 @@ export function mergeOptions(opt1: DisplayObjectConfig<any>, opt2: DisplayObject
61
61
  */
62
62
  export function getSubShapeStyle<T extends Record<string, any>>(
63
63
  style: T,
64
- ): Omit<
65
- T,
66
- 'x' | 'y' | 'z' | 'transform' | 'transformOrigin' | 'className' | 'class' | 'context' | 'zIndex' | 'visibility'
67
- > {
68
- const { x, y, z, class: cls, className, transform, transformOrigin, context, zIndex, visibility, ...rest } = style;
64
+ ): Omit<T, 'x' | 'y' | 'z' | 'transform' | 'transformOrigin' | 'className' | 'class' | 'zIndex' | 'visibility'> {
65
+ const { x, y, z, class: cls, className, transform, transformOrigin, zIndex, visibility, ...rest } = style;
69
66
  return rest;
70
67
  }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '5.0.30';
1
+ export const version = '5.0.32';