@antv/g2 5.0.0-beta.11 → 5.0.0-beta.12

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 (251) hide show
  1. package/dist/g2-lite.min.js +3 -3
  2. package/dist/g2.min.js +3 -3
  3. package/esm/api/chart.d.ts +2 -1
  4. package/esm/api/chart.js +2 -2
  5. package/esm/api/chart.js.map +1 -1
  6. package/esm/api/composition/base.d.ts +1 -1
  7. package/esm/api/composition/base.js +6 -17
  8. package/esm/api/composition/base.js.map +1 -1
  9. package/esm/api/composition/facetCircle.d.ts +2 -2
  10. package/esm/api/composition/facetCircle.js +2 -2
  11. package/esm/api/composition/facetCircle.js.map +1 -1
  12. package/esm/api/composition/facetRect.d.ts +2 -2
  13. package/esm/api/composition/facetRect.js +2 -2
  14. package/esm/api/composition/facetRect.js.map +1 -1
  15. package/esm/api/composition/geoPath.d.ts +2 -2
  16. package/esm/api/composition/geoPath.js +2 -2
  17. package/esm/api/composition/geoPath.js.map +1 -1
  18. package/esm/api/composition/geoView.d.ts +2 -2
  19. package/esm/api/composition/geoView.js +2 -2
  20. package/esm/api/composition/geoView.js.map +1 -1
  21. package/esm/api/composition/index.d.ts +2 -2
  22. package/esm/api/composition/index.js +2 -2
  23. package/esm/api/composition/index.js.map +1 -1
  24. package/esm/api/composition/repeatMatrix.d.ts +2 -2
  25. package/esm/api/composition/repeatMatrix.js +2 -2
  26. package/esm/api/composition/repeatMatrix.js.map +1 -1
  27. package/esm/api/composition/spaceFlex.d.ts +2 -2
  28. package/esm/api/composition/spaceFlex.js +2 -2
  29. package/esm/api/composition/spaceFlex.js.map +1 -1
  30. package/esm/api/composition/spaceLayer.d.ts +2 -2
  31. package/esm/api/composition/spaceLayer.js +2 -2
  32. package/esm/api/composition/spaceLayer.js.map +1 -1
  33. package/esm/api/composition/timingKeyframe.d.ts +2 -2
  34. package/esm/api/composition/timingKeyframe.js +2 -2
  35. package/esm/api/composition/timingKeyframe.js.map +1 -1
  36. package/esm/api/composition/view.d.ts +2 -2
  37. package/esm/api/composition/view.js +2 -2
  38. package/esm/api/composition/view.js.map +1 -1
  39. package/esm/api/index.d.ts +2 -0
  40. package/esm/api/index.js +2 -0
  41. package/esm/api/index.js.map +1 -1
  42. package/esm/api/mark/base.d.ts +1 -1
  43. package/esm/api/mark/base.js +7 -7
  44. package/esm/api/mark/base.js.map +1 -1
  45. package/esm/api/mark/index.d.ts +1 -0
  46. package/esm/api/mark/index.js +1 -0
  47. package/esm/api/mark/index.js.map +1 -1
  48. package/esm/api/mark/mark.d.ts +27 -27
  49. package/esm/api/mark/mark.js +28 -27
  50. package/esm/api/mark/mark.js.map +1 -1
  51. package/esm/api/mark/types.d.ts +1 -0
  52. package/esm/api/node.d.ts +1 -1
  53. package/esm/api/node.js +1 -1
  54. package/esm/api/node.js.map +1 -1
  55. package/esm/api/props.d.ts +1 -1
  56. package/esm/api/props.js +20 -0
  57. package/esm/api/props.js.map +1 -1
  58. package/esm/composition/timingKeyframe.js +13 -7
  59. package/esm/composition/timingKeyframe.js.map +1 -1
  60. package/esm/index.d.ts +1 -1
  61. package/esm/index.js +1 -1
  62. package/esm/index.js.map +1 -1
  63. package/esm/interaction/builtin/tooltip.d.ts +10 -2
  64. package/esm/interaction/index.d.ts +1 -0
  65. package/esm/interaction/index.js +1 -0
  66. package/esm/interaction/index.js.map +1 -1
  67. package/esm/interaction/native/event.d.ts +1 -0
  68. package/esm/interaction/native/event.js +42 -0
  69. package/esm/interaction/native/event.js.map +1 -0
  70. package/esm/interaction/native/tooltip.d.ts +2 -3
  71. package/esm/interaction/native/tooltip.js +68 -73
  72. package/esm/interaction/native/tooltip.js.map +1 -1
  73. package/esm/mark/utils.js +1 -5
  74. package/esm/mark/utils.js.map +1 -1
  75. package/esm/runtime/mark.js +5 -3
  76. package/esm/runtime/mark.js.map +1 -1
  77. package/esm/runtime/plot.js +33 -16
  78. package/esm/runtime/plot.js.map +1 -1
  79. package/esm/runtime/transform.d.ts +5 -0
  80. package/esm/runtime/transform.js +62 -4
  81. package/esm/runtime/transform.js.map +1 -1
  82. package/esm/runtime/types/common.d.ts +1 -0
  83. package/esm/runtime/types/component.d.ts +2 -1
  84. package/esm/runtime/types/options.d.ts +6 -1
  85. package/esm/spec/geometry.d.ts +33 -17
  86. package/esm/spec/interaction.d.ts +6 -1
  87. package/esm/stdlib/index.js +2 -2
  88. package/esm/stdlib/index.js.map +1 -1
  89. package/esm/transform/groupN.js +2 -2
  90. package/esm/transform/groupN.js.map +1 -1
  91. package/esm/transform/maybeTitle.js +13 -3
  92. package/esm/transform/maybeTitle.js.map +1 -1
  93. package/esm/transform/maybeTooltip.js +20 -20
  94. package/esm/transform/maybeTooltip.js.map +1 -1
  95. package/esm/transform/maybeZeroX.js +2 -2
  96. package/esm/transform/maybeZeroX.js.map +1 -1
  97. package/esm/transform/maybeZeroY.js +2 -2
  98. package/esm/transform/maybeZeroY.js.map +1 -1
  99. package/esm/transform/maybeZeroY1.js +2 -2
  100. package/esm/transform/maybeZeroY1.js.map +1 -1
  101. package/esm/transform/utils/helper.d.ts +12 -0
  102. package/esm/transform/utils/helper.js +8 -0
  103. package/esm/transform/utils/helper.js.map +1 -1
  104. package/esm/utils/helper.js +4 -1
  105. package/esm/utils/helper.js.map +1 -1
  106. package/lib/api/chart.d.ts +2 -1
  107. package/lib/api/chart.js +2 -2
  108. package/lib/api/chart.js.map +1 -1
  109. package/lib/api/composition/base.d.ts +1 -1
  110. package/lib/api/composition/base.js +8 -18
  111. package/lib/api/composition/base.js.map +1 -1
  112. package/lib/api/composition/facetCircle.d.ts +2 -2
  113. package/lib/api/composition/facetCircle.js +1 -1
  114. package/lib/api/composition/facetCircle.js.map +1 -1
  115. package/lib/api/composition/facetRect.d.ts +2 -2
  116. package/lib/api/composition/facetRect.js +1 -1
  117. package/lib/api/composition/facetRect.js.map +1 -1
  118. package/lib/api/composition/geoPath.d.ts +2 -2
  119. package/lib/api/composition/geoPath.js +1 -1
  120. package/lib/api/composition/geoPath.js.map +1 -1
  121. package/lib/api/composition/geoView.d.ts +2 -2
  122. package/lib/api/composition/geoView.js +1 -1
  123. package/lib/api/composition/geoView.js.map +1 -1
  124. package/lib/api/composition/index.d.ts +2 -2
  125. package/lib/api/composition/index.js +2 -2
  126. package/lib/api/composition/index.js.map +1 -1
  127. package/lib/api/composition/repeatMatrix.d.ts +2 -2
  128. package/lib/api/composition/repeatMatrix.js +1 -1
  129. package/lib/api/composition/repeatMatrix.js.map +1 -1
  130. package/lib/api/composition/spaceFlex.d.ts +2 -2
  131. package/lib/api/composition/spaceFlex.js +1 -1
  132. package/lib/api/composition/spaceFlex.js.map +1 -1
  133. package/lib/api/composition/spaceLayer.d.ts +2 -2
  134. package/lib/api/composition/spaceLayer.js +1 -1
  135. package/lib/api/composition/spaceLayer.js.map +1 -1
  136. package/lib/api/composition/timingKeyframe.d.ts +2 -2
  137. package/lib/api/composition/timingKeyframe.js +1 -1
  138. package/lib/api/composition/timingKeyframe.js.map +1 -1
  139. package/lib/api/composition/view.d.ts +2 -2
  140. package/lib/api/composition/view.js +1 -1
  141. package/lib/api/composition/view.js.map +1 -1
  142. package/lib/api/index.d.ts +2 -0
  143. package/lib/api/index.js +5 -1
  144. package/lib/api/index.js.map +1 -1
  145. package/lib/api/mark/base.d.ts +1 -1
  146. package/lib/api/mark/base.js +9 -9
  147. package/lib/api/mark/base.js.map +1 -1
  148. package/lib/api/mark/index.d.ts +1 -0
  149. package/lib/api/mark/index.js +3 -1
  150. package/lib/api/mark/index.js.map +1 -1
  151. package/lib/api/mark/mark.d.ts +27 -27
  152. package/lib/api/mark/mark.js +27 -26
  153. package/lib/api/mark/mark.js.map +1 -1
  154. package/lib/api/mark/types.d.ts +1 -0
  155. package/lib/api/node.d.ts +1 -1
  156. package/lib/api/node.js +1 -1
  157. package/lib/api/node.js.map +1 -1
  158. package/lib/api/props.d.ts +1 -1
  159. package/lib/api/props.js +20 -0
  160. package/lib/api/props.js.map +1 -1
  161. package/lib/composition/timingKeyframe.js +13 -7
  162. package/lib/composition/timingKeyframe.js.map +1 -1
  163. package/lib/index.d.ts +1 -1
  164. package/lib/index.js +3 -1
  165. package/lib/index.js.map +1 -1
  166. package/lib/interaction/builtin/tooltip.d.ts +10 -2
  167. package/lib/interaction/index.d.ts +1 -0
  168. package/lib/interaction/index.js +3 -1
  169. package/lib/interaction/index.js.map +1 -1
  170. package/lib/interaction/native/event.d.ts +1 -0
  171. package/lib/interaction/native/event.js +46 -0
  172. package/lib/interaction/native/event.js.map +1 -0
  173. package/lib/interaction/native/tooltip.d.ts +2 -3
  174. package/lib/interaction/native/tooltip.js +67 -72
  175. package/lib/interaction/native/tooltip.js.map +1 -1
  176. package/lib/mark/utils.js +1 -5
  177. package/lib/mark/utils.js.map +1 -1
  178. package/lib/runtime/mark.js +4 -2
  179. package/lib/runtime/mark.js.map +1 -1
  180. package/lib/runtime/plot.js +33 -16
  181. package/lib/runtime/plot.js.map +1 -1
  182. package/lib/runtime/transform.d.ts +5 -0
  183. package/lib/runtime/transform.js +64 -4
  184. package/lib/runtime/transform.js.map +1 -1
  185. package/lib/runtime/types/common.d.ts +1 -0
  186. package/lib/runtime/types/component.d.ts +2 -1
  187. package/lib/runtime/types/options.d.ts +6 -1
  188. package/lib/spec/geometry.d.ts +33 -17
  189. package/lib/spec/interaction.d.ts +6 -1
  190. package/lib/stdlib/index.js +1 -1
  191. package/lib/stdlib/index.js.map +1 -1
  192. package/lib/transform/groupN.js +1 -1
  193. package/lib/transform/groupN.js.map +1 -1
  194. package/lib/transform/maybeTitle.js +12 -2
  195. package/lib/transform/maybeTitle.js.map +1 -1
  196. package/lib/transform/maybeTooltip.js +20 -20
  197. package/lib/transform/maybeTooltip.js.map +1 -1
  198. package/lib/transform/maybeZeroX.js +1 -1
  199. package/lib/transform/maybeZeroX.js.map +1 -1
  200. package/lib/transform/maybeZeroY.js +1 -1
  201. package/lib/transform/maybeZeroY.js.map +1 -1
  202. package/lib/transform/maybeZeroY1.js +1 -1
  203. package/lib/transform/maybeZeroY1.js.map +1 -1
  204. package/lib/transform/utils/helper.d.ts +12 -0
  205. package/lib/transform/utils/helper.js +11 -1
  206. package/lib/transform/utils/helper.js.map +1 -1
  207. package/lib/utils/helper.js +4 -1
  208. package/lib/utils/helper.js.map +1 -1
  209. package/package.json +1 -1
  210. package/src/api/chart.ts +2 -2
  211. package/src/api/composition/base.ts +5 -7
  212. package/src/api/composition/facetCircle.ts +2 -2
  213. package/src/api/composition/facetRect.ts +2 -2
  214. package/src/api/composition/geoPath.ts +2 -2
  215. package/src/api/composition/geoView.ts +2 -2
  216. package/src/api/composition/index.ts +2 -2
  217. package/src/api/composition/repeatMatrix.ts +2 -2
  218. package/src/api/composition/spaceFlex.ts +2 -2
  219. package/src/api/composition/spaceLayer.ts +2 -2
  220. package/src/api/composition/timingKeyframe.ts +2 -2
  221. package/src/api/composition/view.ts +2 -2
  222. package/src/api/index.ts +2 -0
  223. package/src/api/mark/base.ts +7 -7
  224. package/src/api/mark/index.ts +2 -0
  225. package/src/api/mark/mark.ts +28 -27
  226. package/src/api/mark/types.ts +1 -0
  227. package/src/api/node.ts +1 -1
  228. package/src/api/props.ts +22 -1
  229. package/src/composition/timingKeyframe.ts +13 -7
  230. package/src/index.ts +1 -1
  231. package/src/interaction/index.ts +1 -0
  232. package/src/interaction/native/event.ts +44 -0
  233. package/src/interaction/native/tooltip.ts +66 -92
  234. package/src/mark/utils.ts +1 -5
  235. package/src/runtime/mark.ts +6 -2
  236. package/src/runtime/plot.ts +44 -18
  237. package/src/runtime/transform.ts +71 -4
  238. package/src/runtime/types/common.ts +1 -0
  239. package/src/runtime/types/component.ts +2 -0
  240. package/src/runtime/types/options.ts +6 -1
  241. package/src/spec/geometry.ts +38 -30
  242. package/src/spec/interaction.ts +5 -1
  243. package/src/stdlib/index.ts +2 -0
  244. package/src/transform/groupN.ts +2 -2
  245. package/src/transform/maybeTitle.ts +11 -3
  246. package/src/transform/maybeTooltip.ts +17 -21
  247. package/src/transform/maybeZeroX.ts +2 -2
  248. package/src/transform/maybeZeroY.ts +2 -2
  249. package/src/transform/maybeZeroY1.ts +2 -2
  250. package/src/transform/utils/helper.ts +10 -0
  251. package/src/utils/helper.ts +6 -1
@@ -1,11 +1,9 @@
1
1
  import { DisplayObject } from '@antv/g';
2
2
  import { Coordinate } from '@antv/coord';
3
- import { defineProps } from '../props';
4
3
  import { Node } from '../node';
5
4
  import { G2Theme, G2ViewDescriptor } from '../../runtime';
6
5
 
7
- @defineProps([{ name: 'on', type: 'event' }])
8
- export class Base<
6
+ export class CompositionNode<
9
7
  Value extends Record<string, any> = Record<string, any>,
10
8
  ParentValue extends Record<string, any> = Record<string, any>,
11
9
  ChildValue extends Record<string, any> = Record<string, any>,
@@ -14,8 +12,8 @@ export class Base<
14
12
  * Get view instance by key.
15
13
  */
16
14
  getView(): G2ViewDescriptor {
17
- const chart = this.root();
18
- const { views } = chart.context();
15
+ const chart = this.getRoot();
16
+ const { views } = chart.getContext();
19
17
  if (!views?.length) return undefined;
20
18
  return views.find((view) => view.key === this.attr('key'));
21
19
  }
@@ -31,8 +29,8 @@ export class Base<
31
29
  getGroup(): DisplayObject {
32
30
  const key = this.attr('key');
33
31
  if (!key) return undefined;
34
- const chart = this.root();
35
- const chartGroup = chart.context().canvas.getRoot();
32
+ const chart = this.getRoot();
33
+ const chartGroup = chart.getContext().canvas.getRoot();
36
34
  return chartGroup.getElementById(key);
37
35
  }
38
36
 
@@ -7,7 +7,7 @@ import {
7
7
  ObjectAttribute,
8
8
  } from '../types';
9
9
  import { mark, Mark } from '../mark';
10
- import { Composition, Base } from './index';
10
+ import { Composition, CompositionNode } from './index';
11
11
 
12
12
  type FacetCircleSpec = Concrete<FacetCircleComposition>;
13
13
 
@@ -29,7 +29,7 @@ export interface FacetCircle extends Composition, Mark {
29
29
  { type: 'object', name: 'axis' },
30
30
  ...nodeProps(mark),
31
31
  ])
32
- export class FacetCircle extends Base<FacetCircleComposition> {
32
+ export class FacetCircle extends CompositionNode<FacetCircleComposition> {
33
33
  constructor() {
34
34
  super({}, 'facetCircle');
35
35
  }
@@ -7,7 +7,7 @@ import {
7
7
  ObjectAttribute,
8
8
  } from '../types';
9
9
  import { mark, Mark } from '../mark';
10
- import { Composition, Base } from './index';
10
+ import { Composition, CompositionNode } from './index';
11
11
 
12
12
  type FacetRectSpec = Concrete<FacetRectComposition>;
13
13
 
@@ -29,7 +29,7 @@ export interface FacetRect extends Composition, Mark {
29
29
  { type: 'object', name: 'axis' },
30
30
  ...nodeProps(mark),
31
31
  ])
32
- export class FacetRect extends Base<FacetRectComposition> {
32
+ export class FacetRect extends CompositionNode<FacetRectComposition> {
33
33
  constructor() {
34
34
  super({}, 'facetRect');
35
35
  }
@@ -7,7 +7,7 @@ import {
7
7
  Concrete,
8
8
  } from '../types';
9
9
  import { mark, Mark } from '../mark';
10
- import { Composition, Base } from './index';
10
+ import { Composition, CompositionNode } from './index';
11
11
 
12
12
  type GeoPathSpec = Concrete<GeoPathComposition>;
13
13
 
@@ -33,7 +33,7 @@ export interface GeoPath extends Mark, Composition {
33
33
  { type: 'object', name: 'legend' },
34
34
  ...nodeProps(mark),
35
35
  ])
36
- export class GeoPath extends Base<GeoPathComposition> {
36
+ export class GeoPath extends CompositionNode<GeoPathComposition> {
37
37
  constructor() {
38
38
  super({}, 'geoPath');
39
39
  }
@@ -7,7 +7,7 @@ import {
7
7
  Concrete,
8
8
  } from '../types';
9
9
  import { mark, Mark } from '../mark';
10
- import { Composition, Base } from './index';
10
+ import { Composition, CompositionNode } from './index';
11
11
 
12
12
  type GeoViewSpec = Concrete<GeoViewComposition>;
13
13
 
@@ -32,7 +32,7 @@ export interface GeoView extends Mark, Composition {
32
32
  { type: 'object', name: 'legend' },
33
33
  ...nodeProps(mark),
34
34
  ])
35
- export class GeoView extends Base<GeoViewComposition> {
35
+ export class GeoView extends CompositionNode<GeoViewComposition> {
36
36
  constructor() {
37
37
  super({}, 'geoView');
38
38
  }
@@ -1,5 +1,5 @@
1
1
  import { defineProps, nodeProps } from '../props';
2
- import { Base } from './base';
2
+ import { CompositionNode } from './base';
3
3
  import { View } from './view';
4
4
  import { SpaceLayer } from './spaceLayer';
5
5
  import { SpaceFlex } from './spaceFlex';
@@ -35,7 +35,7 @@ export interface Composition {
35
35
  }
36
36
 
37
37
  export {
38
- Base,
38
+ CompositionNode,
39
39
  View,
40
40
  SpaceLayer,
41
41
  SpaceFlex,
@@ -7,7 +7,7 @@ import {
7
7
  ObjectAttribute,
8
8
  } from '../types';
9
9
  import { mark, Mark } from '../mark';
10
- import { Composition, Base } from './index';
10
+ import { Composition, CompositionNode } from './index';
11
11
 
12
12
  type RepeatMatrixSpec = Concrete<RepeatMatrixComposition>;
13
13
 
@@ -29,7 +29,7 @@ export interface RepeatMatrix extends Composition, Mark {
29
29
  { type: 'object', name: 'legend' },
30
30
  ...nodeProps(mark),
31
31
  ])
32
- export class RepeatMatrix extends Base<RepeatMatrixComposition> {
32
+ export class RepeatMatrix extends CompositionNode<RepeatMatrixComposition> {
33
33
  constructor() {
34
34
  super({}, 'repeatMatrix');
35
35
  }
@@ -2,7 +2,7 @@ import { SpaceFlexComposition } from '../../spec';
2
2
  import { defineProps, nodeProps } from '../props';
3
3
  import { ValueAttribute, Concrete } from '../types';
4
4
  import { mark, Mark } from '../mark';
5
- import { Composition, Base } from './index';
5
+ import { Composition, CompositionNode } from './index';
6
6
 
7
7
  type SpaceFlexSpec = Concrete<SpaceFlexComposition>;
8
8
 
@@ -11,7 +11,7 @@ export interface SpaceFlex extends Composition, Mark {
11
11
  }
12
12
 
13
13
  @defineProps([{ type: 'value', name: 'data' }, ...nodeProps(mark)])
14
- export class SpaceFlex extends Base<SpaceFlexSpec> {
14
+ export class SpaceFlex extends CompositionNode<SpaceFlexSpec> {
15
15
  constructor() {
16
16
  super({}, 'spaceFlex');
17
17
  }
@@ -2,7 +2,7 @@ import { SpaceLayerComposition } from '../../spec';
2
2
  import { defineProps, nodeProps } from '../props';
3
3
  import { ValueAttribute, Concrete } from '../types';
4
4
  import { mark, Mark } from '../mark';
5
- import { Composition, Base } from './index';
5
+ import { Composition, CompositionNode } from './index';
6
6
 
7
7
  type SpaceLayerSpec = Concrete<SpaceLayerComposition>;
8
8
 
@@ -11,7 +11,7 @@ export interface SpaceLayer extends Composition, Mark {
11
11
  }
12
12
 
13
13
  @defineProps([{ type: 'value', name: 'data' }, ...nodeProps(mark)])
14
- export class SpaceLayer extends Base<SpaceLayerComposition> {
14
+ export class SpaceLayer extends CompositionNode<SpaceLayerComposition> {
15
15
  constructor() {
16
16
  super({}, 'spaceLayer');
17
17
  }
@@ -2,14 +2,14 @@ import { TimingKeyframeComposition } from '../../spec';
2
2
  import { defineProps, nodeProps } from '../props';
3
3
  import { Concrete } from '../types';
4
4
  import { mark, Mark } from '../mark';
5
- import { Composition, Base } from './index';
5
+ import { Composition, CompositionNode } from './index';
6
6
 
7
7
  type TimingKeyframeSpec = Concrete<TimingKeyframeComposition>;
8
8
 
9
9
  export interface TimingKeyframe extends Composition, Mark {}
10
10
 
11
11
  @defineProps([...nodeProps(mark)])
12
- export class TimingKeyframe extends Base<TimingKeyframeSpec> {
12
+ export class TimingKeyframe extends CompositionNode<TimingKeyframeSpec> {
13
13
  constructor() {
14
14
  super({}, 'timingKeyframe');
15
15
  }
@@ -7,7 +7,7 @@ import {
7
7
  Concrete,
8
8
  } from '../types';
9
9
  import { mark, Mark } from '../mark';
10
- import { Base } from './base';
10
+ import { CompositionNode } from './base';
11
11
 
12
12
  type ViewSpec = Concrete<ViewComposition>;
13
13
 
@@ -35,7 +35,7 @@ export interface View extends Mark {
35
35
  ])
36
36
  export class View<
37
37
  ViewProps extends ViewComposition = ViewComposition,
38
- > extends Base<ViewProps> {
38
+ > extends CompositionNode<ViewProps> {
39
39
  constructor(options = {}, type = 'view') {
40
40
  super(options, type);
41
41
  }
package/src/api/index.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { Chart } from './chart';
2
+ export { MarkNode } from './mark';
3
+ export { CompositionNode } from './composition';
2
4
  export { register } from './library';
@@ -2,13 +2,13 @@ import { DisplayObject } from '@antv/g';
2
2
  import { Node } from '../node';
3
3
  import { G2MarkState, Scale } from '../../runtime';
4
4
 
5
- export class MarkBase<
5
+ export class MarkNode<
6
6
  Value extends Record<string, any> = Record<string, any>,
7
7
  ParentValue extends Record<string, any> = Record<string, any>,
8
8
  ChildValue extends Record<string, any> = Record<string, any>,
9
9
  > extends Node<Value, ParentValue, ChildValue> {
10
10
  changeData(data: any) {
11
- const chart = this.root();
11
+ const chart = this.getRoot();
12
12
  if (!chart) return;
13
13
  this.attr('data', data);
14
14
  return chart?.render();
@@ -18,7 +18,7 @@ export class MarkBase<
18
18
  * Get mark from chart views.
19
19
  */
20
20
  getMark(): G2MarkState {
21
- const chartView = this.root()?.getView();
21
+ const chartView = this.getRoot()?.getView();
22
22
  if (!chartView) return undefined;
23
23
  const { markState } = chartView;
24
24
  const markKey = Array.from(markState.keys()).find(
@@ -31,7 +31,7 @@ export class MarkBase<
31
31
  * Get all scales instance.
32
32
  */
33
33
  getScale(): Record<string, Scale> {
34
- const chartView = this.root()?.getView();
34
+ const chartView = this.getRoot()?.getView();
35
35
  if (!chartView) return undefined;
36
36
  return chartView?.scale;
37
37
  }
@@ -40,7 +40,7 @@ export class MarkBase<
40
40
  * Get the scale instance by channel.
41
41
  */
42
42
  getScaleByChannel(channel: string): Scale {
43
- const chartView = this.root()?.getView();
43
+ const chartView = this.getRoot()?.getView();
44
44
  if (!chartView) return undefined;
45
45
  return chartView?.scale?.[channel];
46
46
  }
@@ -51,8 +51,8 @@ export class MarkBase<
51
51
  getGroup(): DisplayObject {
52
52
  const key = this.attr('key');
53
53
  if (!key) return undefined;
54
- const chart = this.root();
55
- const chartGroup = chart.context().canvas.getRoot();
54
+ const chart = this.getRoot();
55
+ const chartGroup = chart.getContext().canvas.getRoot();
56
56
  return chartGroup.getElementById(key);
57
57
  }
58
58
  }
@@ -56,6 +56,8 @@ export interface Mark {
56
56
  wordCloud(): WordCloud;
57
57
  }
58
58
 
59
+ export { MarkNode } from './base';
60
+
59
61
  export const mark = {
60
62
  interval: Interval,
61
63
  rect: Rect,
@@ -28,7 +28,7 @@ import {
28
28
  } from '../../spec';
29
29
  import { NodePropertyDescriptor, defineProps } from '../props';
30
30
  import { Concrete } from '../types';
31
- import { MarkBase } from './base';
31
+ import { MarkNode } from './base';
32
32
  import { API } from './types';
33
33
 
34
34
  export interface Interval extends API<Concrete<IntervalGeometry>, Interval> {
@@ -149,185 +149,186 @@ export const props: NodePropertyDescriptor[] = [
149
149
  { name: 'slider', type: 'object' },
150
150
  { name: 'scrollbar', type: 'object' },
151
151
  { name: 'state', type: 'object' },
152
+ { name: 'tooltip', type: 'mix' },
152
153
  ];
153
154
 
154
155
  @defineProps(props)
155
- export class Interval extends MarkBase<IntervalGeometry> {
156
+ export class Interval extends MarkNode<IntervalGeometry> {
156
157
  constructor() {
157
158
  super({}, 'interval');
158
159
  }
159
160
  }
160
161
 
161
162
  @defineProps(props)
162
- export class Rect extends MarkBase<RectGeometry> {
163
+ export class Rect extends MarkNode<RectGeometry> {
163
164
  constructor() {
164
165
  super({}, 'rect');
165
166
  }
166
167
  }
167
168
 
168
169
  @defineProps(props)
169
- export class Point extends MarkBase<PointGeometry> {
170
+ export class Point extends MarkNode<PointGeometry> {
170
171
  constructor() {
171
172
  super({}, 'point');
172
173
  }
173
174
  }
174
175
 
175
176
  @defineProps(props)
176
- export class Area extends MarkBase<AreaGeometry> {
177
+ export class Area extends MarkNode<AreaGeometry> {
177
178
  constructor() {
178
179
  super({}, 'area');
179
180
  }
180
181
  }
181
182
 
182
183
  @defineProps(props)
183
- export class Line extends MarkBase<LineGeometry> {
184
+ export class Line extends MarkNode<LineGeometry> {
184
185
  constructor() {
185
186
  super({}, 'line');
186
187
  }
187
188
  }
188
189
 
189
190
  @defineProps(props)
190
- export class Cell extends MarkBase<CellGeometry> {
191
+ export class Cell extends MarkNode<CellGeometry> {
191
192
  constructor() {
192
193
  super({}, 'cell');
193
194
  }
194
195
  }
195
196
 
196
197
  @defineProps(props)
197
- export class Vector extends MarkBase<VectorGeometry> {
198
+ export class Vector extends MarkNode<VectorGeometry> {
198
199
  constructor() {
199
200
  super({}, 'vector');
200
201
  }
201
202
  }
202
203
 
203
204
  @defineProps(props)
204
- export class Link extends MarkBase<LinkGeometry> {
205
+ export class Link extends MarkNode<LinkGeometry> {
205
206
  constructor() {
206
207
  super({}, 'link');
207
208
  }
208
209
  }
209
210
 
210
211
  @defineProps(props)
211
- export class Polygon extends MarkBase<PolygonGeometry> {
212
+ export class Polygon extends MarkNode<PolygonGeometry> {
212
213
  constructor() {
213
214
  super({}, 'polygon');
214
215
  }
215
216
  }
216
217
 
217
218
  @defineProps(props)
218
- export class Image extends MarkBase<ImageGeometry> {
219
+ export class Image extends MarkNode<ImageGeometry> {
219
220
  constructor() {
220
221
  super({}, 'image');
221
222
  }
222
223
  }
223
224
 
224
225
  @defineProps(props)
225
- export class Text extends MarkBase<TextGeometry> {
226
+ export class Text extends MarkNode<TextGeometry> {
226
227
  constructor() {
227
228
  super({}, 'text');
228
229
  }
229
230
  }
230
231
 
231
232
  @defineProps(props)
232
- export class Box extends MarkBase<BoxGeometry> {
233
+ export class Box extends MarkNode<BoxGeometry> {
233
234
  constructor() {
234
235
  super({}, 'box');
235
236
  }
236
237
  }
237
238
 
238
239
  @defineProps(props)
239
- export class LineX extends MarkBase<LineXMark> {
240
+ export class LineX extends MarkNode<LineXMark> {
240
241
  constructor() {
241
242
  super({}, 'lineX');
242
243
  }
243
244
  }
244
245
 
245
246
  @defineProps(props)
246
- export class LineY extends MarkBase<LineYMark> {
247
+ export class LineY extends MarkNode<LineYMark> {
247
248
  constructor() {
248
249
  super({}, 'lineY');
249
250
  }
250
251
  }
251
252
 
252
253
  @defineProps(props)
253
- export class Range extends MarkBase<RangeMark> {
254
+ export class Range extends MarkNode<RangeMark> {
254
255
  constructor() {
255
256
  super({}, 'range');
256
257
  }
257
258
  }
258
259
 
259
260
  @defineProps(props)
260
- export class RangeX extends MarkBase<RangeXMark> {
261
+ export class RangeX extends MarkNode<RangeXMark> {
261
262
  constructor() {
262
263
  super({}, 'rangeX');
263
264
  }
264
265
  }
265
266
 
266
267
  @defineProps(props)
267
- export class RangeY extends MarkBase<RangeYMark> {
268
+ export class RangeY extends MarkNode<RangeYMark> {
268
269
  constructor() {
269
270
  super({}, 'rangeY');
270
271
  }
271
272
  }
272
273
 
273
274
  @defineProps(props)
274
- export class Connector extends MarkBase<ConnectorMark> {
275
+ export class Connector extends MarkNode<ConnectorMark> {
275
276
  constructor() {
276
277
  super({}, 'connector');
277
278
  }
278
279
  }
279
280
 
280
281
  @defineProps(props)
281
- export class Shape extends MarkBase<ShapeMark> {
282
+ export class Shape extends MarkNode<ShapeMark> {
282
283
  constructor() {
283
284
  super({}, 'shape');
284
285
  }
285
286
  }
286
287
 
287
288
  @defineProps([...props, { name: 'layout', type: 'value' }])
288
- export class Sankey extends MarkBase<SankeyMark> {
289
+ export class Sankey extends MarkNode<SankeyMark> {
289
290
  constructor() {
290
291
  super({}, 'sankey');
291
292
  }
292
293
  }
293
294
 
294
295
  @defineProps([...props, { name: 'layout', type: 'value' }])
295
- export class Treemap extends MarkBase<ConnectorMark> {
296
+ export class Treemap extends MarkNode<ConnectorMark> {
296
297
  constructor() {
297
298
  super({}, 'treemap');
298
299
  }
299
300
  }
300
301
 
301
302
  @defineProps(props)
302
- export class Boxplot extends MarkBase<Boxplot> {
303
+ export class Boxplot extends MarkNode<Boxplot> {
303
304
  constructor() {
304
305
  super({}, 'boxplot');
305
306
  }
306
307
  }
307
308
 
308
309
  @defineProps([...props, { name: 'layout', type: 'value' }])
309
- export class Pack extends MarkBase<Pack> {
310
+ export class Pack extends MarkNode<Pack> {
310
311
  constructor() {
311
312
  super({}, 'pack');
312
313
  }
313
314
  }
314
315
 
315
316
  @defineProps([...props, { name: 'layout', type: 'value' }])
316
- export class ForceGraph extends MarkBase<ForceGraph> {
317
+ export class ForceGraph extends MarkNode<ForceGraph> {
317
318
  constructor() {
318
319
  super({}, 'forceGraph');
319
320
  }
320
321
  }
321
322
 
322
323
  @defineProps([...props, { name: 'layout', type: 'value' }])
323
- export class Tree extends MarkBase<Tree> {
324
+ export class Tree extends MarkNode<Tree> {
324
325
  constructor() {
325
326
  super({}, 'tree');
326
327
  }
327
328
  }
328
329
 
329
330
  @defineProps([...props, { name: 'layout', type: 'object' }])
330
- export class WordCloud extends MarkBase<WordCloud> {
331
+ export class WordCloud extends MarkNode<WordCloud> {
331
332
  constructor() {
332
333
  super({}, 'wordCloud');
333
334
  }
@@ -17,4 +17,5 @@ export type API<Props extends Geometry, Mark> = {
17
17
  scrollbar: ObjectAttribute<Props['scrollbar'], Mark>;
18
18
  legend: ObjectAttribute<Props['legend'], Mark>;
19
19
  layout: ValueAttribute<Props['layout'], Mark>;
20
+ tooltip: ValueAttribute<Props['tooltip'], Mark>;
20
21
  };
package/src/api/node.ts CHANGED
@@ -126,7 +126,7 @@ export class Node<
126
126
  return this;
127
127
  }
128
128
 
129
- root(): Chart {
129
+ getRoot(): Chart {
130
130
  // Find the root chart and render.
131
131
  let root: Node = this;
132
132
  while (root && root.parentNode) {
package/src/api/props.ts CHANGED
@@ -1,5 +1,7 @@
1
+ import { isStrictObject } from '../utils/helper';
2
+
1
3
  export type NodePropertyDescriptor = {
2
- type: 'object' | 'value' | 'array' | 'node' | 'container' | 'event';
4
+ type: 'object' | 'value' | 'array' | 'node' | 'container' | 'mix';
3
5
  name: string;
4
6
  key?: string;
5
7
  ctor?: new (...args: any[]) => any;
@@ -36,6 +38,24 @@ function defineObjectProp(
36
38
  };
37
39
  }
38
40
 
41
+ function defineMixProp(Node, { name }: NodePropertyDescriptor) {
42
+ Node.prototype[name] = function (key) {
43
+ if (arguments.length === 0) return this.attr(name);
44
+ if (Array.isArray(key)) return this.attr(name, { items: key });
45
+ if (
46
+ isStrictObject(key) &&
47
+ (key.title !== undefined || key.items !== undefined)
48
+ ) {
49
+ return this.attr(name, key);
50
+ }
51
+ const obj = this.attr(name) || {};
52
+ const { items = [] } = obj;
53
+ items.push(key);
54
+ obj.items = items;
55
+ return this.attr(name, obj);
56
+ };
57
+ }
58
+
39
59
  function defineNodeProp(Node, { name, ctor }: NodePropertyDescriptor) {
40
60
  Node.prototype[name] = function () {
41
61
  return this.append(ctor);
@@ -62,6 +82,7 @@ export function defineProps(descriptors: NodePropertyDescriptor[]) {
62
82
  else if (type === 'object') defineObjectProp(Node, descriptor);
63
83
  else if (type === 'node') defineNodeProp(Node, descriptor);
64
84
  else if (type === 'container') defineContainerProp(Node, descriptor);
85
+ else if (type === 'mix') defineMixProp(Node, descriptor);
65
86
  }
66
87
  return Node;
67
88
  };
@@ -32,13 +32,19 @@ function setAnimation(node: G2ViewTree, duration: number, easing: string) {
32
32
  const n = discovered.pop();
33
33
  n.animate = deepMix(
34
34
  {
35
- enterDuration: duration,
36
- updateDuration: duration,
37
- exitDuration: duration,
38
- updateEasing: easing,
39
- updateType: 'morphing',
40
- updateFill: 'both',
41
- exitType: 'fadeOut',
35
+ enter: {
36
+ duration,
37
+ },
38
+ update: {
39
+ duration,
40
+ easing,
41
+ type: 'morphing',
42
+ fill: 'both',
43
+ },
44
+ exit: {
45
+ type: 'fadeOut',
46
+ duration,
47
+ },
42
48
  },
43
49
  n.animate || {},
44
50
  );
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './runtime';
2
2
  export { createLibrary } from './stdlib';
3
- export { Chart, register } from './api';
3
+ export { Chart, MarkNode, CompositionNode, register } from './api';
4
4
  export type { G2Spec } from './spec';
@@ -20,6 +20,7 @@ export { BrushXFilter } from './native/brushXFilter';
20
20
  export { BrushYFilter } from './native/brushYFilter';
21
21
  export { SliderFilter } from './native/sliderFilter';
22
22
  export { Poptip } from './native/poptip';
23
+ export { Event } from './native/event';
23
24
 
24
25
  export { LEGEND_ITEMS_CLASS_NAME } from './native/legendFilter';
25
26
 
@@ -0,0 +1,44 @@
1
+ function dataOf(element, view) {
2
+ const { __data__: datum } = element;
3
+ const { markKey, index, seriesIndex } = datum;
4
+ const { markState } = view;
5
+ const selectedMark: any = Array.from(markState.keys()).find(
6
+ (mark) => (mark as any).key === markKey,
7
+ );
8
+ if (!selectedMark) return;
9
+ if (seriesIndex) {
10
+ return seriesIndex.map((i) => selectedMark.data[i]);
11
+ }
12
+ return selectedMark.data[index];
13
+ }
14
+
15
+ function clickEvent(view, emitter) {
16
+ return (e) => {
17
+ const { target } = e;
18
+ const { classList } = target;
19
+ const [elementType, markType] = classList;
20
+ if (elementType === 'element') {
21
+ const { data = {} } = e;
22
+ data.data = dataOf(target, view);
23
+ e.data = data;
24
+ emitter.emit('element:click', e);
25
+ emitter.emit(`${markType}:click`, e);
26
+ return;
27
+ }
28
+ // @todo Handle click axis and legend.
29
+ emitter.emit(`${elementType}:click`);
30
+ };
31
+ }
32
+
33
+ // @todo More events such as mouseenter, mouseleave.
34
+ // @todo Provide more info for event.dataset.
35
+ export function Event() {
36
+ return (context, _, emitter) => {
37
+ const { container, view } = context;
38
+ const click = clickEvent(view, emitter);
39
+ container.addEventListener('click', click);
40
+ return () => {
41
+ container.removeEventListener('click', click);
42
+ };
43
+ };
44
+ }