@antv/g2 5.1.23 → 5.2.1
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 +6 -5
- package/README.zh-CN.md +2 -1
- package/dist/g2.lite.min.js +1 -1
- package/dist/g2.min.js +1 -1
- package/esm/api/runtime.d.ts +1 -0
- package/esm/api/runtime.js +2 -1
- package/esm/api/runtime.js.map +1 -1
- package/esm/component/slider.js +2 -1
- package/esm/component/slider.js.map +1 -1
- package/esm/data/utils/d3-cloud/index.js +4 -2
- package/esm/data/utils/d3-cloud/index.js.map +1 -1
- package/esm/data/wordCloud.d.ts +7 -0
- package/esm/data/wordCloud.js +5 -2
- package/esm/data/wordCloud.js.map +1 -1
- package/esm/interaction/tooltip.d.ts +2 -2
- package/esm/interaction/tooltip.js +47 -28
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/runtime/coordinate.js +5 -1
- package/esm/runtime/coordinate.js.map +1 -1
- package/esm/runtime/mark.d.ts +1 -1
- package/esm/runtime/mark.js +1 -2
- package/esm/runtime/mark.js.map +1 -1
- package/esm/runtime/plot.d.ts +2 -2
- package/esm/runtime/plot.js +35 -28
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/render.js +2 -2
- package/esm/runtime/render.js.map +1 -1
- package/esm/runtime/transform.d.ts +12 -13
- package/esm/runtime/transform.js +1 -1
- package/esm/runtime/transform.js.map +1 -1
- package/esm/runtime/types/data.d.ts +2 -1
- package/esm/runtime/types/transform.d.ts +2 -5
- package/esm/spec/interaction.d.ts +2 -0
- package/esm/transform/diffY.js +1 -1
- package/esm/transform/diffY.js.map +1 -1
- package/esm/transform/dodgeX.js +14 -9
- package/esm/transform/dodgeX.js.map +1 -1
- package/esm/transform/stackY.js +2 -1
- package/esm/transform/stackY.js.map +1 -1
- package/esm/transform/utils/order.d.ts +1 -1
- package/esm/transform/utils/order.js +1 -1
- package/esm/transform/utils/order.js.map +1 -1
- package/lib/api/runtime.d.ts +1 -0
- package/lib/api/runtime.js +2 -1
- package/lib/api/runtime.js.map +1 -1
- package/lib/component/slider.js +2 -1
- package/lib/component/slider.js.map +1 -1
- package/lib/data/utils/d3-cloud/index.js +4 -2
- package/lib/data/utils/d3-cloud/index.js.map +1 -1
- package/lib/data/wordCloud.d.ts +7 -0
- package/lib/data/wordCloud.js +5 -2
- package/lib/data/wordCloud.js.map +1 -1
- package/lib/interaction/tooltip.d.ts +2 -2
- package/lib/interaction/tooltip.js +47 -28
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/runtime/coordinate.js +5 -1
- package/lib/runtime/coordinate.js.map +1 -1
- package/lib/runtime/mark.d.ts +1 -1
- package/lib/runtime/mark.js +1 -2
- package/lib/runtime/mark.js.map +1 -1
- package/lib/runtime/plot.d.ts +2 -2
- package/lib/runtime/plot.js +35 -28
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/render.js +2 -2
- package/lib/runtime/render.js.map +1 -1
- package/lib/runtime/transform.d.ts +12 -13
- package/lib/runtime/transform.js +1 -1
- package/lib/runtime/transform.js.map +1 -1
- package/lib/runtime/types/data.d.ts +2 -1
- package/lib/runtime/types/transform.d.ts +2 -5
- package/lib/spec/interaction.d.ts +2 -0
- package/lib/transform/diffY.js +1 -1
- package/lib/transform/diffY.js.map +1 -1
- package/lib/transform/dodgeX.js +14 -9
- package/lib/transform/dodgeX.js.map +1 -1
- package/lib/transform/stackY.js +2 -1
- package/lib/transform/stackY.js.map +1 -1
- package/lib/transform/utils/order.d.ts +1 -1
- package/lib/transform/utils/order.js +1 -1
- package/lib/transform/utils/order.js.map +1 -1
- package/package.json +2 -2
- package/src/api/runtime.ts +4 -1
- package/src/component/slider.ts +2 -1
- package/src/data/utils/d3-cloud/index.ts +6 -2
- package/src/data/wordCloud.ts +14 -2
- package/src/interaction/tooltip.ts +50 -24
- package/src/runtime/coordinate.ts +6 -1
- package/src/runtime/mark.ts +4 -9
- package/src/runtime/plot.ts +36 -39
- package/src/runtime/render.ts +3 -4
- package/src/runtime/transform.ts +13 -14
- package/src/runtime/types/data.ts +3 -1
- package/src/runtime/types/transform.ts +2 -6
- package/src/spec/interaction.ts +2 -0
- package/src/transform/diffY.ts +2 -2
- package/src/transform/dodgeX.ts +16 -10
- package/src/transform/stackY.ts +1 -1
- package/src/transform/utils/order.ts +4 -2
package/src/runtime/transform.ts
CHANGED
|
@@ -12,15 +12,14 @@ import { isFullTooltip } from '../utils/mark';
|
|
|
12
12
|
import { useLibrary } from './library';
|
|
13
13
|
import { createColumnOf } from './mark';
|
|
14
14
|
import { Data, DataComponent } from './types/data';
|
|
15
|
-
import { G2Mark, G2DataOptions } from './types/options';
|
|
16
|
-
import { TransformContext } from './types/transform';
|
|
15
|
+
import { G2Mark, G2DataOptions, G2Context } from './types/options';
|
|
17
16
|
import { isPosition } from './scale';
|
|
18
17
|
|
|
19
18
|
// @todo Add more defaults.
|
|
20
19
|
export function applyDefaults(
|
|
21
20
|
I: number[],
|
|
22
21
|
mark: G2Mark,
|
|
23
|
-
context:
|
|
22
|
+
context: G2Context,
|
|
24
23
|
): [number[], G2Mark] {
|
|
25
24
|
const { encode = {}, scale = {}, transform = [], ...rest } = mark;
|
|
26
25
|
return [I, { ...rest, encode, scale, transform }];
|
|
@@ -29,7 +28,7 @@ export function applyDefaults(
|
|
|
29
28
|
export async function applyDataTransform(
|
|
30
29
|
I: number[],
|
|
31
30
|
mark: G2Mark,
|
|
32
|
-
context:
|
|
31
|
+
context: G2Context,
|
|
33
32
|
): Promise<[number[], G2Mark]> {
|
|
34
33
|
const { library } = context;
|
|
35
34
|
const { data } = mark;
|
|
@@ -40,7 +39,7 @@ export async function applyDataTransform(
|
|
|
40
39
|
const descriptor = normalizedDataSource(data);
|
|
41
40
|
const { transform: T = [], ...connector } = descriptor;
|
|
42
41
|
const transform = [connector, ...T];
|
|
43
|
-
const transformFunctions = transform.map(useData);
|
|
42
|
+
const transformFunctions = transform.map((t) => useData(t, context));
|
|
44
43
|
const transformedData = await composeAsync(transformFunctions)(data);
|
|
45
44
|
|
|
46
45
|
// Maintain the consistency of shape between input and output data.
|
|
@@ -62,7 +61,7 @@ export async function applyDataTransform(
|
|
|
62
61
|
export function flatEncode(
|
|
63
62
|
I: number[],
|
|
64
63
|
mark: G2Mark,
|
|
65
|
-
context:
|
|
64
|
+
context: G2Context,
|
|
66
65
|
): [number[], G2Mark] {
|
|
67
66
|
const { encode } = mark;
|
|
68
67
|
if (!encode) return [I, mark];
|
|
@@ -83,7 +82,7 @@ export function flatEncode(
|
|
|
83
82
|
export function inferChannelsType(
|
|
84
83
|
I: number[],
|
|
85
84
|
mark: G2Mark,
|
|
86
|
-
context:
|
|
85
|
+
context: G2Context,
|
|
87
86
|
): [number[], G2Mark] {
|
|
88
87
|
const { encode, data } = mark;
|
|
89
88
|
if (!encode) return [I, mark];
|
|
@@ -98,7 +97,7 @@ export function inferChannelsType(
|
|
|
98
97
|
export function maybeVisualChannel(
|
|
99
98
|
I: number[],
|
|
100
99
|
mark: G2Mark,
|
|
101
|
-
context:
|
|
100
|
+
context: G2Context,
|
|
102
101
|
): [number[], G2Mark] {
|
|
103
102
|
const { encode } = mark;
|
|
104
103
|
if (!encode) return [I, mark];
|
|
@@ -113,7 +112,7 @@ export function maybeVisualChannel(
|
|
|
113
112
|
export function extractColumns(
|
|
114
113
|
I: number[],
|
|
115
114
|
mark: G2Mark,
|
|
116
|
-
context:
|
|
115
|
+
context: G2Context,
|
|
117
116
|
): [number[], G2Mark] {
|
|
118
117
|
const { encode, data } = mark;
|
|
119
118
|
if (!encode) return [I, mark];
|
|
@@ -129,7 +128,7 @@ export function extractColumns(
|
|
|
129
128
|
export function normalizeTooltip(
|
|
130
129
|
I: number[],
|
|
131
130
|
mark: G2Mark,
|
|
132
|
-
context:
|
|
131
|
+
context: G2Context,
|
|
133
132
|
): [number[], G2Mark] {
|
|
134
133
|
const { tooltip = {} } = mark;
|
|
135
134
|
if (isUnset(tooltip)) return [I, mark];
|
|
@@ -145,7 +144,7 @@ export function normalizeTooltip(
|
|
|
145
144
|
export function extractTooltip(
|
|
146
145
|
I: number[],
|
|
147
146
|
mark: G2Mark,
|
|
148
|
-
context:
|
|
147
|
+
context: G2Context,
|
|
149
148
|
): [number[], G2Mark] {
|
|
150
149
|
const { data, encode, tooltip = {} } = mark;
|
|
151
150
|
if (isUnset(tooltip)) return [I, mark];
|
|
@@ -212,7 +211,7 @@ export function extractTooltip(
|
|
|
212
211
|
export function maybeArrayField(
|
|
213
212
|
I: number[],
|
|
214
213
|
mark: G2Mark,
|
|
215
|
-
context:
|
|
214
|
+
context: G2Context,
|
|
216
215
|
): [number[], G2Mark] {
|
|
217
216
|
const { encode, ...rest } = mark;
|
|
218
217
|
if (!encode) return [I, mark];
|
|
@@ -250,7 +249,7 @@ export function maybeArrayField(
|
|
|
250
249
|
export function addGuideToScale(
|
|
251
250
|
I: number[],
|
|
252
251
|
mark: G2Mark,
|
|
253
|
-
context:
|
|
252
|
+
context: G2Context,
|
|
254
253
|
): [number[], G2Mark] {
|
|
255
254
|
const { axis = {}, legend = {}, slider = {}, scrollbar = {} } = mark;
|
|
256
255
|
const normalize = (guide: boolean | Record<string, any>, channel: string) => {
|
|
@@ -298,7 +297,7 @@ export function addGuideToScale(
|
|
|
298
297
|
export function maybeNonAnimate(
|
|
299
298
|
I: number[],
|
|
300
299
|
mark: G2Mark,
|
|
301
|
-
context:
|
|
300
|
+
context: G2Context,
|
|
302
301
|
): [number[], G2Mark] {
|
|
303
302
|
const { animate } = mark;
|
|
304
303
|
if (animate || animate === undefined) return [I, mark];
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { G2Context } from './options';
|
|
2
|
+
|
|
1
3
|
export type DataOptions = Record<string, any>;
|
|
2
4
|
|
|
3
5
|
export type DataProps = Record<string, never>;
|
|
4
6
|
|
|
5
7
|
export type DataComponent<O extends DataOptions = DataOptions> = {
|
|
6
|
-
(options?: O): Data;
|
|
8
|
+
(options?: O, context?: G2Context): Data;
|
|
7
9
|
props: DataProps;
|
|
8
10
|
};
|
|
9
11
|
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { ColumnValue, NormalizedEncodeSpec } from './encode';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export type TransformContext = {
|
|
5
|
-
library: G2Library;
|
|
6
|
-
};
|
|
2
|
+
import { G2Context, G2Mark } from './options';
|
|
7
3
|
|
|
8
4
|
export type TransformOptions = Record<string, any>;
|
|
9
5
|
|
|
@@ -18,7 +14,7 @@ export type TransformComponent<O extends TransformOptions = TransformOptions> =
|
|
|
18
14
|
export type Transform = (
|
|
19
15
|
I: number[],
|
|
20
16
|
mark: G2Mark,
|
|
21
|
-
context:
|
|
17
|
+
context: G2Context,
|
|
22
18
|
) => [number[], G2Mark] | Promise<[number[], G2Mark]>;
|
|
23
19
|
|
|
24
20
|
export type TransformSpec = {
|
package/src/spec/interaction.ts
CHANGED
|
@@ -177,6 +177,8 @@ export type TooltipInteraction = {
|
|
|
177
177
|
crosshairs?: boolean;
|
|
178
178
|
marker?: boolean;
|
|
179
179
|
groupName?: boolean;
|
|
180
|
+
disableNative?: boolean;
|
|
181
|
+
offset?: [number, number];
|
|
180
182
|
position?: TooltipStyleProps['position'];
|
|
181
183
|
bounding?: BBox;
|
|
182
184
|
mount?: string | HTMLElement;
|
package/src/transform/diffY.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { deepMix } from '@antv/util';
|
|
|
2
2
|
import { TransformComponent as TC } from '../runtime';
|
|
3
3
|
import { DiffYTransform } from '../spec';
|
|
4
4
|
import { column, columnOf, maybeColumnOf } from './utils/helper';
|
|
5
|
-
import {
|
|
5
|
+
import { createGroups } from './utils/order';
|
|
6
6
|
|
|
7
7
|
export type DiffYOptions = Omit<DiffYTransform, 'type'>;
|
|
8
8
|
|
|
@@ -34,7 +34,7 @@ export const DiffY: TC<DiffYOptions> = (options = {}) => {
|
|
|
34
34
|
// Get the max Y of current group with current Y exclude.
|
|
35
35
|
const max = Math.max(...YG.filter((_, _i) => _i !== idx));
|
|
36
36
|
// Diff Y value.
|
|
37
|
-
newY1[i] = Y[i] > max ? max : Y[i];
|
|
37
|
+
newY1[i] = +Y[i] > max ? max : Y[i];
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
package/src/transform/dodgeX.ts
CHANGED
|
@@ -24,14 +24,26 @@ export const DodgeX: TC<DodgeXOptions> = (options = {}) => {
|
|
|
24
24
|
const [Y] = columnOf(encode, 'y');
|
|
25
25
|
const [S] = maybeColumnOf(encode, 'series', 'color');
|
|
26
26
|
const domainSeries = domainOf(S, scaleSeries);
|
|
27
|
+
const newMark = deepMix({}, mark, {
|
|
28
|
+
scale: {
|
|
29
|
+
series: {
|
|
30
|
+
domain: domainSeries,
|
|
31
|
+
paddingInner: padding,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
});
|
|
27
35
|
|
|
28
36
|
// Create groups and apply specified order for each group.
|
|
29
37
|
const groups = createGroups(groupBy, I, mark);
|
|
30
38
|
const createComparator = normalizeComparator(orderBy);
|
|
39
|
+
|
|
40
|
+
if (!createComparator) {
|
|
41
|
+
return [I, deepMix(newMark, { encode: { series: column(S) } })];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Sort and Update series for each mark related to series domain.
|
|
31
45
|
const comparator = createComparator(data, Y, S);
|
|
32
46
|
if (comparator) applyOrder(groups, comparator);
|
|
33
|
-
|
|
34
|
-
// Update series for each mark related to series domain.
|
|
35
47
|
const newS = new Array(I.length);
|
|
36
48
|
for (const G of groups) {
|
|
37
49
|
if (reverse) G.reverse();
|
|
@@ -42,15 +54,9 @@ export const DodgeX: TC<DodgeXOptions> = (options = {}) => {
|
|
|
42
54
|
|
|
43
55
|
return [
|
|
44
56
|
I,
|
|
45
|
-
deepMix(
|
|
46
|
-
scale: {
|
|
47
|
-
series: {
|
|
48
|
-
domain: domainSeries,
|
|
49
|
-
paddingInner: padding,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
57
|
+
deepMix(newMark, {
|
|
52
58
|
encode: {
|
|
53
|
-
series: column(newS),
|
|
59
|
+
series: column(orderBy ? newS : S),
|
|
54
60
|
},
|
|
55
61
|
}),
|
|
56
62
|
];
|
package/src/transform/stackY.ts
CHANGED
|
@@ -35,7 +35,7 @@ export const StackY: TC<StackYOptions> = (options = {}) => {
|
|
|
35
35
|
|
|
36
36
|
// Create groups and apply specified order for each group.
|
|
37
37
|
const groups = createGroups(groupBy, I, mark);
|
|
38
|
-
const createComparator = normalizeComparator(orderBy);
|
|
38
|
+
const createComparator = normalizeComparator(orderBy) ?? (() => null);
|
|
39
39
|
const comparator = createComparator(data, Y, S);
|
|
40
40
|
if (comparator) applyOrder(groups, comparator);
|
|
41
41
|
|
|
@@ -34,14 +34,16 @@ export function createGroups(
|
|
|
34
34
|
return Array.from(group(I, key).values());
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export function normalizeComparator(
|
|
37
|
+
export function normalizeComparator(
|
|
38
|
+
order: Order,
|
|
39
|
+
): IndexComparatorFactory | null {
|
|
38
40
|
if (Array.isArray(order)) return createFieldsOrder(order);
|
|
39
41
|
if (typeof order === 'function') return createFunctionOrder(order);
|
|
40
42
|
if (order === 'series') return createSeriesOrder;
|
|
41
43
|
if (order === 'value') return createValueOrder;
|
|
42
44
|
if (order === 'sum') return createSumOrder;
|
|
43
45
|
if (order === 'maxIndex') return createMaxIndexOrder;
|
|
44
|
-
return
|
|
46
|
+
return null;
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
export function applyOrder(groups: number[][], comparator: IndexComparator) {
|