@antv/g6 5.0.32 → 5.0.34

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 (197) hide show
  1. package/README.md +33 -34
  2. package/README.zh-CN.md +117 -0
  3. package/dist/g6.min.js +29 -29
  4. package/dist/lib/behaviors/collapse-expand.d.ts +6 -0
  5. package/dist/lib/behaviors/drag-element.d.ts +1 -1
  6. package/dist/lib/behaviors/optimize-viewport-transform.d.ts +1 -1
  7. package/dist/lib/elements/edges/base-edge.d.ts +5 -5
  8. package/dist/lib/elements/nodes/base-node.d.ts +2 -0
  9. package/dist/lib/elements/nodes/html.d.ts +4 -0
  10. package/dist/lib/elements/shapes/base-shape.d.ts +2 -2
  11. package/dist/lib/exports.d.ts +3 -2
  12. package/dist/lib/layouts/fishbone.d.ts +2 -1
  13. package/dist/lib/layouts/index.d.ts +2 -0
  14. package/dist/lib/layouts/snake.d.ts +80 -0
  15. package/dist/lib/layouts/types.d.ts +3 -1
  16. package/dist/lib/plugins/minimap/index.d.ts +1 -1
  17. package/dist/lib/plugins/snapline/index.d.ts +1 -1
  18. package/dist/lib/runtime/data.d.ts +1 -1
  19. package/dist/lib/runtime/element.d.ts +29 -2
  20. package/dist/lib/runtime/graph.d.ts +11 -9
  21. package/dist/lib/runtime/viewport.d.ts +22 -2
  22. package/dist/lib/spec/canvas.d.ts +26 -2
  23. package/dist/lib/spec/data.d.ts +2 -2
  24. package/dist/lib/spec/graph.d.ts +60 -12
  25. package/dist/lib/spec/viewport.d.ts +4 -0
  26. package/dist/lib/utils/cache.d.ts +5 -5
  27. package/dist/lib/utils/event/events.d.ts +4 -4
  28. package/dist/lib/utils/id.d.ts +1 -1
  29. package/dist/lib/utils/style.d.ts +5 -5
  30. package/dist/lib/utils/visibility.d.ts +1 -2
  31. package/dist/lib/version.d.ts +1 -1
  32. package/esm/behaviors/collapse-expand.d.ts +6 -0
  33. package/esm/behaviors/collapse-expand.js +4 -3
  34. package/esm/behaviors/collapse-expand.js.map +1 -1
  35. package/esm/behaviors/drag-element.d.ts +1 -1
  36. package/esm/behaviors/optimize-viewport-transform.d.ts +1 -1
  37. package/esm/behaviors/optimize-viewport-transform.js +1 -1
  38. package/esm/behaviors/optimize-viewport-transform.js.map +1 -1
  39. package/esm/elements/edges/base-edge.d.ts +5 -5
  40. package/esm/elements/nodes/base-node.d.ts +2 -0
  41. package/esm/elements/nodes/base-node.js +2 -2
  42. package/esm/elements/nodes/base-node.js.map +1 -1
  43. package/esm/elements/nodes/html.d.ts +4 -0
  44. package/esm/elements/nodes/html.js +7 -0
  45. package/esm/elements/nodes/html.js.map +1 -1
  46. package/esm/elements/shapes/base-shape.d.ts +2 -2
  47. package/esm/elements/shapes/base-shape.js +3 -3
  48. package/esm/elements/shapes/base-shape.js.map +1 -1
  49. package/esm/exports.d.ts +3 -2
  50. package/esm/exports.js +1 -1
  51. package/esm/exports.js.map +1 -1
  52. package/esm/layouts/fishbone.d.ts +2 -1
  53. package/esm/layouts/fishbone.js +1 -1
  54. package/esm/layouts/fishbone.js.map +1 -1
  55. package/esm/layouts/index.d.ts +2 -0
  56. package/esm/layouts/index.js +1 -0
  57. package/esm/layouts/index.js.map +1 -1
  58. package/esm/layouts/snake.d.ts +80 -0
  59. package/esm/layouts/snake.js +162 -0
  60. package/esm/layouts/snake.js.map +1 -0
  61. package/esm/layouts/types.d.ts +3 -1
  62. package/esm/plugins/hull/util.js +6 -1
  63. package/esm/plugins/hull/util.js.map +1 -1
  64. package/esm/plugins/minimap/index.d.ts +1 -1
  65. package/esm/plugins/snapline/index.d.ts +1 -1
  66. package/esm/preset.js +0 -2
  67. package/esm/preset.js.map +1 -1
  68. package/esm/registry/build-in.js +2 -1
  69. package/esm/registry/build-in.js.map +1 -1
  70. package/esm/runtime/data.d.ts +1 -1
  71. package/esm/runtime/data.js +8 -3
  72. package/esm/runtime/data.js.map +1 -1
  73. package/esm/runtime/element.d.ts +29 -2
  74. package/esm/runtime/element.js +34 -4
  75. package/esm/runtime/element.js.map +1 -1
  76. package/esm/runtime/graph.d.ts +11 -9
  77. package/esm/runtime/graph.js +20 -15
  78. package/esm/runtime/graph.js.map +1 -1
  79. package/esm/runtime/viewport.d.ts +22 -2
  80. package/esm/runtime/viewport.js +12 -11
  81. package/esm/runtime/viewport.js.map +1 -1
  82. package/esm/spec/canvas.d.ts +26 -2
  83. package/esm/spec/data.d.ts +2 -2
  84. package/esm/spec/graph.d.ts +60 -12
  85. package/esm/spec/viewport.d.ts +4 -0
  86. package/esm/transforms/place-radial-labels.js +6 -1
  87. package/esm/transforms/place-radial-labels.js.map +1 -1
  88. package/esm/utils/cache.d.ts +5 -5
  89. package/esm/utils/cache.js +5 -5
  90. package/esm/utils/event/events.d.ts +4 -4
  91. package/esm/utils/id.d.ts +1 -1
  92. package/esm/utils/style.d.ts +5 -5
  93. package/esm/utils/style.js +5 -5
  94. package/esm/utils/visibility.d.ts +1 -2
  95. package/esm/utils/visibility.js +8 -34
  96. package/esm/utils/visibility.js.map +1 -1
  97. package/esm/version.d.ts +1 -1
  98. package/esm/version.js +1 -1
  99. package/lib/behaviors/collapse-expand.d.ts +6 -0
  100. package/lib/behaviors/collapse-expand.js +4 -3
  101. package/lib/behaviors/collapse-expand.js.map +1 -1
  102. package/lib/behaviors/drag-element.d.ts +1 -1
  103. package/lib/behaviors/optimize-viewport-transform.d.ts +1 -1
  104. package/lib/behaviors/optimize-viewport-transform.js +1 -1
  105. package/lib/behaviors/optimize-viewport-transform.js.map +1 -1
  106. package/lib/elements/edges/base-edge.d.ts +5 -5
  107. package/lib/elements/edges/base-edge.js +17 -7
  108. package/lib/elements/edges/base-edge.js.map +1 -1
  109. package/lib/elements/nodes/base-node.d.ts +2 -0
  110. package/lib/elements/nodes/base-node.js +2 -2
  111. package/lib/elements/nodes/base-node.js.map +1 -1
  112. package/lib/elements/nodes/html.d.ts +4 -0
  113. package/lib/elements/nodes/html.js +7 -0
  114. package/lib/elements/nodes/html.js.map +1 -1
  115. package/lib/elements/shapes/base-shape.d.ts +2 -2
  116. package/lib/elements/shapes/base-shape.js +3 -3
  117. package/lib/elements/shapes/base-shape.js.map +1 -1
  118. package/lib/exports.d.ts +3 -2
  119. package/lib/exports.js +3 -2
  120. package/lib/exports.js.map +1 -1
  121. package/lib/layouts/fishbone.d.ts +2 -1
  122. package/lib/layouts/fishbone.js +2 -2
  123. package/lib/layouts/fishbone.js.map +1 -1
  124. package/lib/layouts/index.d.ts +2 -0
  125. package/lib/layouts/index.js +3 -1
  126. package/lib/layouts/index.js.map +1 -1
  127. package/lib/layouts/snake.d.ts +80 -0
  128. package/lib/layouts/snake.js +166 -0
  129. package/lib/layouts/snake.js.map +1 -0
  130. package/lib/layouts/types.d.ts +3 -1
  131. package/lib/plugins/hull/util.js +5 -0
  132. package/lib/plugins/hull/util.js.map +1 -1
  133. package/lib/plugins/minimap/index.d.ts +1 -1
  134. package/lib/plugins/snapline/index.d.ts +1 -1
  135. package/lib/preset.js +0 -2
  136. package/lib/preset.js.map +1 -1
  137. package/lib/registry/build-in.js +1 -0
  138. package/lib/registry/build-in.js.map +1 -1
  139. package/lib/runtime/data.d.ts +1 -1
  140. package/lib/runtime/data.js +7 -2
  141. package/lib/runtime/data.js.map +1 -1
  142. package/lib/runtime/element.d.ts +29 -2
  143. package/lib/runtime/element.js +34 -4
  144. package/lib/runtime/element.js.map +1 -1
  145. package/lib/runtime/graph.d.ts +11 -9
  146. package/lib/runtime/graph.js +20 -15
  147. package/lib/runtime/graph.js.map +1 -1
  148. package/lib/runtime/viewport.d.ts +22 -2
  149. package/lib/runtime/viewport.js +12 -11
  150. package/lib/runtime/viewport.js.map +1 -1
  151. package/lib/spec/canvas.d.ts +26 -2
  152. package/lib/spec/data.d.ts +2 -2
  153. package/lib/spec/graph.d.ts +60 -12
  154. package/lib/spec/viewport.d.ts +4 -0
  155. package/lib/transforms/place-radial-labels.js +6 -1
  156. package/lib/transforms/place-radial-labels.js.map +1 -1
  157. package/lib/utils/cache.d.ts +5 -5
  158. package/lib/utils/cache.js +5 -5
  159. package/lib/utils/event/events.d.ts +4 -4
  160. package/lib/utils/id.d.ts +1 -1
  161. package/lib/utils/style.d.ts +5 -5
  162. package/lib/utils/style.js +5 -5
  163. package/lib/utils/visibility.d.ts +1 -2
  164. package/lib/utils/visibility.js +8 -34
  165. package/lib/utils/visibility.js.map +1 -1
  166. package/lib/version.d.ts +1 -1
  167. package/lib/version.js +1 -1
  168. package/package.json +8 -8
  169. package/src/behaviors/collapse-expand.ts +10 -3
  170. package/src/behaviors/optimize-viewport-transform.ts +2 -2
  171. package/src/elements/edges/base-edge.ts +5 -5
  172. package/src/elements/nodes/base-node.ts +4 -2
  173. package/src/elements/nodes/html.ts +9 -0
  174. package/src/elements/shapes/base-shape.ts +3 -3
  175. package/src/exports.ts +3 -1
  176. package/src/layouts/fishbone.ts +3 -2
  177. package/src/layouts/index.ts +3 -0
  178. package/src/layouts/snake.ts +235 -0
  179. package/src/layouts/types.ts +5 -1
  180. package/src/plugins/hull/util.ts +7 -1
  181. package/src/plugins/minimap/index.ts +1 -1
  182. package/src/preset.ts +0 -3
  183. package/src/registry/build-in.ts +2 -0
  184. package/src/runtime/data.ts +11 -4
  185. package/src/runtime/element.ts +51 -4
  186. package/src/runtime/graph.ts +21 -17
  187. package/src/runtime/viewport.ts +36 -10
  188. package/src/spec/canvas.ts +26 -2
  189. package/src/spec/data.ts +2 -2
  190. package/src/spec/graph.ts +60 -12
  191. package/src/spec/viewport.ts +4 -0
  192. package/src/transforms/place-radial-labels.ts +5 -1
  193. package/src/utils/cache.ts +5 -5
  194. package/src/utils/style.ts +5 -5
  195. package/src/utils/visibility.ts +6 -35
  196. package/src/version.ts +1 -1
  197. package/README.en-US.md +0 -118
@@ -17,7 +17,7 @@ export declare function computeElementCallbackStyle(callableStyle: Record<string
17
17
  /**
18
18
  * <zh/> 合并图形配置项
19
19
  *
20
- * <en/> Merge graphic configuration
20
+ * <en/> Merge shape configuration
21
21
  * @param opt1 - <zh/> 配置项1 | <en/> configuration 1
22
22
  * @param opt2 - <zh/> 配置项2 | <en/> configuration 2
23
23
  * @returns <zh/> 合并后的配置项 | <en/> merged configuration
@@ -26,13 +26,13 @@ export declare function mergeOptions(opt1: DisplayObjectConfig<any>, opt2: Displ
26
26
  /**
27
27
  * <zh/> 获取图形子图形样式
28
28
  *
29
- * <en/> Get the style of the sub-shape of the graphic
30
- * @param style - <zh/> 图形样式 | <en/> graphic style
29
+ * <en/> Get the style of the sub-shape of the shape
30
+ * @param style - <zh/> 图形样式 | <en/> shape style
31
31
  * @returns <zh/> 子图形样式 | <en/> sub-shape style
32
32
  * @remarks
33
33
  * <zh/> 从给定的属性对象中提取图形样式属性。删除特定的属性,如位置、变换和类名
34
34
  *
35
- * <en/> Extracts the graphic style properties from a given attribute object.
36
- * Removes specific properties like position, transformation, and class name.
35
+ * <en/> Extracts the shape styles from a given attribute object.
36
+ * Removes specific styles like position, transformation, and class name.
37
37
  */
38
38
  export declare function getSubShapeStyle<T extends Record<string, any>>(style: T): Omit<T, 'x' | 'y' | 'z' | 'transform' | 'transformOrigin' | 'className' | 'class' | 'zIndex' | 'visibility'>;
@@ -35,7 +35,7 @@ function computeElementCallbackStyle(callableStyle, context) {
35
35
  /**
36
36
  * <zh/> 合并图形配置项
37
37
  *
38
- * <en/> Merge graphic configuration
38
+ * <en/> Merge shape configuration
39
39
  * @param opt1 - <zh/> 配置项1 | <en/> configuration 1
40
40
  * @param opt2 - <zh/> 配置项2 | <en/> configuration 2
41
41
  * @returns <zh/> 合并后的配置项 | <en/> merged configuration
@@ -50,14 +50,14 @@ function mergeOptions(opt1, opt2) {
50
50
  /**
51
51
  * <zh/> 获取图形子图形样式
52
52
  *
53
- * <en/> Get the style of the sub-shape of the graphic
54
- * @param style - <zh/> 图形样式 | <en/> graphic style
53
+ * <en/> Get the style of the sub-shape of the shape
54
+ * @param style - <zh/> 图形样式 | <en/> shape style
55
55
  * @returns <zh/> 子图形样式 | <en/> sub-shape style
56
56
  * @remarks
57
57
  * <zh/> 从给定的属性对象中提取图形样式属性。删除特定的属性,如位置、变换和类名
58
58
  *
59
- * <en/> Extracts the graphic style properties from a given attribute object.
60
- * Removes specific properties like position, transformation, and class name.
59
+ * <en/> Extracts the shape styles from a given attribute object.
60
+ * Removes specific styles like position, transformation, and class name.
61
61
  */
62
62
  function getSubShapeStyle(style) {
63
63
  const { x, y, z, class: cls, className, transform, transformOrigin, zIndex, visibility } = style, rest = __rest(style, ["x", "y", "z", "class", "className", "transform", "transformOrigin", "zIndex", "visibility"]);
@@ -5,11 +5,10 @@ import type { BaseStyleProps, DisplayObject } from '@antv/g';
5
5
  * <en/> Set the visibility of the shape instance
6
6
  * @param shape - <zh/> 图形实例 | <en/> shape instance
7
7
  * @param value - <zh/> 可见性 | <en/> visibility
8
- * @param inherited - <zh/> 是否是来自继承样式 | <en/> Whether it is from inherited styles
9
8
  * @param filter - <zh/> 筛选出需要设置可见性的图形 | <en/> Filter out the shapes that need to set visibility
10
9
  * @remarks
11
10
  * <zh/> 在设置 enableCSSParsing 为 false 的情况下,复合图形无法继承父属性,因此需要对所有子图形应用相同的可见性
12
11
  *
13
12
  * <en/> After setting enableCSSParsing to false, the compound shape cannot inherit the parent attribute, so the same visibility needs to be applied to all child shapes
14
13
  */
15
- export declare function setVisibility(shape: DisplayObject, value: BaseStyleProps['visibility'], inherited?: boolean, filter?: (shape: DisplayObject) => boolean): void;
14
+ export declare function setVisibility(shape: DisplayObject, value: BaseStyleProps['visibility'], filter?: (shape: DisplayObject) => boolean): void;
@@ -1,52 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setVisibility = setVisibility;
4
- const ORIGINAL_MAP = new WeakMap();
5
4
  /**
6
5
  * <zh/> 设置图形实例的可见性
7
6
  *
8
7
  * <en/> Set the visibility of the shape instance
9
8
  * @param shape - <zh/> 图形实例 | <en/> shape instance
10
9
  * @param value - <zh/> 可见性 | <en/> visibility
11
- * @param inherited - <zh/> 是否是来自继承样式 | <en/> Whether it is from inherited styles
12
10
  * @param filter - <zh/> 筛选出需要设置可见性的图形 | <en/> Filter out the shapes that need to set visibility
13
11
  * @remarks
14
12
  * <zh/> 在设置 enableCSSParsing 为 false 的情况下,复合图形无法继承父属性,因此需要对所有子图形应用相同的可见性
15
13
  *
16
14
  * <en/> After setting enableCSSParsing to false, the compound shape cannot inherit the parent attribute, so the same visibility needs to be applied to all child shapes
17
15
  */
18
- function setVisibility(shape, value, inherited = false, filter) {
19
- if (value === undefined)
20
- return;
21
- const traverse = (current, scope = value) => {
22
- const walk = (val = scope) => current.childNodes.forEach((node) => traverse(node, val));
23
- if (filter && !filter(current))
24
- return walk();
25
- if (!inherited && current === shape) {
26
- shape.style.visibility = value;
27
- ORIGINAL_MAP.delete(shape);
28
- walk(value);
29
- }
30
- else {
31
- if (!ORIGINAL_MAP.has(current))
32
- ORIGINAL_MAP.set(current, current.style.visibility);
33
- const computedValue = scope === 'hidden' || getOriginalValue(current) === 'hidden' ? 'hidden' : 'visible';
34
- current.style.visibility = computedValue;
35
- walk(computedValue);
36
- }
16
+ function setVisibility(shape, value, filter) {
17
+ const callback = (node) => {
18
+ if (filter && !filter(node))
19
+ return;
20
+ node.style.visibility = value;
37
21
  };
38
- traverse(shape);
39
- }
40
- /**
41
- * <zh/> 获取图形原本的可见性
42
- *
43
- * <en/> Get the original visibility of the shape
44
- * @param shape - <zh/> 图形实例 | <en/> shape instance
45
- * @returns <zh/> 可见性 | <en/> visibility
46
- */
47
- function getOriginalValue(shape) {
48
- if (ORIGINAL_MAP.has(shape))
49
- return ORIGINAL_MAP.get(shape);
50
- return shape.style.visibility;
22
+ shape.forEach((node) => {
23
+ callback(node);
24
+ });
51
25
  }
52
26
  //# sourceMappingURL=visibility.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"visibility.js","sourceRoot":"src/","sources":["utils/visibility.ts"],"names":[],"mappings":";;AAiBA,sCA2BC;AA1CD,MAAM,YAAY,GAAG,IAAI,OAAO,EAA+C,CAAC;AAEhF;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,KAAoB,EACpB,KAAmC,EACnC,SAAS,GAAG,KAAK,EACjB,MAA0C;IAE1C,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO;IAEhC,MAAM,QAAQ,GAAG,CAAC,OAAsB,EAAE,KAAK,GAAG,KAAK,EAAQ,EAAE;QAC/D,MAAM,IAAI,GAAG,CAAC,GAAG,GAAG,KAAK,EAAQ,EAAE,CAAE,OAAO,CAAC,UAA8B,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;QAEnH,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;YAAE,OAAO,IAAI,EAAE,CAAC;QAE9C,IAAI,CAAC,SAAS,IAAI,OAAO,KAAK,KAAK,EAAE,CAAC;YACpC,KAAK,CAAC,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC;YAC/B,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC3B,IAAI,CAAC,KAAK,CAAC,CAAC;QACd,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC;gBAAE,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YAEpF,MAAM,aAAa,GAAG,KAAK,KAAK,QAAQ,IAAI,gBAAgB,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;YAC1G,OAAO,CAAC,KAAK,CAAC,UAAU,GAAG,aAAa,CAAC;YACzC,IAAI,CAAC,aAAa,CAAC,CAAC;QACtB,CAAC;IACH,CAAC,CAAC;IAEF,QAAQ,CAAC,KAAK,CAAC,CAAC;AAClB,CAAC;AAED;;;;;;GAMG;AACH,SAAS,gBAAgB,CAAC,KAAoB;IAC5C,IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,OAAO,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC5D,OAAO,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC;AAChC,CAAC"}
1
+ {"version":3,"file":"visibility.js","sourceRoot":"src/","sources":["utils/visibility.ts"],"names":[],"mappings":";;AAcA,sCAaC;AAzBD;;;;;;;;;;;GAWG;AACH,SAAgB,aAAa,CAC3B,KAAoB,EACpB,KAAmC,EACnC,MAA0C;IAE1C,MAAM,QAAQ,GAAG,CAAC,IAAmB,EAAE,EAAE;QACvC,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YAAE,OAAO;QACpC,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC;IAChC,CAAC,CAAC;IAEF,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACrB,QAAQ,CAAC,IAAqB,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;AACL,CAAC"}
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.0.32";
1
+ export declare const version = "5.0.34";
package/lib/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
- exports.version = '5.0.32';
4
+ exports.version = '5.0.34';
5
5
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/g6",
3
- "version": "5.0.32",
3
+ "version": "5.0.34",
4
4
  "description": "A Graph Visualization Framework in JavaScript",
5
5
  "keywords": [
6
6
  "antv",
@@ -33,12 +33,12 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "@antv/algorithm": "^0.1.26",
36
- "@antv/component": "^2.1.1",
36
+ "@antv/component": "^2.1.2",
37
37
  "@antv/event-emitter": "^0.1.3",
38
- "@antv/g": "^6.1.7",
39
- "@antv/g-canvas": "^2.0.24",
40
- "@antv/g-plugin-dragndrop": "^2.0.18",
41
- "@antv/graphlib": "^2.0.3",
38
+ "@antv/g": "^6.1.14",
39
+ "@antv/g-canvas": "^2.0.32",
40
+ "@antv/g-plugin-dragndrop": "^2.0.25",
41
+ "@antv/graphlib": "^2.0.4",
42
42
  "@antv/hierarchy": "^0.6.14",
43
43
  "@antv/layout": "1.2.14-beta.9",
44
44
  "@antv/util": "^3.3.10",
@@ -46,8 +46,8 @@
46
46
  "hull.js": "^1.0.6"
47
47
  },
48
48
  "devDependencies": {
49
- "@antv/g-svg": "^2.0.20",
50
- "@antv/g-webgl": "^2.0.28",
49
+ "@antv/g-svg": "^2.0.27",
50
+ "@antv/g-webgl": "^2.0.36",
51
51
  "@antv/layout-gpu": "^1.1.7",
52
52
  "@antv/layout-wasm": "^1.4.2",
53
53
  "@types/hull.js": "^1.0.4",
@@ -46,6 +46,12 @@ export interface CollapseExpandOptions extends BaseBehaviorOptions {
46
46
  * <en/> Callback when expand is completed
47
47
  */
48
48
  onExpand?: (id: ID) => void;
49
+ /**
50
+ * <zh/> 是否对准目标元素,避免视图偏移
51
+ *
52
+ * <en/> Whether to focus on the target element to avoid view offset
53
+ */
54
+ align?: boolean;
49
55
  }
50
56
 
51
57
  /**
@@ -62,6 +68,7 @@ export class CollapseExpand extends BaseBehavior<CollapseExpandOptions> {
62
68
  enable: true,
63
69
  animation: true,
64
70
  trigger: CommonEvent.DBLCLICK,
71
+ align: true,
65
72
  };
66
73
 
67
74
  constructor(context: RuntimeContext, options: CollapseExpandOptions) {
@@ -100,12 +107,12 @@ export class CollapseExpand extends BaseBehavior<CollapseExpandOptions> {
100
107
  const data = model.getElementDataById(id) as NodeLikeData;
101
108
  if (!data) return false;
102
109
 
103
- const { onCollapse, onExpand, animation } = this.options;
110
+ const { onCollapse, onExpand, animation, align } = this.options;
104
111
  if (isCollapsed(data)) {
105
- await graph.expandElement(id, animation);
112
+ await graph.expandElement(id, { animation, align });
106
113
  onExpand?.(id);
107
114
  } else {
108
- await graph.collapseElement(id, animation);
115
+ await graph.collapseElement(id, { animation, align });
109
116
  onCollapse?.(id);
110
117
  }
111
118
  };
@@ -24,7 +24,7 @@ export interface OptimizeViewportTransformOptions extends BaseBehaviorOptions {
24
24
  /**
25
25
  * <zh/> 指定始终显示的图形元素。应用此交互后,在画布操作过程中,只有通过该属性指定的图形元素会保持可见,其余图形元素将被隐藏,从而提升渲染性能。默认情况下,节点始终可见,而其他图形元素在操作画布过程中会自动隐藏
26
26
  *
27
- * <en/> Specify the graphic elements that are always visible. After applying this interaction, only the graphic elements specified by this property will remain visible during the canvas operation, and the rest of the graphic elements will be hidden to improve rendering performance. By default, nodes are always visible, while other graphic elements are automatically hidden during canvas operations
27
+ * <en/> Specify the shapes that are always visible. After applying this interaction, only the shapes specified by this property will remain visible during the canvas operation, and the rest of the shapes will be hidden to improve rendering performance. By default, nodes are always visible, while other shapes are automatically hidden during canvas operations
28
28
  */
29
29
  shapes?:
30
30
  | { node?: string[]; edge?: string[]; combo?: string[] }
@@ -70,7 +70,7 @@ export class OptimizeViewportTransform extends BaseBehavior<OptimizeViewportTran
70
70
  } else if (visibility === 'visible' && this.hiddenShapes.includes(element)) {
71
71
  this.hiddenShapes.splice(this.hiddenShapes.indexOf(element), 1);
72
72
  } else {
73
- setVisibility(element, visibility, false, filter);
73
+ setVisibility(element, visibility, filter);
74
74
  }
75
75
  });
76
76
  };
@@ -126,33 +126,33 @@ export interface BaseEdgeStyleProps
126
126
  /**
127
127
  * <zh/> 在 “起点” 处添加一个标记图形,其中 “起始点” 为边与起始节点的交点
128
128
  *
129
- * <en/> Add a marker graphic at the "start point", where the "start point" is the intersection of the edge and the source node
129
+ * <en/> Add a marker at the "start point", where the "start point" is the intersection of the edge and the source node
130
130
  */
131
131
  markerStart?: DisplayObject | null;
132
132
  /**
133
133
  * <zh/> 调整 “起点” 处标记图形的位置,正偏移量向内,负偏移量向外
134
134
  *
135
- * <en/> Adjust the position of the marker graphic at the "start point", positive offset inward, negative offset outward
135
+ * <en/> Adjust the position of the marker at the "start point", positive offset inward, negative offset outward
136
136
  * @defaultValue 0
137
137
  */
138
138
  markerStartOffset?: number;
139
139
  /**
140
140
  * <zh/> 在 “终点” 处添加一个标记图形,其中 “终点” 为边与终止节点的交点
141
141
  *
142
- * <en/> Add a marker graphic at the "end point", where the "end point" is the intersection of the edge and the target node
142
+ * <en/> Add a marker at the "end point", where the "end point" is the intersection of the edge and the target node
143
143
  */
144
144
  markerEnd?: DisplayObject | null;
145
145
  /**
146
146
  * <zh/> 调整 “终点” 处标记图形的位置,正偏移量向内,负偏移量向外
147
147
  *
148
- * <en/> Adjust the position of the marker graphic at the "end point", positive offset inward, negative offset outward
148
+ * <en/> Adjust the position of the marker at the "end point", positive offset inward, negative offset outward
149
149
  * @defaultValue 0
150
150
  */
151
151
  markerEndOffset?: number;
152
152
  /**
153
153
  * <zh/> 在路径除了 “起点” 和 “终点” 之外的每一个顶点上放置标记图形。在内部实现中,由于我们会把路径中部分命令转换成 C 命令,因此这些顶点实际是三阶贝塞尔曲线的控制点
154
154
  *
155
- * <en/> Place a marker graphic on each vertex of the path except for the "start point" and "end point". In the internal implementation, because we will convert some commands in the path to C commands, these controlPoints are actually the control points of the cubic Bezier curve
155
+ * <en/> Place a marker on each vertex of the path except for the "start point" and "end point". In the internal implementation, because we will convert some commands in the path to C commands, these controlPoints are actually the control points of the cubic Bezier curve
156
156
  */
157
157
  markerMid?: DisplayObject | null;
158
158
  /**
@@ -85,6 +85,7 @@ export interface BaseNodeStyleProps
85
85
  * <zh/> 仅在树图中生效
86
86
  *
87
87
  * <en/> Only valid in the tree graph
88
+ * @ignore
88
89
  */
89
90
  childrenNode?: ID[];
90
91
  /**
@@ -95,6 +96,7 @@ export interface BaseNodeStyleProps
95
96
  * <zh/> 仅在树图中生效。如果当前节点为收起状态,children 可能为空,通过 childrenData 能够获取完整的子元素数据
96
97
  *
97
98
  * <en/> Only valid in the tree graph. If the current node is collapsed, children may be empty, and the complete child element data can be obtained through childrenData
99
+ * @ignore
98
100
  */
99
101
  childrenData?: NodeData[];
100
102
  /**
@@ -450,7 +452,7 @@ export abstract class BaseNode<S extends BaseNodeStyleProps = BaseNodeStyleProps
450
452
  /**
451
453
  * <zh/> 在离屏画布中获取图形包围盒
452
454
  *
453
- * <en/> Get the bounding box of the graphic in the off-screen canvas
455
+ * <en/> Get the bounding box of the shape in the off-screen canvas
454
456
  * @param context - <zh/> 运行时上下文 <en/> Runtime context
455
457
  * @param shape - <zh/> 图形实例 <en/> Graphic instance
456
458
  * @returns <zh/> 图形包围盒 <en/> Graphic bounding box
@@ -460,7 +462,7 @@ function getBoundsInOffscreen(context: RuntimeContext, shape: DisplayObject) {
460
462
 
461
463
  // 将主图形靠背至全局空间,避免受到父级 transform 的影响
462
464
  // 合理的操作应该是拷贝至离屏画布,但目前 G 有点问题
463
- // Move the main graphic to the global space to avoid being affected by the parent transform
465
+ // Move the main shape to the global space to avoid being affected by the parent transform
464
466
  // The reasonable operation should be moved to the off-screen canvas, but there is a problem with G at present
465
467
  const canvas = context.canvas.getLayer();
466
468
  const substitute = shape.cloneNode();
@@ -83,6 +83,15 @@ export class HTML extends BaseNode<HTMLStyleProps> {
83
83
  return this.getShape<GHTML>('key').getDomElement();
84
84
  }
85
85
 
86
+ /**
87
+ * @override
88
+ */
89
+ public render(attributes: Required<HTMLStyleProps> = this.parsedAttributes, container: Group = this): void {
90
+ this.drawKeyShape(attributes, container);
91
+
92
+ this.drawPortShapes(attributes, container);
93
+ }
94
+
86
95
  protected getKeyStyle(attributes: Required<HTMLStyleProps>): GHTMLStyleProps {
87
96
  const {
88
97
  dx = 0,
@@ -153,8 +153,8 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
153
153
  /**
154
154
  * <zh/> 从给定的属性对象中提取图形样式属性。删除特定的属性,如位置、变换和类名
155
155
  *
156
- * <en/> Extracts the graphic style properties from a given attribute object.
157
- * Removes specific properties like position, transformation, and class name.
156
+ * <en/> Extracts the shape styles from a given attribute object.
157
+ * Removes specific styles like position, transformation, and class name.
158
158
  * @param style - <zh/> 属性对象 | <en/> attribute object
159
159
  * @returns <zh/> 仅包含样式属性的对象 | <en/> An object containing only the style properties.
160
160
  */
@@ -256,7 +256,7 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
256
256
 
257
257
  private setVisibility() {
258
258
  const { visibility } = this.attributes;
259
- setVisibility(this, visibility, true);
259
+ setVisibility(this, visibility);
260
260
  }
261
261
 
262
262
  public destroy(): void {
package/src/exports.ts CHANGED
@@ -73,6 +73,7 @@ export {
73
73
  mindmap as MindmapLayout,
74
74
  RadialLayout,
75
75
  RandomLayout,
76
+ SnakeLayout,
76
77
  } from './layouts';
77
78
  export {
78
79
  Background,
@@ -181,7 +182,7 @@ export type {
181
182
  } from './elements/shapes';
182
183
  export type { UpsertHooks } from './elements/shapes/base-shape';
183
184
  export type { ContourLabelStyleProps, ContourStyleProps } from './elements/shapes/contour';
184
- export type { FishboneLayoutOptions } from './layouts';
185
+ export type { FishboneLayoutOptions, SnakeLayoutOptions } from './layouts';
185
186
  export type { BaseLayoutOptions, WebWorkerLayoutOptions } from './layouts/types';
186
187
  export type { CategoricalPalette } from './palettes/types';
187
188
  export type {
@@ -206,6 +207,7 @@ export type {
206
207
  WatermarkOptions,
207
208
  } from './plugins';
208
209
  export type { CanvasConfig, DataURLOptions } from './runtime/canvas';
210
+ export type { CollapseExpandNodeOptions } from './runtime/element';
209
211
  export type { RuntimeContext } from './runtime/types';
210
212
  export type {
211
213
  BehaviorOptions,
@@ -1,11 +1,12 @@
1
1
  import { isEmpty, memoize } from '@antv/util';
2
- import { idOf } from '../exports';
2
+ import type { BaseLayoutOptions } from '../layouts/types';
3
3
  import type { EdgeData, GraphData, NodeData } from '../spec';
4
4
  import type { ElementDatum, ID, Point, Size, STDSize } from '../types';
5
+ import { idOf } from '../utils/id';
5
6
  import { parseSize } from '../utils/size';
6
7
  import { BaseLayout } from './base-layout';
7
8
 
8
- export interface FishboneLayoutOptions {
9
+ export interface FishboneLayoutOptions extends BaseLayoutOptions {
9
10
  /**
10
11
  * <zh/> 节点大小
11
12
  *
@@ -16,4 +16,7 @@ export {
16
16
  } from '@antv/layout';
17
17
  export { BaseLayout } from './base-layout';
18
18
  export { FishboneLayout } from './fishbone';
19
+ export { SnakeLayout } from './snake';
20
+
19
21
  export type { FishboneLayoutOptions } from './fishbone';
22
+ export type { SnakeLayoutOptions } from './snake';
@@ -0,0 +1,235 @@
1
+ import type { GraphData, NodeData } from '../spec';
2
+ import type { ID, Padding, Size } from '../types';
3
+ import { parsePadding } from '../utils/padding';
4
+ import { parseSize } from '../utils/size';
5
+ import { BaseLayout } from './base-layout';
6
+ import type { BaseLayoutOptions } from './types';
7
+
8
+ export interface SnakeLayoutOptions extends BaseLayoutOptions {
9
+ /**
10
+ * <zh/> 节点尺寸
11
+ *
12
+ * <en/> Node size
13
+ */
14
+ nodeSize?: Size | ((node: NodeData) => Size);
15
+ /**
16
+ * <zh/> 内边距,即布局区域与画布边界的距离
17
+ *
18
+ * <en/> Padding, the distance between the layout area and the canvas boundary
19
+ * @defaultValue 0
20
+ */
21
+ padding?: Padding;
22
+ /**
23
+ * <zh/> 节点排序方法。默认按照在图中的路径顺序进行展示
24
+ *
25
+ * <en/> Node sorting method
26
+ */
27
+ sortBy?: (nodeA: NodeData, nodeB: NodeData) => -1 | 0 | 1;
28
+ /**
29
+ * <zh/> 节点列数
30
+ *
31
+ * <en/> Number of node columns
32
+ * @defaultValue 5
33
+ */
34
+ cols?: number;
35
+ /**
36
+ * <zh/> 节点行之间的间隙大小。默认将根据画布高度和节点总行数自动计算
37
+ *
38
+ * <en/> The size of the gap between a node's rows
39
+ */
40
+ rowGap?: number;
41
+ /**
42
+ * <zh/> 节点列之间的间隙大小。默认将根据画布宽度和节点总列数自动计算
43
+ *
44
+ * <en/> The size of the gap between a node's columns
45
+ */
46
+ colGap?: number;
47
+ /**
48
+ * <zh/> 节点排布方向是否顺时针
49
+ *
50
+ * <en/> Whether the node arrangement direction is clockwise
51
+ * @defaultValue true
52
+ * @remarks
53
+ * <zh/> 在顺时针排布时,节点从左上角开始,第一行从左到右排列,第二行从右到左排列,依次类推,形成 S 型路径。在逆时针排布时,节点从右上角开始,第一行从右到左排列,第二行从左到右排列,依次类推,形成反向 S 型路径。
54
+ *
55
+ * <en/> When arranged clockwise, the nodes start from the upper left corner, the first row is arranged from left to right, the second row is arranged from right to left, and so on, forming an S-shaped path. When arranged counterclockwise, the nodes start from the upper right corner, the first row is arranged from right to left, the second row is arranged from left to right, and so on, forming a reverse S-shaped path.
56
+ */
57
+ clockwise?: boolean;
58
+ }
59
+
60
+ /**
61
+ * <zh/> 蛇形布局
62
+ *
63
+ * <en/> Snake layout
64
+ * @remarks
65
+ * <zh/> 蛇形布局(Snake Layout)是一种特殊的图形布局方式,能够在较小的空间内更有效地展示长链结构。需要注意的是,其图数据需要确保节点按照从源节点到汇节点的顺序进行线性排列,形成一条明确的路径。
66
+ *
67
+ * <zh/> 节点按 S 字型排列,第一个节点位于第一行的起始位置,接下来的节点在第一行向右排列,直到行末尾。到达行末尾后,下一行的节点从右向左反向排列。这个过程重复进行,直到所有节点排列完毕。
68
+ *
69
+ * <en/> The Snake layout is a special way of graph layout that can more effectively display long chain structures in a smaller space. Note that the graph data needs to ensure that the nodes are linearly arranged in the order from the source node to the sink node to form a clear path.
70
+ *
71
+ * <en/> The nodes are arranged in an S-shaped pattern, with the first node at the beginning of the first row, and the following nodes arranged to the right until the end of the row. After reaching the end of the row, the nodes in the next row are arranged in reverse from right to left. This process is repeated until all nodes are arranged.
72
+ */
73
+ export class SnakeLayout extends BaseLayout {
74
+ public id = 'snake';
75
+
76
+ static defaultOptions: Partial<SnakeLayoutOptions> = {
77
+ padding: 0,
78
+ cols: 5,
79
+ clockwise: true,
80
+ };
81
+
82
+ private formatSize(nodes: NodeData[], size?: Size | ((node: NodeData) => Size)): [number, number] {
83
+ const sizeFn = typeof size === 'function' ? size : ((() => size) as (node: NodeData) => Size);
84
+ return nodes.reduce(
85
+ (acc, node) => {
86
+ const [w, h] = parseSize(sizeFn(node)) || [0, 0];
87
+ return [Math.max(acc[0], w), Math.max(acc[1], h)];
88
+ },
89
+ [0, 0],
90
+ );
91
+ }
92
+
93
+ /**
94
+ * Validates the graph data to ensure it meets the requirements for linear arrangement.
95
+ * @param data - Graph data
96
+ * @returns false if the graph is not connected, has more than one source or sink node, or contains cycles.
97
+ */
98
+ private validate(data: GraphData): boolean {
99
+ const { nodes = [], edges = [] } = data;
100
+ const inDegree: { [key: ID]: number } = {};
101
+ const outDegree: { [key: ID]: number } = {};
102
+ const adjList: { [key: ID]: ID[] } = {};
103
+
104
+ nodes.forEach((node) => {
105
+ inDegree[node.id] = 0;
106
+ outDegree[node.id] = 0;
107
+ adjList[node.id] = [];
108
+ });
109
+
110
+ edges.forEach((edge) => {
111
+ inDegree[edge.target]++;
112
+ outDegree[edge.source]++;
113
+ adjList[edge.source].push(edge.target);
114
+ });
115
+
116
+ // 检查图是否连通
117
+ // Check if the graph is connected
118
+ const visited: Set<ID> = new Set();
119
+ const dfs = (nodeId: ID) => {
120
+ if (visited.has(nodeId)) return;
121
+ visited.add(nodeId);
122
+ adjList[nodeId].forEach(dfs);
123
+ };
124
+ dfs(nodes[0].id);
125
+ if (visited.size !== nodes.length) return false;
126
+
127
+ // 检查是否有且仅有一个源节点和一个汇节点
128
+ // Check if there is exactly one source node and one sink node
129
+ const sourceNodes = nodes.filter((node) => inDegree[node.id] === 0);
130
+ const sinkNodes = nodes.filter((node) => outDegree[node.id] === 0);
131
+ if (sourceNodes.length !== 1 || sinkNodes.length !== 1) return false;
132
+
133
+ // 检查中间节点是否只有一个前驱和一个后继
134
+ // Check if the middle nodes have only one predecessor and one successor
135
+ const middleNodes = nodes.filter((node) => inDegree[node.id] === 1 && outDegree[node.id] === 1);
136
+ if (middleNodes.length !== nodes.length - 2) return false;
137
+
138
+ return true;
139
+ }
140
+
141
+ async execute(model: GraphData, options?: SnakeLayoutOptions): Promise<GraphData> {
142
+ if (!this.validate(model)) return model;
143
+
144
+ const {
145
+ nodeSize: propNodeSize,
146
+ padding: propPadding,
147
+ sortBy,
148
+ cols,
149
+ colGap: propColSep,
150
+ rowGap: propRowSep,
151
+ clockwise,
152
+ width,
153
+ height,
154
+ } = Object.assign({}, SnakeLayout.defaultOptions, this.options, options) as Required<SnakeLayoutOptions>;
155
+
156
+ const [top, right, bottom, left] = parsePadding(propPadding);
157
+ const nodeSize = this.formatSize(model.nodes || [], propNodeSize);
158
+
159
+ const rows = Math.ceil((model.nodes || []).length / cols);
160
+ let colSep = propColSep ? propColSep : (width - left - right - cols * nodeSize[0]) / (cols - 1);
161
+ let rowSep = propRowSep ? propRowSep : (height - top - bottom - rows * nodeSize[1]) / (rows - 1);
162
+ if (rowSep === Infinity || rowSep < 0) rowSep = 0;
163
+ if (colSep === Infinity || colSep < 0) colSep = 0;
164
+
165
+ const sortedNodes = sortBy ? model.nodes?.sort(sortBy) : topologicalSort(model);
166
+
167
+ const nodes = (sortedNodes || []).map((node, index) => {
168
+ const rowIndex = Math.floor(index / cols);
169
+ const colIndex = index % cols;
170
+
171
+ const actualColIndex = clockwise
172
+ ? rowIndex % 2 === 0
173
+ ? colIndex
174
+ : cols - 1 - colIndex
175
+ : rowIndex % 2 === 0
176
+ ? cols - 1 - colIndex
177
+ : colIndex;
178
+
179
+ const x = left + actualColIndex * (nodeSize[0] + colSep) + nodeSize[0] / 2;
180
+ const y = top + rowIndex * (nodeSize[1] + rowSep) + nodeSize[1] / 2;
181
+
182
+ return {
183
+ id: node.id,
184
+ style: { x, y },
185
+ };
186
+ });
187
+
188
+ return { nodes };
189
+ }
190
+ }
191
+
192
+ /**
193
+ * Topological sorting. The nodes are sorted according to the order of the paths(from the start node to the end node).
194
+ * @param data - Graph data
195
+ * @returns Sorted nodes
196
+ */
197
+ function topologicalSort(data: GraphData): NodeData[] {
198
+ const { nodes = [], edges = [] } = data;
199
+ const inDegree: { [key: ID]: number } = {};
200
+ const adjList: { [key: ID]: ID[] } = {};
201
+
202
+ nodes.forEach((node) => {
203
+ inDegree[node.id] = 0;
204
+ adjList[node.id] = [];
205
+ });
206
+
207
+ edges.forEach((edge) => {
208
+ inDegree[edge.target]++;
209
+ adjList[edge.source].push(edge.target);
210
+ });
211
+
212
+ const queue: ID[] = [];
213
+ const sortedNodes: NodeData[] = [];
214
+
215
+ nodes.forEach((node) => {
216
+ if (inDegree[node.id] === 0) {
217
+ queue.push(node.id);
218
+ }
219
+ });
220
+
221
+ while (queue.length > 0) {
222
+ const nodeId = queue.shift()!;
223
+ const node = nodes.find((n) => n.id === nodeId)!;
224
+ sortedNodes.push(node);
225
+
226
+ adjList[nodeId].forEach((neighbor) => {
227
+ inDegree[neighbor]--;
228
+ if (inDegree[neighbor] === 0) {
229
+ queue.push(neighbor);
230
+ }
231
+ });
232
+ }
233
+
234
+ return sortedNodes;
235
+ }