@antv/g6 5.0.34 → 5.0.35-beta.1

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 (139) hide show
  1. package/dist/g6.min.js +11 -11
  2. package/dist/lib/elements/shapes/base-shape.d.ts +0 -7
  3. package/dist/lib/layouts/types.d.ts +20 -0
  4. package/dist/lib/plugins/tooltip.d.ts +6 -0
  5. package/dist/lib/runtime/data.d.ts +2 -8
  6. package/dist/lib/runtime/element.d.ts +5 -2
  7. package/dist/lib/runtime/layout.d.ts +18 -1
  8. package/dist/lib/runtime/options.d.ts +9 -0
  9. package/dist/lib/runtime/transform.d.ts +2 -1
  10. package/dist/lib/spec/data.d.ts +0 -14
  11. package/dist/lib/transforms/base-transform.d.ts +2 -1
  12. package/dist/lib/utils/element.d.ts +9 -1
  13. package/dist/lib/utils/layout.d.ts +13 -1
  14. package/dist/lib/utils/transform.d.ts +2 -2
  15. package/dist/lib/version.d.ts +1 -1
  16. package/esm/animations/executor.js +3 -2
  17. package/esm/animations/executor.js.map +1 -1
  18. package/esm/behaviors/drag-element.js +9 -2
  19. package/esm/behaviors/drag-element.js.map +1 -1
  20. package/esm/elements/combos/base-combo.js +1 -1
  21. package/esm/elements/combos/base-combo.js.map +1 -1
  22. package/esm/elements/edges/base-edge.js +8 -2
  23. package/esm/elements/edges/base-edge.js.map +1 -1
  24. package/esm/elements/shapes/base-shape.d.ts +0 -7
  25. package/esm/elements/shapes/base-shape.js +22 -19
  26. package/esm/elements/shapes/base-shape.js.map +1 -1
  27. package/esm/layouts/types.d.ts +20 -0
  28. package/esm/plugins/background/index.js +1 -0
  29. package/esm/plugins/background/index.js.map +1 -1
  30. package/esm/plugins/grid-line.js +1 -0
  31. package/esm/plugins/grid-line.js.map +1 -1
  32. package/esm/plugins/tooltip.d.ts +6 -0
  33. package/esm/plugins/tooltip.js +8 -6
  34. package/esm/plugins/tooltip.js.map +1 -1
  35. package/esm/runtime/data.d.ts +2 -8
  36. package/esm/runtime/data.js +14 -18
  37. package/esm/runtime/data.js.map +1 -1
  38. package/esm/runtime/element.d.ts +5 -2
  39. package/esm/runtime/element.js +39 -15
  40. package/esm/runtime/element.js.map +1 -1
  41. package/esm/runtime/graph.js +19 -7
  42. package/esm/runtime/graph.js.map +1 -1
  43. package/esm/runtime/layout.d.ts +18 -1
  44. package/esm/runtime/layout.js +85 -20
  45. package/esm/runtime/layout.js.map +1 -1
  46. package/esm/runtime/options.d.ts +9 -0
  47. package/esm/runtime/options.js +49 -0
  48. package/esm/runtime/options.js.map +1 -0
  49. package/esm/runtime/transform.d.ts +2 -1
  50. package/esm/runtime/transform.js.map +1 -1
  51. package/esm/spec/data.d.ts +0 -14
  52. package/esm/transforms/base-transform.d.ts +2 -1
  53. package/esm/transforms/base-transform.js +1 -1
  54. package/esm/transforms/base-transform.js.map +1 -1
  55. package/esm/utils/element.d.ts +9 -1
  56. package/esm/utils/element.js +35 -1
  57. package/esm/utils/element.js.map +1 -1
  58. package/esm/utils/layout.d.ts +13 -1
  59. package/esm/utils/layout.js +14 -0
  60. package/esm/utils/layout.js.map +1 -1
  61. package/esm/utils/transform.d.ts +2 -2
  62. package/esm/utils/transform.js +13 -8
  63. package/esm/utils/transform.js.map +1 -1
  64. package/esm/version.d.ts +1 -1
  65. package/esm/version.js +1 -1
  66. package/esm/version.js.map +1 -1
  67. package/lib/animations/executor.js +3 -2
  68. package/lib/animations/executor.js.map +1 -1
  69. package/lib/behaviors/drag-element.js +9 -2
  70. package/lib/behaviors/drag-element.js.map +1 -1
  71. package/lib/elements/combos/base-combo.js +1 -1
  72. package/lib/elements/combos/base-combo.js.map +1 -1
  73. package/lib/elements/edges/base-edge.js +7 -1
  74. package/lib/elements/edges/base-edge.js.map +1 -1
  75. package/lib/elements/shapes/base-shape.d.ts +0 -7
  76. package/lib/elements/shapes/base-shape.js +21 -18
  77. package/lib/elements/shapes/base-shape.js.map +1 -1
  78. package/lib/layouts/types.d.ts +20 -0
  79. package/lib/plugins/background/index.js +1 -0
  80. package/lib/plugins/background/index.js.map +1 -1
  81. package/lib/plugins/grid-line.js +1 -0
  82. package/lib/plugins/grid-line.js.map +1 -1
  83. package/lib/plugins/tooltip.d.ts +6 -0
  84. package/lib/plugins/tooltip.js +8 -6
  85. package/lib/plugins/tooltip.js.map +1 -1
  86. package/lib/runtime/data.d.ts +2 -8
  87. package/lib/runtime/data.js +14 -18
  88. package/lib/runtime/data.js.map +1 -1
  89. package/lib/runtime/element.d.ts +5 -2
  90. package/lib/runtime/element.js +39 -15
  91. package/lib/runtime/element.js.map +1 -1
  92. package/lib/runtime/graph.js +21 -9
  93. package/lib/runtime/graph.js.map +1 -1
  94. package/lib/runtime/layout.d.ts +18 -1
  95. package/lib/runtime/layout.js +84 -19
  96. package/lib/runtime/layout.js.map +1 -1
  97. package/lib/runtime/options.d.ts +9 -0
  98. package/lib/runtime/options.js +52 -0
  99. package/lib/runtime/options.js.map +1 -0
  100. package/lib/runtime/transform.d.ts +2 -1
  101. package/lib/runtime/transform.js.map +1 -1
  102. package/lib/spec/data.d.ts +0 -14
  103. package/lib/transforms/base-transform.d.ts +2 -1
  104. package/lib/transforms/base-transform.js +1 -1
  105. package/lib/transforms/base-transform.js.map +1 -1
  106. package/lib/utils/element.d.ts +9 -1
  107. package/lib/utils/element.js +35 -0
  108. package/lib/utils/element.js.map +1 -1
  109. package/lib/utils/layout.d.ts +13 -1
  110. package/lib/utils/layout.js +15 -0
  111. package/lib/utils/layout.js.map +1 -1
  112. package/lib/utils/transform.d.ts +2 -2
  113. package/lib/utils/transform.js +13 -8
  114. package/lib/utils/transform.js.map +1 -1
  115. package/lib/version.d.ts +1 -1
  116. package/lib/version.js +1 -1
  117. package/lib/version.js.map +1 -1
  118. package/package.json +2 -2
  119. package/src/animations/executor.ts +4 -4
  120. package/src/behaviors/drag-element.ts +9 -2
  121. package/src/elements/combos/base-combo.ts +1 -1
  122. package/src/elements/edges/base-edge.ts +9 -5
  123. package/src/elements/shapes/base-shape.ts +21 -19
  124. package/src/layouts/types.ts +20 -0
  125. package/src/plugins/background/index.ts +1 -0
  126. package/src/plugins/grid-line.ts +1 -0
  127. package/src/plugins/tooltip.ts +11 -4
  128. package/src/runtime/data.ts +14 -19
  129. package/src/runtime/element.ts +62 -13
  130. package/src/runtime/graph.ts +19 -8
  131. package/src/runtime/layout.ts +79 -23
  132. package/src/runtime/options.ts +52 -0
  133. package/src/runtime/transform.ts +2 -0
  134. package/src/spec/data.ts +0 -14
  135. package/src/transforms/base-transform.ts +3 -1
  136. package/src/utils/element.ts +21 -2
  137. package/src/utils/layout.ts +16 -1
  138. package/src/utils/transform.ts +13 -9
  139. package/src/version.ts +1 -1
@@ -1,5 +1,5 @@
1
- import type { AABB, DisplayObject, TextStyleProps } from '@antv/g';
2
- import { get, isString, set } from '@antv/util';
1
+ import type { AABB, BaseStyleProps, DisplayObject, TextStyleProps } from '@antv/g';
2
+ import { get, isNumber, isString, set } from '@antv/util';
3
3
  import { BaseCombo, BaseEdge, BaseNode } from '../elements';
4
4
  import type { Combo, Edge, Element, Node, NodePortStyleProps, Placement, Point, TriangleDirection } from '../types';
5
5
  import type { NodeLabelStyleProps, Port } from '../types/node';
@@ -467,6 +467,25 @@ export function isVisible(element: DisplayObject) {
467
467
  return get(element, ['style', 'visibility']) !== 'hidden';
468
468
  }
469
469
 
470
+ /**
471
+ * <zh/> 设置元素属性(优化性能)
472
+ *
473
+ * <en/> Set element attributes (optimize performance)
474
+ * @param element - <zh/> 元素 | <en/> element
475
+ * @param style - <zh/> 样式 | <en/> style
476
+ */
477
+ export function setAttributes(element: DisplayObject, style: BaseStyleProps) {
478
+ const { zIndex, transform, transformOrigin, visibility, cursor, clipPath, ...rest } = style;
479
+ Object.assign(element.attributes, rest);
480
+
481
+ if (transform) element.setAttribute('transform', transform);
482
+ if (isNumber(zIndex)) element.setAttribute('zIndex', zIndex);
483
+ if (transformOrigin) element.setAttribute('transformOrigin', transformOrigin);
484
+ if (visibility) element.setAttribute('visibility', visibility);
485
+ if (cursor) element.setAttribute('cursor', cursor);
486
+ if (clipPath) element.setAttribute('clipPath', clipPath);
487
+ }
488
+
470
489
  /**
471
490
  * <zh/> 更新图形样式
472
491
  *
@@ -9,7 +9,7 @@ import type { LayoutMapping, Graph as LayoutModel, Node as LayoutNodeData } from
9
9
  import type { AntVLayout } from '../layouts/types';
10
10
  import type { RuntimeContext } from '../runtime/types';
11
11
  import type { GraphData } from '../spec/data';
12
- import type { STDLayoutOptions } from '../spec/layout';
12
+ import type { LayoutOptions, STDLayoutOptions } from '../spec/layout';
13
13
  import type { AdaptiveLayout, ID } from '../types';
14
14
 
15
15
  /**
@@ -49,6 +49,21 @@ export function isPositionSpecified(data: Record<string, unknown>) {
49
49
  return isNumber(data.x) && isNumber(data.y);
50
50
  }
51
51
 
52
+ /**
53
+ * <zh/> 是否是前布局
54
+ *
55
+ * <en/> Is pre-layout
56
+ * @remarks
57
+ * <zh/> 前布局是指在初始化元素前计算布局,适用于一些布局需要提前计算位置的场景。
58
+ *
59
+ * <en/> Pre-layout refers to calculating the layout before initializing the elements, which is suitable for some layouts that need to calculate the position in advance.
60
+ * @param options - <zh/> 布局配置项 | <en/> Layout options
61
+ * @returns <zh/> 是否是前布局 | <en/> Is it a pre-layout
62
+ */
63
+ export function isPreLayout(options?: LayoutOptions) {
64
+ return !Array.isArray(options) && options?.preLayout;
65
+ }
66
+
52
67
  /**
53
68
  * <zh/> 将图布局结果转换为 G6 数据
54
69
  *
@@ -1,4 +1,5 @@
1
1
  import type { TransformArray } from '@antv/g';
2
+ import { isNumber } from '@antv/util';
2
3
 
3
4
  /**
4
5
  * <zh/> 从 transform 字符串中替换 translate 部分
@@ -8,36 +9,39 @@ import type { TransformArray } from '@antv/g';
8
9
  * @param y - <zh/> y | <en/> y
9
10
  * @param z - <zh/> z | <en/> z
10
11
  * @param transform - <zh/> transform 字符串 | <en/> transform string
11
- * @returns <zh/> 替换后的 transform 字符串 | <en/> replaced transform string
12
+ * @returns <zh/> 替换后的 transform 字符串,返回 null 表示无需替换 | <en/> the replaced transform string, return null means no need to replace
12
13
  */
13
14
  export function replaceTranslateInTransform(
14
15
  x: number,
15
16
  y: number,
16
- z: number,
17
- transform: string | TransformArray,
17
+ z?: number,
18
+ transform: string | TransformArray = [],
18
19
  ): string | TransformArray | null {
20
+ if (!transform && x === 0 && y === 0 && z === 0) return null;
21
+
19
22
  if (Array.isArray(transform)) {
20
- let hasTranslate = false;
23
+ let translateIndex = -1;
21
24
  const newTransform: TransformArray = [];
22
25
 
23
26
  for (let i = 0; i < transform.length; i++) {
24
27
  const t = transform[i];
25
28
  if (t[0] === 'translate') {
26
29
  if (t[1] === x && t[2] === y) return null;
27
- hasTranslate = true;
30
+ translateIndex = i;
28
31
  newTransform.push(['translate', x, y]);
29
32
  } else if (t[0] === 'translate3d') {
30
33
  if (t[1] === x && t[2] === y && t[3] === z) return null;
31
- hasTranslate = true;
32
- newTransform.push(['translate3d', x, y, z]);
34
+ translateIndex = i;
35
+ newTransform.push(['translate3d', x, y, z ?? 0]);
33
36
  } else {
34
37
  newTransform.push(t);
35
38
  }
36
39
  }
37
40
 
38
- if (!hasTranslate) {
39
- newTransform.splice(0, 0, z === 0 ? ['translate', x, y] : ['translate3d', x, y, z]);
41
+ if (translateIndex === -1) {
42
+ newTransform.splice(0, 0, isNumber(z) ? ['translate3d', x, y, z ?? 0] : ['translate', x, y]);
40
43
  }
44
+ if (newTransform.length === 0) return null;
41
45
  return newTransform;
42
46
  }
43
47
 
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '5.0.34';
1
+ export const version = '5.0.35-beta.1';