@antv/g2 5.1.13 → 5.1.15-beta.0

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 (239) hide show
  1. package/dist/g2.lite.min.js +1 -1
  2. package/dist/g2.min.js +1 -1
  3. package/esm/animation/growInX.js +1 -1
  4. package/esm/animation/growInX.js.map +1 -1
  5. package/esm/animation/growInY.js +1 -1
  6. package/esm/animation/growInY.js.map +1 -1
  7. package/esm/animation/morphing.js +8 -4
  8. package/esm/animation/morphing.js.map +1 -1
  9. package/esm/animation/scaleInY.js +2 -5
  10. package/esm/animation/scaleInY.js.map +1 -1
  11. package/esm/animation/waveIn.js +2 -1
  12. package/esm/animation/waveIn.js.map +1 -1
  13. package/esm/api/utils.js +27 -15
  14. package/esm/api/utils.js.map +1 -1
  15. package/esm/component/axis.js +13 -7
  16. package/esm/component/axis.js.map +1 -1
  17. package/esm/component/title.js +2 -1
  18. package/esm/component/title.js.map +1 -1
  19. package/esm/coordinate/polar.d.ts +1 -1
  20. package/esm/coordinate/polar.js +3 -1
  21. package/esm/coordinate/polar.js.map +1 -1
  22. package/esm/index.d.ts +2 -0
  23. package/esm/interaction/event.js +15 -3
  24. package/esm/interaction/event.js.map +1 -1
  25. package/esm/interaction/index.d.ts +1 -0
  26. package/esm/interaction/index.js +1 -0
  27. package/esm/interaction/index.js.map +1 -1
  28. package/esm/interaction/legendFilter.d.ts +1 -0
  29. package/esm/interaction/legendFilter.js +6 -0
  30. package/esm/interaction/legendFilter.js.map +1 -1
  31. package/esm/interaction/scrollbarFilter.js +5 -1
  32. package/esm/interaction/scrollbarFilter.js.map +1 -1
  33. package/esm/interaction/sliderFilter.d.ts +1 -1
  34. package/esm/interaction/sliderFilter.js +19 -2
  35. package/esm/interaction/sliderFilter.js.map +1 -1
  36. package/esm/interaction/tooltip.js +2 -2
  37. package/esm/interaction/tooltip.js.map +1 -1
  38. package/esm/interaction/treemapDrillDown.d.ts +10 -0
  39. package/esm/interaction/treemapDrillDown.js +229 -0
  40. package/esm/interaction/treemapDrillDown.js.map +1 -0
  41. package/esm/interaction/utils.js +7 -6
  42. package/esm/interaction/utils.js.map +1 -1
  43. package/esm/lib/core.d.ts +2 -1
  44. package/esm/lib/core.js +2 -1
  45. package/esm/lib/core.js.map +1 -1
  46. package/esm/lib/std.d.ts +1 -0
  47. package/esm/mark/chord.js +0 -1
  48. package/esm/mark/chord.js.map +1 -1
  49. package/esm/mark/gauge.js +4 -1
  50. package/esm/mark/gauge.js.map +1 -1
  51. package/esm/mark/sankey.js +1 -1
  52. package/esm/mark/sankey.js.map +1 -1
  53. package/esm/mark/treemap.js +37 -57
  54. package/esm/mark/treemap.js.map +1 -1
  55. package/esm/mark/utils.d.ts +0 -5
  56. package/esm/mark/utils.js +0 -13
  57. package/esm/mark/utils.js.map +1 -1
  58. package/esm/runtime/plot.js +52 -35
  59. package/esm/runtime/plot.js.map +1 -1
  60. package/esm/runtime/types/common.d.ts +1 -1
  61. package/esm/shape/connector/connector.js +1 -1
  62. package/esm/shape/connector/connector.js.map +1 -1
  63. package/esm/shape/gauge/round.d.ts +3 -0
  64. package/esm/shape/gauge/round.js +40 -0
  65. package/esm/shape/gauge/round.js.map +1 -0
  66. package/esm/shape/image/image.js +1 -1
  67. package/esm/shape/index.d.ts +1 -0
  68. package/esm/shape/index.js +1 -0
  69. package/esm/shape/index.js.map +1 -1
  70. package/esm/shape/interval/color.js +1 -1
  71. package/esm/shape/interval/color.js.map +1 -1
  72. package/esm/shape/interval/funnel.js +1 -1
  73. package/esm/shape/interval/funnel.js.map +1 -1
  74. package/esm/shape/label/position/default.js +9 -9
  75. package/esm/shape/label/position/default.js.map +1 -1
  76. package/esm/shape/lineXY/line.js +1 -1
  77. package/esm/shape/lineXY/line.js.map +1 -1
  78. package/esm/shape/liquid/liquid.js +4 -4
  79. package/esm/shape/liquid/liquid.js.map +1 -1
  80. package/esm/shape/liquid/wave.js +1 -1
  81. package/esm/shape/liquid/wave.js.map +1 -1
  82. package/esm/shape/point/color.js +1 -0
  83. package/esm/shape/point/color.js.map +1 -1
  84. package/esm/shape/text/advance.js +2 -1
  85. package/esm/shape/text/advance.js.map +1 -1
  86. package/esm/shape/utils.js +2 -2
  87. package/esm/shape/utils.js.map +1 -1
  88. package/esm/theme/create.d.ts +2 -2
  89. package/esm/theme/create.js +2 -2
  90. package/esm/theme/create.js.map +1 -1
  91. package/esm/utils/angle.d.ts +4 -0
  92. package/esm/utils/angle.js +18 -0
  93. package/esm/utils/angle.js.map +1 -1
  94. package/esm/utils/marker.d.ts +1 -1
  95. package/esm/utils/marker.js +2 -2
  96. package/esm/utils/marker.js.map +1 -1
  97. package/esm/utils/treeDataTransform.d.ts +21 -0
  98. package/esm/utils/treeDataTransform.js +90 -0
  99. package/esm/utils/treeDataTransform.js.map +1 -0
  100. package/lib/animation/growInX.js +1 -1
  101. package/lib/animation/growInX.js.map +1 -1
  102. package/lib/animation/growInY.js +1 -1
  103. package/lib/animation/growInY.js.map +1 -1
  104. package/lib/animation/morphing.js +8 -4
  105. package/lib/animation/morphing.js.map +1 -1
  106. package/lib/animation/scaleInY.js +2 -5
  107. package/lib/animation/scaleInY.js.map +1 -1
  108. package/lib/animation/waveIn.js +2 -1
  109. package/lib/animation/waveIn.js.map +1 -1
  110. package/lib/api/utils.js +27 -15
  111. package/lib/api/utils.js.map +1 -1
  112. package/lib/component/axis.js +13 -7
  113. package/lib/component/axis.js.map +1 -1
  114. package/lib/component/title.js +2 -1
  115. package/lib/component/title.js.map +1 -1
  116. package/lib/coordinate/polar.d.ts +1 -1
  117. package/lib/coordinate/polar.js +3 -1
  118. package/lib/coordinate/polar.js.map +1 -1
  119. package/lib/index.d.ts +2 -0
  120. package/lib/interaction/event.js +15 -3
  121. package/lib/interaction/event.js.map +1 -1
  122. package/lib/interaction/index.d.ts +1 -0
  123. package/lib/interaction/index.js +3 -1
  124. package/lib/interaction/index.js.map +1 -1
  125. package/lib/interaction/legendFilter.d.ts +1 -0
  126. package/lib/interaction/legendFilter.js +8 -1
  127. package/lib/interaction/legendFilter.js.map +1 -1
  128. package/lib/interaction/scrollbarFilter.js +5 -1
  129. package/lib/interaction/scrollbarFilter.js.map +1 -1
  130. package/lib/interaction/sliderFilter.d.ts +1 -1
  131. package/lib/interaction/sliderFilter.js +19 -2
  132. package/lib/interaction/sliderFilter.js.map +1 -1
  133. package/lib/interaction/tooltip.js +2 -2
  134. package/lib/interaction/tooltip.js.map +1 -1
  135. package/lib/interaction/treemapDrillDown.d.ts +10 -0
  136. package/lib/interaction/treemapDrillDown.js +233 -0
  137. package/lib/interaction/treemapDrillDown.js.map +1 -0
  138. package/lib/interaction/utils.js +7 -6
  139. package/lib/interaction/utils.js.map +1 -1
  140. package/lib/lib/core.d.ts +2 -1
  141. package/lib/lib/core.js +1 -0
  142. package/lib/lib/core.js.map +1 -1
  143. package/lib/lib/std.d.ts +1 -0
  144. package/lib/mark/chord.js +0 -1
  145. package/lib/mark/chord.js.map +1 -1
  146. package/lib/mark/gauge.js +4 -1
  147. package/lib/mark/gauge.js.map +1 -1
  148. package/lib/mark/sankey.js +1 -1
  149. package/lib/mark/sankey.js.map +1 -1
  150. package/lib/mark/treemap.js +36 -56
  151. package/lib/mark/treemap.js.map +1 -1
  152. package/lib/mark/utils.d.ts +0 -5
  153. package/lib/mark/utils.js +1 -15
  154. package/lib/mark/utils.js.map +1 -1
  155. package/lib/runtime/plot.js +51 -34
  156. package/lib/runtime/plot.js.map +1 -1
  157. package/lib/runtime/types/common.d.ts +1 -1
  158. package/lib/shape/connector/connector.js +1 -1
  159. package/lib/shape/connector/connector.js.map +1 -1
  160. package/lib/shape/gauge/round.d.ts +3 -0
  161. package/lib/shape/gauge/round.js +44 -0
  162. package/lib/shape/gauge/round.js.map +1 -0
  163. package/lib/shape/image/image.js +1 -1
  164. package/lib/shape/index.d.ts +1 -0
  165. package/lib/shape/index.js +3 -1
  166. package/lib/shape/index.js.map +1 -1
  167. package/lib/shape/interval/color.js +1 -1
  168. package/lib/shape/interval/color.js.map +1 -1
  169. package/lib/shape/interval/funnel.js +1 -1
  170. package/lib/shape/interval/funnel.js.map +1 -1
  171. package/lib/shape/label/position/default.js +9 -9
  172. package/lib/shape/label/position/default.js.map +1 -1
  173. package/lib/shape/lineXY/line.js +1 -1
  174. package/lib/shape/lineXY/line.js.map +1 -1
  175. package/lib/shape/liquid/liquid.js +4 -4
  176. package/lib/shape/liquid/liquid.js.map +1 -1
  177. package/lib/shape/liquid/wave.js +1 -1
  178. package/lib/shape/liquid/wave.js.map +1 -1
  179. package/lib/shape/point/color.js +1 -0
  180. package/lib/shape/point/color.js.map +1 -1
  181. package/lib/shape/text/advance.js +2 -1
  182. package/lib/shape/text/advance.js.map +1 -1
  183. package/lib/shape/utils.js +1 -1
  184. package/lib/shape/utils.js.map +1 -1
  185. package/lib/theme/create.d.ts +2 -2
  186. package/lib/theme/create.js +2 -2
  187. package/lib/theme/create.js.map +1 -1
  188. package/lib/utils/angle.d.ts +4 -0
  189. package/lib/utils/angle.js +20 -1
  190. package/lib/utils/angle.js.map +1 -1
  191. package/lib/utils/marker.d.ts +1 -1
  192. package/lib/utils/marker.js +2 -2
  193. package/lib/utils/marker.js.map +1 -1
  194. package/lib/utils/treeDataTransform.d.ts +21 -0
  195. package/lib/utils/treeDataTransform.js +94 -0
  196. package/lib/utils/treeDataTransform.js.map +1 -0
  197. package/package.json +15 -15
  198. package/src/animation/growInX.ts +1 -1
  199. package/src/animation/growInY.ts +1 -1
  200. package/src/animation/morphing.ts +7 -5
  201. package/src/animation/scaleInY.ts +2 -5
  202. package/src/animation/waveIn.ts +2 -1
  203. package/src/api/utils.ts +41 -13
  204. package/src/component/axis.ts +17 -10
  205. package/src/component/title.ts +4 -0
  206. package/src/coordinate/polar.ts +6 -1
  207. package/src/interaction/event.ts +20 -7
  208. package/src/interaction/index.ts +1 -0
  209. package/src/interaction/legendFilter.ts +8 -0
  210. package/src/interaction/scrollbarFilter.ts +4 -0
  211. package/src/interaction/sliderFilter.ts +21 -1
  212. package/src/interaction/tooltip.ts +3 -3
  213. package/src/interaction/treemapDrillDown.ts +282 -0
  214. package/src/interaction/utils.ts +8 -5
  215. package/src/lib/core.ts +2 -0
  216. package/src/mark/chord.ts +0 -1
  217. package/src/mark/gauge.ts +5 -1
  218. package/src/mark/sankey.ts +1 -1
  219. package/src/mark/treemap.ts +76 -123
  220. package/src/mark/utils.ts +0 -17
  221. package/src/runtime/plot.ts +93 -45
  222. package/src/runtime/types/common.ts +5 -1
  223. package/src/shape/connector/connector.ts +1 -1
  224. package/src/shape/gauge/round.ts +57 -0
  225. package/src/shape/image/image.ts +1 -1
  226. package/src/shape/index.ts +1 -0
  227. package/src/shape/interval/color.ts +1 -1
  228. package/src/shape/interval/funnel.ts +1 -1
  229. package/src/shape/label/position/default.ts +9 -9
  230. package/src/shape/lineXY/line.ts +1 -2
  231. package/src/shape/liquid/liquid.ts +4 -4
  232. package/src/shape/liquid/wave.ts +1 -1
  233. package/src/shape/point/color.ts +1 -0
  234. package/src/shape/text/advance.ts +3 -1
  235. package/src/shape/utils.ts +3 -2
  236. package/src/theme/create.ts +2 -2
  237. package/src/utils/angle.ts +22 -0
  238. package/src/utils/marker.ts +2 -11
  239. package/src/utils/treeDataTransform.ts +153 -0
@@ -1,7 +1,7 @@
1
1
  import { Vector2 } from '@antv/coord';
2
2
  import { DisplayObject, IAnimation as GAnimation, Rect } from '@antv/g';
3
- import { deepMix, upperFirst } from '@antv/util';
4
- import { group, groups, sort } from 'd3-array';
3
+ import { deepMix, upperFirst, isArray } from '@antv/util';
4
+ import { group, groups } from 'd3-array';
5
5
  import { format } from 'd3-format';
6
6
  import { mapObject } from '../utils/array';
7
7
  import { ChartEvent } from '../utils/event';
@@ -66,6 +66,7 @@ import {
66
66
  InteractionComponent,
67
67
  LabelTransform,
68
68
  LabelTransformComponent,
69
+ Scale,
69
70
  Shape,
70
71
  ShapeComponent,
71
72
  Theme,
@@ -89,6 +90,8 @@ import {
89
90
  G2ViewTree,
90
91
  } from './types/options';
91
92
 
93
+ type Store = Map<any, (options: G2ViewTree) => G2ViewTree>;
94
+
92
95
  export async function plot<T extends G2ViewTree>(
93
96
  options: T,
94
97
  selection: Selection,
@@ -241,12 +244,19 @@ export async function plot<T extends G2ViewTree>(
241
244
  // Apply interactions.
242
245
  const viewInstanceof = (
243
246
  viewContainer: Map<G2ViewDescriptor, DisplayObject>,
247
+ updateInteractions?: (
248
+ container: Map<G2ViewDescriptor, DisplayObject>,
249
+ updateTypes?: string[],
250
+ store?: Store,
251
+ ) => void,
252
+ oldStore?: Store,
244
253
  ) => {
245
254
  return Array.from(viewContainer.entries()).map(([view, container]) => {
246
255
  // Index state by component or interaction name,
247
256
  // such as legend, scrollbar, brushFilter.
248
257
  // Each state transform options to another options.
249
- const store = new Map<any, (options: G2ViewTree) => G2ViewTree>();
258
+ const store =
259
+ oldStore || new Map<any, (options: G2ViewTree) => G2ViewTree>();
250
260
  const setState = (key, reducer = (x) => x) => store.set(key, reducer);
251
261
  const options = viewNode.get(view);
252
262
  const update = createUpdateView(
@@ -260,18 +270,68 @@ export async function plot<T extends G2ViewTree>(
260
270
  container,
261
271
  options,
262
272
  setState,
263
- update: async (from) => {
273
+ update: async (from, updateTypes) => {
264
274
  // Apply all state functions to get new options.
265
275
  const reducer = compose(Array.from(store.values()));
266
276
  const newOptions = reducer(options);
267
- return await update(newOptions, from);
277
+ return await update(newOptions, from, () => {
278
+ if (isArray(updateTypes)) {
279
+ updateInteractions(viewContainer, updateTypes, store);
280
+ }
281
+ });
268
282
  },
269
283
  };
270
284
  });
271
285
  };
272
286
 
287
+ const updateInteractions = (
288
+ container = updateContainer,
289
+ updateType?: string[],
290
+ oldStore?: Map<any, (options: G2ViewTree) => G2ViewTree>,
291
+ ) => {
292
+ // Interactions for update views.
293
+ const updateViewInstances = viewInstanceof(
294
+ container,
295
+ updateInteractions,
296
+ oldStore,
297
+ );
298
+
299
+ for (const target of updateViewInstances) {
300
+ const { options, container } = target;
301
+ const nameInteraction = container['nameInteraction'];
302
+ let typeOptions = inferInteraction(options);
303
+
304
+ if (updateType) {
305
+ typeOptions = typeOptions.filter((v) => updateType.includes(v[0]));
306
+ }
307
+
308
+ for (const typeOption of typeOptions) {
309
+ const [type, option] = typeOption;
310
+ // Remove interaction for existed views.
311
+ const prevInteraction = nameInteraction.get(type);
312
+ if (prevInteraction) prevInteraction.destroy?.();
313
+
314
+ // Apply new interaction.
315
+ if (option) {
316
+ const interaction = useThemeInteraction(
317
+ target.view,
318
+ type,
319
+ option as Record<string, any>,
320
+ useInteraction,
321
+ );
322
+ const destroy = interaction(
323
+ target,
324
+ updateViewInstances,
325
+ context.emitter,
326
+ );
327
+ nameInteraction.set(type, { destroy });
328
+ }
329
+ }
330
+ }
331
+ };
332
+
273
333
  // Interactions for enter views.
274
- const enterViewInstances = viewInstanceof(enterContainer);
334
+ const enterViewInstances = viewInstanceof(enterContainer, updateInteractions);
275
335
  for (const target of enterViewInstances) {
276
336
  const { options } = target;
277
337
 
@@ -299,35 +359,7 @@ export async function plot<T extends G2ViewTree>(
299
359
  }
300
360
  }
301
361
 
302
- // Interactions for update views.
303
- const updateViewInstances = viewInstanceof(updateContainer);
304
- for (const target of updateViewInstances) {
305
- const { options, container } = target;
306
- const nameInteraction = container['nameInteraction'];
307
- for (const typeOption of inferInteraction(options)) {
308
- const [type, option] = typeOption;
309
-
310
- // Remove interaction for existed views.
311
- const prevInteraction = nameInteraction.get(type);
312
- if (prevInteraction) prevInteraction.destroy?.();
313
-
314
- // Apply new interaction.
315
- if (option) {
316
- const interaction = useThemeInteraction(
317
- target.view,
318
- type,
319
- option as Record<string, any>,
320
- useInteraction,
321
- );
322
- const destroy = interaction(
323
- target,
324
- updateViewInstances,
325
- context.emitter,
326
- );
327
- nameInteraction.set(type, { destroy });
328
- }
329
- }
330
- }
362
+ updateInteractions();
331
363
 
332
364
  // Author animations.
333
365
  const { width, height } = options;
@@ -402,7 +434,7 @@ function createUpdateView(
402
434
  .filter(filter)
403
435
  .map((d) => d[0]);
404
436
 
405
- return async (newOptions, source) => {
437
+ return async (newOptions, source, callback) => {
406
438
  const transitions = [];
407
439
  const [newView, newChildren] = await initializeView(newOptions, library);
408
440
  plotView(newView, selection, transitions, library, context);
@@ -415,7 +447,7 @@ function createUpdateView(
415
447
  for (const child of newChildren) {
416
448
  plot(child, selection, library, context);
417
449
  }
418
-
450
+ callback();
419
451
  return { options: newOptions, view: newView };
420
452
  };
421
453
  }
@@ -710,7 +742,7 @@ function initializeState(
710
742
  processAxisZ(components);
711
743
 
712
744
  // Scale from marks and components.
713
- const scaleInstance = {};
745
+ const scaleInstance: Record<string, Scale> = {};
714
746
 
715
747
  // Initialize scale from components.
716
748
  for (const component of components) {
@@ -720,8 +752,17 @@ function initializeState(
720
752
  const { name } = descriptor;
721
753
  const scale = useRelationScale(descriptor, library);
722
754
  scales.push(scale);
755
+ // Delivery the scale of axisX to the AxisY,
756
+ // in order to calculate the angle of axisY component when rendering radar chart.
757
+ if (name === 'y') {
758
+ scale.update({
759
+ ...scale.getOptions(),
760
+ xScale: scaleInstance.x,
761
+ });
762
+ }
723
763
  assignScale(scaleInstance, { [name]: scale });
724
764
  }
765
+
725
766
  component.scaleInstances = scales;
726
767
  }
727
768
 
@@ -1653,8 +1694,15 @@ async function applyTransform<T extends G2ViewTree>(
1653
1694
 
1654
1695
  function updateBBox(selection: Selection) {
1655
1696
  selection
1656
- .style('x', (d) => d.paddingLeft + d.marginLeft)
1657
- .style('y', (d) => d.paddingTop + d.marginTop)
1697
+ .style(
1698
+ 'transform',
1699
+ (d) =>
1700
+ `translate(${d.paddingLeft + d.marginLeft}, ${
1701
+ d.paddingTop + d.marginTop
1702
+ })`,
1703
+ )
1704
+ // .style('x', (d) => d.paddingLeft + d.marginLeft)
1705
+ // .style('y', (d) => d.paddingTop + d.marginTop)
1658
1706
  .style('width', (d) => d.innerWidth)
1659
1707
  .style('height', (d) => d.innerHeight);
1660
1708
  }
@@ -1662,7 +1710,7 @@ function updateBBox(selection: Selection) {
1662
1710
  function animateBBox(selection: Selection, extent: [number, number]) {
1663
1711
  const [delay, duration] = extent;
1664
1712
  selection.transition(function (data, i, element) {
1665
- const { x, y, width, height } = element.style;
1713
+ const { transform, width, height } = element.style;
1666
1714
  const {
1667
1715
  paddingLeft,
1668
1716
  paddingTop,
@@ -1673,14 +1721,14 @@ function animateBBox(selection: Selection, extent: [number, number]) {
1673
1721
  } = data;
1674
1722
  const keyframes = [
1675
1723
  {
1676
- x,
1677
- y,
1724
+ transform,
1678
1725
  width,
1679
1726
  height,
1680
1727
  },
1681
1728
  {
1682
- x: paddingLeft + marginLeft,
1683
- y: paddingTop + marginTop,
1729
+ transform: `translate(${paddingLeft + marginLeft}, ${
1730
+ paddingTop + marginTop
1731
+ })`,
1684
1732
  width: innerWidth,
1685
1733
  height: innerHeight,
1686
1734
  },
@@ -53,7 +53,11 @@ export type G2ViewInstance = {
53
53
  view: G2ViewDescriptor;
54
54
  container: DisplayObject;
55
55
  options: G2ViewTree;
56
- update: (options: G2ViewTree, source?: string) => Promise<any>;
56
+ update: (
57
+ options: G2ViewTree,
58
+ source?: string | string[],
59
+ callback?: any,
60
+ ) => Promise<any>;
57
61
  };
58
62
 
59
63
  export type ChannelGroups = {
@@ -89,7 +89,7 @@ export const Connector: SC<ConnectorOptions> = (options, context) => {
89
89
 
90
90
  return select(new Path())
91
91
  .call(applyStyle, rest)
92
- .style('path', inferConnectorPath(P))
92
+ .style('d', inferConnectorPath(P))
93
93
  .style('stroke', color || defaultColor)
94
94
  .style('transform', transform)
95
95
  .style(
@@ -0,0 +1,57 @@
1
+ import { omit } from '@antv/util';
2
+ import type { Vector2, ShapeComponent as SC } from '../../runtime';
3
+
4
+ export type RoundOptions = Record<string, any>;
5
+
6
+ // Get point1 point2 radius.
7
+ const getR = (point1, point2) => {
8
+ return (
9
+ Math.sqrt(
10
+ Math.pow(point1[0] - point2[0], 2) + Math.pow(point1[1] - point2[1], 2),
11
+ ) / 2
12
+ );
13
+ };
14
+
15
+ // Gauge round.
16
+ export const Round: SC<RoundOptions> = (options, context) => {
17
+ if (!context) return;
18
+ const { coordinate } = context;
19
+ if (!coordinate?.getCenter) return;
20
+ // Get coordinate center point.
21
+ const center = coordinate.getCenter() as Vector2;
22
+
23
+ return (points, cfg, defaultCfg) => {
24
+ const { document } = context.canvas;
25
+ const { color, index } = cfg;
26
+
27
+ const g = document.createElement('g', {});
28
+
29
+ const minR = getR(points[0], points[1]);
30
+ const maxR = getR(points[0], center) * 2;
31
+
32
+ /**
33
+ * MinR small circle radius, maxR big circle radius.
34
+ * Draw four arcs.
35
+ * Style lineWidth and stroke for the time being inset.
36
+ */
37
+ const roundPath = document.createElement('path', {
38
+ style: {
39
+ d: [
40
+ ['M', ...points[0]],
41
+ ['A', minR, minR, 0, 1, 0, ...points[1]],
42
+ ['A', maxR + minR * 2, maxR + minR * 2, 0, 0, 0, ...points[2]],
43
+ ['A', minR, minR, 0, 1, index === 0 ? 0 : 1, ...points[3]],
44
+ ['A', maxR, maxR, 0, 0, 1, ...points[0]],
45
+ ['Z'],
46
+ ],
47
+ ...defaultCfg,
48
+ ...omit(options, ['shape', 'last', 'first']),
49
+ fill: color || defaultCfg.color,
50
+ },
51
+ });
52
+
53
+ g.appendChild(roundPath);
54
+
55
+ return g;
56
+ };
57
+ };
@@ -25,7 +25,7 @@ export const Image: SC<ImageOptions> = (options, context) => {
25
25
  .call(applyStyle, rest)
26
26
  .style('x', x)
27
27
  .style('y', y)
28
- .style('img', src)
28
+ .style('src', src)
29
29
  .style('stroke', color)
30
30
  .style('transform', transform)
31
31
  .call(applyStyle, options)
@@ -58,6 +58,7 @@ export { Rect as RectShape } from './interval/rect';
58
58
  export { Hollow as RectHollow } from './interval/hollow';
59
59
  export { Shape as ShapeShape } from './shape/shape';
60
60
  export { Liquid as LiquidShape } from './liquid/liquid';
61
+ export { Round as GaugeRound } from './gauge/round';
61
62
 
62
63
  export type { RectOptions as IntervalShapeOptions } from './interval/rect';
63
64
  export type { HollowOptions as IntervalHollowOptions } from './interval/hollow';
@@ -101,7 +101,7 @@ export function rect(
101
101
  .padAngle((inset * Math.PI) / 180);
102
102
 
103
103
  return select(document.createElement('path', {}))
104
- .style('path', path(arcObject))
104
+ .style('d', path(arcObject))
105
105
  .style('transform', `translate(${center[0]}, ${center[1]})`)
106
106
  .style('radius', radius)
107
107
  .style('inset', inset)
@@ -51,7 +51,7 @@ export const Funnel: SC<FunnelOptions> = (options, context) => {
51
51
  const b = line().curve(curveLinearClosed)([p0, p1, p2, p3]);
52
52
  return select(document.createElement('path', {}))
53
53
  .call(applyStyle, rest)
54
- .style('path', b)
54
+ .style('d', b)
55
55
  .style('fill', color)
56
56
  .style('fillOpacity', opacity)
57
57
  .call(applyStyle, style)
@@ -42,27 +42,27 @@ export function inferNonCircularStyle(
42
42
  };
43
43
  // 4 direction.
44
44
  if (position === 'left')
45
- return xy({ x: 0, y: h / 2, textAnchor: 'start', textBaseline: 'middle' });
45
+ return xy({ x: 0, y: h / 2, textAlign: 'start', textBaseline: 'middle' });
46
46
  if (position === 'right')
47
- return xy({ x: w, y: h / 2, textAnchor: 'end', textBaseline: 'middle' });
47
+ return xy({ x: w, y: h / 2, textAlign: 'end', textBaseline: 'middle' });
48
48
  if (position === 'top')
49
- return xy({ x: w / 2, y: 0, textAnchor: 'center', textBaseline: 'top' });
49
+ return xy({ x: w / 2, y: 0, textAlign: 'center', textBaseline: 'top' });
50
50
  if (position === 'bottom')
51
- return xy({ x: w / 2, y: h, textAnchor: 'center', textBaseline: 'bottom' });
51
+ return xy({ x: w / 2, y: h, textAlign: 'center', textBaseline: 'bottom' });
52
52
  // 4 corner position.
53
53
  if (position === 'top-left')
54
- return xy({ x: 0, y: 0, textAnchor: 'start', textBaseline: 'top' });
54
+ return xy({ x: 0, y: 0, textAlign: 'start', textBaseline: 'top' });
55
55
  if (position === 'top-right')
56
- return xy({ x: w, y: 0, textAnchor: 'end', textBaseline: 'top' });
56
+ return xy({ x: w, y: 0, textAlign: 'end', textBaseline: 'top' });
57
57
  if (position === 'bottom-left')
58
- return xy({ x: 0, y: h, textAnchor: 'start', textBaseline: 'bottom' });
58
+ return xy({ x: 0, y: h, textAlign: 'start', textBaseline: 'bottom' });
59
59
  if (position === 'bottom-right')
60
- return xy({ x: w, y: h, textAnchor: 'end', textBaseline: 'bottom' });
60
+ return xy({ x: w, y: h, textAlign: 'end', textBaseline: 'bottom' });
61
61
  // default return 'inside'
62
62
  return xy({
63
63
  x: w / 2,
64
64
  y: h / 2,
65
- textAnchor: 'center',
65
+ textAlign: 'center',
66
66
  textBaseline: 'middle',
67
67
  });
68
68
  }
@@ -38,8 +38,7 @@ function getArrowMarker(
38
38
  ) {
39
39
  const arrowMarker = document.createElement('path', {
40
40
  style: {
41
- path: `M ${arrowSize},${arrowSize} L -${arrowSize},0 L ${arrowSize},-${arrowSize} L 0,0 Z`,
42
- anchor: '0.5 0.5',
41
+ d: `M ${arrowSize},${arrowSize} L -${arrowSize},0 L ${arrowSize},-${arrowSize} L 0,0 Z`,
43
42
  transformOrigin: 'center',
44
43
  ...arrowStyle,
45
44
  },
@@ -46,7 +46,7 @@ export const Liquid: SC<LiquidOptions> = (options, context) => {
46
46
  if (Object.keys(backgroundStyle).length) {
47
47
  const backgroundShape = document.createElement('path', {
48
48
  style: {
49
- path: shapePath,
49
+ d: shapePath,
50
50
  fill: '#fff',
51
51
  ...backgroundStyle,
52
52
  },
@@ -60,7 +60,7 @@ export const Liquid: SC<LiquidOptions> = (options, context) => {
60
60
  // 3. Clip create.
61
61
  const clipShape = document.createElement('path', {
62
62
  style: {
63
- path: shapePath,
63
+ d: shapePath,
64
64
  },
65
65
  });
66
66
 
@@ -86,7 +86,7 @@ export const Liquid: SC<LiquidOptions> = (options, context) => {
86
86
  // 5. Draw distance.
87
87
  const distanceShape = document.createElement('path', {
88
88
  style: {
89
- path: shapePath,
89
+ d: shapePath,
90
90
  fill: 'transparent',
91
91
  lineWidth: border + 2 * distance,
92
92
  stroke: '#fff',
@@ -96,7 +96,7 @@ export const Liquid: SC<LiquidOptions> = (options, context) => {
96
96
  // 6. Draw border.
97
97
  const borderShape = document.createElement('path', {
98
98
  style: {
99
- path: shapePath,
99
+ d: shapePath,
100
100
  stroke: color,
101
101
  strokeOpacity: fillOpacity,
102
102
  lineWidth: border,
@@ -214,7 +214,7 @@ export function addWave(
214
214
  // Create wave path.
215
215
  const wave = document.createElement('path', {
216
216
  style: {
217
- path,
217
+ d: path,
218
218
  fill,
219
219
  opacity: lerp(0.2, 0.9, factor) * Number(opacity || fillOpacity),
220
220
  },
@@ -51,6 +51,7 @@ export const Color: SC<ColorOptions> = (options, context) => {
51
51
  .style('d', path(cx, cy, finalRadius))
52
52
  .style('lineWidth', finalLineWidth)
53
53
  .style('transform', transform)
54
+ .style('transformOrigin', `${cx - finalRadius} ${cy - finalRadius}`)
54
55
  .style('stroke', color)
55
56
  .style(toOpacityKey(options), opacity)
56
57
  .style(colorAttribute, color)
@@ -151,6 +151,8 @@ export const Advance = createElement((g) => {
151
151
  ...rest
152
152
  } = g.attributes as TextShapeStyleProps;
153
153
 
154
+ g.style.transform = `translate(${x}, ${y})`;
155
+
154
156
  // Position is invalid, do not render the UI,
155
157
  // or clear previous elements.
156
158
  if ([x, y, x0, y0].some((v) => !isNumber(v))) {
@@ -220,7 +222,7 @@ export const Advance = createElement((g) => {
220
222
  select(g)
221
223
  .maybeAppend('connector', 'path')
222
224
  .style('zIndex', 0)
223
- .style('path', connectorPath)
225
+ .style('d', connectorPath)
224
226
  .style('markerStart', markerStart)
225
227
  .style('markerEnd', markerEnd)
226
228
  .call(applyStyle, connector ? connectorStyle : {});
@@ -1,6 +1,6 @@
1
1
  import { Coordinate } from '@antv/coord';
2
2
  import { Linear } from '@antv/scale';
3
- import { lowerFirst } from '@antv/util';
3
+ import { isNumber, lowerFirst } from '@antv/util';
4
4
  import { extent } from 'd3-array';
5
5
  import { Path as D3Path } from 'd3-path';
6
6
  import { Primitive, Vector2, Vector3 } from '../runtime';
@@ -148,7 +148,8 @@ export function computeGradient(
148
148
  range: [0, 100],
149
149
  });
150
150
 
151
- const percentage = (i) => p.map(P[i]);
151
+ const percentage = (i) =>
152
+ isNumber(P[i]) && !Number.isNaN(P[i]) ? p.map(P[i]) : 0;
152
153
 
153
154
  const gradientMode = {
154
155
  // Interpolate the colors for this segment.
@@ -139,7 +139,7 @@ export function create({
139
139
  text: {
140
140
  fill: '#1D2129',
141
141
  fontSize: 12,
142
- strokeWidth: 0,
142
+ lineWidth: 0,
143
143
  connectorStroke: colorStroke,
144
144
  connectorStrokeOpacity: 0.45,
145
145
  connectorLineWidth: 1,
@@ -154,7 +154,7 @@ export function create({
154
154
  badge: {
155
155
  fill: '#1D2129',
156
156
  fillOpacity: 0.65,
157
- strokeWidth: 0,
157
+ lineWidth: 0,
158
158
  fontSize: 10,
159
159
  textAlign: 'center',
160
160
  textBaseline: 'middle',
@@ -5,3 +5,25 @@ export function toRadian(degree: number): number {
5
5
  export function toDegree(radian: number): number {
6
6
  return (radian * 180) / Math.PI;
7
7
  }
8
+
9
+ // convert the angle to the range of 0 to 4*Math.PI
10
+ export function convertAngles(startAngle: number, endAngle: number) {
11
+ startAngle = startAngle % (2 * Math.PI);
12
+ endAngle = endAngle % (2 * Math.PI);
13
+
14
+ if (startAngle < 0) {
15
+ startAngle = 2 * Math.PI + startAngle;
16
+ }
17
+ if (endAngle < 0) {
18
+ endAngle = 2 * Math.PI + endAngle;
19
+ }
20
+
21
+ if (startAngle >= endAngle) {
22
+ endAngle = endAngle + 2 * Math.PI;
23
+ }
24
+
25
+ return {
26
+ startAngle,
27
+ endAngle,
28
+ };
29
+ }
@@ -255,23 +255,14 @@ export const Symbols = new Map<string, SymbolFactor>([
255
255
 
256
256
  export function useMarker(
257
257
  type: string,
258
- {
259
- d,
260
- fill,
261
- strokeWidth,
262
- path,
263
- stroke,
264
- lineWidth,
265
- color,
266
- ...style
267
- }: Record<string, any>,
258
+ { d, fill, lineWidth, path, stroke, color, ...style }: Record<string, any>,
268
259
  ) {
269
260
  const symbol = Symbols.get(type) || Symbols.get('point');
270
261
  return (...args: Parameters<SymbolFactor>) => {
271
262
  const path = new Path({
272
263
  style: {
273
264
  ...style,
274
- path: symbol(...args),
265
+ d: symbol(...args),
275
266
  stroke: symbol.style.includes('stroke') ? color || stroke : '',
276
267
  fill: symbol.style.includes('fill') ? color || fill : '',
277
268
  lineWidth: symbol.style.includes('lineWidth')