/
adaptor.ts
66 lines (57 loc) · 1.43 KB
/
adaptor.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { Params } from '../../core/adaptor';
import { flow, deepAssign } from '../../utils';
import { scale, theme, animation, annotation, tooltip } from '../../adaptor/common';
import { line, point } from '../../adaptor/geometries';
import { adjustYMetaByZero } from '../../utils/data';
import { TinyLineOptions } from './types';
import { X_FIELD, Y_FIELD } from './constants';
/**
* 字段
* @param params
*/
function geometry(params: Params<TinyLineOptions>): Params<TinyLineOptions> {
const { chart, options } = params;
const { data, xAxis, yAxis, color, lineStyle, point: pointMapping } = options;
const seriesData = data.map((y: number, x: number) => {
return { x, y };
});
chart.data(seriesData);
// line geometry 处理
const p = deepAssign({}, params, {
options: {
xField: X_FIELD,
yField: Y_FIELD,
line: {
color,
style: lineStyle,
},
point: pointMapping,
},
});
line(p);
point(p);
chart.axis(false);
chart.legend(false);
// scale
scale(
{
[X_FIELD]: xAxis,
[Y_FIELD]: yAxis,
},
{
[X_FIELD]: {
type: 'cat',
},
[Y_FIELD]: adjustYMetaByZero(seriesData, Y_FIELD),
}
)(params);
return params;
}
/**
* 迷你折线图适配器
* @param chart
* @param options
*/
export function adaptor(params: Params<TinyLineOptions>) {
return flow(geometry, theme, tooltip, animation, annotation())(params);
}