-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaxisRadar.ts
72 lines (65 loc) · 1.88 KB
/
axisRadar.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
67
68
69
70
71
72
import { Coordinate } from '@antv/coord';
import { G2Theme, GuideComponentComponent as GCC, Scale } from '../runtime';
import { angleOf } from '../utils/coordinate';
import { AxisOptions, LinearAxis } from './axis';
export type AxisRadarOptions = AxisOptions & {
radar: {
count: number;
index: number;
};
};
function inferTitleTransform(orientation: number) {
const internalOrientation = orientation % (Math.PI * 2);
if (internalOrientation === Math.PI / 2) {
return { titleTransform: 'translate(0, 50%)' };
}
if (internalOrientation > -Math.PI / 2 && internalOrientation < Math.PI / 2) {
return { titleTransform: 'translate(50%, 0)' };
}
if (
internalOrientation > Math.PI / 2 &&
internalOrientation < (Math.PI * 3) / 2
) {
return { titleTransform: 'translate(-50%, 0)' };
}
return {};
}
function inferAxisStyle(
options: AxisRadarOptions,
theme: G2Theme,
coordinate: Coordinate,
scales: Scale[],
) {
const { radar } = options;
const [scale] = scales;
const name = scale.getOptions().name;
const [startAngle, endAngle] = angleOf(coordinate);
const { axisRadar: radarTheme = {} } = theme;
return {
...radarTheme,
grid: name === 'position',
gridConnect: 'line',
gridControlAngles: new Array(radar.count).fill(0).map((_, i) => {
const angle = (endAngle - startAngle) / radar.count;
return angle * i;
}),
};
}
export const AxisRadar: GCC<AxisRadarOptions> = (options) => {
const { important = {}, ...restOptions } = options;
return (context) => {
const { theme, coordinate, scales } = context;
return LinearAxis({
...restOptions,
...inferTitleTransform(options.orientation),
important: {
...inferAxisStyle(options, theme, coordinate, scales),
...important,
},
})(context);
};
};
AxisRadar.props = {
...LinearAxis.props,
defaultPosition: 'center',
};