@antv/g6 5.0.3 → 5.0.4

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 (242) hide show
  1. package/README.en-US.md +118 -0
  2. package/README.md +118 -0
  3. package/dist/g6.min.js +2 -2
  4. package/dist/lib/behaviors/base-behavior.d.ts +1 -1
  5. package/dist/lib/behaviors/scroll-canvas.d.ts +1 -1
  6. package/dist/lib/behaviors/types.d.ts +0 -4
  7. package/dist/lib/behaviors/zoom-canvas.d.ts +1 -1
  8. package/dist/lib/elements/shapes/badge.d.ts +1 -1
  9. package/dist/lib/index.d.ts +1 -1
  10. package/dist/lib/layouts/index.d.ts +0 -1
  11. package/dist/lib/plugins/types.d.ts +0 -2
  12. package/dist/lib/registry/extension/index.d.ts +17 -6
  13. package/dist/lib/registry/extension/types.d.ts +15 -33
  14. package/dist/lib/runtime/data.d.ts +1 -1
  15. package/dist/lib/runtime/element.d.ts +1 -1
  16. package/dist/lib/spec/behavior.d.ts +4 -5
  17. package/dist/lib/spec/element/combo.d.ts +8 -4
  18. package/dist/lib/spec/element/edge.d.ts +8 -4
  19. package/dist/lib/spec/element/node.d.ts +8 -4
  20. package/dist/lib/spec/plugin.d.ts +4 -5
  21. package/dist/lib/spec/transform.d.ts +5 -6
  22. package/dist/lib/transforms/types.d.ts +1 -2
  23. package/dist/lib/types/index.d.ts +0 -1
  24. package/dist/lib/types/style.d.ts +2 -0
  25. package/dist/lib/utils/event/events.d.ts +4 -4
  26. package/dist/lib/utils/extension.d.ts +5 -2
  27. package/dist/lib/utils/style.d.ts +5 -2
  28. package/dist/lib/utils/transform.d.ts +1 -1
  29. package/dist/lib/version.d.ts +1 -0
  30. package/esm/behaviors/base-behavior.d.ts +1 -1
  31. package/esm/behaviors/base-behavior.js.map +1 -1
  32. package/esm/behaviors/scroll-canvas.d.ts +1 -1
  33. package/esm/behaviors/scroll-canvas.js.map +1 -1
  34. package/esm/behaviors/types.d.ts +0 -4
  35. package/esm/behaviors/zoom-canvas.d.ts +1 -1
  36. package/esm/elements/shapes/badge.d.ts +1 -1
  37. package/esm/index.d.ts +1 -1
  38. package/esm/index.js +1 -1
  39. package/esm/index.js.map +1 -1
  40. package/esm/layouts/index.d.ts +0 -1
  41. package/esm/plugins/camera-setting.js.map +1 -1
  42. package/esm/plugins/types.d.ts +0 -2
  43. package/esm/registry/extension/index.d.ts +17 -6
  44. package/esm/registry/extension/index.js +1 -1
  45. package/esm/registry/extension/index.js.map +1 -1
  46. package/esm/registry/extension/types.d.ts +15 -33
  47. package/esm/runtime/data.d.ts +1 -1
  48. package/esm/runtime/element.d.ts +1 -1
  49. package/esm/runtime/element.js +7 -4
  50. package/esm/runtime/element.js.map +1 -1
  51. package/esm/runtime/graph.js +3 -3
  52. package/esm/runtime/graph.js.map +1 -1
  53. package/esm/spec/behavior.d.ts +4 -5
  54. package/esm/spec/element/combo.d.ts +8 -4
  55. package/esm/spec/element/edge.d.ts +8 -4
  56. package/esm/spec/element/node.d.ts +8 -4
  57. package/esm/spec/plugin.d.ts +4 -5
  58. package/esm/spec/transform.d.ts +5 -6
  59. package/esm/transforms/types.d.ts +1 -2
  60. package/esm/types/index.d.ts +0 -1
  61. package/esm/types/style.d.ts +2 -0
  62. package/esm/utils/event/events.d.ts +4 -4
  63. package/esm/utils/extension.d.ts +5 -2
  64. package/esm/utils/extension.js +5 -1
  65. package/esm/utils/extension.js.map +1 -1
  66. package/esm/utils/style.d.ts +5 -2
  67. package/esm/utils/style.js +5 -6
  68. package/esm/utils/style.js.map +1 -1
  69. package/esm/utils/transform.d.ts +1 -1
  70. package/esm/version.d.ts +1 -0
  71. package/esm/version.js +2 -0
  72. package/esm/version.js.map +1 -0
  73. package/lib/behaviors/base-behavior.d.ts +1 -1
  74. package/lib/behaviors/base-behavior.js.map +1 -1
  75. package/lib/behaviors/scroll-canvas.d.ts +1 -1
  76. package/lib/behaviors/scroll-canvas.js.map +1 -1
  77. package/lib/behaviors/types.d.ts +0 -4
  78. package/lib/behaviors/zoom-canvas.d.ts +1 -1
  79. package/lib/elements/effect.js +1 -2
  80. package/lib/elements/effect.js.map +1 -1
  81. package/lib/elements/shapes/badge.d.ts +1 -1
  82. package/lib/index.d.ts +1 -1
  83. package/lib/index.js +2 -1
  84. package/lib/index.js.map +1 -1
  85. package/lib/layouts/index.d.ts +0 -1
  86. package/lib/plugins/camera-setting.js.map +1 -1
  87. package/lib/plugins/contextmenu/util.js +2 -2
  88. package/lib/plugins/contextmenu/util.js.map +1 -1
  89. package/lib/plugins/history/util.js +2 -3
  90. package/lib/plugins/history/util.js.map +1 -1
  91. package/lib/plugins/hull/util.js +1 -2
  92. package/lib/plugins/hull/util.js.map +1 -1
  93. package/lib/plugins/toolbar/util.js +2 -2
  94. package/lib/plugins/toolbar/util.js.map +1 -1
  95. package/lib/plugins/types.d.ts +0 -2
  96. package/lib/plugins/watermark/util.js +2 -3
  97. package/lib/plugins/watermark/util.js.map +1 -1
  98. package/lib/registry/extension/index.d.ts +17 -6
  99. package/lib/registry/extension/index.js +1 -1
  100. package/lib/registry/extension/index.js.map +1 -1
  101. package/lib/registry/extension/types.d.ts +15 -33
  102. package/lib/registry/index.js +4 -5
  103. package/lib/registry/index.js.map +1 -1
  104. package/lib/runtime/data.d.ts +1 -1
  105. package/lib/runtime/element.d.ts +1 -1
  106. package/lib/runtime/element.js +7 -4
  107. package/lib/runtime/element.js.map +1 -1
  108. package/lib/runtime/graph.js +3 -3
  109. package/lib/runtime/graph.js.map +1 -1
  110. package/lib/spec/behavior.d.ts +4 -5
  111. package/lib/spec/element/combo.d.ts +8 -4
  112. package/lib/spec/element/edge.d.ts +8 -4
  113. package/lib/spec/element/node.d.ts +8 -4
  114. package/lib/spec/plugin.d.ts +4 -5
  115. package/lib/spec/transform.d.ts +5 -6
  116. package/lib/themes/base.js +1 -2
  117. package/lib/themes/base.js.map +1 -1
  118. package/lib/transforms/types.d.ts +1 -2
  119. package/lib/transforms/utils.js +1 -2
  120. package/lib/transforms/utils.js.map +1 -1
  121. package/lib/types/index.d.ts +0 -1
  122. package/lib/types/style.d.ts +2 -0
  123. package/lib/utils/anchor.js +1 -2
  124. package/lib/utils/anchor.js.map +1 -1
  125. package/lib/utils/animation.js +5 -6
  126. package/lib/utils/animation.js.map +1 -1
  127. package/lib/utils/array.js +1 -2
  128. package/lib/utils/array.js.map +1 -1
  129. package/lib/utils/bbox.js +13 -14
  130. package/lib/utils/bbox.js.map +1 -1
  131. package/lib/utils/cache.js +4 -5
  132. package/lib/utils/cache.js.map +1 -1
  133. package/lib/utils/change.js +2 -3
  134. package/lib/utils/change.js.map +1 -1
  135. package/lib/utils/collapsibility.js +1 -2
  136. package/lib/utils/collapsibility.js.map +1 -1
  137. package/lib/utils/data.js +3 -4
  138. package/lib/utils/data.js.map +1 -1
  139. package/lib/utils/diff.js +1 -2
  140. package/lib/utils/diff.js.map +1 -1
  141. package/lib/utils/dom.js +4 -5
  142. package/lib/utils/dom.js.map +1 -1
  143. package/lib/utils/edge.js +18 -18
  144. package/lib/utils/edge.js.map +1 -1
  145. package/lib/utils/element.js +26 -27
  146. package/lib/utils/element.js.map +1 -1
  147. package/lib/utils/event/events.d.ts +4 -4
  148. package/lib/utils/event/index.js +2 -3
  149. package/lib/utils/event/index.js.map +1 -1
  150. package/lib/utils/extension.d.ts +5 -2
  151. package/lib/utils/extension.js +6 -3
  152. package/lib/utils/extension.js.map +1 -1
  153. package/lib/utils/graphlib.js +3 -4
  154. package/lib/utils/graphlib.js.map +1 -1
  155. package/lib/utils/id.js +3 -4
  156. package/lib/utils/id.js.map +1 -1
  157. package/lib/utils/is.js +4 -5
  158. package/lib/utils/is.js.map +1 -1
  159. package/lib/utils/layout.js +7 -8
  160. package/lib/utils/layout.js.map +1 -1
  161. package/lib/utils/line.js +2 -3
  162. package/lib/utils/line.js.map +1 -1
  163. package/lib/utils/math.js +1 -2
  164. package/lib/utils/math.js.map +1 -1
  165. package/lib/utils/node.js +1 -2
  166. package/lib/utils/node.js.map +1 -1
  167. package/lib/utils/padding.js +1 -2
  168. package/lib/utils/padding.js.map +1 -1
  169. package/lib/utils/palette.js +3 -4
  170. package/lib/utils/palette.js.map +1 -1
  171. package/lib/utils/path.js +4 -4
  172. package/lib/utils/path.js.map +1 -1
  173. package/lib/utils/placement.js +1 -2
  174. package/lib/utils/placement.js.map +1 -1
  175. package/lib/utils/point.js +21 -22
  176. package/lib/utils/point.js.map +1 -1
  177. package/lib/utils/polygon.js +1 -2
  178. package/lib/utils/polygon.js.map +1 -1
  179. package/lib/utils/position.js +5 -5
  180. package/lib/utils/position.js.map +1 -1
  181. package/lib/utils/prefix.js +7 -8
  182. package/lib/utils/prefix.js.map +1 -1
  183. package/lib/utils/relation.js +2 -3
  184. package/lib/utils/relation.js.map +1 -1
  185. package/lib/utils/router/orth.js +9 -10
  186. package/lib/utils/router/orth.js.map +1 -1
  187. package/lib/utils/shape.js +1 -2
  188. package/lib/utils/shape.js.map +1 -1
  189. package/lib/utils/size.js +1 -2
  190. package/lib/utils/size.js.map +1 -1
  191. package/lib/utils/style.d.ts +5 -2
  192. package/lib/utils/style.js +8 -10
  193. package/lib/utils/style.js.map +1 -1
  194. package/lib/utils/text.js +3 -4
  195. package/lib/utils/text.js.map +1 -1
  196. package/lib/utils/theme.js +1 -2
  197. package/lib/utils/theme.js.map +1 -1
  198. package/lib/utils/transform.d.ts +1 -1
  199. package/lib/utils/transform.js +2 -2
  200. package/lib/utils/transform.js.map +1 -1
  201. package/lib/utils/traverse.js +2 -3
  202. package/lib/utils/traverse.js.map +1 -1
  203. package/lib/utils/tree.js +1 -2
  204. package/lib/utils/tree.js.map +1 -1
  205. package/lib/utils/vector.js +16 -17
  206. package/lib/utils/vector.js.map +1 -1
  207. package/lib/utils/visibility.js +1 -2
  208. package/lib/utils/visibility.js.map +1 -1
  209. package/lib/version.d.ts +1 -0
  210. package/lib/version.js +5 -0
  211. package/lib/version.js.map +1 -0
  212. package/package.json +6 -3
  213. package/src/behaviors/base-behavior.ts +1 -1
  214. package/src/behaviors/scroll-canvas.ts +1 -1
  215. package/src/behaviors/types.ts +0 -4
  216. package/src/index.ts +1 -1
  217. package/src/plugins/camera-setting.ts +2 -2
  218. package/src/plugins/types.ts +0 -2
  219. package/src/registry/extension/index.ts +15 -8
  220. package/src/registry/extension/types.ts +15 -40
  221. package/src/runtime/element.ts +7 -4
  222. package/src/runtime/graph.ts +3 -3
  223. package/src/spec/behavior.ts +4 -5
  224. package/src/spec/element/combo.ts +16 -4
  225. package/src/spec/element/edge.ts +16 -4
  226. package/src/spec/element/node.ts +16 -4
  227. package/src/spec/plugin.ts +4 -5
  228. package/src/spec/transform.ts +5 -6
  229. package/src/transforms/types.ts +1 -2
  230. package/src/types/index.ts +0 -1
  231. package/src/types/style.ts +2 -0
  232. package/src/utils/extension.ts +10 -3
  233. package/src/utils/style.ts +11 -6
  234. package/src/version.ts +1 -0
  235. package/dist/lib/types/callable.d.ts +0 -19
  236. package/esm/types/callable.d.ts +0 -19
  237. package/esm/types/callable.js +0 -2
  238. package/esm/types/callable.js.map +0 -1
  239. package/lib/types/callable.d.ts +0 -19
  240. package/lib/types/callable.js +0 -3
  241. package/lib/types/callable.js.map +0 -1
  242. package/src/types/callable.ts +0 -21
@@ -1,11 +1,10 @@
1
- import type { BuiltInPluginOptions } from '../plugins/types';
2
- import type { ExtensionOptions } from '../registry/extension/types';
1
+ import type { Graph } from '../runtime/graph';
3
2
 
4
- export type PluginOptions = ExtensionOptions<BuiltInPluginOptions>;
3
+ export type PluginOptions = (string | CustomPluginOption | ((this: Graph) => CustomPluginOption))[];
5
4
 
6
5
  export interface UpdatePluginOption {
7
6
  key: string;
8
- [key: string]: any;
7
+ [key: string]: unknown;
9
8
  }
10
9
 
11
10
  export interface CustomPluginOption extends Record<string, any> {
@@ -14,7 +13,7 @@ export interface CustomPluginOption extends Record<string, any> {
14
13
  *
15
14
  * <en/> Plugin type
16
15
  */
17
- type?: string;
16
+ type: string;
18
17
  /**
19
18
  * <zh/> 插件 key,即唯一标识
20
19
  *
@@ -1,15 +1,14 @@
1
- import type { ExtensionOptions } from '../registry/extension/types';
2
- import type { BuiltInTransformOptions } from '../transforms/types';
1
+ import type { Graph } from '../runtime/graph';
3
2
 
4
- export type TransformOptions = ExtensionOptions<BuiltInTransformOptions>;
3
+ export type TransformOptions = (string | CustomTransformOption | ((this: Graph) => CustomTransformOption))[];
5
4
 
6
5
  export interface UpdateTransformOption {
7
6
  key: string;
8
- [key: string]: any;
7
+ [key: string]: unknown;
9
8
  }
10
9
 
11
10
  export interface CustomTransformOption {
12
- type?: string;
11
+ type: string;
13
12
  key?: string;
14
- [key: string]: any;
13
+ [key: string]: unknown;
15
14
  }
@@ -1,8 +1,7 @@
1
1
  import type { ComboData, EdgeData, NodeData } from '../spec';
2
2
  import type { ID } from '../types';
3
- import type { BaseTransform, BaseTransformOptions } from './base-transform';
3
+ import type { BaseTransform } from './base-transform';
4
4
 
5
- export type BuiltInTransformOptions = BaseTransformOptions;
6
5
  export type Transform = BaseTransform<any>;
7
6
 
8
7
  /**
@@ -1,6 +1,5 @@
1
1
  export type * from './anchor';
2
2
  export type * from './animation';
3
- export type * from './callable';
4
3
  export type * from './canvas';
5
4
  export type * from './change';
6
5
  export type * from './combo';
@@ -1,3 +1,4 @@
1
+ import type { Graph } from '../runtime/graph';
1
2
  import type { ElementDatum } from './data';
2
3
 
3
4
  /**
@@ -7,4 +8,5 @@ import type { ElementDatum } from './data';
7
8
  */
8
9
  export type StyleIterationContext = {
9
10
  datum: ElementDatum;
11
+ graph: Graph;
10
12
  };
@@ -1,14 +1,17 @@
1
- import type { ExtensionOptions, STDExtensionOption } from '../registry/extension/types';
1
+ import type { STDExtensionOption } from '../registry/extension/types';
2
+ import type { Graph } from '../runtime/graph';
3
+ import type { TransformOptions } from '../spec/transform';
2
4
 
3
5
  /**
4
6
  * <zh/> 将模块配置项转换为标准模块格式
5
7
  *
6
8
  * <en/> Convert extension options to standard format
9
+ * @param graph - <zh/> 图实例 <en/> graph instance
7
10
  * @param category - <zh/> 模块类型 <en/> extension type
8
11
  * @param extensions - <zh/> 模块配置项 <en/> extension options
9
12
  * @returns <zh/> 标准模块配置项 <en/> Standard extension options
10
13
  */
11
- export function parseExtensions(category: string, extensions: ExtensionOptions): STDExtensionOption[] {
14
+ export function parseExtensions(graph: Graph, category: string, extensions: TransformOptions): STDExtensionOption[] {
12
15
  const counter: Record<string, number> = {};
13
16
 
14
17
  const getKey = (type: string) => {
@@ -20,7 +23,11 @@ export function parseExtensions(category: string, extensions: ExtensionOptions):
20
23
  if (typeof extension === 'string') {
21
24
  return { type: extension, key: getKey(extension) };
22
25
  }
26
+ if (typeof extension === 'function') {
27
+ return extension.call(graph);
28
+ }
29
+
23
30
  if (extension.key) return extension;
24
- return { ...extension, key: getKey(extension.type) };
31
+ return { ...extension, key: getKey(extension.type!) };
25
32
  }) as STDExtensionOption[];
26
33
  }
@@ -1,6 +1,6 @@
1
1
  import type { DisplayObjectConfig } from '@antv/g';
2
- import { isFunction } from '@antv/util';
3
- import type { CallableObject, ElementDatum, StyleIterationContext } from '../types';
2
+ import type { Graph } from '../runtime/graph';
3
+ import type { ElementDatum, StyleIterationContext } from '../types';
4
4
 
5
5
  /**
6
6
  * <zh/> 计算支持回调的动态样式
@@ -11,16 +11,21 @@ import type { CallableObject, ElementDatum, StyleIterationContext } from '../typ
11
11
  * @returns <zh/> 静态样式 | <en/> static style
12
12
  */
13
13
  export function computeElementCallbackStyle(
14
- callableStyle: CallableObject<Record<string, unknown>, ElementDatum>,
14
+ callableStyle:
15
+ | Record<string, unknown>
16
+ | ((this: Graph, datum: ElementDatum) => Record<string, unknown>)
17
+ | {
18
+ [key: string]: (this: Graph, datum: ElementDatum) => unknown;
19
+ },
15
20
  context: StyleIterationContext,
16
21
  ) {
17
- const { datum } = context;
22
+ const { datum, graph } = context;
18
23
 
19
- if (isFunction(callableStyle)) return callableStyle(datum);
24
+ if (typeof callableStyle === 'function') return callableStyle.call(graph, datum);
20
25
 
21
26
  return Object.fromEntries(
22
27
  Object.entries(callableStyle).map(([key, style]) => {
23
- if (isFunction(style)) return [key, style(datum)];
28
+ if (typeof style === 'function') return [key, style.call(graph, datum)];
24
29
  return [key, style];
25
30
  }),
26
31
  );
package/src/version.ts ADDED
@@ -0,0 +1 @@
1
+ export const version = '5.0.4';
@@ -1,19 +0,0 @@
1
- /**
2
- * <zh/> 可回调对象
3
- *
4
- * <en/> Callable object
5
- * @example
6
- * type Style = {
7
- * fill?: string;
8
- * }
9
- * type CallableObjectStyle = CallableObject<Style, { model: { value: string } }>;
10
- * const style1: CallableObjectStyle = {
11
- * fill: 'red',
12
- * }
13
- * const style2: CallableObjectStyle = {
14
- * fill: ({ model }) => model.value,
15
- * }
16
- */
17
- export type CallableObject<Obj extends Record<string, unknown>, T> = ((datum: T) => Obj) | {
18
- [K in keyof Obj]: Obj[K] | ((datum: T) => NonNullable<Obj[K]>);
19
- };
@@ -1,19 +0,0 @@
1
- /**
2
- * <zh/> 可回调对象
3
- *
4
- * <en/> Callable object
5
- * @example
6
- * type Style = {
7
- * fill?: string;
8
- * }
9
- * type CallableObjectStyle = CallableObject<Style, { model: { value: string } }>;
10
- * const style1: CallableObjectStyle = {
11
- * fill: 'red',
12
- * }
13
- * const style2: CallableObjectStyle = {
14
- * fill: ({ model }) => model.value,
15
- * }
16
- */
17
- export type CallableObject<Obj extends Record<string, unknown>, T> = ((datum: T) => Obj) | {
18
- [K in keyof Obj]: Obj[K] | ((datum: T) => NonNullable<Obj[K]>);
19
- };
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=callable.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"callable.js","sourceRoot":"src/","sources":["types/callable.ts"],"names":[],"mappings":""}
@@ -1,19 +0,0 @@
1
- /**
2
- * <zh/> 可回调对象
3
- *
4
- * <en/> Callable object
5
- * @example
6
- * type Style = {
7
- * fill?: string;
8
- * }
9
- * type CallableObjectStyle = CallableObject<Style, { model: { value: string } }>;
10
- * const style1: CallableObjectStyle = {
11
- * fill: 'red',
12
- * }
13
- * const style2: CallableObjectStyle = {
14
- * fill: ({ model }) => model.value,
15
- * }
16
- */
17
- export type CallableObject<Obj extends Record<string, unknown>, T> = ((datum: T) => Obj) | {
18
- [K in keyof Obj]: Obj[K] | ((datum: T) => NonNullable<Obj[K]>);
19
- };
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=callable.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"callable.js","sourceRoot":"src/","sources":["types/callable.ts"],"names":[],"mappings":""}
@@ -1,21 +0,0 @@
1
- /**
2
- * <zh/> 可回调对象
3
- *
4
- * <en/> Callable object
5
- * @example
6
- * type Style = {
7
- * fill?: string;
8
- * }
9
- * type CallableObjectStyle = CallableObject<Style, { model: { value: string } }>;
10
- * const style1: CallableObjectStyle = {
11
- * fill: 'red',
12
- * }
13
- * const style2: CallableObjectStyle = {
14
- * fill: ({ model }) => model.value,
15
- * }
16
- */
17
- export type CallableObject<Obj extends Record<string, unknown>, T> =
18
- | ((datum: T) => Obj)
19
- | {
20
- [K in keyof Obj]: Obj[K] | ((datum: T) => NonNullable<Obj[K]>);
21
- };