@antv/g2 5.0.0-rc.1 → 5.0.0-rc.2

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 (313) hide show
  1. package/README.en-US.md +4 -1
  2. package/README.md +3 -2
  3. package/dist/g2-lite.min.js +3 -3
  4. package/dist/g2.min.js +3 -3
  5. package/esm/animation/fadeIn.js +1 -1
  6. package/esm/animation/fadeIn.js.map +1 -1
  7. package/esm/animation/fadeOut.js +1 -1
  8. package/esm/animation/fadeOut.js.map +1 -1
  9. package/esm/animation/morphing.js +1 -1
  10. package/esm/animation/morphing.js.map +1 -1
  11. package/esm/animation/scaleInX.js +1 -1
  12. package/esm/animation/scaleInX.js.map +1 -1
  13. package/esm/animation/scaleInY.js +1 -1
  14. package/esm/animation/scaleInY.js.map +1 -1
  15. package/esm/animation/scaleOutX.js +1 -1
  16. package/esm/animation/scaleOutX.js.map +1 -1
  17. package/esm/animation/scaleOutY.js +1 -1
  18. package/esm/animation/scaleOutY.js.map +1 -1
  19. package/esm/animation/waveIn.js +2 -2
  20. package/esm/animation/waveIn.js.map +1 -1
  21. package/esm/animation/zoomIn.js +1 -1
  22. package/esm/animation/zoomIn.js.map +1 -1
  23. package/esm/animation/zoomOut.js +1 -1
  24. package/esm/animation/zoomOut.js.map +1 -1
  25. package/esm/api/chart.d.ts +1 -0
  26. package/esm/api/chart.js +16 -11
  27. package/esm/api/chart.js.map +1 -1
  28. package/esm/api/composition/base.d.ts +2 -2
  29. package/esm/api/composition/base.js +3 -2
  30. package/esm/api/composition/base.js.map +1 -1
  31. package/esm/component/axis.js +7 -5
  32. package/esm/component/axis.js.map +1 -1
  33. package/esm/component/legendCategory.js +20 -5
  34. package/esm/component/legendCategory.js.map +1 -1
  35. package/esm/component/legendContinuous.js +2 -2
  36. package/esm/component/legendContinuous.js.map +1 -1
  37. package/esm/component/legendContinuousBlockSize.js +1 -1
  38. package/esm/component/legendContinuousBlockSize.js.map +1 -1
  39. package/esm/component/legendContinuousSize.js +1 -1
  40. package/esm/component/legendContinuousSize.js.map +1 -1
  41. package/esm/component/scrollbar.d.ts +1 -1
  42. package/esm/component/scrollbar.js +3 -3
  43. package/esm/component/scrollbar.js.map +1 -1
  44. package/esm/component/scrollbarX.js +1 -1
  45. package/esm/component/scrollbarX.js.map +1 -1
  46. package/esm/component/scrollbarY.js +1 -1
  47. package/esm/component/scrollbarY.js.map +1 -1
  48. package/esm/component/slider.d.ts +1 -1
  49. package/esm/component/slider.js +3 -3
  50. package/esm/component/slider.js.map +1 -1
  51. package/esm/component/sliderX.js +1 -1
  52. package/esm/component/sliderX.js.map +1 -1
  53. package/esm/component/sliderY.js +1 -1
  54. package/esm/component/sliderY.js.map +1 -1
  55. package/esm/component/utils.d.ts +1 -1
  56. package/esm/component/utils.js +2 -2
  57. package/esm/component/utils.js.map +1 -1
  58. package/esm/geo/geoView.js +1 -1
  59. package/esm/geo/geoView.js.map +1 -1
  60. package/esm/index.d.ts +1 -0
  61. package/esm/index.js +1 -0
  62. package/esm/index.js.map +1 -1
  63. package/esm/interaction/brushFilter.js +1 -1
  64. package/esm/interaction/brushFilter.js.map +1 -1
  65. package/esm/interaction/brushHighlight.js +6 -3
  66. package/esm/interaction/brushHighlight.js.map +1 -1
  67. package/esm/interaction/elementHighlight.js +1 -1
  68. package/esm/interaction/elementHighlight.js.map +1 -1
  69. package/esm/interaction/event.js +20 -20
  70. package/esm/interaction/event.js.map +1 -1
  71. package/esm/interaction/legendFilter.d.ts +1 -4
  72. package/esm/interaction/legendFilter.js +45 -73
  73. package/esm/interaction/legendFilter.js.map +1 -1
  74. package/esm/interaction/sliderFilter.js +6 -6
  75. package/esm/interaction/sliderFilter.js.map +1 -1
  76. package/esm/interaction/tooltip.d.ts +2 -2
  77. package/esm/interaction/tooltip.js +40 -18
  78. package/esm/interaction/tooltip.js.map +1 -1
  79. package/esm/interaction/utils.js +7 -5
  80. package/esm/interaction/utils.js.map +1 -1
  81. package/esm/label-transform/overflowHide.js +3 -2
  82. package/esm/label-transform/overflowHide.js.map +1 -1
  83. package/esm/label-transform/overlapHide.js +3 -2
  84. package/esm/label-transform/overlapHide.js.map +1 -1
  85. package/esm/mark/gauge.js +2 -2
  86. package/esm/mark/gauge.js.map +1 -1
  87. package/esm/mark/sankey.js +2 -2
  88. package/esm/mark/sankey.js.map +1 -1
  89. package/esm/mark/utils.d.ts +2 -2
  90. package/esm/mark/utils.js +2 -2
  91. package/esm/mark/utils.js.map +1 -1
  92. package/esm/runtime/component.js +18 -3
  93. package/esm/runtime/component.js.map +1 -1
  94. package/esm/runtime/plot.js +56 -22
  95. package/esm/runtime/plot.js.map +1 -1
  96. package/esm/runtime/render.d.ts +1 -1
  97. package/esm/runtime/render.js +15 -8
  98. package/esm/runtime/render.js.map +1 -1
  99. package/esm/shape/interval/color.js +18 -9
  100. package/esm/shape/interval/color.js.map +1 -1
  101. package/esm/shape/label/label.js +1 -1
  102. package/esm/shape/label/label.js.map +1 -1
  103. package/esm/shape/label/position/area.js +1 -1
  104. package/esm/shape/label/position/area.js.map +1 -1
  105. package/esm/shape/line/curve.js +1 -1
  106. package/esm/shape/line/curve.js.map +1 -1
  107. package/esm/shape/text/advance.js +3 -1
  108. package/esm/shape/text/advance.js.map +1 -1
  109. package/esm/shape/text/text.js +1 -1
  110. package/esm/shape/text/text.js.map +1 -1
  111. package/esm/spec/interaction.d.ts +2 -0
  112. package/esm/spec/scale.d.ts +3 -2
  113. package/esm/stdlib/index.js +1 -1
  114. package/esm/stdlib/index.js.map +1 -1
  115. package/esm/theme/academy.js +5 -5
  116. package/esm/theme/academy.js.map +1 -1
  117. package/esm/theme/dark.js +5 -5
  118. package/esm/theme/dark.js.map +1 -1
  119. package/esm/theme/light.js +6 -8
  120. package/esm/theme/light.js.map +1 -1
  121. package/esm/transform/filter.js +4 -1
  122. package/esm/transform/filter.js.map +1 -1
  123. package/esm/utils/event.d.ts +33 -14
  124. package/esm/utils/event.js +43 -16
  125. package/esm/utils/event.js.map +1 -1
  126. package/esm/utils/helper.js +2 -1
  127. package/esm/utils/helper.js.map +1 -1
  128. package/esm/utils/style.d.ts +5 -0
  129. package/esm/utils/style.js +23 -0
  130. package/esm/utils/style.js.map +1 -0
  131. package/lib/animation/fadeIn.js +1 -1
  132. package/lib/animation/fadeIn.js.map +1 -1
  133. package/lib/animation/fadeOut.js +1 -1
  134. package/lib/animation/fadeOut.js.map +1 -1
  135. package/lib/animation/morphing.js +1 -1
  136. package/lib/animation/morphing.js.map +1 -1
  137. package/lib/animation/scaleInX.js +1 -1
  138. package/lib/animation/scaleInX.js.map +1 -1
  139. package/lib/animation/scaleInY.js +1 -1
  140. package/lib/animation/scaleInY.js.map +1 -1
  141. package/lib/animation/scaleOutX.js +1 -1
  142. package/lib/animation/scaleOutX.js.map +1 -1
  143. package/lib/animation/scaleOutY.js +1 -1
  144. package/lib/animation/scaleOutY.js.map +1 -1
  145. package/lib/animation/waveIn.js +2 -2
  146. package/lib/animation/waveIn.js.map +1 -1
  147. package/lib/animation/zoomIn.js +1 -1
  148. package/lib/animation/zoomIn.js.map +1 -1
  149. package/lib/animation/zoomOut.js +1 -1
  150. package/lib/animation/zoomOut.js.map +1 -1
  151. package/lib/api/chart.d.ts +1 -0
  152. package/lib/api/chart.js +15 -10
  153. package/lib/api/chart.js.map +1 -1
  154. package/lib/api/composition/base.d.ts +2 -2
  155. package/lib/api/composition/base.js +3 -2
  156. package/lib/api/composition/base.js.map +1 -1
  157. package/lib/component/axis.js +7 -5
  158. package/lib/component/axis.js.map +1 -1
  159. package/lib/component/legendCategory.js +20 -5
  160. package/lib/component/legendCategory.js.map +1 -1
  161. package/lib/component/legendContinuous.js +2 -2
  162. package/lib/component/legendContinuous.js.map +1 -1
  163. package/lib/component/legendContinuousBlockSize.js +1 -1
  164. package/lib/component/legendContinuousBlockSize.js.map +1 -1
  165. package/lib/component/legendContinuousSize.js +1 -1
  166. package/lib/component/legendContinuousSize.js.map +1 -1
  167. package/lib/component/scrollbar.d.ts +1 -1
  168. package/lib/component/scrollbar.js +3 -3
  169. package/lib/component/scrollbar.js.map +1 -1
  170. package/lib/component/scrollbarX.js +1 -1
  171. package/lib/component/scrollbarX.js.map +1 -1
  172. package/lib/component/scrollbarY.js +1 -1
  173. package/lib/component/scrollbarY.js.map +1 -1
  174. package/lib/component/slider.d.ts +1 -1
  175. package/lib/component/slider.js +3 -3
  176. package/lib/component/slider.js.map +1 -1
  177. package/lib/component/sliderX.js +1 -1
  178. package/lib/component/sliderX.js.map +1 -1
  179. package/lib/component/sliderY.js +1 -1
  180. package/lib/component/sliderY.js.map +1 -1
  181. package/lib/component/utils.d.ts +1 -1
  182. package/lib/component/utils.js +2 -2
  183. package/lib/component/utils.js.map +1 -1
  184. package/lib/geo/geoView.js +1 -1
  185. package/lib/geo/geoView.js.map +1 -1
  186. package/lib/index.d.ts +1 -0
  187. package/lib/index.js +3 -1
  188. package/lib/index.js.map +1 -1
  189. package/lib/interaction/brushFilter.js +1 -1
  190. package/lib/interaction/brushFilter.js.map +1 -1
  191. package/lib/interaction/brushHighlight.js +6 -3
  192. package/lib/interaction/brushHighlight.js.map +1 -1
  193. package/lib/interaction/event.js +20 -20
  194. package/lib/interaction/event.js.map +1 -1
  195. package/lib/interaction/legendFilter.d.ts +1 -4
  196. package/lib/interaction/legendFilter.js +45 -73
  197. package/lib/interaction/legendFilter.js.map +1 -1
  198. package/lib/interaction/sliderFilter.js +6 -6
  199. package/lib/interaction/sliderFilter.js.map +1 -1
  200. package/lib/interaction/tooltip.d.ts +2 -2
  201. package/lib/interaction/tooltip.js +40 -18
  202. package/lib/interaction/tooltip.js.map +1 -1
  203. package/lib/interaction/utils.js +7 -5
  204. package/lib/interaction/utils.js.map +1 -1
  205. package/lib/label-transform/overflowHide.js +3 -2
  206. package/lib/label-transform/overflowHide.js.map +1 -1
  207. package/lib/label-transform/overlapHide.js +3 -2
  208. package/lib/label-transform/overlapHide.js.map +1 -1
  209. package/lib/mark/gauge.js +2 -2
  210. package/lib/mark/gauge.js.map +1 -1
  211. package/lib/mark/sankey.js +2 -2
  212. package/lib/mark/sankey.js.map +1 -1
  213. package/lib/mark/utils.d.ts +2 -2
  214. package/lib/mark/utils.js +2 -2
  215. package/lib/mark/utils.js.map +1 -1
  216. package/lib/runtime/component.js +18 -3
  217. package/lib/runtime/component.js.map +1 -1
  218. package/lib/runtime/plot.js +55 -21
  219. package/lib/runtime/plot.js.map +1 -1
  220. package/lib/runtime/render.d.ts +1 -1
  221. package/lib/runtime/render.js +14 -7
  222. package/lib/runtime/render.js.map +1 -1
  223. package/lib/shape/interval/color.js +18 -9
  224. package/lib/shape/interval/color.js.map +1 -1
  225. package/lib/shape/label/label.js +1 -1
  226. package/lib/shape/label/label.js.map +1 -1
  227. package/lib/shape/label/position/area.js +1 -1
  228. package/lib/shape/label/position/area.js.map +1 -1
  229. package/lib/shape/line/curve.js +1 -1
  230. package/lib/shape/line/curve.js.map +1 -1
  231. package/lib/shape/text/advance.js +3 -1
  232. package/lib/shape/text/advance.js.map +1 -1
  233. package/lib/shape/text/text.js +1 -1
  234. package/lib/shape/text/text.js.map +1 -1
  235. package/lib/spec/interaction.d.ts +2 -0
  236. package/lib/spec/scale.d.ts +3 -2
  237. package/lib/stdlib/index.js +1 -1
  238. package/lib/stdlib/index.js.map +1 -1
  239. package/lib/theme/academy.js +5 -5
  240. package/lib/theme/academy.js.map +1 -1
  241. package/lib/theme/dark.js +5 -5
  242. package/lib/theme/dark.js.map +1 -1
  243. package/lib/theme/light.js +6 -8
  244. package/lib/theme/light.js.map +1 -1
  245. package/lib/transform/filter.js +4 -1
  246. package/lib/transform/filter.js.map +1 -1
  247. package/lib/utils/event.d.ts +33 -14
  248. package/lib/utils/event.js +44 -17
  249. package/lib/utils/event.js.map +1 -1
  250. package/lib/utils/helper.js +2 -1
  251. package/lib/utils/helper.js.map +1 -1
  252. package/lib/utils/style.d.ts +5 -0
  253. package/lib/utils/style.js +30 -0
  254. package/lib/utils/style.js.map +1 -0
  255. package/package.json +2 -2
  256. package/src/animation/fadeIn.ts +1 -1
  257. package/src/animation/fadeOut.ts +1 -1
  258. package/src/animation/morphing.ts +1 -1
  259. package/src/animation/scaleInX.ts +4 -4
  260. package/src/animation/scaleInY.ts +4 -4
  261. package/src/animation/scaleOutX.ts +4 -4
  262. package/src/animation/scaleOutY.ts +4 -4
  263. package/src/animation/waveIn.ts +4 -4
  264. package/src/animation/zoomIn.ts +4 -4
  265. package/src/animation/zoomOut.ts +4 -4
  266. package/src/api/chart.ts +16 -12
  267. package/src/api/composition/base.ts +5 -4
  268. package/src/component/axis.ts +8 -6
  269. package/src/component/legendCategory.ts +19 -11
  270. package/src/component/legendContinuous.ts +2 -2
  271. package/src/component/legendContinuousBlockSize.ts +1 -5
  272. package/src/component/legendContinuousSize.ts +1 -1
  273. package/src/component/scrollbar.ts +5 -5
  274. package/src/component/scrollbarX.ts +1 -1
  275. package/src/component/scrollbarY.ts +1 -1
  276. package/src/component/slider.ts +6 -7
  277. package/src/component/sliderX.ts +1 -1
  278. package/src/component/sliderY.ts +1 -1
  279. package/src/component/utils.ts +2 -2
  280. package/src/geo/geoView.ts +1 -1
  281. package/src/index.ts +1 -0
  282. package/src/interaction/brushFilter.ts +2 -2
  283. package/src/interaction/brushHighlight.ts +8 -3
  284. package/src/interaction/elementHighlight.ts +6 -6
  285. package/src/interaction/event.ts +30 -20
  286. package/src/interaction/legendFilter.ts +45 -70
  287. package/src/interaction/sliderFilter.ts +6 -6
  288. package/src/interaction/tooltip.ts +51 -21
  289. package/src/interaction/utils.ts +6 -3
  290. package/src/label-transform/overflowHide.ts +3 -3
  291. package/src/label-transform/overlapHide.ts +3 -2
  292. package/src/mark/gauge.ts +2 -1
  293. package/src/mark/sankey.ts +2 -1
  294. package/src/mark/utils.ts +2 -4
  295. package/src/runtime/component.ts +27 -10
  296. package/src/runtime/plot.ts +70 -20
  297. package/src/runtime/render.ts +16 -8
  298. package/src/shape/interval/color.ts +19 -4
  299. package/src/shape/label/label.ts +1 -1
  300. package/src/shape/label/position/area.ts +1 -1
  301. package/src/shape/line/curve.ts +1 -1
  302. package/src/shape/text/advance.ts +3 -2
  303. package/src/shape/text/text.ts +1 -1
  304. package/src/spec/interaction.ts +3 -0
  305. package/src/spec/scale.ts +3 -2
  306. package/src/stdlib/index.ts +2 -2
  307. package/src/theme/academy.ts +5 -5
  308. package/src/theme/dark.ts +5 -5
  309. package/src/theme/light.ts +6 -8
  310. package/src/transform/filter.ts +4 -1
  311. package/src/utils/event.ts +47 -15
  312. package/src/utils/helper.ts +2 -1
  313. package/src/utils/style.ts +34 -0
@@ -37,9 +37,9 @@ export const WaveIn: AC<WaveInOptions> = (options) => {
37
37
  const {
38
38
  radius = 0,
39
39
  inset = 0,
40
- fillOpacity,
41
- strokeOpacity,
42
- opacity,
40
+ fillOpacity = 1,
41
+ strokeOpacity = 1,
42
+ opacity = 1,
43
43
  } = style;
44
44
 
45
45
  const { points, y, y1 } = __data__;
@@ -62,7 +62,7 @@ export const WaveIn: AC<WaveInOptions> = (options) => {
62
62
  transform: `translate(${center[0]}, ${center[1]})`,
63
63
  });
64
64
  const convertedPathDefinition = convertToPath(pathForConversion);
65
- pathForConversion.style.transform = 'none';
65
+ pathForConversion.style.transform = '';
66
66
  return convertedPathDefinition;
67
67
  };
68
68
 
@@ -12,10 +12,10 @@ export const ZoomIn: AC<ZoomInOptions> = (options) => {
12
12
  return (from, to, value, coordinate, defaults) => {
13
13
  const [shape] = from;
14
14
  const {
15
- transform: prefix,
16
- fillOpacity,
17
- strokeOpacity,
18
- opacity,
15
+ transform: prefix = '',
16
+ fillOpacity = 1,
17
+ strokeOpacity = 1,
18
+ opacity = 1,
19
19
  } = shape.style;
20
20
  const keyframes = [
21
21
  {
@@ -12,10 +12,10 @@ export const ZoomOut: AC<ZoomOutOptions> = (options) => {
12
12
  return (from, to, value, coordinate, defaults) => {
13
13
  const [shape] = from;
14
14
  const {
15
- transform: prefix,
16
- fillOpacity,
17
- strokeOpacity,
18
- opacity,
15
+ transform: prefix = '',
16
+ fillOpacity = 1,
17
+ strokeOpacity = 1,
18
+ opacity = 1,
19
19
  } = shape.style;
20
20
  const keyframes = [
21
21
  { transform: `${prefix} scale(1)`.trimStart() },
package/src/api/chart.ts CHANGED
@@ -6,7 +6,7 @@ import EventEmitter from '@antv/event-emitter';
6
6
  import { G2Context, render, destroy } from '../runtime';
7
7
  import { ViewComposition } from '../spec';
8
8
  import { getChartSize } from '../utils/size';
9
- import { CHART_LIFE_CIRCLE } from '../utils/event';
9
+ import { ChartEvent } from '../utils/event';
10
10
  import { G2ViewTree } from '../runtime/types/options';
11
11
  import { Node } from './node';
12
12
  import {
@@ -65,6 +65,7 @@ function normalizeRoot(node: Node) {
65
65
  root.attr('padding', node.attr('padding'));
66
66
  root.attr('margin', node.attr('margin'));
67
67
  root.attr('inset', node.attr('inset'));
68
+ root.attr('theme', node.attr('theme'));
68
69
  return root;
69
70
  }
70
71
 
@@ -122,6 +123,7 @@ export type ChartOptions = ViewComposition & {
122
123
  autoFit?: boolean;
123
124
  renderer?: CanvasRenderer;
124
125
  plugins?: RendererPlugin[];
126
+ theme?: string;
125
127
  };
126
128
 
127
129
  type ChartProps = Concrete<ViewComposition>;
@@ -154,7 +156,6 @@ export const props: NodePropertyDescriptor[] = [
154
156
  { name: 'title', type: 'value' },
155
157
  { name: 'key', type: 'value' },
156
158
  { name: 'transform', type: 'array' },
157
- { name: 'theme', type: 'object' },
158
159
  { name: 'scale', type: 'object' },
159
160
  { name: 'axis', type: 'object' },
160
161
  { name: 'legend', type: 'object' },
@@ -208,8 +209,12 @@ export class Chart extends View<ChartOptions> {
208
209
  );
209
210
  }
210
211
 
211
- return new Promise((resolve) => {
212
- render(this.options(), this._context, () => resolve(this));
212
+ return new Promise((resolve, reject) => {
213
+ try {
214
+ render(this.options(), this._context, () => resolve(this), reject);
215
+ } catch (e) {
216
+ reject(e);
217
+ }
213
218
  });
214
219
  }
215
220
  /**
@@ -233,10 +238,9 @@ export class Chart extends View<ChartOptions> {
233
238
  return this._options || optionsOf(this);
234
239
  }
235
240
  this._options = deepMix(
236
- this._options || {},
241
+ this._options || optionsOf(this),
237
242
  omit(options, SPEC_EXTERNAL_KEYS),
238
243
  );
239
-
240
244
  return this;
241
245
  }
242
246
 
@@ -270,19 +274,19 @@ export class Chart extends View<ChartOptions> {
270
274
 
271
275
  destroy() {
272
276
  const options = this.options();
273
- this.emit(CHART_LIFE_CIRCLE.BEFORE_DESTROY);
277
+ this.emit(ChartEvent.BEFORE_DESTROY);
274
278
  this.unbindAutoFit();
275
279
  destroy(options, this._context);
276
280
  // Remove the container.
277
281
  removeContainer(this._container);
278
- this.emit(CHART_LIFE_CIRCLE.AFTER_DESTROY);
282
+ this.emit(ChartEvent.AFTER_DESTROY);
279
283
  }
280
284
 
281
285
  clear() {
282
286
  const options = this.options();
283
- this.emit(CHART_LIFE_CIRCLE.BEFORE_CLEAR);
287
+ this.emit(ChartEvent.BEFORE_CLEAR);
284
288
  destroy(options, this._context);
285
- this.emit(CHART_LIFE_CIRCLE.AFTER_CLEAR);
289
+ this.emit(ChartEvent.AFTER_CLEAR);
286
290
  }
287
291
 
288
292
  forceFit() {
@@ -303,12 +307,12 @@ export class Chart extends View<ChartOptions> {
303
307
  if (width === adjustedWidth && height === adjustedHeight) {
304
308
  return Promise.resolve(this);
305
309
  }
306
- this.emit(CHART_LIFE_CIRCLE.BEFORE_CHANGE_SIZE);
310
+ this.emit(ChartEvent.BEFORE_CHANGE_SIZE);
307
311
  this.width(adjustedWidth);
308
312
  this.height(adjustedHeight);
309
313
  const finished = this.render();
310
314
  finished.then(() => {
311
- this.emit(CHART_LIFE_CIRCLE.AFTER_CHANGE_SIZE);
315
+ this.emit(ChartEvent.AFTER_CHANGE_SIZE);
312
316
  });
313
317
  return finished;
314
318
  }
@@ -1,7 +1,8 @@
1
- import { DisplayObject } from '@antv/g';
2
1
  import { Coordinate } from '@antv/coord';
3
- import { Node } from '../node';
2
+ import { DisplayObject } from '@antv/g';
4
3
  import { G2Theme, G2ViewDescriptor } from '../../runtime';
4
+ import { hide, show } from '../../utils/style';
5
+ import { Node } from '../node';
5
6
 
6
7
  export class CompositionNode<
7
8
  Value extends Record<string, any> = Record<string, any>,
@@ -40,7 +41,7 @@ export class CompositionNode<
40
41
  show() {
41
42
  const group = this.getGroup();
42
43
  if (!group) return;
43
- !group.isVisible() && group.setAttribute('visibility', 'visible');
44
+ !group.isVisible() && show(group);
44
45
  }
45
46
 
46
47
  /**
@@ -49,6 +50,6 @@ export class CompositionNode<
49
50
  hide() {
50
51
  const group = this.getGroup();
51
52
  if (!group) return;
52
- group.isVisible() && group.setAttribute('visibility', 'hidden');
53
+ group.isVisible() && hide(group);
53
54
  }
54
55
  }
@@ -141,6 +141,7 @@ function getTicks(
141
141
  const ticks = ticksOf(scale, domain, tickMethod);
142
142
  const filteredTicks = tickFilter ? ticks.filter(tickFilter) : ticks;
143
143
  const labelFormatter = scale.getFormatter?.() || defaultTickFormatter;
144
+ const toString = (d) => (typeof d === 'object' ? d : String(d));
144
145
  const applyInset = createInset(position, coordinate);
145
146
  const applyFisheye = createFisheye(position, coordinate);
146
147
 
@@ -150,7 +151,7 @@ function getTicks(
150
151
  const tick = applyInset(scale.map(d) + offset);
151
152
  return {
152
153
  value: isTranspose(coordinate) && scale.getTicks?.() ? 1 - tick : tick,
153
- label: labelFormatter(d, i, array),
154
+ label: toString(labelFormatter(prettyNumber(d), i, array)),
154
155
  id: String(i),
155
156
  };
156
157
  });
@@ -166,7 +167,7 @@ function getTicks(
166
167
  const tick = applyFisheye(applyInset(scale.map(d) + offset));
167
168
  return {
168
169
  value: tick,
169
- label: `${labelFormatter(prettyNumber(d), i, array)}`,
170
+ label: toString(labelFormatter(prettyNumber(d), i, array)),
170
171
  id: String(i),
171
172
  };
172
173
  });
@@ -204,7 +205,8 @@ function inferArcStyle(
204
205
  const common = {
205
206
  center,
206
207
  radius,
207
- angleRange: [startAngle, endAngle],
208
+ startAngle,
209
+ endAngle,
208
210
  titleFillOpacity: 0,
209
211
  titlePosition: 'inner',
210
212
  showLine: false,
@@ -369,7 +371,7 @@ const ArcAxisComponent: GCC<AxisOptions> = (options) => {
369
371
  style: deepMix({}, axisTheme, defaultStyle, {
370
372
  type: 'arc',
371
373
  data: ticks,
372
- title: titleContent(title),
374
+ titleText: titleContent(title),
373
375
  showGrid,
374
376
  ...rest,
375
377
  ...important,
@@ -490,9 +492,9 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
490
492
  ...style,
491
493
  type: 'linear' as const,
492
494
  data: ticks,
493
- title: titleContent(title),
495
+ titleText: titleContent(title),
494
496
  showLabel,
495
- labelTransforms: labelTransforms(labelAutoHide, labelAutoRotate),
497
+ labelOverlap: labelTransforms(labelAutoHide, labelAutoRotate),
496
498
  showGrid,
497
499
  showTick,
498
500
  gridLength,
@@ -68,16 +68,24 @@ function createShape(
68
68
  'shape',
69
69
  library,
70
70
  );
71
- return () =>
72
- useShape({ type: `point.${shape}` })(
73
- [
74
- [0, 0],
75
- [0, 0],
76
- ],
77
- { size: 6, ...style },
78
- coordinate,
79
- theme,
80
- );
71
+ const shapeOptions = [
72
+ [
73
+ [0, 0],
74
+ [0, 0],
75
+ ],
76
+ { size: 6, ...style },
77
+ coordinate,
78
+ theme,
79
+ ];
80
+ return () => {
81
+ try {
82
+ // @ts-ignore
83
+ return useShape({ type: `point.${shape}` })(...shapeOptions);
84
+ } catch (e) {
85
+ // @ts-ignore
86
+ return useShape({ type: 'point.point' })(...shapeOptions);
87
+ }
88
+ };
81
89
  }
82
90
 
83
91
  function inferItemMarker(
@@ -211,7 +219,7 @@ export const LegendCategory: GCC<LegendCategoryOptions> = (options) => {
211
219
  );
212
220
 
213
221
  const legendStyle = {
214
- orient: ['right', 'left', 'center'].includes(position)
222
+ orientation: ['right', 'left', 'center'].includes(position)
215
223
  ? 'vertical'
216
224
  : 'horizontal',
217
225
  width,
@@ -31,13 +31,13 @@ function inferContinuousConfig(
31
31
  const colorScale = scaleOf(scales, 'color');
32
32
  const { domain, range } = colorScale.getOptions();
33
33
  const [min, max] = [domain[0], domain.slice(-1)[0]];
34
- const { orient, width, height, length } = inferComponentShape(
34
+ const { orientation, width, height, length } = inferComponentShape(
35
35
  value,
36
36
  options,
37
37
  component,
38
38
  );
39
39
 
40
- const shape = { orient, width, height };
40
+ const shape = { orientation, width, height };
41
41
 
42
42
  if (colorScale instanceof Threshold) {
43
43
  const thresholds = (colorScale as any).thresholds as number[];
@@ -7,11 +7,7 @@ export const LegendContinuousBlockSize: GCC<
7
7
  LegendContinuousBlockSizeOptions
8
8
  > = (options) => {
9
9
  return LegendContinuous(
10
- Object.assign(
11
- {},
12
- { type: 'size', block: true, labelShowTick: false },
13
- options,
14
- ),
10
+ Object.assign({}, { type: 'size', block: true, showTick: false }, options),
15
11
  );
16
12
  };
17
13
 
@@ -11,7 +11,7 @@ export const LegendContinuousSize: GCC<LegendContinuousSizeOptions> = (
11
11
  {},
12
12
  {
13
13
  type: 'size',
14
- labelShowTick: false,
14
+ showTick: false,
15
15
  labelFilter: (datum, index, data) =>
16
16
  index === 0 || index === data.length - 1,
17
17
  },
@@ -2,7 +2,7 @@ import { Scrollbar as ScrollbarComponent } from '@antv/gui';
2
2
  import { GuideComponentComponent as GCC } from '../runtime';
3
3
 
4
4
  export type ScrollbarOptions = {
5
- orient: 'horizontal' | 'vertical';
5
+ orientation: 'horizontal' | 'vertical';
6
6
  [key: string]: any;
7
7
  };
8
8
 
@@ -10,7 +10,7 @@ export type ScrollbarOptions = {
10
10
  * Scrollbar component.
11
11
  */
12
12
  export const Scrollbar: GCC<ScrollbarOptions> = (options) => {
13
- const { orient, labelFormatter, style, ...rest } = options;
13
+ const { orientation, labelFormatter, style, ...rest } = options;
14
14
 
15
15
  return (scales, value, coordinate, theme) => {
16
16
  const { bbox } = value;
@@ -23,13 +23,13 @@ export const Scrollbar: GCC<ScrollbarOptions> = (options) => {
23
23
  ...style,
24
24
  x,
25
25
  y,
26
- trackLength: orient === 'horizontal' ? width : height,
26
+ trackLength: orientation === 'horizontal' ? width : height,
27
27
  ...rest,
28
- orient,
28
+ orientation,
29
29
  value: 0,
30
30
  // @todo Get actual length of content.
31
31
  contentLength: 1500,
32
- viewportLength: orient === 'horizontal' ? width : height,
32
+ viewportLength: orientation === 'horizontal' ? width : height,
33
33
  }),
34
34
  });
35
35
  };
@@ -7,7 +7,7 @@ export type ScrollbarXOptions = ScrollbarOptions;
7
7
  * ScrollbarX component.
8
8
  */
9
9
  export const ScrollbarX: GCC<ScrollbarXOptions> = (options) => {
10
- return Scrollbar({ ...options, orient: 'horizontal' });
10
+ return Scrollbar({ ...options, orientation: 'horizontal' });
11
11
  };
12
12
 
13
13
  ScrollbarX.props = {
@@ -7,7 +7,7 @@ export type ScrollbarYOptions = ScrollbarOptions;
7
7
  * ScrollbarY component.
8
8
  */
9
9
  export const ScrollbarY: GCC<ScrollbarYOptions> = (options) => {
10
- return Scrollbar({ ...options, orient: 'vertical' });
10
+ return Scrollbar({ ...options, orientation: 'vertical' });
11
11
  };
12
12
 
13
13
  ScrollbarY.props = {
@@ -1,11 +1,10 @@
1
1
  import { Slider as SliderComponent } from '@antv/gui';
2
2
  import { format } from 'd3-format';
3
- import { least } from 'd3-array';
4
- import { GuideComponentComponent as GCC, Scale } from '../runtime';
3
+ import { GuideComponentComponent as GCC } from '../runtime';
5
4
  import { invert } from '../utils/scale';
6
5
 
7
6
  export type SliderOptions = {
8
- orient: 'horizontal' | 'vertical';
7
+ orientation: 'horizontal' | 'vertical';
9
8
  [key: string]: any;
10
9
  };
11
10
 
@@ -14,13 +13,13 @@ export type SliderOptions = {
14
13
  */
15
14
  export const Slider: GCC<SliderOptions> = (options) => {
16
15
  // do not pass size.
17
- const { orient, labelFormatter, size, style, ...rest } = options;
16
+ const { orientation, labelFormatter, size, style, ...rest } = options;
18
17
 
19
18
  return ([scale], value, coordinate, theme) => {
20
19
  const { bbox } = value;
21
20
  const { x, y, width, height } = bbox;
22
21
  const { slider: sliderTheme = {} } = theme;
23
- const defaultFormatter = scale.getFormatter?.() || ((v) => v);
22
+ const defaultFormatter = scale.getFormatter?.() || ((v) => v.toString());
24
23
  const formatter =
25
24
  typeof labelFormatter === 'string'
26
25
  ? format(labelFormatter)
@@ -31,8 +30,8 @@ export const Slider: GCC<SliderOptions> = (options) => {
31
30
  style: Object.assign({}, sliderTheme, {
32
31
  x,
33
32
  y,
34
- trackLength: orient === 'horizontal' ? width : height,
35
- orient,
33
+ trackLength: orientation === 'horizontal' ? width : height,
34
+ orientation,
36
35
  formatter: (v) => {
37
36
  const f = formatter || defaultFormatter;
38
37
  // @todo Pass index to distinguish the left and the right value.
@@ -7,7 +7,7 @@ export type SliderXOptions = SliderOptions;
7
7
  * SliderX component.
8
8
  */
9
9
  export const SliderX: GCC<SliderXOptions> = (options) => {
10
- return Slider({ ...options, orient: 'horizontal' });
10
+ return Slider({ ...options, orientation: 'horizontal' });
11
11
  };
12
12
 
13
13
  SliderX.props = {
@@ -7,7 +7,7 @@ export type SliderYOptions = SliderOptions;
7
7
  * SliderY component.
8
8
  */
9
9
  export const SliderY: GCC<SliderYOptions> = (options) => {
10
- return Slider({ ...options, orient: 'vertical' });
10
+ return Slider({ ...options, orientation: 'vertical' });
11
11
  };
12
12
 
13
13
  SliderY.props = {
@@ -120,9 +120,9 @@ export function inferComponentShape(
120
120
  const { defaultSize, defaultLength } = component.props;
121
121
  const size = userDefinedSize || defaultSize || bboxSize;
122
122
  const length = userDefinedLength || defaultLength || bboxLength;
123
- const orient = isHorizontal ? 'horizontal' : 'vertical';
123
+ const orientation = isHorizontal ? 'horizontal' : 'vertical';
124
124
  const [width, height] = isHorizontal ? [length, size] : [size, length];
125
- return { orient, width, height, size, length };
125
+ return { orientation, width, height, size, length };
126
126
  }
127
127
 
128
128
  export function domainOf(scales: Scale[]): any[] {
@@ -214,7 +214,7 @@ export const GeoView: CC<GeoViewOptions> = () => {
214
214
  }),
215
215
  style: {
216
216
  ...style,
217
- d: (d) => path(d),
217
+ d: (d) => path(d) || [],
218
218
  },
219
219
  };
220
220
  }
package/src/index.ts CHANGED
@@ -14,3 +14,4 @@ export type { G2Context } from './runtime';
14
14
  export { createLibrary } from './stdlib';
15
15
  export { Chart, MarkNode, CompositionNode, register } from './api';
16
16
  export * from './spec';
17
+ export { ChartEvent } from './utils/event';
@@ -104,8 +104,8 @@ export function BrushFilter({ hideX = true, hideY = true, ...rest }) {
104
104
  {
105
105
  // Hide label to keep smooth transition.
106
106
  axis: {
107
- ...(hideX && { x: { labelTransform: [{ type: 'hide' }] } }),
108
- ...(hideY && { y: { labelTransform: [{ type: 'hide' }] } }),
107
+ ...(hideX && { x: { labelOverlap: [{ type: 'hide' }] } }),
108
+ ...(hideY && { y: { labelOverlap: [{ type: 'hide' }] } }),
109
109
  },
110
110
  },
111
111
  mark,
@@ -83,8 +83,11 @@ export function brush(
83
83
  mask = new Rect({
84
84
  // @ts-ignore
85
85
  style: {
86
+ x: 0,
87
+ y: 0,
88
+ width: 0,
89
+ height: 0,
86
90
  draggable: true,
87
- fill: 'transparent',
88
91
  },
89
92
  className: 'mask',
90
93
  });
@@ -96,6 +99,8 @@ export function brush(
96
99
  mask = new Rect({
97
100
  // @ts-ignore
98
101
  style: {
102
+ x: 0,
103
+ y: 0,
99
104
  ...style,
100
105
  fill,
101
106
  fillOpacity,
@@ -305,8 +310,8 @@ export function brushHighlight(
305
310
  const {
306
311
  width: rootWidth,
307
312
  height: rootHeight,
308
- x: ordinalX,
309
- y: ordinalY,
313
+ x: ordinalX = 0,
314
+ y: ordinalY = 0,
310
315
  } = bboxOf(root);
311
316
  const extent = optionalExtent
312
317
  ? optionalExtent
@@ -3,15 +3,15 @@ import { deepMix } from '@antv/util';
3
3
  import { group } from 'd3-array';
4
4
  import { subObject } from '../utils/helper';
5
5
  import {
6
- createValueof,
7
6
  createDatumof,
8
- selectG2Elements,
9
- useState,
10
- renderLink,
11
- renderBackground,
12
- selectPlotArea,
7
+ createValueof,
13
8
  mergeState,
14
9
  offsetTransform,
10
+ renderBackground,
11
+ renderLink,
12
+ selectG2Elements,
13
+ selectPlotArea,
14
+ useState,
15
15
  } from './utils';
16
16
 
17
17
  /**
@@ -1,3 +1,5 @@
1
+ import { ChartEvent } from '../utils/event';
2
+
1
3
  function dataOf(element, view) {
2
4
  const { __data__: datum } = element;
3
5
  const { markKey, index, seriesIndex } = datum;
@@ -22,8 +24,7 @@ function bubblesEvent(eventType, view, emitter, predicate = (event) => true) {
22
24
  return (e) => {
23
25
  if (!predicate(e)) return;
24
26
  const { target } = e;
25
- const { classList = [] } = target;
26
- const [elementType, markType] = classList;
27
+ const { className: elementType, markType } = target;
27
28
  if (elementType === 'element') {
28
29
  updateData(e, target, view);
29
30
  emitter.emit(`element:${eventType}`, e);
@@ -41,33 +42,42 @@ export function Event() {
41
42
  const { container, view } = context;
42
43
 
43
44
  // Click events.
44
- const click = bubblesEvent('click', view, emitter, (e) => e.detail === 1);
45
+ const click = bubblesEvent(
46
+ ChartEvent.CLICK,
47
+ view,
48
+ emitter,
49
+ (e) => e.detail === 1,
50
+ );
45
51
  const dblclick = bubblesEvent(
46
- 'dblclick',
52
+ ChartEvent.DBLCLICK,
47
53
  view,
48
54
  emitter,
49
55
  (e) => e.detail === 2,
50
56
  );
51
57
 
52
58
  // Pointer events.
53
- const pointertap = bubblesEvent('pointertap', view, emitter);
54
- const pointerdown = bubblesEvent('pointerdown', view, emitter);
55
- const pointerup = bubblesEvent('pointerup', view, emitter);
56
- const pointerover = bubblesEvent('pointerover', view, emitter);
57
- const pointerout = bubblesEvent('pointerout', view, emitter);
58
- const pointermove = bubblesEvent('pointermove', view, emitter);
59
- const pointerenter = bubblesEvent('pointerenter', view, emitter);
60
- const pointerleave = bubblesEvent('pointerleave', view, emitter);
61
- const pointerupoutside = bubblesEvent('pointerupoutside', view, emitter);
59
+ const pointertap = bubblesEvent(ChartEvent.POINTER_TAP, view, emitter);
60
+ const pointerdown = bubblesEvent(ChartEvent.POINTER_DOWN, view, emitter);
61
+ const pointerup = bubblesEvent(ChartEvent.POINTER_UP, view, emitter);
62
+ const pointerover = bubblesEvent(ChartEvent.POINTER_OVER, view, emitter);
63
+ const pointerout = bubblesEvent(ChartEvent.POINTER_OUT, view, emitter);
64
+ const pointermove = bubblesEvent(ChartEvent.POINTER_MOVE, view, emitter);
65
+ const pointerenter = bubblesEvent(ChartEvent.POINTER_ENTER, view, emitter);
66
+ const pointerleave = bubblesEvent(ChartEvent.POINTER_LEAVE, view, emitter);
67
+ const pointerupoutside = bubblesEvent(
68
+ ChartEvent.POINTER_UPOUTSIDE,
69
+ view,
70
+ emitter,
71
+ );
62
72
 
63
73
  // Drag and drop events.
64
- const dragstart = bubblesEvent('dragstart', view, emitter);
65
- const drag = bubblesEvent('drag', view, emitter);
66
- const dragend = bubblesEvent('dragend', view, emitter);
67
- const dragenter = bubblesEvent('dragenter', view, emitter);
68
- const dragleave = bubblesEvent('dragleave', view, emitter);
69
- const dragover = bubblesEvent('dragover', view, emitter);
70
- const drop = bubblesEvent('drop', view, emitter);
74
+ const dragstart = bubblesEvent(ChartEvent.DRAG_START, view, emitter);
75
+ const drag = bubblesEvent(ChartEvent.DRAG, view, emitter);
76
+ const dragend = bubblesEvent(ChartEvent.DRAG_END, view, emitter);
77
+ const dragenter = bubblesEvent(ChartEvent.DRAG_ENTER, view, emitter);
78
+ const dragleave = bubblesEvent(ChartEvent.DRAG_LEAVE, view, emitter);
79
+ const dragover = bubblesEvent(ChartEvent.DRAG_OVER, view, emitter);
80
+ const drop = bubblesEvent(ChartEvent.DROP, view, emitter);
71
81
 
72
82
  // For legacy usage.
73
83
  container.addEventListener('click', click);