@antv/g2 5.0.0-beta.1 → 5.0.0-beta.3

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 (162) hide show
  1. package/dist/g2-lite.min.js +2 -2
  2. package/dist/g2.min.js +2 -2
  3. package/esm/animation/morphing.js +10 -8
  4. package/esm/animation/morphing.js.map +1 -1
  5. package/esm/api/chart.js +2 -5
  6. package/esm/api/chart.js.map +1 -1
  7. package/esm/component/axis.d.ts +1 -2
  8. package/esm/component/axis.js +81 -198
  9. package/esm/component/axis.js.map +1 -1
  10. package/esm/component/legendCategory.d.ts +0 -1
  11. package/esm/component/legendCategory.js +36 -49
  12. package/esm/component/legendCategory.js.map +1 -1
  13. package/esm/component/legendContinuous.js +29 -19
  14. package/esm/component/legendContinuous.js.map +1 -1
  15. package/esm/component/utils.d.ts +1 -0
  16. package/esm/component/utils.js +3 -0
  17. package/esm/component/utils.js.map +1 -1
  18. package/esm/composition/facetRect.js +2 -4
  19. package/esm/composition/facetRect.js.map +1 -1
  20. package/esm/composition/repeatMatrix.js +2 -2
  21. package/esm/composition/repeatMatrix.js.map +1 -1
  22. package/esm/interaction/action/service/legendItemSelection.js.map +1 -1
  23. package/esm/interaction/action/transformer/setItemState.js.map +1 -1
  24. package/esm/mark/cell.js +1 -1
  25. package/esm/shape/area/curve.js +2 -9
  26. package/esm/shape/area/curve.js.map +1 -1
  27. package/esm/shape/interval/color.js +2 -2
  28. package/esm/shape/interval/color.js.map +1 -1
  29. package/esm/shape/line/curve.js +23 -12
  30. package/esm/shape/line/curve.js.map +1 -1
  31. package/esm/shape/line/line.js +6 -2
  32. package/esm/shape/line/line.js.map +1 -1
  33. package/esm/shape/line/smooth.js +6 -2
  34. package/esm/shape/line/smooth.js.map +1 -1
  35. package/esm/shape/text/advance.js +2 -2
  36. package/esm/shape/text/advance.js.map +1 -1
  37. package/esm/shape/utils.d.ts +1 -0
  38. package/esm/shape/utils.js +8 -1
  39. package/esm/shape/utils.js.map +1 -1
  40. package/esm/spec/geometry.d.ts +1 -1
  41. package/esm/spec/transform.d.ts +10 -2
  42. package/esm/stdlib/index.js +2 -2
  43. package/esm/stdlib/index.js.map +1 -1
  44. package/esm/theme/dark.js +78 -65
  45. package/esm/theme/dark.js.map +1 -1
  46. package/esm/theme/light.js +84 -74
  47. package/esm/theme/light.js.map +1 -1
  48. package/esm/transform/groupN.js +2 -0
  49. package/esm/transform/groupN.js.map +1 -1
  50. package/esm/transform/index.d.ts +8 -6
  51. package/esm/transform/index.js +4 -3
  52. package/esm/transform/index.js.map +1 -1
  53. package/esm/transform/sample.d.ts +8 -0
  54. package/esm/transform/sample.js +48 -0
  55. package/esm/transform/sample.js.map +1 -0
  56. package/esm/transform/{Select.d.ts → select.d.ts} +0 -0
  57. package/esm/transform/{Select.js → select.js} +1 -1
  58. package/esm/transform/{Select.js.map → select.js.map} +1 -1
  59. package/esm/transform/{SelectX.d.ts → selectX.d.ts} +0 -0
  60. package/esm/transform/{SelectX.js → selectX.js} +2 -2
  61. package/esm/transform/{SelectX.js.map → selectX.js.map} +1 -1
  62. package/esm/transform/{SelectY.d.ts → selectY.d.ts} +0 -0
  63. package/esm/transform/{SelectY.js → selectY.js} +2 -2
  64. package/esm/transform/{SelectY.js.map → selectY.js.map} +1 -1
  65. package/esm/transform/sort.d.ts +1 -1
  66. package/esm/transform/sort.js +39 -21
  67. package/esm/transform/sort.js.map +1 -1
  68. package/lib/animation/morphing.js +10 -8
  69. package/lib/animation/morphing.js.map +1 -1
  70. package/lib/api/chart.js +2 -5
  71. package/lib/api/chart.js.map +1 -1
  72. package/lib/component/axis.d.ts +1 -2
  73. package/lib/component/axis.js +80 -197
  74. package/lib/component/axis.js.map +1 -1
  75. package/lib/component/legendCategory.d.ts +0 -1
  76. package/lib/component/legendCategory.js +36 -49
  77. package/lib/component/legendCategory.js.map +1 -1
  78. package/lib/component/legendContinuous.js +29 -19
  79. package/lib/component/legendContinuous.js.map +1 -1
  80. package/lib/component/utils.d.ts +1 -0
  81. package/lib/component/utils.js +5 -1
  82. package/lib/component/utils.js.map +1 -1
  83. package/lib/composition/facetRect.js +2 -4
  84. package/lib/composition/facetRect.js.map +1 -1
  85. package/lib/composition/repeatMatrix.js +2 -2
  86. package/lib/composition/repeatMatrix.js.map +1 -1
  87. package/lib/interaction/action/service/legendItemSelection.js.map +1 -1
  88. package/lib/interaction/action/transformer/setItemState.js.map +1 -1
  89. package/lib/mark/cell.js +1 -1
  90. package/lib/shape/area/curve.js +2 -9
  91. package/lib/shape/area/curve.js.map +1 -1
  92. package/lib/shape/interval/color.js +2 -2
  93. package/lib/shape/interval/color.js.map +1 -1
  94. package/lib/shape/line/curve.js +21 -10
  95. package/lib/shape/line/curve.js.map +1 -1
  96. package/lib/shape/line/line.js +5 -1
  97. package/lib/shape/line/line.js.map +1 -1
  98. package/lib/shape/line/smooth.js +5 -1
  99. package/lib/shape/line/smooth.js.map +1 -1
  100. package/lib/shape/text/advance.js +2 -2
  101. package/lib/shape/text/advance.js.map +1 -1
  102. package/lib/shape/utils.d.ts +1 -0
  103. package/lib/shape/utils.js +9 -1
  104. package/lib/shape/utils.js.map +1 -1
  105. package/lib/spec/geometry.d.ts +1 -1
  106. package/lib/spec/transform.d.ts +10 -2
  107. package/lib/stdlib/index.js +1 -1
  108. package/lib/stdlib/index.js.map +1 -1
  109. package/lib/theme/dark.js +78 -65
  110. package/lib/theme/dark.js.map +1 -1
  111. package/lib/theme/light.js +84 -74
  112. package/lib/theme/light.js.map +1 -1
  113. package/lib/transform/groupN.js +2 -0
  114. package/lib/transform/groupN.js.map +1 -1
  115. package/lib/transform/index.d.ts +8 -6
  116. package/lib/transform/index.js +9 -7
  117. package/lib/transform/index.js.map +1 -1
  118. package/lib/transform/sample.d.ts +8 -0
  119. package/lib/transform/sample.js +52 -0
  120. package/lib/transform/sample.js.map +1 -0
  121. package/lib/transform/{Select.d.ts → select.d.ts} +0 -0
  122. package/lib/transform/{Select.js → select.js} +1 -1
  123. package/lib/transform/{Select.js.map → select.js.map} +1 -1
  124. package/lib/transform/{SelectX.d.ts → selectX.d.ts} +0 -0
  125. package/lib/transform/{SelectX.js → selectX.js} +3 -3
  126. package/lib/transform/{SelectX.js.map → selectX.js.map} +1 -1
  127. package/lib/transform/{SelectY.d.ts → selectY.d.ts} +0 -0
  128. package/lib/transform/{SelectY.js → selectY.js} +3 -3
  129. package/lib/transform/{SelectY.js.map → selectY.js.map} +1 -1
  130. package/lib/transform/sort.d.ts +1 -1
  131. package/lib/transform/sort.js +38 -20
  132. package/lib/transform/sort.js.map +1 -1
  133. package/package.json +3 -3
  134. package/src/animation/morphing.ts +12 -8
  135. package/src/api/chart.ts +2 -5
  136. package/src/component/axis.ts +233 -310
  137. package/src/component/legendCategory.ts +52 -68
  138. package/src/component/legendContinuous.ts +24 -25
  139. package/src/component/utils.ts +4 -0
  140. package/src/composition/facetRect.ts +2 -4
  141. package/src/composition/repeatMatrix.ts +2 -2
  142. package/src/interaction/action/service/legendItemSelection.ts +1 -2
  143. package/src/interaction/action/transformer/setItemState.ts +2 -3
  144. package/src/mark/cell.ts +1 -1
  145. package/src/shape/area/curve.ts +7 -9
  146. package/src/shape/interval/color.ts +7 -7
  147. package/src/shape/line/curve.ts +27 -12
  148. package/src/shape/line/line.ts +6 -2
  149. package/src/shape/line/smooth.ts +11 -2
  150. package/src/shape/text/advance.ts +2 -2
  151. package/src/shape/utils.ts +8 -1
  152. package/src/spec/geometry.ts +1 -7
  153. package/src/spec/transform.ts +10 -1
  154. package/src/stdlib/index.ts +2 -0
  155. package/src/theme/dark.ts +78 -66
  156. package/src/theme/light.ts +84 -75
  157. package/src/transform/groupN.ts +2 -0
  158. package/src/transform/index.ts +8 -6
  159. package/src/transform/sample.ts +44 -0
  160. package/src/transform/selectX.ts +1 -1
  161. package/src/transform/selectY.ts +1 -1
  162. package/src/transform/sort.ts +53 -21
@@ -1,9 +1,9 @@
1
1
  import { Category } from '@antv/gui';
2
- import { deepMix } from '@antv/util';
3
2
  import {
4
3
  GuideComponentComponent as GCC,
5
4
  GuideComponentPosition,
6
5
  } from '../runtime';
6
+ import { titleContent } from './utils';
7
7
 
8
8
  export type LegendCategoryOptions = {
9
9
  position?: GuideComponentPosition;
@@ -14,19 +14,37 @@ export type LegendCategoryOptions = {
14
14
  [key: string]: any;
15
15
  };
16
16
 
17
+ function inferLayout(
18
+ position: GuideComponentPosition,
19
+ gridRow?: number,
20
+ gridCol?: number,
21
+ ): [number, number] {
22
+ const [gridRowLimit, gridColLimit] = [gridRow || 100, gridCol || 100];
23
+ const config = {
24
+ top: [1, gridColLimit],
25
+ bottom: [1, gridColLimit],
26
+ left: [gridRowLimit, 1],
27
+ right: [gridRowLimit, 1],
28
+ arcCenter: [gridRowLimit, 1],
29
+ }[position];
30
+
31
+ return config || [gridRow, gridCol];
32
+ }
33
+
17
34
  /**
18
35
  * Guide Component for ordinal color scale.
19
- * @todo Custom style.
20
36
  */
21
37
  export const LegendCategory: GCC<LegendCategoryOptions> = (options) => {
22
38
  const {
39
+ order,
40
+ size,
23
41
  position,
24
42
  labelFormatter = (d) => `${d}`,
25
43
  dx = 0,
26
44
  dy = 0,
27
45
  title,
28
- cols = undefined,
29
- autoWrap = false,
46
+ gridCol,
47
+ gridRow,
30
48
  ...rest
31
49
  } = options;
32
50
  return (scale, value, coordinate, theme) => {
@@ -34,73 +52,39 @@ export const LegendCategory: GCC<LegendCategoryOptions> = (options) => {
34
52
  const { x, y, width, height } = bbox;
35
53
  const items = domain.map((d) => ({
36
54
  id: d,
37
- name: labelFormatter(d),
55
+ label: labelFormatter(d),
56
+ value: '',
38
57
  color: scale.map(d),
39
58
  }));
40
- const maxItemWidth = autoWrap && cols ? width / cols : undefined;
41
- const legendStyle = deepMix(
42
- {},
43
- {
44
- items,
45
- x: x + dx,
46
- y: y + dy,
47
- orient: ['right', 'left', 'arcCenter'].includes(position)
48
- ? 'vertical'
49
- : 'horizontal',
50
- maxWidth: width,
51
- maxHeight: height,
52
- autoWrap,
53
- maxItemWidth,
54
- itemWidth: maxItemWidth,
55
- spacing: [8, 0],
56
- itemName: {
57
- style: {
58
- fontSize: 12,
59
- fillOpacity: 1,
60
- fill: '#000',
61
- fontWeight: 'lighter',
62
- active: {
63
- fillOpacity: 0.8,
64
- },
65
- inactive: {
66
- fill: '#d8d8d8',
67
- },
68
- unchecked: {
69
- fill: '#d8d8d8',
70
- },
71
- },
72
- },
73
- ...(title && {
74
- title: {
75
- content: Array.isArray(title) ? title[0] : title,
76
- style: {
77
- fontSize: 12,
78
- fontWeight: 'bold',
79
- fillOpacity: 1,
80
- },
81
- },
82
- }),
83
- itemMarker: {
84
- size: 8,
85
- symbol: 'circle',
86
- style: {
87
- fillOpacity: 1,
88
- inactive: {
89
- fillOpacity: 0.2,
90
- },
91
- unchecked: {
92
- fill: '#d8d8d8',
93
- stroke: '#d8d8d8',
94
- },
95
- },
96
- },
97
- itemBackgroundStyle: {
98
- fill: 'transparent',
99
- },
100
- },
101
- { ...rest },
59
+
60
+ // Calc layout config
61
+ const [finalGridRow, finalGridCol] = inferLayout(
62
+ position,
63
+ gridRow,
64
+ gridCol,
102
65
  );
103
- return new Category({ className: 'category-legend', style: legendStyle });
66
+
67
+ const legendStyle = {
68
+ data: items,
69
+ x: x + dx,
70
+ y: y + dy,
71
+ orient: ['right', 'left', 'arcCenter'].includes(position)
72
+ ? 'vertical'
73
+ : 'horizontal',
74
+ width,
75
+ height,
76
+ gridCol: finalGridCol,
77
+ gridRow: finalGridRow,
78
+ rowPadding: 0,
79
+ colPadding: 8,
80
+ titleText: titleContent(title),
81
+ itemMarkerFill: (d) => (d ? d.color : '#fff'),
82
+ };
83
+
84
+ const { legend: legendTheme = {} } = theme;
85
+ return new Category({
86
+ style: Object.assign({}, legendTheme, legendStyle, rest),
87
+ });
104
88
  };
105
89
  };
106
90
 
@@ -3,6 +3,7 @@ import {
3
3
  GuideComponentComponent as GCC,
4
4
  GuideComponentPosition,
5
5
  } from '../runtime';
6
+ import { titleContent } from './utils';
6
7
 
7
8
  export type LegendContinuousOptions = {
8
9
  position?: GuideComponentPosition;
@@ -14,37 +15,35 @@ export type LegendContinuousOptions = {
14
15
  * @todo Custom style.
15
16
  */
16
17
  export const LegendContinuous: GCC<LegendContinuousOptions> = (options) => {
17
- const { title } = options;
18
+ const { title, ...rest } = options;
18
19
  return (scale, value, coordinate, theme) => {
19
20
  const { domain, bbox } = value;
20
21
  const { x, y } = bbox;
21
- const ticks = scale.getTicks?.() || [];
22
22
  const [min, max] = domain;
23
+
24
+ const { continuousLegend: legendTheme = {} } = theme;
25
+
23
26
  return new Continuous({
24
- style: {
25
- x,
26
- y,
27
- rail: {
28
- // @ts-ignore
29
- length: 120,
30
- // @ts-ignore
31
- size: 12,
32
- ticks,
27
+ style: Object.assign(
28
+ {},
29
+ legendTheme,
30
+ {
31
+ x,
32
+ y,
33
+ width: 400,
34
+ height: 300,
35
+ data: [{ value: min }, { value: max }],
36
+ titleText: titleContent(title),
37
+ titleFontSize: 12,
38
+ ribbonLen: 120,
39
+ ribbonSize: 12,
40
+ ribbonColor: domain.map((d) => scale.map(d)),
41
+ showHandle: false,
42
+ showIndicator: false,
43
+ labelAlign: 'value',
33
44
  },
34
- min,
35
- max,
36
- indicator: null,
37
- handle: null,
38
- ...(title && {
39
- title: {
40
- content: Array.isArray(title) ? title[0] : title,
41
- style: {
42
- fontSize: 12,
43
- },
44
- },
45
- }),
46
- color: domain.map((d) => scale.map(d)),
47
- },
45
+ rest,
46
+ ),
48
47
  });
49
48
  };
50
49
  };
@@ -36,3 +36,7 @@ export function maybeAppend<T>(
36
36
  }
37
37
  return select(parent).select(selector);
38
38
  }
39
+
40
+ export function titleContent(field: string | string[]): string {
41
+ return Array.isArray(field) ? field.join(', ') : `${field || ''}`;
42
+ }
@@ -296,18 +296,16 @@ export function createInnerGuide(guide, data) {
296
296
  ? deepMix(
297
297
  {
298
298
  title: false,
299
- tickLine: null,
299
+ tick: null,
300
300
  label: null,
301
- subTickLine: null,
302
301
  },
303
302
  guide,
304
303
  )
305
304
  : deepMix(
306
305
  {
307
306
  title: false,
308
- tickLine: null,
307
+ tick: null,
309
308
  label: null,
310
- subTickLine: null,
311
309
  grid: null,
312
310
  },
313
311
  guide,
@@ -71,8 +71,8 @@ const setChildren = useOverrideAdaptor<G2ViewTree>((options) => {
71
71
  y: createGuideY(guideY)(facet, data),
72
72
  };
73
73
  const defaultAxis = {
74
- x: { titleAnchor: 'center', titleTextAnchor: 'center', tickCount: 5 },
75
- y: { titleAnchor: 'center', titleTextAnchor: 'center', tickCount: 5 },
74
+ x: { tickCount: 5 },
75
+ y: { tickCount: 5 },
76
76
  };
77
77
  return {
78
78
  data,
@@ -1,4 +1,3 @@
1
- import { Category } from '@antv/gui';
2
1
  import { ActionComponent as AC } from '../../types';
3
2
  import { LegendItemSelectionAction } from '../../../spec';
4
3
 
@@ -14,7 +13,7 @@ export const LegendItemSelection: AC<LegendItemSelectionOptions> = (
14
13
 
15
14
  return (context) => {
16
15
  const { shared, selection, scale } = context;
17
- const legend = selection.select('.category-legend').node() as Category;
16
+ const legend = selection.select('.category-legend').node() as any;
18
17
 
19
18
  if (from === 'triggerInfo') {
20
19
  shared.selectedLegendItems = shared.triggerInfo.map(({ id }) =>
@@ -1,10 +1,9 @@
1
- import { Category } from '@antv/gui';
2
1
  import { ActionComponent as AC } from '../../types';
3
2
  import { SetItemStateAction } from '../../../spec';
4
3
 
5
4
  export type SetItemStateOptions = Omit<SetItemStateAction, 'type'>;
6
5
 
7
- function highlightLegendItems(legend: Category, items) {
6
+ function highlightLegendItems(legend: any, items) {
8
7
  const itemStates = legend?.getItemsStates() || [];
9
8
 
10
9
  if (items.length) {
@@ -22,7 +21,7 @@ export const SetItemState: AC<SetItemStateOptions> = (options) => {
22
21
 
23
22
  if (items.includes('legendItem')) {
24
23
  const { selectedLegendItems: selectedItems = [] } = shared;
25
- const legend = selection.select('.category-legend').node() as Category;
24
+ const legend = selection.select('.category-legend').node() as any;
26
25
  if (state === 'highlight') {
27
26
  highlightLegendItems(legend, selectedItems);
28
27
  } else {
package/src/mark/cell.ts CHANGED
@@ -35,7 +35,7 @@ export const Cell: MC<CellOptions> = () => {
35
35
  };
36
36
  };
37
37
 
38
- const shapes = ['rect', 'hollow'];
38
+ const shapes = ['cell', 'hollow'];
39
39
 
40
40
  Cell.props = {
41
41
  defaultShape: 'cell',
@@ -4,7 +4,12 @@ import { select } from '../../utils/selection';
4
4
  import { isPolar } from '../../utils/coordinate';
5
5
  import { Vector2, ShapeComponent as SC } from '../../runtime';
6
6
  import { angleWithQuadrant, sub, dist } from '../../utils/vector';
7
- import { applyStyle, computeGradient, getShapeTheme } from '../utils';
7
+ import {
8
+ applyStyle,
9
+ computeGradient,
10
+ getShapeTheme,
11
+ getTransform,
12
+ } from '../utils';
8
13
  import { subObject } from '../../utils/helper';
9
14
  import { createElement } from '../createElement';
10
15
 
@@ -65,13 +70,6 @@ function segmentation(
65
70
  return [definedPointsY1.concat(definedPointsY0), segments];
66
71
  }
67
72
 
68
- function getTransform(coordinate, value) {
69
- if (!isPolar(coordinate)) return '';
70
- const center = coordinate.getCenter() as Vector2;
71
- const { transform: suffix } = value;
72
- return `translate(${center[0]}, ${center[1]}) ${suffix || ''}`;
73
- }
74
-
75
73
  export type CurveOptions = {
76
74
  curve?: CurveFactory;
77
75
  gradient?: boolean | string;
@@ -113,7 +111,7 @@ export const Curve: SC<CurveOptions> = (options) => {
113
111
 
114
112
  const [DP, MS] = segmentation(P, defined);
115
113
 
116
- const connectStyle = subObject(style, 'connect');
114
+ const connectStyle = subObject(finalStyle, 'connect');
117
115
  const missing = !!MS.length;
118
116
 
119
117
  const getPathNode = (path) => {
@@ -35,16 +35,16 @@ export const Color: SC<ColorOptions> = (options) => {
35
35
 
36
36
  return (points, value, coordinate, theme) => {
37
37
  const { mark, shape, defaultShape } = value;
38
- const { [colorAttribute]: defaultColor, ...defaults } = getShapeTheme(
39
- theme,
40
- mark,
41
- shape,
42
- defaultShape,
43
- );
38
+ const {
39
+ [colorAttribute]: defaultColor,
40
+ radius: defaultRadius = 0,
41
+ ...defaults
42
+ } = getShapeTheme(theme, mark, shape, defaultShape);
43
+
44
44
  const defaultLineWidth = defaults.lineWidth || 1;
45
45
  const {
46
46
  stroke,
47
- radius = 0,
47
+ radius = defaultRadius,
48
48
  radiusTopLeft = radius,
49
49
  radiusTopRight = radius,
50
50
  radiusBottomRight = radius,
@@ -1,12 +1,18 @@
1
- import { line, CurveFactory, CurveFactoryLineOnly } from 'd3-shape';
1
+ import { line, lineRadial, CurveFactory, CurveFactoryLineOnly } from 'd3-shape';
2
2
  import { Vector2 } from '@antv/coord';
3
3
  import { Path } from '@antv/g';
4
4
  import { isPolar } from '../../utils/coordinate';
5
5
  import { select } from '../../utils/selection';
6
6
  import { ShapeComponent as SC } from '../../runtime';
7
- import { applyStyle, computeGradient, getShapeTheme } from '../utils';
7
+ import {
8
+ applyStyle,
9
+ computeGradient,
10
+ getShapeTheme,
11
+ getTransform,
12
+ } from '../utils';
8
13
  import { createElement } from '../createElement';
9
14
  import { subObject } from '../../utils/helper';
15
+ import { angleWithQuadrant, dist, sub } from '../../utils/vector';
10
16
 
11
17
  const DoublePath = createElement((g) => {
12
18
  const { d1, d2, style1, style2 } = g.attributes;
@@ -77,7 +83,7 @@ export const Curve: SC<CurveOptions> = (options) => {
77
83
  connectNulls = false,
78
84
  ...style
79
85
  } = options;
80
- return (points, value, coordinate, theme) => {
86
+ return (P, value, coordinate, theme) => {
81
87
  // Compute styles.
82
88
  const { mark, shape, defaultShape } = value;
83
89
  const {
@@ -88,7 +94,6 @@ export const Curve: SC<CurveOptions> = (options) => {
88
94
  const {
89
95
  color = defaultColor,
90
96
  size = defaultSize,
91
- transform,
92
97
  seriesColor: sc,
93
98
  seriesX: sx,
94
99
  seriesY: sy,
@@ -97,6 +102,7 @@ export const Curve: SC<CurveOptions> = (options) => {
97
102
  gradient && sc
98
103
  ? computeGradient(sc, sx, sy, gradient, gradientColor)
99
104
  : color;
105
+ const transform = getTransform(coordinate, value);
100
106
  const finalStyle = {
101
107
  ...defaults,
102
108
  ...(stroke && { stroke }),
@@ -106,15 +112,24 @@ export const Curve: SC<CurveOptions> = (options) => {
106
112
  };
107
113
 
108
114
  // Compute points and segments.
109
- // Append first point to draw close line in polar coordinate.
110
- const P = isPolar(coordinate) ? [...points, points[0]] : points;
111
- const linePath = line()
112
- .x((d) => d[0])
113
- .y((d) => d[1])
114
- .defined(([x, y]) => defined(x) && defined(y))
115
- .curve(curve);
115
+ let linePath;
116
+ if (isPolar(coordinate)) {
117
+ const center = coordinate.getCenter() as Vector2;
118
+ linePath = (points) =>
119
+ lineRadial()
120
+ .angle((_, idx) => angleWithQuadrant(sub(points[idx], center)))
121
+ .radius((_, idx) => dist(points[idx], center))
122
+ .defined(([x, y]) => defined(x) && defined(y))
123
+ .curve(curve)(points);
124
+ } else {
125
+ linePath = line()
126
+ .x((d) => d[0])
127
+ .y((d) => d[1])
128
+ .defined(([x, y]) => defined(x) && defined(y))
129
+ .curve(curve);
130
+ }
116
131
  const [DP, MS] = segmentation(P, defined);
117
- const connectStyle = subObject(style, 'connect');
132
+ const connectStyle = subObject(finalStyle, 'connect');
118
133
  const missing = !!MS.length;
119
134
 
120
135
  // Draw one path of connected defined points.
@@ -1,11 +1,15 @@
1
- import { curveLinear } from 'd3-shape';
1
+ import { curveLinear, curveLinearClosed } from 'd3-shape';
2
+ import { isPolar } from '../../utils/coordinate';
2
3
  import { ShapeComponent as SC } from '../../runtime';
3
4
  import { Curve } from './curve';
4
5
 
5
6
  export type LineOptions = Record<string, any>;
6
7
 
7
8
  export const Line: SC<LineOptions> = (options) => {
8
- return Curve({ curve: curveLinear, ...options });
9
+ return (P, value, coordinate, theme) => {
10
+ const curve = isPolar(coordinate) ? curveLinearClosed : curveLinear;
11
+ return Curve({ curve, ...options })(P, value, coordinate, theme);
12
+ };
9
13
  };
10
14
 
11
15
  Line.props = {
@@ -1,4 +1,5 @@
1
- import { curveCatmullRom } from 'd3-shape';
1
+ import { curveCatmullRom, curveCatmullRomClosed } from 'd3-shape';
2
+ import { isPolar } from '../../utils/coordinate';
2
3
  import { ShapeComponent as SC } from '../../runtime';
3
4
  import { Curve } from './curve';
4
5
 
@@ -8,7 +9,15 @@ export type SmoothOptions = {
8
9
 
9
10
  export const Smooth: SC<SmoothOptions> = (options) => {
10
11
  const { alpha = 0.5, ...rest } = options;
11
- return Curve({ curve: curveCatmullRom.alpha(alpha), ...rest });
12
+ return (P, value, coordinate, theme) => {
13
+ const curve = isPolar(coordinate) ? curveCatmullRomClosed : curveCatmullRom;
14
+ return Curve({ curve: curve.alpha(alpha), ...rest })(
15
+ P,
16
+ value,
17
+ coordinate,
18
+ theme,
19
+ );
20
+ };
12
21
  };
13
22
 
14
23
  Smooth.props = {
@@ -164,13 +164,13 @@ export const Advance = createElement((g) => {
164
164
  startMarker &&
165
165
  new Marker({
166
166
  id: 'startMarker',
167
- style: subObject(rest, 'startMarker') as any,
167
+ style: { x: 0, y: 0, ...(subObject(rest, 'startMarker') as any) },
168
168
  });
169
169
  const markerEnd =
170
170
  endMarker &&
171
171
  new Marker({
172
172
  id: 'endMarker',
173
- style: subObject(rest, 'endMarker') as any,
173
+ style: { x: 0, y: 0, ...(subObject(rest, 'endMarker') as any) },
174
174
  });
175
175
  select(g)
176
176
  .maybeAppend('connector', 'path')
@@ -4,7 +4,7 @@ import { Coordinate } from '@antv/coord';
4
4
  import { Linear } from '@antv/scale';
5
5
  import { lowerFirst } from '@antv/util';
6
6
  import { G2Theme, Primitive, Vector2 } from '../runtime';
7
- import { isTranspose } from '../utils/coordinate';
7
+ import { isPolar, isTranspose } from '../utils/coordinate';
8
8
  import { angle, angleWithQuadrant, dist, sub } from '../utils/vector';
9
9
  import { Selection } from '../utils/selection';
10
10
  import { indexOf } from '../utils/array';
@@ -232,3 +232,10 @@ export function toOpacityKey(options) {
232
232
  const { opacityAttribute = 'fill' } = options;
233
233
  return `${opacityAttribute}Opacity`;
234
234
  }
235
+
236
+ export function getTransform(coordinate, value) {
237
+ if (!isPolar(coordinate)) return '';
238
+ const center = coordinate.getCenter() as Vector2;
239
+ const { transform: suffix } = value;
240
+ return `translate(${center[0]}, ${center[1]}) ${suffix || ''}`;
241
+ }
@@ -141,13 +141,7 @@ export type BaseGeometry<
141
141
  enterDuration?: number;
142
142
  enterDelay?: number;
143
143
  enterEasing?: string;
144
- enterFill?:
145
- | 'forwards'
146
- | 'none'
147
- | 'backwards'
148
- | 'forwards'
149
- | 'both'
150
- | 'auto';
144
+ enterFill?: 'forwards' | 'none' | 'backwards' | 'both' | 'auto';
151
145
  updateType?: AnimationTypes;
152
146
  updateDuration?: number;
153
147
  updateDelay?: number;
@@ -23,6 +23,7 @@ export type Transform =
23
23
  | PackTransform
24
24
  | BinXTransform
25
25
  | BinTransform
26
+ | SampleTransform
26
27
  | FlexXTransform;
27
28
 
28
29
  export type TransformTypes =
@@ -45,7 +46,8 @@ export type TransformTypes =
45
46
  | 'sortColor'
46
47
  | 'sortY'
47
48
  | 'flexX'
48
- | 'Pack'
49
+ | 'pack'
50
+ | 'sample'
49
51
  | TransformComponent;
50
52
 
51
53
  export type TransformOrder =
@@ -171,6 +173,7 @@ export type SortXTransform = {
171
173
  reverse?: boolean;
172
174
  by?: string;
173
175
  slice?: number | [number, number];
176
+ ordinal?: boolean;
174
177
  reducer?:
175
178
  | 'max'
176
179
  | 'min'
@@ -246,3 +249,9 @@ export type BinTransform = {
246
249
  thresholdsX?: number;
247
250
  thresholdsY?: number;
248
251
  } & { [key in ChannelTypes]?: Reducer };
252
+
253
+ export type SampleTransform = {
254
+ type?: 'sample';
255
+ groupBy?: string | string[];
256
+ thresholds?: number;
257
+ } & { [key in ChannelTypes]?: Reducer };
@@ -230,6 +230,7 @@ import {
230
230
  MaybeFunctionAttribute,
231
231
  MaybeGradient,
232
232
  MaybeTooltip,
233
+ Sample,
233
234
  } from '../transform';
234
235
  import {
235
236
  Fetch,
@@ -311,6 +312,7 @@ export function createLibrary(): G2Library {
311
312
  'transform.maybeGradient': MaybeGradient,
312
313
  'transform.maybeTooltip': MaybeTooltip,
313
314
  'transform.pack': Pack,
315
+ 'transform.sample': Sample,
314
316
  'coordinate.cartesian': Cartesian,
315
317
  'coordinate.polar': Polar,
316
318
  'coordinate.helix': Helix,