@antv/g6 5.0.3 → 5.0.5

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 (295) 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/click-select.d.ts +17 -0
  6. package/dist/lib/behaviors/scroll-canvas.d.ts +1 -1
  7. package/dist/lib/behaviors/types.d.ts +0 -4
  8. package/dist/lib/behaviors/zoom-canvas.d.ts +1 -1
  9. package/dist/lib/constants/events/graph.d.ts +12 -0
  10. package/dist/lib/elements/shapes/badge.d.ts +1 -1
  11. package/dist/lib/exports.d.ts +2 -0
  12. package/dist/lib/index.d.ts +1 -1
  13. package/dist/lib/layouts/index.d.ts +0 -1
  14. package/dist/lib/plugins/types.d.ts +0 -2
  15. package/dist/lib/registry/extension/index.d.ts +17 -6
  16. package/dist/lib/registry/extension/types.d.ts +15 -33
  17. package/dist/lib/runtime/data.d.ts +1 -1
  18. package/dist/lib/runtime/element.d.ts +1 -1
  19. package/dist/lib/runtime/viewport.d.ts +3 -5
  20. package/dist/lib/spec/behavior.d.ts +4 -5
  21. package/dist/lib/spec/element/combo.d.ts +8 -4
  22. package/dist/lib/spec/element/edge.d.ts +8 -4
  23. package/dist/lib/spec/element/node.d.ts +8 -4
  24. package/dist/lib/spec/plugin.d.ts +4 -5
  25. package/dist/lib/spec/transform.d.ts +5 -6
  26. package/dist/lib/transforms/types.d.ts +1 -2
  27. package/dist/lib/types/index.d.ts +0 -1
  28. package/dist/lib/types/style.d.ts +2 -0
  29. package/dist/lib/utils/event/events.d.ts +4 -4
  30. package/dist/lib/utils/extension.d.ts +5 -2
  31. package/dist/lib/utils/style.d.ts +5 -2
  32. package/dist/lib/utils/transform.d.ts +1 -1
  33. package/dist/lib/version.d.ts +1 -0
  34. package/esm/behaviors/base-behavior.d.ts +1 -1
  35. package/esm/behaviors/base-behavior.js.map +1 -1
  36. package/esm/behaviors/click-select.d.ts +17 -0
  37. package/esm/behaviors/click-select.js +35 -4
  38. package/esm/behaviors/click-select.js.map +1 -1
  39. package/esm/behaviors/scroll-canvas.d.ts +1 -1
  40. package/esm/behaviors/scroll-canvas.js.map +1 -1
  41. package/esm/behaviors/types.d.ts +0 -4
  42. package/esm/behaviors/zoom-canvas.d.ts +1 -1
  43. package/esm/constants/events/graph.d.ts +12 -0
  44. package/esm/constants/events/graph.js +12 -0
  45. package/esm/constants/events/graph.js.map +1 -1
  46. package/esm/elements/shapes/badge.d.ts +1 -1
  47. package/esm/exports.d.ts +2 -0
  48. package/esm/exports.js +1 -0
  49. package/esm/exports.js.map +1 -1
  50. package/esm/index.d.ts +1 -1
  51. package/esm/index.js +1 -1
  52. package/esm/index.js.map +1 -1
  53. package/esm/layouts/index.d.ts +0 -1
  54. package/esm/plugins/camera-setting.js.map +1 -1
  55. package/esm/plugins/types.d.ts +0 -2
  56. package/esm/registry/extension/index.d.ts +17 -6
  57. package/esm/registry/extension/index.js +1 -1
  58. package/esm/registry/extension/index.js.map +1 -1
  59. package/esm/registry/extension/types.d.ts +15 -33
  60. package/esm/runtime/behavior.js +5 -0
  61. package/esm/runtime/behavior.js.map +1 -1
  62. package/esm/runtime/data.d.ts +1 -1
  63. package/esm/runtime/data.js +2 -0
  64. package/esm/runtime/data.js.map +1 -1
  65. package/esm/runtime/element.d.ts +1 -1
  66. package/esm/runtime/element.js +7 -4
  67. package/esm/runtime/element.js.map +1 -1
  68. package/esm/runtime/graph.js +3 -3
  69. package/esm/runtime/graph.js.map +1 -1
  70. package/esm/runtime/layout.js +4 -1
  71. package/esm/runtime/layout.js.map +1 -1
  72. package/esm/runtime/viewport.d.ts +3 -5
  73. package/esm/runtime/viewport.js +18 -49
  74. package/esm/runtime/viewport.js.map +1 -1
  75. package/esm/spec/behavior.d.ts +4 -5
  76. package/esm/spec/element/combo.d.ts +8 -4
  77. package/esm/spec/element/edge.d.ts +8 -4
  78. package/esm/spec/element/node.d.ts +8 -4
  79. package/esm/spec/plugin.d.ts +4 -5
  80. package/esm/spec/transform.d.ts +5 -6
  81. package/esm/transforms/types.d.ts +1 -2
  82. package/esm/types/index.d.ts +0 -1
  83. package/esm/types/style.d.ts +2 -0
  84. package/esm/utils/animation.js +6 -1
  85. package/esm/utils/animation.js.map +1 -1
  86. package/esm/utils/event/events.d.ts +4 -4
  87. package/esm/utils/event/events.js.map +1 -1
  88. package/esm/utils/extension.d.ts +5 -2
  89. package/esm/utils/extension.js +5 -1
  90. package/esm/utils/extension.js.map +1 -1
  91. package/esm/utils/style.d.ts +5 -2
  92. package/esm/utils/style.js +5 -6
  93. package/esm/utils/style.js.map +1 -1
  94. package/esm/utils/transform.d.ts +1 -1
  95. package/esm/version.d.ts +1 -0
  96. package/esm/version.js +2 -0
  97. package/esm/version.js.map +1 -0
  98. package/lib/behaviors/base-behavior.d.ts +1 -1
  99. package/lib/behaviors/base-behavior.js.map +1 -1
  100. package/lib/behaviors/click-select.d.ts +17 -0
  101. package/lib/behaviors/click-select.js +33 -2
  102. package/lib/behaviors/click-select.js.map +1 -1
  103. package/lib/behaviors/scroll-canvas.d.ts +1 -1
  104. package/lib/behaviors/scroll-canvas.js.map +1 -1
  105. package/lib/behaviors/types.d.ts +0 -4
  106. package/lib/behaviors/zoom-canvas.d.ts +1 -1
  107. package/lib/constants/events/graph.d.ts +12 -0
  108. package/lib/constants/events/graph.js +12 -0
  109. package/lib/constants/events/graph.js.map +1 -1
  110. package/lib/elements/effect.js +1 -2
  111. package/lib/elements/effect.js.map +1 -1
  112. package/lib/elements/shapes/badge.d.ts +1 -1
  113. package/lib/exports.d.ts +2 -0
  114. package/lib/exports.js +3 -1
  115. package/lib/exports.js.map +1 -1
  116. package/lib/index.d.ts +1 -1
  117. package/lib/index.js +2 -1
  118. package/lib/index.js.map +1 -1
  119. package/lib/layouts/index.d.ts +0 -1
  120. package/lib/plugins/camera-setting.js.map +1 -1
  121. package/lib/plugins/contextmenu/util.js +2 -2
  122. package/lib/plugins/contextmenu/util.js.map +1 -1
  123. package/lib/plugins/history/util.js +2 -3
  124. package/lib/plugins/history/util.js.map +1 -1
  125. package/lib/plugins/hull/util.js +1 -2
  126. package/lib/plugins/hull/util.js.map +1 -1
  127. package/lib/plugins/toolbar/util.js +2 -2
  128. package/lib/plugins/toolbar/util.js.map +1 -1
  129. package/lib/plugins/types.d.ts +0 -2
  130. package/lib/plugins/watermark/util.js +2 -3
  131. package/lib/plugins/watermark/util.js.map +1 -1
  132. package/lib/registry/extension/index.d.ts +17 -6
  133. package/lib/registry/extension/index.js +1 -1
  134. package/lib/registry/extension/index.js.map +1 -1
  135. package/lib/registry/extension/types.d.ts +15 -33
  136. package/lib/registry/index.js +4 -5
  137. package/lib/registry/index.js.map +1 -1
  138. package/lib/runtime/behavior.js +5 -0
  139. package/lib/runtime/behavior.js.map +1 -1
  140. package/lib/runtime/data.d.ts +1 -1
  141. package/lib/runtime/data.js +2 -0
  142. package/lib/runtime/data.js.map +1 -1
  143. package/lib/runtime/element.d.ts +1 -1
  144. package/lib/runtime/element.js +7 -4
  145. package/lib/runtime/element.js.map +1 -1
  146. package/lib/runtime/graph.js +3 -3
  147. package/lib/runtime/graph.js.map +1 -1
  148. package/lib/runtime/layout.js +4 -1
  149. package/lib/runtime/layout.js.map +1 -1
  150. package/lib/runtime/viewport.d.ts +3 -5
  151. package/lib/runtime/viewport.js +18 -49
  152. package/lib/runtime/viewport.js.map +1 -1
  153. package/lib/spec/behavior.d.ts +4 -5
  154. package/lib/spec/element/combo.d.ts +8 -4
  155. package/lib/spec/element/edge.d.ts +8 -4
  156. package/lib/spec/element/node.d.ts +8 -4
  157. package/lib/spec/plugin.d.ts +4 -5
  158. package/lib/spec/transform.d.ts +5 -6
  159. package/lib/themes/base.js +1 -2
  160. package/lib/themes/base.js.map +1 -1
  161. package/lib/transforms/types.d.ts +1 -2
  162. package/lib/transforms/utils.js +1 -2
  163. package/lib/transforms/utils.js.map +1 -1
  164. package/lib/types/index.d.ts +0 -1
  165. package/lib/types/style.d.ts +2 -0
  166. package/lib/utils/anchor.js +1 -2
  167. package/lib/utils/anchor.js.map +1 -1
  168. package/lib/utils/animation.js +11 -7
  169. package/lib/utils/animation.js.map +1 -1
  170. package/lib/utils/array.js +1 -2
  171. package/lib/utils/array.js.map +1 -1
  172. package/lib/utils/bbox.js +13 -14
  173. package/lib/utils/bbox.js.map +1 -1
  174. package/lib/utils/cache.js +4 -5
  175. package/lib/utils/cache.js.map +1 -1
  176. package/lib/utils/change.js +2 -3
  177. package/lib/utils/change.js.map +1 -1
  178. package/lib/utils/collapsibility.js +1 -2
  179. package/lib/utils/collapsibility.js.map +1 -1
  180. package/lib/utils/data.js +3 -4
  181. package/lib/utils/data.js.map +1 -1
  182. package/lib/utils/diff.js +1 -2
  183. package/lib/utils/diff.js.map +1 -1
  184. package/lib/utils/dom.js +4 -5
  185. package/lib/utils/dom.js.map +1 -1
  186. package/lib/utils/edge.js +18 -18
  187. package/lib/utils/edge.js.map +1 -1
  188. package/lib/utils/element.js +26 -27
  189. package/lib/utils/element.js.map +1 -1
  190. package/lib/utils/event/events.d.ts +4 -4
  191. package/lib/utils/event/events.js.map +1 -1
  192. package/lib/utils/event/index.js +2 -3
  193. package/lib/utils/event/index.js.map +1 -1
  194. package/lib/utils/extension.d.ts +5 -2
  195. package/lib/utils/extension.js +6 -3
  196. package/lib/utils/extension.js.map +1 -1
  197. package/lib/utils/graphlib.js +3 -4
  198. package/lib/utils/graphlib.js.map +1 -1
  199. package/lib/utils/id.js +3 -4
  200. package/lib/utils/id.js.map +1 -1
  201. package/lib/utils/is.js +4 -5
  202. package/lib/utils/is.js.map +1 -1
  203. package/lib/utils/layout.js +7 -8
  204. package/lib/utils/layout.js.map +1 -1
  205. package/lib/utils/line.js +2 -3
  206. package/lib/utils/line.js.map +1 -1
  207. package/lib/utils/math.js +1 -2
  208. package/lib/utils/math.js.map +1 -1
  209. package/lib/utils/node.js +1 -2
  210. package/lib/utils/node.js.map +1 -1
  211. package/lib/utils/padding.js +1 -2
  212. package/lib/utils/padding.js.map +1 -1
  213. package/lib/utils/palette.js +3 -4
  214. package/lib/utils/palette.js.map +1 -1
  215. package/lib/utils/path.js +4 -4
  216. package/lib/utils/path.js.map +1 -1
  217. package/lib/utils/placement.js +1 -2
  218. package/lib/utils/placement.js.map +1 -1
  219. package/lib/utils/point.js +21 -22
  220. package/lib/utils/point.js.map +1 -1
  221. package/lib/utils/polygon.js +1 -2
  222. package/lib/utils/polygon.js.map +1 -1
  223. package/lib/utils/position.js +5 -5
  224. package/lib/utils/position.js.map +1 -1
  225. package/lib/utils/prefix.js +7 -8
  226. package/lib/utils/prefix.js.map +1 -1
  227. package/lib/utils/relation.js +2 -3
  228. package/lib/utils/relation.js.map +1 -1
  229. package/lib/utils/router/orth.js +9 -10
  230. package/lib/utils/router/orth.js.map +1 -1
  231. package/lib/utils/shape.js +1 -2
  232. package/lib/utils/shape.js.map +1 -1
  233. package/lib/utils/size.js +1 -2
  234. package/lib/utils/size.js.map +1 -1
  235. package/lib/utils/style.d.ts +5 -2
  236. package/lib/utils/style.js +8 -10
  237. package/lib/utils/style.js.map +1 -1
  238. package/lib/utils/text.js +3 -4
  239. package/lib/utils/text.js.map +1 -1
  240. package/lib/utils/theme.js +1 -2
  241. package/lib/utils/theme.js.map +1 -1
  242. package/lib/utils/transform.d.ts +1 -1
  243. package/lib/utils/transform.js +2 -2
  244. package/lib/utils/transform.js.map +1 -1
  245. package/lib/utils/traverse.js +2 -3
  246. package/lib/utils/traverse.js.map +1 -1
  247. package/lib/utils/tree.js +1 -2
  248. package/lib/utils/tree.js.map +1 -1
  249. package/lib/utils/vector.js +16 -17
  250. package/lib/utils/vector.js.map +1 -1
  251. package/lib/utils/visibility.js +1 -2
  252. package/lib/utils/visibility.js.map +1 -1
  253. package/lib/version.d.ts +1 -0
  254. package/lib/version.js +5 -0
  255. package/lib/version.js.map +1 -0
  256. package/package.json +6 -3
  257. package/src/behaviors/base-behavior.ts +1 -1
  258. package/src/behaviors/click-select.ts +35 -4
  259. package/src/behaviors/scroll-canvas.ts +1 -1
  260. package/src/behaviors/types.ts +0 -4
  261. package/src/constants/events/graph.ts +12 -0
  262. package/src/exports.ts +2 -0
  263. package/src/index.ts +1 -1
  264. package/src/plugins/camera-setting.ts +2 -2
  265. package/src/plugins/types.ts +0 -2
  266. package/src/registry/extension/index.ts +15 -8
  267. package/src/registry/extension/types.ts +15 -40
  268. package/src/runtime/behavior.ts +5 -0
  269. package/src/runtime/data.ts +1 -0
  270. package/src/runtime/element.ts +7 -4
  271. package/src/runtime/graph.ts +3 -3
  272. package/src/runtime/layout.ts +5 -2
  273. package/src/runtime/viewport.ts +17 -48
  274. package/src/spec/behavior.ts +4 -5
  275. package/src/spec/element/combo.ts +16 -4
  276. package/src/spec/element/edge.ts +16 -4
  277. package/src/spec/element/node.ts +16 -4
  278. package/src/spec/plugin.ts +4 -5
  279. package/src/spec/transform.ts +5 -6
  280. package/src/transforms/types.ts +1 -2
  281. package/src/types/index.ts +0 -1
  282. package/src/types/style.ts +2 -0
  283. package/src/utils/animation.ts +7 -1
  284. package/src/utils/event/events.ts +2 -0
  285. package/src/utils/extension.ts +10 -3
  286. package/src/utils/style.ts +11 -6
  287. package/src/version.ts +1 -0
  288. package/dist/lib/types/callable.d.ts +0 -19
  289. package/esm/types/callable.d.ts +0 -19
  290. package/esm/types/callable.js +0 -2
  291. package/esm/types/callable.js.map +0 -1
  292. package/lib/types/callable.d.ts +0 -19
  293. package/lib/types/callable.js +0 -3
  294. package/lib/types/callable.js.map +0 -1
  295. package/src/types/callable.ts +0 -21
@@ -1,6 +1,6 @@
1
1
  import type { AnimationOptions } from '../../animations/types';
2
2
  import type { BaseNodeStyleProps } from '../../elements/nodes';
3
- import type { CallableObject } from '../../types';
3
+ import type { Graph } from '../../runtime/graph';
4
4
  import type { NodeData } from '../data';
5
5
  import type { AnimationStage } from './animation';
6
6
  import type { PaletteOptions } from './palette';
@@ -16,19 +16,31 @@ export interface NodeOptions {
16
16
  *
17
17
  * <en/> Node type
18
18
  */
19
- type?: string | ((datum: NodeData) => string);
19
+ type?: string | ((this: Graph, datum: NodeData) => string);
20
20
  /**
21
21
  * <zh/> 节点样式
22
22
  *
23
23
  * <en/> Node style
24
24
  */
25
- style?: CallableObject<NodeStyle, NodeData>;
25
+ style?:
26
+ | NodeStyle
27
+ | ((this: Graph, data: NodeData) => NodeStyle)
28
+ | {
29
+ [K in keyof NodeStyle]: NodeStyle[K] | ((this: Graph, data: NodeData) => NodeStyle[K]);
30
+ };
26
31
  /**
27
32
  * <zh/> 节点状态样式
28
33
  *
29
34
  * <en/> Node state style
30
35
  */
31
- state?: Record<string, CallableObject<NodeStyle, NodeData>>;
36
+ state?: Record<
37
+ string,
38
+ | NodeStyle
39
+ | ((this: Graph, data: NodeData) => NodeStyle)
40
+ | {
41
+ [K in keyof NodeStyle]: NodeStyle[K] | ((this: Graph, data: NodeData) => NodeStyle[K]);
42
+ }
43
+ >;
32
44
  /**
33
45
  * <zh/> 节点动画
34
46
  *
@@ -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
  };
@@ -86,13 +86,19 @@ export function preprocessKeyframes(keyframes: Keyframe[]): Keyframe[] {
86
86
 
87
87
  // 将 PropertyIndexedKeyframes 转化为 Keyframe 格式
88
88
  // convert PropertyIndexedKeyframes to Keyframe format
89
- return Object.entries(propertyIndexedKeyframes).reduce((acc, [key, values]) => {
89
+ const output = Object.entries(propertyIndexedKeyframes).reduce((acc, [key, values]) => {
90
90
  values.forEach((value, index) => {
91
91
  if (!acc[index]) acc[index] = { [key]: value };
92
92
  else acc[index][key] = value;
93
93
  });
94
94
  return acc;
95
95
  }, [] as Keyframe[]);
96
+
97
+ // 如果处理后所有的属性都被过滤掉,则添加一个没有实际作用的属性用于触发动画
98
+ // If all properties are filtered out after processing, add a property that has no actual effect to trigger the animation
99
+ if (keyframes.length !== 0 && output.length === 0) output.push(...[{ _: 0 }, { _: 0 }]);
100
+
101
+ return output;
96
102
  }
97
103
 
98
104
  /**
@@ -23,6 +23,8 @@ export class GraphLifeCycleEvent extends BaseEvent implements IGraphLifeCycleEve
23
23
  | GraphEvent.AFTER_DRAW
24
24
  | GraphEvent.BEFORE_LAYOUT
25
25
  | GraphEvent.AFTER_LAYOUT
26
+ | GraphEvent.BEFORE_STAGE_LAYOUT
27
+ | GraphEvent.AFTER_STAGE_LAYOUT
26
28
  | GraphEvent.BEFORE_SIZE_CHANGE
27
29
  | GraphEvent.AFTER_SIZE_CHANGE
28
30
  | GraphEvent.BATCH_START
@@ -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.5';
@@ -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
- };