@antv/g2 5.1.16 → 5.1.18

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 (222) 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 +4 -2
  4. package/esm/animation/growInX.js.map +1 -1
  5. package/esm/animation/growInY.js +4 -2
  6. package/esm/animation/growInY.js.map +1 -1
  7. package/esm/animation/morphing.js +35 -18
  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/utils.d.ts +10 -1
  12. package/esm/animation/utils.js +29 -3
  13. package/esm/animation/utils.js.map +1 -1
  14. package/esm/animation/waveIn.js +3 -14
  15. package/esm/animation/waveIn.js.map +1 -1
  16. package/esm/component/title.js +2 -1
  17. package/esm/component/title.js.map +1 -1
  18. package/esm/exports.js +0 -2
  19. package/esm/exports.js.map +1 -1
  20. package/esm/index.d.ts +2 -0
  21. package/esm/interaction/brushAxisHighlight.js +3 -3
  22. package/esm/interaction/brushAxisHighlight.js.map +1 -1
  23. package/esm/interaction/brushHighlight.js +4 -5
  24. package/esm/interaction/brushHighlight.js.map +1 -1
  25. package/esm/interaction/elementPointMove.d.ts +9 -0
  26. package/esm/interaction/elementPointMove.js +506 -0
  27. package/esm/interaction/elementPointMove.js.map +1 -0
  28. package/esm/interaction/event.js +1 -8
  29. package/esm/interaction/event.js.map +1 -1
  30. package/esm/interaction/index.d.ts +1 -0
  31. package/esm/interaction/index.js +1 -0
  32. package/esm/interaction/index.js.map +1 -1
  33. package/esm/interaction/tooltip.js +15 -5
  34. package/esm/interaction/tooltip.js.map +1 -1
  35. package/esm/interaction/treemapDrillDown.js +1 -4
  36. package/esm/interaction/treemapDrillDown.js.map +1 -1
  37. package/esm/interaction/utils.d.ts +8 -2
  38. package/esm/interaction/utils.js +51 -8
  39. package/esm/interaction/utils.js.map +1 -1
  40. package/esm/lib/core.d.ts +2 -1
  41. package/esm/lib/core.js +2 -1
  42. package/esm/lib/core.js.map +1 -1
  43. package/esm/lib/std.d.ts +1 -0
  44. package/esm/mark/chord.js +0 -1
  45. package/esm/mark/chord.js.map +1 -1
  46. package/esm/mark/point.js +3 -1
  47. package/esm/mark/point.js.map +1 -1
  48. package/esm/mark/sankey.js +1 -1
  49. package/esm/mark/sankey.js.map +1 -1
  50. package/esm/runtime/plot.js +4 -7
  51. package/esm/runtime/plot.js.map +1 -1
  52. package/esm/shape/connector/connector.js +1 -1
  53. package/esm/shape/connector/connector.js.map +1 -1
  54. package/esm/shape/gauge/round.js +1 -1
  55. package/esm/shape/gauge/round.js.map +1 -1
  56. package/esm/shape/image/image.js +1 -1
  57. package/esm/shape/index.d.ts +2 -0
  58. package/esm/shape/index.js +2 -0
  59. package/esm/shape/index.js.map +1 -1
  60. package/esm/shape/interval/color.js +1 -1
  61. package/esm/shape/interval/color.js.map +1 -1
  62. package/esm/shape/interval/funnel.js +1 -1
  63. package/esm/shape/interval/funnel.js.map +1 -1
  64. package/esm/shape/label/position/default.js +9 -9
  65. package/esm/shape/label/position/default.js.map +1 -1
  66. package/esm/shape/lineXY/line.js +1 -1
  67. package/esm/shape/lineXY/line.js.map +1 -1
  68. package/esm/shape/liquid/liquid.js +4 -4
  69. package/esm/shape/liquid/liquid.js.map +1 -1
  70. package/esm/shape/liquid/wave.js +2 -2
  71. package/esm/shape/liquid/wave.js.map +1 -1
  72. package/esm/shape/point/circle.d.ts +16 -0
  73. package/esm/shape/point/circle.js +56 -0
  74. package/esm/shape/point/circle.js.map +1 -0
  75. package/esm/shape/point/color.d.ts +2 -0
  76. package/esm/shape/point/color.js +2 -1
  77. package/esm/shape/point/color.js.map +1 -1
  78. package/esm/shape/point/hollowCircle.d.ts +6 -0
  79. package/esm/shape/point/hollowCircle.js +9 -0
  80. package/esm/shape/point/hollowCircle.js.map +1 -0
  81. package/esm/shape/text/advance.js +2 -1
  82. package/esm/shape/text/advance.js.map +1 -1
  83. package/esm/shape/text/badge.js +2 -3
  84. package/esm/shape/text/badge.js.map +1 -1
  85. package/esm/theme/create.d.ts +4 -2
  86. package/esm/theme/create.js +4 -2
  87. package/esm/theme/create.js.map +1 -1
  88. package/esm/utils/helper.js +1 -8
  89. package/esm/utils/helper.js.map +1 -1
  90. package/esm/utils/marker.d.ts +1 -1
  91. package/esm/utils/marker.js +2 -2
  92. package/esm/utils/marker.js.map +1 -1
  93. package/lib/animation/growInX.js +4 -2
  94. package/lib/animation/growInX.js.map +1 -1
  95. package/lib/animation/growInY.js +4 -2
  96. package/lib/animation/growInY.js.map +1 -1
  97. package/lib/animation/morphing.js +33 -16
  98. package/lib/animation/morphing.js.map +1 -1
  99. package/lib/animation/scaleInY.js +2 -5
  100. package/lib/animation/scaleInY.js.map +1 -1
  101. package/lib/animation/utils.d.ts +10 -1
  102. package/lib/animation/utils.js +30 -4
  103. package/lib/animation/utils.js.map +1 -1
  104. package/lib/animation/waveIn.js +2 -13
  105. package/lib/animation/waveIn.js.map +1 -1
  106. package/lib/component/title.js +2 -1
  107. package/lib/component/title.js.map +1 -1
  108. package/lib/exports.js +0 -2
  109. package/lib/exports.js.map +1 -1
  110. package/lib/index.d.ts +2 -0
  111. package/lib/interaction/brushAxisHighlight.js +3 -3
  112. package/lib/interaction/brushAxisHighlight.js.map +1 -1
  113. package/lib/interaction/brushHighlight.js +4 -5
  114. package/lib/interaction/brushHighlight.js.map +1 -1
  115. package/lib/interaction/elementPointMove.d.ts +9 -0
  116. package/lib/interaction/elementPointMove.js +510 -0
  117. package/lib/interaction/elementPointMove.js.map +1 -0
  118. package/lib/interaction/event.js +4 -11
  119. package/lib/interaction/event.js.map +1 -1
  120. package/lib/interaction/index.d.ts +1 -0
  121. package/lib/interaction/index.js +3 -1
  122. package/lib/interaction/index.js.map +1 -1
  123. package/lib/interaction/tooltip.js +14 -4
  124. package/lib/interaction/tooltip.js.map +1 -1
  125. package/lib/interaction/treemapDrillDown.js +2 -5
  126. package/lib/interaction/treemapDrillDown.js.map +1 -1
  127. package/lib/interaction/utils.d.ts +8 -2
  128. package/lib/interaction/utils.js +56 -8
  129. package/lib/interaction/utils.js.map +1 -1
  130. package/lib/lib/core.d.ts +2 -1
  131. package/lib/lib/core.js +1 -0
  132. package/lib/lib/core.js.map +1 -1
  133. package/lib/lib/std.d.ts +1 -0
  134. package/lib/mark/chord.js +0 -1
  135. package/lib/mark/chord.js.map +1 -1
  136. package/lib/mark/point.js +2 -0
  137. package/lib/mark/point.js.map +1 -1
  138. package/lib/mark/sankey.js +1 -1
  139. package/lib/mark/sankey.js.map +1 -1
  140. package/lib/runtime/plot.js +4 -7
  141. package/lib/runtime/plot.js.map +1 -1
  142. package/lib/shape/connector/connector.js +1 -1
  143. package/lib/shape/connector/connector.js.map +1 -1
  144. package/lib/shape/gauge/round.js +1 -1
  145. package/lib/shape/gauge/round.js.map +1 -1
  146. package/lib/shape/image/image.js +1 -1
  147. package/lib/shape/index.d.ts +2 -0
  148. package/lib/shape/index.js +6 -2
  149. package/lib/shape/index.js.map +1 -1
  150. package/lib/shape/interval/color.js +1 -1
  151. package/lib/shape/interval/color.js.map +1 -1
  152. package/lib/shape/interval/funnel.js +1 -1
  153. package/lib/shape/interval/funnel.js.map +1 -1
  154. package/lib/shape/label/position/default.js +9 -9
  155. package/lib/shape/label/position/default.js.map +1 -1
  156. package/lib/shape/lineXY/line.js +1 -1
  157. package/lib/shape/lineXY/line.js.map +1 -1
  158. package/lib/shape/liquid/liquid.js +4 -4
  159. package/lib/shape/liquid/liquid.js.map +1 -1
  160. package/lib/shape/liquid/wave.js +2 -2
  161. package/lib/shape/liquid/wave.js.map +1 -1
  162. package/lib/shape/point/circle.d.ts +16 -0
  163. package/lib/shape/point/circle.js +61 -0
  164. package/lib/shape/point/circle.js.map +1 -0
  165. package/lib/shape/point/color.d.ts +2 -0
  166. package/lib/shape/point/color.js +3 -1
  167. package/lib/shape/point/color.js.map +1 -1
  168. package/lib/shape/point/hollowCircle.d.ts +6 -0
  169. package/lib/shape/point/hollowCircle.js +13 -0
  170. package/lib/shape/point/hollowCircle.js.map +1 -0
  171. package/lib/shape/text/advance.js +2 -1
  172. package/lib/shape/text/advance.js.map +1 -1
  173. package/lib/shape/text/badge.js +2 -3
  174. package/lib/shape/text/badge.js.map +1 -1
  175. package/lib/theme/create.d.ts +4 -2
  176. package/lib/theme/create.js +4 -2
  177. package/lib/theme/create.js.map +1 -1
  178. package/lib/utils/helper.js +1 -8
  179. package/lib/utils/helper.js.map +1 -1
  180. package/lib/utils/marker.d.ts +1 -1
  181. package/lib/utils/marker.js +2 -2
  182. package/lib/utils/marker.js.map +1 -1
  183. package/package.json +12 -13
  184. package/src/animation/growInX.ts +9 -2
  185. package/src/animation/growInY.ts +9 -2
  186. package/src/animation/morphing.ts +36 -24
  187. package/src/animation/scaleInY.ts +2 -5
  188. package/src/animation/utils.ts +34 -4
  189. package/src/animation/waveIn.ts +3 -20
  190. package/src/component/title.ts +4 -0
  191. package/src/exports.ts +0 -4
  192. package/src/interaction/brushAxisHighlight.ts +5 -4
  193. package/src/interaction/brushHighlight.ts +8 -5
  194. package/src/interaction/elementPointMove.ts +659 -0
  195. package/src/interaction/event.ts +1 -7
  196. package/src/interaction/index.ts +1 -0
  197. package/src/interaction/tooltip.ts +15 -4
  198. package/src/interaction/treemapDrillDown.ts +1 -5
  199. package/src/interaction/utils.ts +71 -7
  200. package/src/lib/core.ts +2 -0
  201. package/src/mark/chord.ts +0 -1
  202. package/src/mark/point.ts +4 -0
  203. package/src/mark/sankey.ts +1 -1
  204. package/src/runtime/plot.ts +12 -7
  205. package/src/shape/connector/connector.ts +1 -1
  206. package/src/shape/gauge/round.ts +1 -1
  207. package/src/shape/image/image.ts +1 -1
  208. package/src/shape/index.ts +2 -0
  209. package/src/shape/interval/color.ts +1 -1
  210. package/src/shape/interval/funnel.ts +1 -1
  211. package/src/shape/label/position/default.ts +9 -9
  212. package/src/shape/lineXY/line.ts +1 -2
  213. package/src/shape/liquid/liquid.ts +4 -4
  214. package/src/shape/liquid/wave.ts +2 -2
  215. package/src/shape/point/circle.ts +57 -0
  216. package/src/shape/point/color.ts +2 -1
  217. package/src/shape/point/hollowCircle.ts +16 -0
  218. package/src/shape/text/advance.ts +3 -1
  219. package/src/shape/text/badge.ts +2 -3
  220. package/src/theme/create.ts +4 -2
  221. package/src/utils/helper.ts +1 -7
  222. package/src/utils/marker.ts +2 -11
@@ -17,6 +17,7 @@ import {
17
17
  createDatumof,
18
18
  selectElementByData,
19
19
  bboxOf,
20
+ maybeRoot,
20
21
  } from './utils';
21
22
  import { dataOf } from './event';
22
23
 
@@ -381,7 +382,7 @@ function updateMarker(root, { data, style, theme }) {
381
382
  fill,
382
383
  r: 4,
383
384
  stroke: '#fff',
384
- strokeWidth: 2,
385
+ lineWidth: 2,
385
386
  ...style,
386
387
  },
387
388
  });
@@ -422,6 +423,13 @@ function hasSeries(markState): boolean {
422
423
  );
423
424
  }
424
425
 
426
+ function findElement(node: DisplayObject) {
427
+ return maybeRoot(node, (node) => {
428
+ if (!node.classList) return false;
429
+ return node.classList.includes('element');
430
+ });
431
+ }
432
+
425
433
  /**
426
434
  * Show tooltip for series item.
427
435
  */
@@ -798,18 +806,21 @@ export function tooltip(
798
806
  }: Record<string, any>,
799
807
  ) {
800
808
  const elements = elementsof(root);
801
- const elementSet = new Set(elements);
802
809
  const keyGroup = group(elements, groupKey);
803
810
 
804
811
  const pointermove = throttle(
805
812
  (event) => {
806
- const { target: element } = event;
807
- if (!elementSet.has(element)) {
813
+ const { target } = event;
814
+ const element = findElement(target);
815
+ if (!element) {
808
816
  hideTooltip({ root, single, emitter, event });
809
817
  return;
810
818
  }
811
819
  const k = groupKey(element);
812
820
  const group = keyGroup.get(k);
821
+ if (!group) {
822
+ return;
823
+ }
813
824
  const data =
814
825
  group.length === 1 && !shared
815
826
  ? singleItem(group[0])
@@ -7,11 +7,7 @@ import { PLOT_CLASS_NAME } from '../runtime';
7
7
  import { select } from '../utils/selection';
8
8
  import { treeDataTransform } from '../utils/treeDataTransform';
9
9
  import { legendClearSetState } from './legendFilter';
10
-
11
- // Get element.
12
- const getElements = (plot) => {
13
- return plot.querySelectorAll('.element');
14
- };
10
+ import { getElements } from './utils';
15
11
 
16
12
  function selectPlotArea(root: DisplayObject): DisplayObject {
17
13
  return select(root).select(`.${PLOT_CLASS_NAME}`).node();
@@ -1,7 +1,9 @@
1
- import { DisplayObject, Path } from '@antv/g';
1
+ import { DisplayObject, Path, AABB } from '@antv/g';
2
2
  import { path as d3Path } from 'd3-path';
3
3
  import { sort } from 'd3-array';
4
4
  import { Vector2 } from '@antv/coord';
5
+ import { filter } from '@antv/util';
6
+ import type { PathArray } from '@antv/util';
5
7
  import { G2Element, select } from '../utils/selection';
6
8
  import { mapObject } from '../utils/array';
7
9
  import {
@@ -42,10 +44,15 @@ export function selectPlotArea(root: DisplayObject): DisplayObject {
42
44
  return select(root).select(`.${PLOT_CLASS_NAME}`).node();
43
45
  }
44
46
 
45
- export function bboxOf(node) {
46
- if (node.nodeName !== 'rect') return node.getRenderBounds();
47
- const { x, y, width, height } = node.style;
48
- return { min: [x, y], max: [x + width, y + height] };
47
+ export function bboxOf(element: DisplayObject) {
48
+ // The geometry bounds of a group is empty, so return the render bounds.
49
+ if (element.tagName === 'g') return element.getRenderBounds();
50
+
51
+ // Compute the geometry bounds related to the parent.
52
+ const bounds = element.getGeometryBounds();
53
+ const aabb = new AABB();
54
+ aabb.setFromTransformedAABB(bounds, element.getWorldTransform());
55
+ return aabb;
49
56
  }
50
57
 
51
58
  export function mousePosition(target, event) {
@@ -419,7 +426,7 @@ export function renderBackground({
419
426
  fillOpacity = 0.3,
420
427
  zIndex = -2,
421
428
  padding = 0.001,
422
- strokeWidth = 0,
429
+ lineWidth = 0,
423
430
  ...style
424
431
  } = mapObject(rest, (d) => valueof(d, element));
425
432
  const finalStyle = {
@@ -428,7 +435,7 @@ export function renderBackground({
428
435
  fillOpacity,
429
436
  zIndex,
430
437
  padding,
431
- strokeWidth,
438
+ lineWidth,
432
439
  };
433
440
  const shapeOf = isOrdinalShape() ? bandShapeOf : cloneShapeOf;
434
441
  const shape = shapeOf(element, finalStyle);
@@ -468,3 +475,60 @@ export function selectElementByData(elements, data, datum) {
468
475
  Object.entries(data).every(([key, value]) => datum(d)[key] === value),
469
476
  );
470
477
  }
478
+
479
+ export function getPointsR(point: number[], nextPoint: number[]) {
480
+ return Math.sqrt(
481
+ Math.pow(point[0] - nextPoint[0], 2) + Math.pow(point[1] - nextPoint[1], 2),
482
+ );
483
+ }
484
+
485
+ // Points create path.
486
+ export function getPointsPath(points: number[][], isClose = false) {
487
+ const path = filter(points, (d) => !!d).map((d, i) => {
488
+ return [i === 0 ? 'M' : 'L', ...d];
489
+ }) as PathArray;
490
+
491
+ if (isClose) {
492
+ path.push(['Z']);
493
+ }
494
+ return path;
495
+ }
496
+
497
+ // Get element.
498
+ export function getElements(plot) {
499
+ return plot.querySelectorAll('.element');
500
+ }
501
+
502
+ // Get Theta coordinate round path.
503
+ export function getThetaPath(
504
+ center: number[],
505
+ points: number[][],
506
+ isBig = 0,
507
+ ): PathArray {
508
+ const path = [['M', ...points[1]]];
509
+ const innerRadius = getPointsR(center, points[1]);
510
+ const outerRadius = getPointsR(center, points[0]);
511
+
512
+ if (innerRadius === 0) {
513
+ path.push(
514
+ ['L', ...points[3]],
515
+ ['A', outerRadius, outerRadius, 0, isBig, 1, ...points[0]],
516
+ ['Z'],
517
+ );
518
+ } else {
519
+ path.push(
520
+ ['A', innerRadius, innerRadius, 0, isBig, 0, ...points[2]],
521
+ ['L', ...points[3]],
522
+ ['A', outerRadius, outerRadius, 0, isBig, 1, ...points[0]],
523
+ ['Z'],
524
+ );
525
+ }
526
+ return path as PathArray;
527
+ }
528
+
529
+ export function maybeRoot(node, rootOf) {
530
+ if (rootOf(node)) return node;
531
+ let root = node.parent;
532
+ while (root && !rootOf(root)) root = root.parent;
533
+ return root;
534
+ }
package/src/lib/core.ts CHANGED
@@ -101,6 +101,7 @@ import {
101
101
  Poptip,
102
102
  ScrollbarFilter,
103
103
  TreemapDrillDown,
104
+ ElementPointMove,
104
105
  } from '../interaction';
105
106
  import {
106
107
  SpaceLayer,
@@ -301,6 +302,7 @@ export function corelib() {
301
302
  'interaction.scrollbarFilter': ScrollbarFilter,
302
303
  'interaction.poptip': Poptip,
303
304
  'interaction.treemapDrillDown': TreemapDrillDown,
305
+ 'interaction.elementPointMove': ElementPointMove,
304
306
  'composition.spaceLayer': SpaceLayer,
305
307
  'composition.spaceFlex': SpaceFlex,
306
308
  'composition.facetRect': FacetRect,
package/src/mark/chord.ts CHANGED
@@ -51,7 +51,6 @@ const DEFAULT_LINK_OPTIONS = {
51
51
  style: {
52
52
  opacity: 0.5,
53
53
  lineWidth: 1,
54
- strokeWidth: 1,
55
54
  },
56
55
  };
57
56
 
package/src/mark/point.ts CHANGED
@@ -20,6 +20,8 @@ import {
20
20
  PointShape,
21
21
  PointTick,
22
22
  PointTriangle,
23
+ PointCircle,
24
+ PointHollowCircle,
23
25
  } from '../shape';
24
26
  import { MaybeZeroX, MaybeZeroY, MaybeSize } from '../transform';
25
27
  import {
@@ -38,6 +40,7 @@ const shape = {
38
40
  hollowTriangleDown: PointHollowTriangleDown,
39
41
  hollowTriangle: PointHollowTriangle,
40
42
  hollowBowtie: PointHollowBowtie,
43
+ hollowCircle: PointHollowCircle,
41
44
  point: PointShape,
42
45
  plus: PointPlus,
43
46
  diamond: PointDiamond,
@@ -50,6 +53,7 @@ const shape = {
50
53
  line: PointLine,
51
54
  tick: PointTick,
52
55
  triangleDown: PointTriangleDown,
56
+ circle: PointCircle,
53
57
  };
54
58
 
55
59
  export type PointOptions = Omit<PointMark, 'type'>;
@@ -136,7 +136,7 @@ export const Sankey: CC<SankeyOptions> = (options) => {
136
136
  labels: linkLabels,
137
137
  style: {
138
138
  fill: linkEncode.color ? undefined : '#aaa',
139
- strokeWidth: 0,
139
+ lineWidth: 0,
140
140
  ...subObject(style, 'link'),
141
141
  },
142
142
  tooltip: linkTooltip,
@@ -1694,8 +1694,13 @@ async function applyTransform<T extends G2ViewTree>(
1694
1694
 
1695
1695
  function updateBBox(selection: Selection) {
1696
1696
  selection
1697
- .style('x', (d) => d.paddingLeft + d.marginLeft)
1698
- .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
+ )
1699
1704
  .style('width', (d) => d.innerWidth)
1700
1705
  .style('height', (d) => d.innerHeight);
1701
1706
  }
@@ -1703,7 +1708,7 @@ function updateBBox(selection: Selection) {
1703
1708
  function animateBBox(selection: Selection, extent: [number, number]) {
1704
1709
  const [delay, duration] = extent;
1705
1710
  selection.transition(function (data, i, element) {
1706
- const { x, y, width, height } = element.style;
1711
+ const { transform, width, height } = element.style;
1707
1712
  const {
1708
1713
  paddingLeft,
1709
1714
  paddingTop,
@@ -1714,14 +1719,14 @@ function animateBBox(selection: Selection, extent: [number, number]) {
1714
1719
  } = data;
1715
1720
  const keyframes = [
1716
1721
  {
1717
- x,
1718
- y,
1722
+ transform,
1719
1723
  width,
1720
1724
  height,
1721
1725
  },
1722
1726
  {
1723
- x: paddingLeft + marginLeft,
1724
- y: paddingTop + marginTop,
1727
+ transform: `translate(${paddingLeft + marginLeft}, ${
1728
+ paddingTop + marginTop
1729
+ })`,
1725
1730
  width: innerWidth,
1726
1731
  height: innerHeight,
1727
1732
  },
@@ -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(
@@ -36,7 +36,7 @@ export const Round: SC<RoundOptions> = (options, context) => {
36
36
  */
37
37
  const roundPath = document.createElement('path', {
38
38
  style: {
39
- path: [
39
+ d: [
40
40
  ['M', ...points[0]],
41
41
  ['A', minR, minR, 0, 1, 0, ...points[1]],
42
42
  ['A', maxR + minR * 2, maxR + minR * 2, 0, 0, 0, ...points[2]],
@@ -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)
@@ -17,6 +17,7 @@ export { HollowPoint as PointHollow } from './point/hollow';
17
17
  export { HollowSquare as PointHollowSquare } from './point/hollowSquare';
18
18
  export { HollowTriangle as PointHollowTriangle } from './point/hollowTriangle';
19
19
  export { HollowTriangleDown as PointHollowTriangleDown } from './point/hollowTriangleDown';
20
+ export { HollowCircle as PointHollowCircle } from './point/hollowCircle';
20
21
  export { Bowtie as PointBowtie } from './point/bowtie';
21
22
  export { Cross as PointCross } from './point/cross';
22
23
  export { Diamond as PointDiamond } from './point/diamond';
@@ -29,6 +30,7 @@ export { Square as PointSquare } from './point/square';
29
30
  export { Tick as PointTick } from './point/tick';
30
31
  export { Triangle as PointTriangle } from './point/triangle';
31
32
  export { TriangleDown as PointTriangleDown } from './point/triangleDown';
33
+ export { Circle as PointCircle } from './point/circle';
32
34
  export { Vector as VectorShape } from './vector/vector';
33
35
  export { Text as TextShape } from './text/text';
34
36
  export { Badge as TextBadge } from './text/badge';
@@ -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
  },
@@ -230,7 +230,7 @@ export function addWave(
230
230
  transform: 'translate(0, 0)',
231
231
  },
232
232
  {
233
- transform: `translate(${waveLength * 2}px, 0)`,
233
+ transform: `translate(${waveLength * 2}, 0)`,
234
234
  },
235
235
  ];
236
236
 
@@ -0,0 +1,57 @@
1
+ import { ShapeComponent as SC } from '../../runtime';
2
+ import { select } from '../../utils/selection';
3
+ import { applyStyle, getOrigin, toOpacityKey } from '../utils';
4
+ import { getRadius } from './color';
5
+
6
+ export type PointOptions = Record<string, any>;
7
+
8
+ type ColorOptions = {
9
+ colorAttribute: 'fill' | 'stroke';
10
+ mode?: 'fixed' | 'auto' | 'normal';
11
+ [key: string]: any;
12
+ };
13
+
14
+ /**
15
+ * Render point in different coordinate.
16
+ */
17
+ export const BaseCircle: SC<ColorOptions> = (options, context) => {
18
+ // Render border only when colorAttribute is stroke.
19
+ const { colorAttribute, mode = 'auto', ...style } = options;
20
+
21
+ const { coordinate, document } = context;
22
+ return (points, value, defaults) => {
23
+ const { lineWidth, color: defaultColor } = defaults;
24
+ const finalLineWidth = style.stroke ? lineWidth || 1 : lineWidth;
25
+ const { color = defaultColor, transform, opacity } = value;
26
+ const [cx, cy] = getOrigin(points);
27
+ const r = getRadius(mode, points, value, coordinate);
28
+ const finalRadius = r || style.r || defaults.r;
29
+ return select(document.createElement('circle', {}))
30
+ .call(applyStyle, defaults)
31
+ .style('fill', 'transparent')
32
+ .style('cx', cx)
33
+ .style('cy', cy)
34
+ .style('r', finalRadius)
35
+ .style('lineWidth', finalLineWidth)
36
+ .style('transform', transform)
37
+ .style('transformOrigin', `${cx} ${cy}`)
38
+ .style('stroke', color)
39
+ .style(toOpacityKey(options), opacity)
40
+ .style(colorAttribute, color)
41
+ .call(applyStyle, style)
42
+ .node();
43
+ };
44
+ };
45
+
46
+ /**
47
+ * ●
48
+ */
49
+ export const Circle: SC<PointOptions> = (options, context) => {
50
+ return BaseCircle({ colorAttribute: 'fill', ...options }, context);
51
+ };
52
+
53
+ Circle.props = {
54
+ defaultMarker: 'circle',
55
+ defaultEnterAnimation: 'fadeIn',
56
+ defaultExitAnimation: 'fadeOut',
57
+ };
@@ -12,7 +12,7 @@ export type ColorOptions = {
12
12
  [key: string]: any;
13
13
  };
14
14
 
15
- function getRadius(
15
+ export function getRadius(
16
16
  mode: ColorOptions['mode'],
17
17
  points: Vector2[],
18
18
  value: Record<string, any>,
@@ -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)
@@ -0,0 +1,16 @@
1
+ import { ShapeComponent as SC } from '../../runtime';
2
+ import { BaseCircle, Circle } from './circle';
3
+
4
+ export type HollowCircleOptions = Record<string, any>;
5
+
6
+ /**
7
+ * ○
8
+ */
9
+ export const HollowCircle: SC<HollowCircleOptions> = (options, context) => {
10
+ return BaseCircle({ colorAttribute: 'stroke', ...options }, context);
11
+ };
12
+
13
+ HollowCircle.props = {
14
+ defaultMarker: 'hollowPoint',
15
+ ...Circle.props,
16
+ };
@@ -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 : {});
@@ -35,7 +35,7 @@ function inferTextPosition(shape: DisplayObject) {
35
35
  }
36
36
 
37
37
  const BadgeShape = createElement((g) => {
38
- const { class: className, x: x0, y: y0, ...rest } = g.attributes;
38
+ const { class: className, x: x0, y: y0, transform, ...rest } = g.attributes;
39
39
 
40
40
  const markerStyle = subObject(rest, 'marker');
41
41
  const { size = 24 } = markerStyle;
@@ -69,8 +69,7 @@ export const Badge: SC<BadgeOptions> = (options, context) => {
69
69
  const [[x0, y0]] = points;
70
70
  return select(new BadgeShape())
71
71
  .call(applyStyle, rest)
72
- .style('x', x0)
73
- .style('y', y0)
72
+ .style('transform', `translate(${x0},${y0})`)
74
73
  .call(applyStyle, textStyle)
75
74
  .call(applyStyle, style)
76
75
  .node();
@@ -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',
@@ -249,6 +249,7 @@ export function create({
249
249
  titleSpacing: 12,
250
250
  labelSpacing: 4,
251
251
  titleTextBaseline: 'bottom',
252
+ titleTransform: 'translate(0, 8)',
252
253
  },
253
254
  axisLeft: {
254
255
  gridDirection: 'positive',
@@ -259,6 +260,7 @@ export function create({
259
260
  titleSpacing: 12,
260
261
  titleTextBaseline: 'middle',
261
262
  titleDirection: 'vertical',
263
+ titleTransform: 'rotate(-90) translate(0, -8)',
262
264
  titleTransformOrigin: 'center',
263
265
  },
264
266
  axisRight: {
@@ -46,13 +46,7 @@ export function copyAttributes(target: DisplayObject, source: DisplayObject) {
46
46
  const exclude = new Set(['id', 'className']);
47
47
  for (const [key, value] of Object.entries(attributes)) {
48
48
  if (!exclude.has(key)) {
49
- // @todo Fix in @antv/g
50
- if (key === 'transform') {
51
- target.attr(key, '');
52
- target.attr(key, value);
53
- } else {
54
- target.attr(key, value);
55
- }
49
+ target.attr(key, value);
56
50
  }
57
51
  }
58
52
  }
@@ -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')