@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
@@ -4,7 +4,7 @@ import { deepMix, upperFirst } from '@antv/util';
4
4
  import { group } from 'd3-array';
5
5
  import { format } from 'd3-format';
6
6
  import { mapObject } from '../utils/array';
7
- import { CHART_LIFE_CIRCLE } from '../utils/event';
7
+ import { ChartEvent } from '../utils/event';
8
8
  import {
9
9
  appendTransform,
10
10
  copyAttributes,
@@ -171,7 +171,7 @@ export async function plot<T extends G2ViewTree>(
171
171
  }
172
172
  }
173
173
 
174
- context.emitter.emit(CHART_LIFE_CIRCLE.BEFORE_PAINT);
174
+ context.emitter.emit(ChartEvent.BEFORE_PAINT);
175
175
 
176
176
  // Plot chart.
177
177
  const enterContainer = new Map<G2ViewDescriptor, DisplayObject>();
@@ -245,7 +245,7 @@ export async function plot<T extends G2ViewTree>(
245
245
  for (const option of inferInteraction(options)) {
246
246
  // Remove interaction for existed views.
247
247
  const prevInteraction = nameInteraction.get(option.type);
248
- if (prevInteraction) prevInteraction.destroy();
248
+ if (prevInteraction) prevInteraction.destroy?.();
249
249
 
250
250
  // Apply new interaction.
251
251
  const interaction = useInteraction(option);
@@ -274,7 +274,7 @@ export async function plot<T extends G2ViewTree>(
274
274
  context.views = views;
275
275
  context.animations = transitions;
276
276
 
277
- context.emitter.emit(CHART_LIFE_CIRCLE.AFTER_PAINT);
277
+ context.emitter.emit(ChartEvent.AFTER_PAINT);
278
278
 
279
279
  // Note!!!
280
280
  // The returned promise will never resolved if one of nodeGenerator
@@ -303,14 +303,43 @@ function createUpdateView(
303
303
  const transitions = [];
304
304
  const [newView, newChildren] = await initializeView(newOptions, library);
305
305
  plotView(newView, selection, transitions, library);
306
+ updateTooltip(selection, newOptions, newView, library, context);
306
307
  for (const child of newChildren) {
307
308
  plot(child, selection, library, context);
308
309
  }
309
- return {
310
- options: newOptions,
311
- view: newView,
312
- };
310
+ return { options: newOptions, view: newView };
311
+ };
312
+ }
313
+
314
+ function updateTooltip(selection, options, view, library, context) {
315
+ const [useInteraction] = useLibrary<
316
+ G2InteractionOptions,
317
+ InteractionComponent,
318
+ Interaction
319
+ >('interaction', library);
320
+
321
+ // Instances for tooltip.
322
+ const container = selection.node();
323
+ const nameInteraction = container['nameInteraction'];
324
+ const { interaction } = options;
325
+ const tooltipOptions = inferInteraction(interaction).find(
326
+ (d) => d.type === 'tooltip',
327
+ );
328
+
329
+ // Destroy older tooltip.
330
+ const tooltip = nameInteraction.get('tooltip');
331
+ if (!tooltip) return;
332
+ tooltip.destroy?.();
333
+
334
+ // Apply new tooltip interaction.
335
+ const applyTooltip = useInteraction(tooltipOptions);
336
+ const target = {
337
+ options,
338
+ view,
339
+ container: selection.node(),
340
+ update: (options) => Promise.resolve(options),
313
341
  };
342
+ applyTooltip(target, [], context.emitter);
314
343
  }
315
344
 
316
345
  async function initializeView(
@@ -726,7 +755,7 @@ async function plotView(
726
755
  enter
727
756
  // Make this layer interactive, such as click and mousemove events.
728
757
  .append('rect')
729
- // todo zIndex
758
+ .style('zIndex', 0)
730
759
  .style('fill', 'transparent')
731
760
  .attr('className', PLOT_CLASS_NAME)
732
761
  .call(updateBBox)
@@ -749,15 +778,18 @@ async function plotView(
749
778
  for (const [mark, state] of markState.entries()) {
750
779
  const { data } = state;
751
780
  const { key, class: cls, type } = mark;
781
+ const viewNode = selection.select(`#${key}`);
752
782
  const shapeFunction = createMarkShapeFunction(mark, state, view, library);
753
783
  const enterFunction = createEnterFunction(mark, state, view, library);
754
784
  const updateFunction = createUpdateFunction(mark, state, view, library);
755
785
  const exitFunction = createExitFunction(mark, state, view, library);
756
- const facetElements = selectFacetElements(selection, cls, 'element');
757
- const classNames = [ELEMENT_CLASS_NAME];
758
- if (typeof type === 'string') classNames.push(type);
759
- const T = selection
760
- .select(`#${key}`)
786
+ const facetElements = selectFacetElements(
787
+ selection,
788
+ viewNode,
789
+ cls,
790
+ 'element',
791
+ );
792
+ const T = viewNode
761
793
  .selectAll(className(ELEMENT_CLASS_NAME))
762
794
  .selectFacetAll(facetElements)
763
795
  .data(
@@ -769,7 +801,10 @@ async function plotView(
769
801
  (enter) =>
770
802
  enter
771
803
  .append(shapeFunction)
772
- .attr('className', classNames.join(' '))
804
+ // Note!!! Only one className can be set.
805
+ // Using attribute as alternative for other classNames.
806
+ .attr('className', ELEMENT_CLASS_NAME)
807
+ .attr('markType', type)
773
808
  .transition(function (data) {
774
809
  return enterFunction(data, [this]);
775
810
  }),
@@ -803,6 +838,7 @@ async function plotView(
803
838
  // Append elements to be merged.
804
839
  .append(shapeFunction)
805
840
  .attr('className', ELEMENT_CLASS_NAME)
841
+ .attr('markType', type)
806
842
  .transition(function (data) {
807
843
  // Remove merged elements after animation finishing.
808
844
  const { __fromElements__: fromElements } = this;
@@ -819,6 +855,7 @@ async function plotView(
819
855
  const toElements = enter
820
856
  .append(shapeFunction)
821
857
  .attr('className', ELEMENT_CLASS_NAME)
858
+ .attr('markType', type)
822
859
  .nodes();
823
860
  return updateFunction(data, [this], toElements);
824
861
  })
@@ -1114,12 +1151,18 @@ function computeAnimationExtent(markState): [number, number] {
1114
1151
 
1115
1152
  function selectFacetElements(
1116
1153
  selection: Selection,
1154
+ current: Selection,
1117
1155
  facetClassName: string,
1118
1156
  elementClassName: string,
1119
1157
  ): DisplayObject[] {
1120
1158
  const group = selection.node().parentElement;
1121
1159
  return group
1122
- .findAll((node) => node.style.facet === facetClassName)
1160
+ .findAll(
1161
+ (node) =>
1162
+ node.style.facet !== undefined &&
1163
+ node.style.facet === facetClassName &&
1164
+ node !== current.node(), // Exclude current view.
1165
+ )
1123
1166
  .flatMap((node) => node.getElementsByClassName(elementClassName));
1124
1167
  }
1125
1168
 
@@ -1292,9 +1335,10 @@ function createExitFunction(
1292
1335
  return createAnimationFunction('exit', mark, state, view, library);
1293
1336
  }
1294
1337
 
1295
- function inferTheme(theme: G2ThemeOptions = { type: 'light' }): G2ThemeOptions {
1296
- const { type = 'light' } = theme;
1297
- return { ...theme, type };
1338
+ function inferTheme(theme: G2ThemeOptions = {}): G2ThemeOptions {
1339
+ if (typeof theme === 'string') return { type: theme };
1340
+ const { type = 'classic', ...rest } = theme;
1341
+ return { ...rest, type };
1298
1342
  }
1299
1343
 
1300
1344
  /**
@@ -1304,6 +1348,9 @@ function inferInteraction(view: G2View): G2InteractionOptions[] {
1304
1348
  const defaults = {
1305
1349
  event: true,
1306
1350
  tooltip: true,
1351
+ // @todo Inferred by slider self.
1352
+ sliderFilter: true,
1353
+ legendFilter: true,
1307
1354
  };
1308
1355
  const { interaction = {} } = view;
1309
1356
  return Object.entries(deepMix(defaults, interaction))
@@ -1395,7 +1442,10 @@ function updateLayers(selection: Selection, marks: G2Mark[]) {
1395
1442
 
1396
1443
  const labelLayer = selection.select(className(LABEL_LAYER_CLASS_NAME)).node();
1397
1444
  if (labelLayer) return;
1398
- selection.append('g').attr('className', LABEL_LAYER_CLASS_NAME);
1445
+ selection
1446
+ .append('g')
1447
+ .attr('className', LABEL_LAYER_CLASS_NAME)
1448
+ .style('zIndex', 0);
1399
1449
  }
1400
1450
 
1401
1451
  function className(...names: string[]): string {
@@ -5,7 +5,8 @@ import { deepMix } from '@antv/util';
5
5
  import EventEmitter from '@antv/event-emitter';
6
6
  import { createLibrary } from '../stdlib';
7
7
  import { select } from '../utils/selection';
8
- import { CHART_LIFE_CIRCLE } from '../utils/event';
8
+ import { ChartEvent } from '../utils/event';
9
+ import { error } from '../utils/helper';
9
10
  import { G2Context, G2ViewTree } from './types/options';
10
11
  import { plot } from './plot';
11
12
 
@@ -61,10 +62,14 @@ function Canvas(width: number, height: number): GCanvas {
61
62
  export function render<T extends G2ViewTree = G2ViewTree>(
62
63
  options: T,
63
64
  context: G2Context = {},
64
- callback?: () => void,
65
+ resolve?: () => void,
66
+ reject?: (e: Error) => void,
65
67
  ): HTMLElement {
66
68
  // Initialize the context if it is not provided.
67
- const { width = 640, height = 480, on } = options;
69
+ const { width = 640, height = 480, theme } = options;
70
+ if (!theme) {
71
+ error('ChartOptions.theme is required, such as classic.');
72
+ }
68
73
  const keyed = inferKeys(options);
69
74
  const {
70
75
  canvas = Canvas(width, height),
@@ -76,7 +81,7 @@ export function render<T extends G2ViewTree = G2ViewTree>(
76
81
  context.emitter = emitter;
77
82
  canvas.resize(width, height);
78
83
 
79
- emitter.emit(CHART_LIFE_CIRCLE.BEFORE_RENDER);
84
+ emitter.emit(ChartEvent.BEFORE_RENDER);
80
85
 
81
86
  // Plot the chart and mutate context.
82
87
  // Make sure that plot chart after container is ready for every time.
@@ -86,8 +91,11 @@ export function render<T extends G2ViewTree = G2ViewTree>(
86
91
  plot<T>({ ...keyed, width, height }, selection, library, context),
87
92
  )
88
93
  .then(() => {
89
- emitter.emit(CHART_LIFE_CIRCLE.AFTER_RENDER);
90
- callback?.();
94
+ emitter.emit(ChartEvent.AFTER_RENDER);
95
+ resolve?.();
96
+ })
97
+ .catch((e) => {
98
+ reject?.(e);
91
99
  });
92
100
 
93
101
  // Return the container HTML element wraps the canvas or svg element.
@@ -119,11 +127,11 @@ export function renderToMountedElement<T extends G2ViewTree = G2ViewTree>(
119
127
  context.library = library;
120
128
  context.emitter = emitter;
121
129
 
122
- emitter.emit(CHART_LIFE_CIRCLE.BEFORE_RENDER);
130
+ emitter.emit(ChartEvent.BEFORE_RENDER);
123
131
  // Plot the chart and mutate context.
124
132
  // Make sure that plot chart after container is ready for every time.
125
133
  plot<T>({ ...keyed, width, height }, selection, library, context).then(() => {
126
- emitter.emit(CHART_LIFE_CIRCLE.AFTER_RENDER);
134
+ emitter.emit(ChartEvent.AFTER_RENDER);
127
135
  callback?.();
128
136
  });
129
137
 
@@ -134,12 +134,27 @@ export const Color: SC<ColorOptions> = (options) => {
134
134
 
135
135
  // Extended style, which is not supported by native g shape,
136
136
  // should apply at first.
137
+ const standardDirRadius = [
138
+ first ? radiusTopLeft : innerRadiusTopLeft,
139
+ first ? radiusTopRight : innerRadiusTopRight,
140
+ last ? radiusBottomRight : innerRadiusBottomRight,
141
+ last ? radiusBottomLeft : innerRadiusBottomLeft,
142
+ ];
143
+ const standardDir = [
144
+ 'radiusTopLeft',
145
+ 'radiusTopRight',
146
+ 'radiusBottomRight',
147
+ 'radiusBottomLeft',
148
+ ];
149
+ // Transpose: rotate it clockwise by 90.
150
+ if (isTranspose(coordinate)) {
151
+ standardDir.push(standardDir.shift());
152
+ }
137
153
  const extendedStyle = {
138
154
  radius,
139
- radiusTopLeft: first ? radiusTopLeft : innerRadiusTopLeft,
140
- radiusTopRight: first ? radiusTopRight : innerRadiusTopRight,
141
- radiusBottomRight: last ? radiusBottomRight : innerRadiusBottomRight,
142
- radiusBottomLeft: last ? radiusBottomLeft : innerRadiusBottomLeft,
155
+ ...Object.fromEntries(
156
+ standardDir.map((d, i) => [d, standardDirRadius[i]]),
157
+ ),
143
158
  inset,
144
159
  insetLeft,
145
160
  insetRight,
@@ -56,7 +56,7 @@ export const Label: SC<LabelOptions> = (options) => {
56
56
  return select(new Advance())
57
57
  .call(applyStyle, defaultStyle)
58
58
  .style('text', `${text}`)
59
- .style('transform', `${transform}rotate(${+rotate}deg)`)
59
+ .style('transform', `${transform}rotate(${+rotate})`)
60
60
  .style('coordCenter', coordinate.getCenter())
61
61
  .call(applyStyle, overrideStyle)
62
62
  .node();
@@ -32,7 +32,7 @@ export function area(
32
32
  return {
33
33
  x: point[0],
34
34
  y: point[1],
35
- transform: `rotate(${rotate}deg)`,
35
+ transform: `rotate(${rotate})`,
36
36
  textAlign: 'center',
37
37
  textBaseline: 'middle',
38
38
  };
@@ -135,7 +135,7 @@ export const Curve: SC<CurveOptions> = (options) => {
135
135
  // Draw one path of connected defined points.
136
136
  if (!missing || (connectNulls && !Object.keys(connectStyle).length)) {
137
137
  return select(new Path({}))
138
- .style('d', linePath(DP))
138
+ .style('d', linePath(DP) || [])
139
139
  .call(applyStyle, finalStyle)
140
140
  .node();
141
141
  }
@@ -144,10 +144,10 @@ export const Advance = createElement((g) => {
144
144
  [+x0, +y0],
145
145
  [+x, +y],
146
146
  ];
147
-
148
147
  const shape1 = select(g)
149
148
  .maybeAppend('text', 'text')
150
- .call(applyStyle, rest)
149
+ .style('zIndex', 0)
150
+ .call(applyStyle, { textBaseline: 'middle', ...rest })
151
151
  .node();
152
152
 
153
153
  const shape2 = select(g)
@@ -177,6 +177,7 @@ export const Advance = createElement((g) => {
177
177
  });
178
178
  select(g)
179
179
  .maybeAppend('connector', 'path')
180
+ .style('zIndex', 0)
180
181
  .style('path', connectorPath)
181
182
  .style('markerStart', markerStart)
182
183
  .style('markerEnd', markerEnd)
@@ -28,7 +28,7 @@ export const Text: SC<TextOptions> = (options) => {
28
28
  .style('x', x0)
29
29
  .style('y', y0)
30
30
  .call(applyStyle, shapeTheme)
31
- .style('transform', `${transform}rotate(${+rotate}deg)`)
31
+ .style('transform', `${transform}rotate(${+rotate})`)
32
32
  .style('coordCenter', coordinate.getCenter())
33
33
  .call(applyStyle, textStyle)
34
34
  .call(applyStyle, style)
@@ -1,3 +1,4 @@
1
+ import type { TooltipStyleProps } from '@antv/gui';
1
2
  import { InteractionComponent } from '../runtime';
2
3
  import { FisheyeCoordinate } from './coordinateTransform';
3
4
  import { TooltipItemValue } from './component';
@@ -198,6 +199,8 @@ export type TooltipInteraction = {
198
199
  body?: boolean;
199
200
  crosshairs?: boolean;
200
201
  groupName?: boolean;
202
+ position?: TooltipStyleProps['position'];
203
+ // enterable?: boolean;
201
204
  sort?: (d: TooltipItemValue) => any;
202
205
  filter?: (d: TooltipItemValue) => any;
203
206
  render?: (
package/src/spec/scale.ts CHANGED
@@ -57,8 +57,9 @@ export type BaseScale<T extends ScaleTypes, O> = {
57
57
  rangeMax?: number;
58
58
  rangeMin?: number;
59
59
  domainMax?: number;
60
- domainMix?: number;
61
- field?: string | string[];
60
+ domainMin?: number;
61
+ key?: string;
62
+ facet?: boolean;
62
63
  independent?: boolean;
63
64
  zero?: boolean;
64
65
  offset?: (t: number) => number;
@@ -424,8 +424,8 @@ export function createLibrary(): G2Library {
424
424
  'shape.rangeY.range': RectShape,
425
425
  'shape.path.path': PathShape,
426
426
  'shape.path.hollow': HollowPath,
427
- 'theme.light': Light,
428
- 'theme.dark': Dark,
427
+ 'theme.classic': Light,
428
+ 'theme.classicDark': Dark,
429
429
  'theme.academy': Academy,
430
430
  'component.axisX': AxisX,
431
431
  'component.axisY': AxisY,
@@ -228,7 +228,7 @@ export const Academy: TC<AcademyOptions> = (options) => {
228
228
  lineStroke: '#888',
229
229
  lineStrokeOpacity: 1,
230
230
  lineLineWidth: 1,
231
- lineArrow: null,
231
+ showArrow: false,
232
232
  tickStroke: COLORS.STROKE,
233
233
  tickStrokeOpacity: 1,
234
234
  tickLineWidth: 1,
@@ -356,7 +356,7 @@ export const Academy: TC<AcademyOptions> = (options) => {
356
356
  fillOpacity: 0.65,
357
357
  fontSize: 10,
358
358
  fontWeight: 'normal',
359
- stroke: null,
359
+ stroke: undefined,
360
360
  offset: 12,
361
361
  connectorStroke: COLORS.BLACK,
362
362
  connectorStrokeOpacity: 0.45,
@@ -370,13 +370,13 @@ export const Academy: TC<AcademyOptions> = (options) => {
370
370
  fontSize: 10,
371
371
  fillOpacity: 0.85,
372
372
  fontWeight: 'normal',
373
- stroke: null,
373
+ stroke: undefined,
374
374
  offset: 0,
375
375
  },
376
376
  slider: {
377
377
  trackSize: 16,
378
- backgroundFill: COLORS.STROKE,
379
- backgroundFillOpacity: 0.05,
378
+ trackFill: COLORS.STROKE,
379
+ trackFillOpacity: 0.05,
380
380
  selectionFill: DEFAULT_COLOR,
381
381
  selectionFillOpacity: 0.15,
382
382
  handleIconSize: 10,
package/src/theme/dark.ts CHANGED
@@ -230,7 +230,7 @@ export const Dark: TC<DarkOptions> = (options) => {
230
230
  lineStroke: COLORS.BLACK,
231
231
  lineStrokeOpacity: 0.45,
232
232
  lineLineWidth: 0.5,
233
- lineArrow: null,
233
+ showArrow: false,
234
234
  // axis tick line
235
235
  tickStroke: COLORS.BLACK,
236
236
  tickStrokeOpacity: 0.25,
@@ -360,7 +360,7 @@ export const Dark: TC<DarkOptions> = (options) => {
360
360
  fillOpacity: 0.65,
361
361
  fontSize: 12,
362
362
  fontWeight: 'normal',
363
- stroke: null,
363
+ stroke: undefined,
364
364
  offset: 12,
365
365
  connectorStroke: COLORS.BLACK,
366
366
  connectorStrokeOpacity: 0.45,
@@ -374,13 +374,13 @@ export const Dark: TC<DarkOptions> = (options) => {
374
374
  fontSize: 12,
375
375
  fillOpacity: 0.85,
376
376
  fontWeight: 'normal',
377
- stroke: null,
377
+ stroke: undefined,
378
378
  offset: 0,
379
379
  },
380
380
  slider: {
381
381
  trackSize: 16,
382
- backgroundFill: COLORS.STROKE,
383
- backgroundFillOpacity: 1,
382
+ trackFill: COLORS.STROKE,
383
+ trackFillOpacity: 1,
384
384
  selectionFill: DEFAULT_COLOR,
385
385
  selectionFillOpacity: 0.15,
386
386
  handleIconSize: 10,
@@ -230,7 +230,7 @@ export const Light: TC<LightOptions> = (options) => {
230
230
  lineStroke: COLORS.BLACK,
231
231
  lineStrokeOpacity: 0.45,
232
232
  lineLineWidth: 0.5,
233
- lineArrow: null,
233
+ showArrow: false,
234
234
  // axis tick line
235
235
  tickStroke: COLORS.BLACK,
236
236
  tickStrokeOpacity: 0.25,
@@ -354,7 +354,7 @@ export const Light: TC<LightOptions> = (options) => {
354
354
  handleLabelFillOpacity: 0.45,
355
355
  handleLabelFontSize: 12,
356
356
  handleLabelFontWeight: 'normal',
357
- labelShowTick: true,
357
+ showTick: true,
358
358
  labelSpacing: 8,
359
359
  // [todo] legend rail
360
360
  },
@@ -363,7 +363,7 @@ export const Light: TC<LightOptions> = (options) => {
363
363
  fillOpacity: 0.65,
364
364
  fontSize: 12,
365
365
  fontWeight: 'normal',
366
- stroke: null,
366
+ stroke: undefined,
367
367
  offset: 12,
368
368
  connectorStroke: COLORS.BLACK,
369
369
  connectorStrokeOpacity: 0.45,
@@ -377,13 +377,13 @@ export const Light: TC<LightOptions> = (options) => {
377
377
  fontSize: 12,
378
378
  fillOpacity: 0.85,
379
379
  fontWeight: 'normal',
380
- stroke: null,
380
+ stroke: undefined,
381
381
  offset: 0,
382
382
  },
383
383
  slider: {
384
384
  trackSize: 16,
385
- backgroundFill: COLORS.STROKE,
386
- backgroundFillOpacity: 1,
385
+ trackFill: COLORS.STROKE,
386
+ trackFillOpacity: 1,
387
387
  selectionFill: DEFAULT_COLOR,
388
388
  selectionFillOpacity: 0.15,
389
389
  handleIconSize: 10,
@@ -406,10 +406,8 @@ export const Light: TC<LightOptions> = (options) => {
406
406
  scrollable: true,
407
407
  trackFill: '#e5e5e5',
408
408
  trackFillOpacity: 0,
409
- trackStroke: 'none',
410
409
  thumbFill: '#000',
411
410
  thumbFillOpacity: 0.15,
412
- thumbStroke: 'none',
413
411
  thumbHighlightedFillOpacity: 0.2,
414
412
  },
415
413
  title: {
@@ -41,7 +41,10 @@ export const Filter: TC<FilterOptions> = (options = {}) => {
41
41
  },
42
42
  ];
43
43
  });
44
- return [I, deepMix({}, mark, { encode: Object.fromEntries(newEncodes) })];
44
+ return [
45
+ newIndex,
46
+ deepMix({}, mark, { encode: Object.fromEntries(newEncodes) }),
47
+ ];
45
48
  };
46
49
  };
47
50
 
@@ -1,20 +1,52 @@
1
- // Life cycle stage.
2
- export enum CHART_LIFE_CIRCLE {
3
- BEFORE_RENDER = 'beforerender',
4
- AFTER_RENDER = 'afterrender',
1
+ // to prevent users from tampering with internal values.
2
+ const ChartEvent = new Proxy(
3
+ {
4
+ BEFORE_RENDER: 'beforerender',
5
+ AFTER_RENDER: 'afterrender',
5
6
 
6
- BEFORE_PAINT = 'beforepaint',
7
- AFTER_PAINT = 'afterpaint',
7
+ BEFORE_PAINT: 'beforepaint',
8
+ AFTER_PAINT: 'afterpaint',
8
9
 
9
- BEFORE_CHANGE_DATA = 'beforechangedata',
10
- AFTER_CHANGE_DATA = 'afterchangedata',
10
+ BEFORE_CHANGE_DATA: 'beforechangedata',
11
+ AFTER_CHANGE_DATA: 'afterchangedata',
11
12
 
12
- BEFORE_CLEAR = 'beforeclear',
13
- AFTER_CLEAR = 'afterclear',
13
+ BEFORE_CLEAR: 'beforeclear',
14
+ AFTER_CLEAR: 'afterclear',
14
15
 
15
- BEFORE_DESTROY = 'beforedestroy',
16
- AFTER_DESTROY = 'afterdestroy',
16
+ BEFORE_DESTROY: 'beforedestroy',
17
+ AFTER_DESTROY: 'afterdestroy',
17
18
 
18
- BEFORE_CHANGE_SIZE = 'beforechangesize',
19
- AFTER_CHANGE_SIZE = 'afterchangesize',
20
- }
19
+ BEFORE_CHANGE_SIZE: 'beforechangesize',
20
+ AFTER_CHANGE_SIZE: 'afterchangesize',
21
+
22
+ POINTER_TAP: 'pointertap',
23
+ POINTER_DOWN: 'pointerdown',
24
+ POINTER_UP: 'pointerup',
25
+ POINTER_OVER: 'pointerover',
26
+ POINTER_OUT: 'pointerout',
27
+ POINTER_MOVE: 'pointermove',
28
+ POINTER_ENTER: 'pointerenter',
29
+ POINTER_LEAVE: 'pointerleave',
30
+ POINTER_UPOUTSIDE: 'pointerupoutside',
31
+ DRAG_START: 'dragstart',
32
+ DRAG: 'drag',
33
+ DRAG_END: 'dragend',
34
+ DRAG_ENTER: 'dragenter',
35
+ DRAG_LEAVE: 'dragleave',
36
+ DRAG_OVER: 'dragover',
37
+ DROP: 'DROP',
38
+ CLICK: 'click',
39
+ DBLCLICK: 'dblclick',
40
+ } as const,
41
+ {
42
+ get(target, prop) {
43
+ if (prop in target) return target[prop];
44
+ return undefined;
45
+ },
46
+ set() {
47
+ return true;
48
+ },
49
+ },
50
+ );
51
+
52
+ export { ChartEvent };
@@ -71,7 +71,8 @@ export function useMemo<T = unknown, U = unknown>(
71
71
 
72
72
  export function appendTransform(node: DisplayObject, transform: any) {
73
73
  const { transform: preTransform } = node.style;
74
- const prefix = preTransform === 'none' ? '' : preTransform;
74
+ const unset = (d) => d === 'none' || d === undefined;
75
+ const prefix = unset(preTransform) ? '' : preTransform;
75
76
  node.style.transform = `${prefix} ${transform}`.trimStart();
76
77
  }
77
78
 
@@ -0,0 +1,34 @@
1
+ import type { DisplayObject, BaseStyleProps } from '@antv/g';
2
+
3
+ const defaultStyle: BaseStyleProps = {
4
+ visibility: 'visible',
5
+ opacity: 1,
6
+ fillOpacity: 1,
7
+ strokeOpacity: 1,
8
+ };
9
+
10
+ export function getStyle(element: DisplayObject, key: string) {
11
+ return element.style[key] ?? defaultStyle[key];
12
+ }
13
+
14
+ export function setStyle(
15
+ element: DisplayObject,
16
+ key: string,
17
+ value: any,
18
+ recursive: boolean,
19
+ ) {
20
+ element.style[key] = value;
21
+ if (recursive) {
22
+ element.children.forEach((child: DisplayObject) =>
23
+ setStyle(child, key, value, recursive),
24
+ );
25
+ }
26
+ }
27
+
28
+ export function hide(element: DisplayObject) {
29
+ setStyle(element, 'visibility', 'hidden', true);
30
+ }
31
+
32
+ export function show(element: DisplayObject) {
33
+ setStyle(element, 'visibility', 'visible', true);
34
+ }