@antv/g2 5.0.0-alpha.4 → 5.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/README.md +29 -27
  2. package/dist/g2-lite.min.js +2 -2
  3. package/dist/g2.min.js +2 -2
  4. package/esm/animation/morphing.js +10 -8
  5. package/esm/animation/morphing.js.map +1 -1
  6. package/esm/api/chart.js +2 -5
  7. package/esm/api/chart.js.map +1 -1
  8. package/esm/component/axis.d.ts +1 -2
  9. package/esm/component/axis.js +81 -198
  10. package/esm/component/axis.js.map +1 -1
  11. package/esm/component/legendCategory.d.ts +0 -1
  12. package/esm/component/legendCategory.js +36 -49
  13. package/esm/component/legendCategory.js.map +1 -1
  14. package/esm/component/legendContinuous.js +29 -19
  15. package/esm/component/legendContinuous.js.map +1 -1
  16. package/esm/component/utils.d.ts +1 -0
  17. package/esm/component/utils.js +3 -0
  18. package/esm/component/utils.js.map +1 -1
  19. package/esm/composition/facetRect.js +2 -4
  20. package/esm/composition/facetRect.js.map +1 -1
  21. package/esm/composition/repeatMatrix.js +2 -2
  22. package/esm/composition/repeatMatrix.js.map +1 -1
  23. package/esm/interaction/action/service/legendItemSelection.js.map +1 -1
  24. package/esm/interaction/action/transformer/setItemState.js.map +1 -1
  25. package/esm/mark/cell.js +1 -1
  26. package/esm/mark/pack.js +2 -2
  27. package/esm/mark/pack.js.map +1 -1
  28. package/esm/mark/sankey.js +1 -0
  29. package/esm/mark/sankey.js.map +1 -1
  30. package/esm/mark/treemap.js +2 -2
  31. package/esm/mark/treemap.js.map +1 -1
  32. package/esm/mark/wordCloud.js +2 -2
  33. package/esm/mark/wordCloud.js.map +1 -1
  34. package/esm/shape/area/curve.js +2 -9
  35. package/esm/shape/area/curve.js.map +1 -1
  36. package/esm/shape/interval/color.js +2 -2
  37. package/esm/shape/interval/color.js.map +1 -1
  38. package/esm/shape/line/curve.js +23 -12
  39. package/esm/shape/line/curve.js.map +1 -1
  40. package/esm/shape/line/line.js +6 -2
  41. package/esm/shape/line/line.js.map +1 -1
  42. package/esm/shape/line/smooth.js +6 -2
  43. package/esm/shape/line/smooth.js.map +1 -1
  44. package/esm/shape/text/advance.js +2 -2
  45. package/esm/shape/text/advance.js.map +1 -1
  46. package/esm/shape/utils.d.ts +1 -0
  47. package/esm/shape/utils.js +8 -1
  48. package/esm/shape/utils.js.map +1 -1
  49. package/esm/spec/geometry.d.ts +2 -2
  50. package/esm/spec/transform.d.ts +10 -2
  51. package/esm/stdlib/index.js +2 -2
  52. package/esm/stdlib/index.js.map +1 -1
  53. package/esm/theme/dark.js +78 -65
  54. package/esm/theme/dark.js.map +1 -1
  55. package/esm/theme/light.js +84 -74
  56. package/esm/theme/light.js.map +1 -1
  57. package/esm/transform/groupN.js +2 -0
  58. package/esm/transform/groupN.js.map +1 -1
  59. package/esm/transform/index.d.ts +8 -6
  60. package/esm/transform/index.js +4 -3
  61. package/esm/transform/index.js.map +1 -1
  62. package/esm/transform/sample.d.ts +8 -0
  63. package/esm/transform/sample.js +48 -0
  64. package/esm/transform/sample.js.map +1 -0
  65. package/esm/transform/{Select.d.ts → select.d.ts} +0 -0
  66. package/esm/transform/{Select.js → select.js} +1 -1
  67. package/esm/transform/{Select.js.map → select.js.map} +1 -1
  68. package/esm/transform/{SelectX.d.ts → selectX.d.ts} +0 -0
  69. package/esm/transform/{SelectX.js → selectX.js} +1 -1
  70. package/esm/transform/{SelectX.js.map → selectX.js.map} +1 -1
  71. package/esm/transform/{SelectY.d.ts → selectY.d.ts} +0 -0
  72. package/esm/transform/{SelectY.js → selectY.js} +1 -1
  73. package/esm/transform/{SelectY.js.map → selectY.js.map} +1 -1
  74. package/esm/transform/sort.d.ts +1 -1
  75. package/esm/transform/sort.js +39 -21
  76. package/esm/transform/sort.js.map +1 -1
  77. package/lib/animation/morphing.js +10 -8
  78. package/lib/animation/morphing.js.map +1 -1
  79. package/lib/api/chart.js +2 -5
  80. package/lib/api/chart.js.map +1 -1
  81. package/lib/component/axis.d.ts +1 -2
  82. package/lib/component/axis.js +80 -197
  83. package/lib/component/axis.js.map +1 -1
  84. package/lib/component/legendCategory.d.ts +0 -1
  85. package/lib/component/legendCategory.js +36 -49
  86. package/lib/component/legendCategory.js.map +1 -1
  87. package/lib/component/legendContinuous.js +29 -19
  88. package/lib/component/legendContinuous.js.map +1 -1
  89. package/lib/component/utils.d.ts +1 -0
  90. package/lib/component/utils.js +5 -1
  91. package/lib/component/utils.js.map +1 -1
  92. package/lib/composition/facetRect.js +2 -4
  93. package/lib/composition/facetRect.js.map +1 -1
  94. package/lib/composition/repeatMatrix.js +2 -2
  95. package/lib/composition/repeatMatrix.js.map +1 -1
  96. package/lib/interaction/action/service/legendItemSelection.js.map +1 -1
  97. package/lib/interaction/action/transformer/setItemState.js.map +1 -1
  98. package/lib/mark/cell.js +1 -1
  99. package/lib/mark/pack.js +2 -2
  100. package/lib/mark/pack.js.map +1 -1
  101. package/lib/mark/sankey.js +1 -0
  102. package/lib/mark/sankey.js.map +1 -1
  103. package/lib/mark/treemap.js +2 -2
  104. package/lib/mark/treemap.js.map +1 -1
  105. package/lib/mark/wordCloud.js +2 -2
  106. package/lib/mark/wordCloud.js.map +1 -1
  107. package/lib/shape/area/curve.js +2 -9
  108. package/lib/shape/area/curve.js.map +1 -1
  109. package/lib/shape/interval/color.js +2 -2
  110. package/lib/shape/interval/color.js.map +1 -1
  111. package/lib/shape/line/curve.js +21 -10
  112. package/lib/shape/line/curve.js.map +1 -1
  113. package/lib/shape/line/line.js +5 -1
  114. package/lib/shape/line/line.js.map +1 -1
  115. package/lib/shape/line/smooth.js +5 -1
  116. package/lib/shape/line/smooth.js.map +1 -1
  117. package/lib/shape/text/advance.js +2 -2
  118. package/lib/shape/text/advance.js.map +1 -1
  119. package/lib/shape/utils.d.ts +1 -0
  120. package/lib/shape/utils.js +9 -1
  121. package/lib/shape/utils.js.map +1 -1
  122. package/lib/spec/geometry.d.ts +2 -2
  123. package/lib/spec/transform.d.ts +10 -2
  124. package/lib/stdlib/index.js +1 -1
  125. package/lib/stdlib/index.js.map +1 -1
  126. package/lib/theme/dark.js +78 -65
  127. package/lib/theme/dark.js.map +1 -1
  128. package/lib/theme/light.js +84 -74
  129. package/lib/theme/light.js.map +1 -1
  130. package/lib/transform/groupN.js +2 -0
  131. package/lib/transform/groupN.js.map +1 -1
  132. package/lib/transform/index.d.ts +8 -6
  133. package/lib/transform/index.js +9 -7
  134. package/lib/transform/index.js.map +1 -1
  135. package/lib/transform/sample.d.ts +8 -0
  136. package/lib/transform/sample.js +52 -0
  137. package/lib/transform/sample.js.map +1 -0
  138. package/lib/transform/{Select.d.ts → select.d.ts} +0 -0
  139. package/lib/transform/{Select.js → select.js} +1 -1
  140. package/lib/transform/{Select.js.map → select.js.map} +1 -1
  141. package/lib/transform/{SelectX.d.ts → selectX.d.ts} +0 -0
  142. package/lib/transform/{SelectX.js → selectX.js} +1 -1
  143. package/lib/transform/{SelectX.js.map → selectX.js.map} +1 -1
  144. package/lib/transform/{SelectY.d.ts → selectY.d.ts} +0 -0
  145. package/lib/transform/{SelectY.js → selectY.js} +1 -1
  146. package/lib/transform/{SelectY.js.map → selectY.js.map} +1 -1
  147. package/lib/transform/sort.d.ts +1 -1
  148. package/lib/transform/sort.js +38 -20
  149. package/lib/transform/sort.js.map +1 -1
  150. package/package.json +3 -3
  151. package/src/animation/morphing.ts +12 -8
  152. package/src/api/chart.ts +2 -5
  153. package/src/component/axis.ts +233 -310
  154. package/src/component/legendCategory.ts +52 -68
  155. package/src/component/legendContinuous.ts +24 -25
  156. package/src/component/utils.ts +4 -0
  157. package/src/composition/facetRect.ts +2 -4
  158. package/src/composition/repeatMatrix.ts +2 -2
  159. package/src/interaction/action/service/legendItemSelection.ts +1 -2
  160. package/src/interaction/action/transformer/setItemState.ts +2 -3
  161. package/src/mark/cell.ts +1 -1
  162. package/src/mark/pack.ts +1 -0
  163. package/src/mark/sankey.ts +1 -0
  164. package/src/mark/treemap.ts +1 -0
  165. package/src/mark/wordCloud.ts +1 -0
  166. package/src/shape/area/curve.ts +7 -9
  167. package/src/shape/interval/color.ts +7 -7
  168. package/src/shape/line/curve.ts +27 -12
  169. package/src/shape/line/line.ts +6 -2
  170. package/src/shape/line/smooth.ts +11 -2
  171. package/src/shape/text/advance.ts +2 -2
  172. package/src/shape/utils.ts +8 -1
  173. package/src/spec/geometry.ts +2 -1
  174. package/src/spec/transform.ts +10 -1
  175. package/src/stdlib/index.ts +2 -0
  176. package/src/theme/dark.ts +78 -66
  177. package/src/theme/light.ts +84 -75
  178. package/src/transform/groupN.ts +2 -0
  179. package/src/transform/index.ts +8 -6
  180. package/src/transform/sample.ts +45 -0
  181. package/src/transform/sort.ts +53 -21
@@ -0,0 +1,45 @@
1
+ import { max } from 'd3-array';
2
+ import { TransformComponent as TC, G2Mark, Primitive } from '../runtime';
3
+ import { SampleTransform } from '../spec';
4
+ import { createGroups } from './utils/order';
5
+ import { GroupN } from './groupN';
6
+
7
+ export type SampleOptions = Omit<SampleTransform, 'type'>;
8
+
9
+ /**
10
+ * Split the array into frame with each frameSize.
11
+ */
12
+ function getFrames(I: Primitive[], frameSize: number) {
13
+ const size = I.length;
14
+ const frames = [];
15
+ let i = 0;
16
+ while (i < size) {
17
+ frames.push(I.slice(i, (i += frameSize)));
18
+ }
19
+ return frames;
20
+ }
21
+
22
+ /**
23
+ * The sample transform groups marks with specified groupBy fields, and
24
+ * sample data for each group when data.length >= threshold(default = 2000).
25
+ */
26
+ export const Sample: TC<SampleOptions> = (options = {}) => {
27
+ const { groupBy: by, thresholds = 2000, ...rest } = options;
28
+
29
+ const groupBy = (I, mark) => {
30
+ const groups = createGroups(by, I, mark);
31
+ // Skip
32
+ if (groups.every((g) => g.length <= thresholds)) return null;
33
+
34
+ return groups.flatMap((g) => {
35
+ // Keep more data as possible.
36
+ // After sampled, the length of each group.
37
+ const frameSize = Math.max(1, Math.floor(g.length / thresholds));
38
+ const frames = getFrames(g, frameSize);
39
+ return frames;
40
+ });
41
+ };
42
+ return GroupN({ ...rest, groupBy });
43
+ };
44
+
45
+ Sample.props = {};
@@ -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