@antv/g2 5.2.11 → 5.2.12
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 +2 -2
- package/README.zh-CN.md +2 -2
- package/dist/g2.lite.min.js +22 -22
- package/dist/g2.min.js +22 -22
- package/esm/animation/scaleInY.js +2 -20
- package/esm/animation/scaleInY.js.map +1 -1
- package/esm/api/runtime.js +2 -0
- package/esm/api/runtime.js.map +1 -1
- package/esm/component/legendCategory.js +5 -1
- package/esm/component/legendCategory.js.map +1 -1
- package/esm/data/utils/arc/arc.d.ts +25 -2
- package/esm/data/utils/arc/arc.js.map +1 -1
- package/esm/data/utils/arc/types.d.ts +27 -2
- package/esm/exports.d.ts +2 -0
- package/esm/exports.js +2 -0
- package/esm/exports.js.map +1 -1
- package/esm/interaction/elementSelect.d.ts +1 -0
- package/esm/interaction/elementSelect.js +31 -2
- package/esm/interaction/elementSelect.js.map +1 -1
- package/esm/interaction/event.d.ts +0 -1
- package/esm/interaction/event.js +2 -13
- package/esm/interaction/event.js.map +1 -1
- package/esm/interaction/legendHighlight.js.map +1 -1
- package/esm/interaction/tooltip.js +7 -34
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/runtime/layout.js +1 -1
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/transform.d.ts +1 -0
- package/esm/runtime/transform.js +2 -1
- package/esm/runtime/transform.js.map +1 -1
- package/esm/spec/interaction.d.ts +1 -0
- package/esm/transform/bin.js.map +1 -1
- package/esm/transform/sort.js +19 -51
- package/esm/transform/sort.js.map +1 -1
- package/esm/utils/helper.d.ts +24 -0
- package/esm/utils/helper.js +76 -0
- package/esm/utils/helper.js.map +1 -1
- package/lib/animation/scaleInY.js +1 -19
- package/lib/animation/scaleInY.js.map +1 -1
- package/lib/api/runtime.js +2 -0
- package/lib/api/runtime.js.map +1 -1
- package/lib/component/legendCategory.js +5 -1
- package/lib/component/legendCategory.js.map +1 -1
- package/lib/data/utils/arc/arc.d.ts +25 -2
- package/lib/data/utils/arc/arc.js.map +1 -1
- package/lib/data/utils/arc/types.d.ts +27 -2
- package/lib/exports.d.ts +2 -0
- package/lib/exports.js +7 -1
- package/lib/exports.js.map +1 -1
- package/lib/interaction/elementSelect.d.ts +1 -0
- package/lib/interaction/elementSelect.js +31 -2
- package/lib/interaction/elementSelect.js.map +1 -1
- package/lib/interaction/event.d.ts +0 -1
- package/lib/interaction/event.js +3 -15
- package/lib/interaction/event.js.map +1 -1
- package/lib/interaction/legendHighlight.js.map +1 -1
- package/lib/interaction/tooltip.js +9 -36
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/transform.d.ts +1 -0
- package/lib/runtime/transform.js +3 -2
- package/lib/runtime/transform.js.map +1 -1
- package/lib/spec/interaction.d.ts +1 -0
- package/lib/transform/bin.js.map +1 -1
- package/lib/transform/sort.js +19 -51
- package/lib/transform/sort.js.map +1 -1
- package/lib/utils/helper.d.ts +24 -0
- package/lib/utils/helper.js +81 -1
- package/lib/utils/helper.js.map +1 -1
- package/package.json +3 -3
- package/src/animation/scaleInY.ts +2 -45
- package/src/api/runtime.ts +3 -0
- package/src/component/legendCategory.ts +9 -1
- package/src/data/utils/arc/arc.ts +5 -5
- package/src/data/utils/arc/types.ts +28 -2
- package/src/exports.ts +3 -0
- package/src/interaction/elementSelect.ts +32 -2
- package/src/interaction/event.ts +2 -15
- package/src/interaction/legendHighlight.ts +4 -2
- package/src/interaction/tooltip.ts +9 -38
- package/src/runtime/layout.ts +15 -2
- package/src/runtime/transform.ts +4 -1
- package/src/spec/interaction.ts +1 -0
- package/src/transform/bin.ts +2 -2
- package/src/transform/sort.ts +20 -42
- package/src/utils/helper.ts +83 -0
package/src/transform/bin.ts
CHANGED
|
@@ -39,7 +39,7 @@ export const Bin: TC<BinOptions> = (options = {}) => {
|
|
|
39
39
|
const channelIndexKey = {};
|
|
40
40
|
|
|
41
41
|
// Group indexes and update channelIndexKey.
|
|
42
|
-
const groupBy = (I, mark) => {
|
|
42
|
+
const groupBy = (I, mark): number[][] => {
|
|
43
43
|
const { encode } = mark;
|
|
44
44
|
const binValues = binChannels.map((channel) => {
|
|
45
45
|
const [V] = columnOf(encode, channel);
|
|
@@ -80,7 +80,7 @@ export const Bin: TC<BinOptions> = (options = {}) => {
|
|
|
80
80
|
|
|
81
81
|
// Group by indexes by channel keys.
|
|
82
82
|
const key = (i: number) => groupKeys.map((key) => key(i)).join('-');
|
|
83
|
-
return Array.from(group(DI, key).values());
|
|
83
|
+
return Array.from(group(DI, key).values()) as number[][];
|
|
84
84
|
};
|
|
85
85
|
|
|
86
86
|
return GroupN({
|
package/src/transform/sort.ts
CHANGED
|
@@ -43,16 +43,6 @@ export type SortOptions = {
|
|
|
43
43
|
| ((I: number[], V: Primitive[]) => Primitive);
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
function sortQuantitative(I, mark, options): [number[], G2Mark] {
|
|
47
|
-
const { reverse, 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
46
|
// If domain is specified, only sort data in the domain.
|
|
57
47
|
function filterIndex(I, values, specifiedDomain): number[] {
|
|
58
48
|
if (!Array.isArray(specifiedDomain)) return I;
|
|
@@ -60,44 +50,32 @@ function filterIndex(I, values, specifiedDomain): number[] {
|
|
|
60
50
|
return I.filter((i) => domain.has(values[i]));
|
|
61
51
|
}
|
|
62
52
|
|
|
63
|
-
function sortOrdinal(I, mark, options): [number[], G2Mark] {
|
|
64
|
-
const { reverse, slice, channel, ...rest } = options;
|
|
65
|
-
const { encode, scale = {} } = mark;
|
|
66
|
-
const domain = scale[channel]?.domain;
|
|
67
|
-
const [T] = columnOf(encode, channel);
|
|
68
|
-
const normalizeReducer = createReducer(channel, rest, encode);
|
|
69
|
-
const SI = filterIndex(I, T, domain);
|
|
70
|
-
const sortedDomain = groupSort(SI, normalizeReducer, (i: number) => T[i]);
|
|
71
|
-
if (reverse) sortedDomain.reverse();
|
|
72
|
-
const s = typeof slice === 'number' ? [0, slice] : slice;
|
|
73
|
-
const slicedDomain = slice ? sortedDomain.slice(...s) : sortedDomain;
|
|
74
|
-
return [
|
|
75
|
-
I,
|
|
76
|
-
deepMix(mark, {
|
|
77
|
-
scale: {
|
|
78
|
-
[channel]: {
|
|
79
|
-
domain: slicedDomain,
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
}),
|
|
83
|
-
];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
53
|
/**
|
|
87
54
|
* Sort marks groups by groups.
|
|
88
55
|
*/
|
|
89
56
|
export const Sort: TC<SortOptions> = (options = {}) => {
|
|
90
|
-
const { reverse = false, slice, channel, ordinal = true, ...rest } = options;
|
|
91
57
|
return (I, mark) => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
58
|
+
const { reverse, slice, channel, by, ordinal = true, reducer } = options;
|
|
59
|
+
const { encode, scale = {} } = mark;
|
|
60
|
+
const domain = scale[channel].domain;
|
|
61
|
+
const [V] = columnOf(encode, by ?? channel);
|
|
62
|
+
const [T] = columnOf(encode, channel);
|
|
63
|
+
const normalizeReducer = createReducer(channel, { by, reducer }, encode);
|
|
64
|
+
const SI = filterIndex(I, T, domain);
|
|
65
|
+
const sortedDomain = groupSort(SI, normalizeReducer, (i: number) => T[i]);
|
|
66
|
+
|
|
67
|
+
// when ordinal is true, do not change the index of the data.
|
|
68
|
+
const sortedI = !ordinal ? sort(I, (i: number) => V[i]) : I;
|
|
69
|
+
if (reverse) {
|
|
70
|
+
!ordinal && sortedI.reverse();
|
|
71
|
+
sortedDomain.reverse();
|
|
99
72
|
}
|
|
100
|
-
|
|
73
|
+
const s = typeof slice === 'number' ? [0, slice] : slice;
|
|
74
|
+
const slicedDomain = slice ? sortedDomain.slice(...s) : sortedDomain;
|
|
75
|
+
return [
|
|
76
|
+
sortedI,
|
|
77
|
+
deepMix(mark, { scale: { [channel]: { domain: slicedDomain } } }),
|
|
78
|
+
];
|
|
101
79
|
};
|
|
102
80
|
};
|
|
103
81
|
|
package/src/utils/helper.ts
CHANGED
|
@@ -1,5 +1,88 @@
|
|
|
1
1
|
import { DisplayObject } from '@antv/g';
|
|
2
2
|
import { lowerFirst, upperFirst, isPlainObject } from '@antv/util';
|
|
3
|
+
import { Band, Base, Constant } from '@antv/scale';
|
|
4
|
+
import { G2Element } from './selection';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @description Get element's ancestor view node.
|
|
8
|
+
* @param elemenet G2 element.
|
|
9
|
+
* @returns Element's ancestor view node.
|
|
10
|
+
*/
|
|
11
|
+
export function getViewFromElement(element: G2Element) {
|
|
12
|
+
let current = element as G2Element;
|
|
13
|
+
while (current) {
|
|
14
|
+
if (current.attributes?.class === 'view') return current;
|
|
15
|
+
current = current.parentNode as G2Element;
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @description Get element's original data.
|
|
22
|
+
* @param elemenet G2 element.
|
|
23
|
+
* @returns The original data of the element.
|
|
24
|
+
*/
|
|
25
|
+
export function dataOf(element: G2Element) {
|
|
26
|
+
const view = getViewFromElement(element);
|
|
27
|
+
const datum = element.__data__;
|
|
28
|
+
const { markKey, index, seriesIndex } = datum;
|
|
29
|
+
const { markState } = view.__data__;
|
|
30
|
+
const selectedMark: any = Array.from(markState.keys()).find(
|
|
31
|
+
(mark) => (mark as any).key === markKey,
|
|
32
|
+
);
|
|
33
|
+
if (!selectedMark) return;
|
|
34
|
+
if (seriesIndex) {
|
|
35
|
+
return seriesIndex.map((i) => selectedMark.data[i]);
|
|
36
|
+
}
|
|
37
|
+
return selectedMark.data[index];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @description Get element's series name.
|
|
42
|
+
* @param elemenet G2 element.
|
|
43
|
+
* @returns The series name of the element.
|
|
44
|
+
*/
|
|
45
|
+
export function seriesOf(elemenet: G2Element): string {
|
|
46
|
+
const viewData = getViewFromElement(elemenet).__data__;
|
|
47
|
+
const { scale } = viewData;
|
|
48
|
+
return groupNameOf(scale, elemenet.__data__);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get group name with view's scale and element's datum.
|
|
53
|
+
*/
|
|
54
|
+
export function groupNameOf(scale: Record<string, Base<any>>, datum) {
|
|
55
|
+
const { color: scaleColor, series: scaleSeries, facet = false } = scale;
|
|
56
|
+
const { color, series } = datum;
|
|
57
|
+
const invertAble = (scale) => {
|
|
58
|
+
return (
|
|
59
|
+
scale &&
|
|
60
|
+
scale.invert &&
|
|
61
|
+
!(scale instanceof Band) &&
|
|
62
|
+
!(scale instanceof Constant)
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
// For non constant color channel.
|
|
66
|
+
if (invertAble(scaleSeries)) {
|
|
67
|
+
const cloned = scaleSeries.clone();
|
|
68
|
+
return cloned.invert(series);
|
|
69
|
+
}
|
|
70
|
+
if (
|
|
71
|
+
series &&
|
|
72
|
+
scaleSeries instanceof Band &&
|
|
73
|
+
scaleSeries.invert(series) !== color &&
|
|
74
|
+
!facet
|
|
75
|
+
) {
|
|
76
|
+
return scaleSeries.invert(series);
|
|
77
|
+
}
|
|
78
|
+
if (invertAble(scaleColor)) {
|
|
79
|
+
const name = scaleColor.invert(color);
|
|
80
|
+
// For threshold scale.
|
|
81
|
+
if (Array.isArray(name)) return null;
|
|
82
|
+
return name;
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
3
86
|
|
|
4
87
|
export function identity<T>(x: T): T {
|
|
5
88
|
return x;
|