@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.
- package/README.md +29 -27
- package/dist/g2-lite.min.js +2 -2
- package/dist/g2.min.js +2 -2
- package/esm/animation/morphing.js +10 -8
- package/esm/animation/morphing.js.map +1 -1
- package/esm/api/chart.js +2 -5
- package/esm/api/chart.js.map +1 -1
- package/esm/component/axis.d.ts +1 -2
- package/esm/component/axis.js +81 -198
- package/esm/component/axis.js.map +1 -1
- package/esm/component/legendCategory.d.ts +0 -1
- package/esm/component/legendCategory.js +36 -49
- package/esm/component/legendCategory.js.map +1 -1
- package/esm/component/legendContinuous.js +29 -19
- package/esm/component/legendContinuous.js.map +1 -1
- package/esm/component/utils.d.ts +1 -0
- package/esm/component/utils.js +3 -0
- package/esm/component/utils.js.map +1 -1
- package/esm/composition/facetRect.js +2 -4
- package/esm/composition/facetRect.js.map +1 -1
- package/esm/composition/repeatMatrix.js +2 -2
- package/esm/composition/repeatMatrix.js.map +1 -1
- package/esm/interaction/action/service/legendItemSelection.js.map +1 -1
- package/esm/interaction/action/transformer/setItemState.js.map +1 -1
- package/esm/mark/cell.js +1 -1
- package/esm/mark/pack.js +2 -2
- package/esm/mark/pack.js.map +1 -1
- package/esm/mark/sankey.js +1 -0
- package/esm/mark/sankey.js.map +1 -1
- package/esm/mark/treemap.js +2 -2
- package/esm/mark/treemap.js.map +1 -1
- package/esm/mark/wordCloud.js +2 -2
- package/esm/mark/wordCloud.js.map +1 -1
- package/esm/shape/area/curve.js +2 -9
- package/esm/shape/area/curve.js.map +1 -1
- package/esm/shape/interval/color.js +2 -2
- package/esm/shape/interval/color.js.map +1 -1
- package/esm/shape/line/curve.js +23 -12
- package/esm/shape/line/curve.js.map +1 -1
- package/esm/shape/line/line.js +6 -2
- package/esm/shape/line/line.js.map +1 -1
- package/esm/shape/line/smooth.js +6 -2
- package/esm/shape/line/smooth.js.map +1 -1
- package/esm/shape/text/advance.js +2 -2
- package/esm/shape/text/advance.js.map +1 -1
- package/esm/shape/utils.d.ts +1 -0
- package/esm/shape/utils.js +8 -1
- package/esm/shape/utils.js.map +1 -1
- package/esm/spec/geometry.d.ts +2 -2
- package/esm/spec/transform.d.ts +10 -2
- package/esm/stdlib/index.js +2 -2
- package/esm/stdlib/index.js.map +1 -1
- package/esm/theme/dark.js +78 -65
- package/esm/theme/dark.js.map +1 -1
- package/esm/theme/light.js +84 -74
- package/esm/theme/light.js.map +1 -1
- package/esm/transform/groupN.js +2 -0
- package/esm/transform/groupN.js.map +1 -1
- package/esm/transform/index.d.ts +8 -6
- package/esm/transform/index.js +4 -3
- package/esm/transform/index.js.map +1 -1
- package/esm/transform/sample.d.ts +8 -0
- package/esm/transform/sample.js +48 -0
- package/esm/transform/sample.js.map +1 -0
- package/esm/transform/{Select.d.ts → select.d.ts} +0 -0
- package/esm/transform/{Select.js → select.js} +1 -1
- package/esm/transform/{Select.js.map → select.js.map} +1 -1
- package/esm/transform/{SelectX.d.ts → selectX.d.ts} +0 -0
- package/esm/transform/{SelectX.js → selectX.js} +1 -1
- package/esm/transform/{SelectX.js.map → selectX.js.map} +1 -1
- package/esm/transform/{SelectY.d.ts → selectY.d.ts} +0 -0
- package/esm/transform/{SelectY.js → selectY.js} +1 -1
- package/esm/transform/{SelectY.js.map → selectY.js.map} +1 -1
- package/esm/transform/sort.d.ts +1 -1
- package/esm/transform/sort.js +39 -21
- package/esm/transform/sort.js.map +1 -1
- package/lib/animation/morphing.js +10 -8
- package/lib/animation/morphing.js.map +1 -1
- package/lib/api/chart.js +2 -5
- package/lib/api/chart.js.map +1 -1
- package/lib/component/axis.d.ts +1 -2
- package/lib/component/axis.js +80 -197
- package/lib/component/axis.js.map +1 -1
- package/lib/component/legendCategory.d.ts +0 -1
- package/lib/component/legendCategory.js +36 -49
- package/lib/component/legendCategory.js.map +1 -1
- package/lib/component/legendContinuous.js +29 -19
- package/lib/component/legendContinuous.js.map +1 -1
- package/lib/component/utils.d.ts +1 -0
- package/lib/component/utils.js +5 -1
- package/lib/component/utils.js.map +1 -1
- package/lib/composition/facetRect.js +2 -4
- package/lib/composition/facetRect.js.map +1 -1
- package/lib/composition/repeatMatrix.js +2 -2
- package/lib/composition/repeatMatrix.js.map +1 -1
- package/lib/interaction/action/service/legendItemSelection.js.map +1 -1
- package/lib/interaction/action/transformer/setItemState.js.map +1 -1
- package/lib/mark/cell.js +1 -1
- package/lib/mark/pack.js +2 -2
- package/lib/mark/pack.js.map +1 -1
- package/lib/mark/sankey.js +1 -0
- package/lib/mark/sankey.js.map +1 -1
- package/lib/mark/treemap.js +2 -2
- package/lib/mark/treemap.js.map +1 -1
- package/lib/mark/wordCloud.js +2 -2
- package/lib/mark/wordCloud.js.map +1 -1
- package/lib/shape/area/curve.js +2 -9
- package/lib/shape/area/curve.js.map +1 -1
- package/lib/shape/interval/color.js +2 -2
- package/lib/shape/interval/color.js.map +1 -1
- package/lib/shape/line/curve.js +21 -10
- package/lib/shape/line/curve.js.map +1 -1
- package/lib/shape/line/line.js +5 -1
- package/lib/shape/line/line.js.map +1 -1
- package/lib/shape/line/smooth.js +5 -1
- package/lib/shape/line/smooth.js.map +1 -1
- package/lib/shape/text/advance.js +2 -2
- package/lib/shape/text/advance.js.map +1 -1
- package/lib/shape/utils.d.ts +1 -0
- package/lib/shape/utils.js +9 -1
- package/lib/shape/utils.js.map +1 -1
- package/lib/spec/geometry.d.ts +2 -2
- package/lib/spec/transform.d.ts +10 -2
- package/lib/stdlib/index.js +1 -1
- package/lib/stdlib/index.js.map +1 -1
- package/lib/theme/dark.js +78 -65
- package/lib/theme/dark.js.map +1 -1
- package/lib/theme/light.js +84 -74
- package/lib/theme/light.js.map +1 -1
- package/lib/transform/groupN.js +2 -0
- package/lib/transform/groupN.js.map +1 -1
- package/lib/transform/index.d.ts +8 -6
- package/lib/transform/index.js +9 -7
- package/lib/transform/index.js.map +1 -1
- package/lib/transform/sample.d.ts +8 -0
- package/lib/transform/sample.js +52 -0
- package/lib/transform/sample.js.map +1 -0
- package/lib/transform/{Select.d.ts → select.d.ts} +0 -0
- package/lib/transform/{Select.js → select.js} +1 -1
- package/lib/transform/{Select.js.map → select.js.map} +1 -1
- package/lib/transform/{SelectX.d.ts → selectX.d.ts} +0 -0
- package/lib/transform/{SelectX.js → selectX.js} +1 -1
- package/lib/transform/{SelectX.js.map → selectX.js.map} +1 -1
- package/lib/transform/{SelectY.d.ts → selectY.d.ts} +0 -0
- package/lib/transform/{SelectY.js → selectY.js} +1 -1
- package/lib/transform/{SelectY.js.map → selectY.js.map} +1 -1
- package/lib/transform/sort.d.ts +1 -1
- package/lib/transform/sort.js +38 -20
- package/lib/transform/sort.js.map +1 -1
- package/package.json +3 -3
- package/src/animation/morphing.ts +12 -8
- package/src/api/chart.ts +2 -5
- package/src/component/axis.ts +233 -310
- package/src/component/legendCategory.ts +52 -68
- package/src/component/legendContinuous.ts +24 -25
- package/src/component/utils.ts +4 -0
- package/src/composition/facetRect.ts +2 -4
- package/src/composition/repeatMatrix.ts +2 -2
- package/src/interaction/action/service/legendItemSelection.ts +1 -2
- package/src/interaction/action/transformer/setItemState.ts +2 -3
- package/src/mark/cell.ts +1 -1
- package/src/mark/pack.ts +1 -0
- package/src/mark/sankey.ts +1 -0
- package/src/mark/treemap.ts +1 -0
- package/src/mark/wordCloud.ts +1 -0
- package/src/shape/area/curve.ts +7 -9
- package/src/shape/interval/color.ts +7 -7
- package/src/shape/line/curve.ts +27 -12
- package/src/shape/line/line.ts +6 -2
- package/src/shape/line/smooth.ts +11 -2
- package/src/shape/text/advance.ts +2 -2
- package/src/shape/utils.ts +8 -1
- package/src/spec/geometry.ts +2 -1
- package/src/spec/transform.ts +10 -1
- package/src/stdlib/index.ts +2 -0
- package/src/theme/dark.ts +78 -66
- package/src/theme/light.ts +84 -75
- package/src/transform/groupN.ts +2 -0
- package/src/transform/index.ts +8 -6
- package/src/transform/sample.ts +45 -0
- 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 = {};
|
package/src/transform/sort.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { deepMix } from '@antv/util';
|
|
2
|
-
import {
|
|
3
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
|