-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaybeDefaultX.ts
36 lines (33 loc) · 901 Bytes
/
maybeDefaultX.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { deepMix } from '@antv/util';
import { TransformComponent as TC } from '../runtime';
import { column, isObject } from './utils/helper';
export type MaybeDefaultXOptions = Record<string, never>;
/**
* Add a default encode for rangeX
* when data is just an array
*/
export const MaybeDefaultX: TC<MaybeDefaultXOptions> = () => {
return (I, mark) => {
const { data } = mark;
if (
Array.isArray(data) &&
(data.every(Array.isArray) || !data.some(isObject))
) {
const extractX = (data, index: number) =>
Array.isArray(data[0])
? data.map((item) => item[index])
: [data[index]];
return [
I,
deepMix({}, mark, {
encode: {
x: column(extractX(data, 0)),
x1: column(extractX(data, 1)),
},
}),
];
}
return [I, mark];
};
};
MaybeDefaultX.props = {};