@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
@@ -0,0 +1,44 @@
1
+ import { TransformComponent as TC, Primitive } from '../runtime';
2
+ import { SampleTransform } from '../spec';
3
+ import { createGroups } from './utils/order';
4
+ import { GroupN } from './groupN';
5
+
6
+ export type SampleOptions = Omit<SampleTransform, 'type'>;
7
+
8
+ /**
9
+ * Split the array into frame with each frameSize.
10
+ */
11
+ function getFrames(I: Primitive[], frameSize: number) {
12
+ const size = I.length;
13
+ const frames = [];
14
+ let i = 0;
15
+ while (i < size) {
16
+ frames.push(I.slice(i, (i += frameSize)));
17
+ }
18
+ return frames;
19
+ }
20
+
21
+ /**
22
+ * The sample transform groups marks with specified groupBy fields, and
23
+ * sample data for each group when data.length >= threshold(default = 2000).
24
+ */
25
+ export const Sample: TC<SampleOptions> = (options = {}) => {
26
+ const { groupBy: by, thresholds = 2000, ...rest } = options;
27
+
28
+ const groupBy = (I, mark) => {
29
+ const groups = createGroups(by, I, mark);
30
+ // Skip
31
+ if (groups.every((g) => g.length <= thresholds)) return null;
32
+
33
+ return groups.flatMap((g) => {
34
+ // Keep more data as possible.
35
+ // After sampled, the length of each group.
36
+ const frameSize = Math.max(1, Math.floor(g.length / thresholds));
37
+ const frames = getFrames(g, frameSize);
38
+ return frames;
39
+ });
40
+ };
41
+ return GroupN({ ...rest, groupBy });
42
+ };
43
+
44
+ Sample.props = {};
@@ -1,6 +1,6 @@
1
1
  import { TransformComponent as TC } from '../runtime';
2
2
  import { SelectXTransform } from '../spec';
3
- import { Select } from './Select';
3
+ import { Select } from './select';
4
4
 
5
5
  export type SelectXOptions = Omit<SelectXTransform, 'type'>;
6
6
 
@@ -1,6 +1,6 @@
1
1
  import { TransformComponent as TC } from '../runtime';
2
2
  import { SelectYTransform } from '../spec';
3
- import { Select } from './Select';
3
+ import { Select } from './select';
4
4
 
5
5
  export type SelectYOptions = Omit<SelectYTransform, 'type'>;
6
6
 
@@ -1,6 +1,15 @@
1
1
  import { deepMix } from '@antv/util';
2
- import { Primitive, groupSort, max, min, sum, mean, median } from 'd3-array';
3
- import { TransformComponent as TC } from '../runtime';
2
+ import {
3
+ Primitive,
4
+ groupSort,
5
+ max,
6
+ min,
7
+ sum,
8
+ mean,
9
+ median,
10
+ sort,
11
+ } from 'd3-array';
12
+ import { G2Mark, TransformComponent as TC } from '../runtime';
4
13
  import { columnOf } from './utils/helper';
5
14
 
6
15
  function createReducer(channel, options, encode): (I: number[]) => any {
@@ -22,6 +31,7 @@ export type SortOptions = {
22
31
  reverse?: boolean;
23
32
  channel?: string;
24
33
  slice?: number | [number, number];
34
+ ordinal?: boolean;
25
35
  reducer?:
26
36
  | 'max'
27
37
  | 'min'
@@ -33,30 +43,52 @@ export type SortOptions = {
33
43
  | ((I: number[], V: Primitive[]) => Primitive);
34
44
  };
35
45
 
46
+ function sortQuantitative(I, mark, options): [number[], G2Mark] {
47
+ const { reverse, slice, channel } = options;
48
+ const { encode } = mark;
49
+ const [V] = columnOf(encode, channel);
50
+ const sortedI = sort(I, (i: number) => V[i]);
51
+ if (reverse) sortedI.reverse();
52
+ // const s = typeof slice === 'number' ? [0, slice] : slice;
53
+ return [sortedI, mark];
54
+ }
55
+
56
+ function sortOrdinal(I, mark, options): [number[], G2Mark] {
57
+ const { reverse, slice, channel, ...rest } = options;
58
+ const { encode } = mark;
59
+ const [T] = columnOf(encode, channel);
60
+ const normalizeReducer = createReducer(channel, rest, encode);
61
+ const sortedDomain = groupSort(I, normalizeReducer, (i: number) => T[i]);
62
+ if (reverse) sortedDomain.reverse();
63
+ const s = typeof slice === 'number' ? [0, slice] : slice;
64
+ const slicedDomain = slice ? sortedDomain.slice(...s) : sortedDomain;
65
+ return [
66
+ I,
67
+ deepMix(mark, {
68
+ scale: {
69
+ [channel]: {
70
+ domain: slicedDomain,
71
+ },
72
+ },
73
+ }),
74
+ ];
75
+ }
76
+
36
77
  /**
37
78
  * Sort marks groups by groups.
38
- * @todo Add more reducers: first, last, etc,.
39
79
  */
40
80
  export const Sort: TC<SortOptions> = (options = {}) => {
41
- const { reverse = false, slice, channel, ...rest } = options;
81
+ const { reverse = false, slice, channel, ordinal = true, ...rest } = options;
42
82
  return (I, mark) => {
43
- const { encode } = mark;
44
- const [T] = columnOf(encode, channel);
45
- const normalizeReducer = createReducer(channel, rest, encode);
46
- const sortedDomain = groupSort(I, normalizeReducer, (i) => T[i]);
47
- if (reverse) sortedDomain.reverse();
48
- const s = typeof slice === 'number' ? [0, slice] : slice;
49
- const slicedDomain = slice ? sortedDomain.slice(...s) : sortedDomain;
50
- return [
51
- I,
52
- deepMix(mark, {
53
- scale: {
54
- [channel]: {
55
- domain: slicedDomain,
56
- },
57
- },
58
- }),
59
- ];
83
+ if (!ordinal) {
84
+ return sortQuantitative(I, mark, {
85
+ reverse,
86
+ slice,
87
+ channel,
88
+ ...rest,
89
+ });
90
+ }
91
+ return sortOrdinal(I, mark, { reverse, slice, channel, ...rest });
60
92
  };
61
93
  };
62
94