UNPKG

3.68 kBJavaScriptView Raw
1import { deepMix, get, map } from '@antv/util';
2/**
3 * @ignore
4 * get the grid theme by type, will mix the common cfg of axis
5 * @param theme
6 * @param direction
7 * @returns theme object
8 */
9export function getGridThemeCfg(theme, direction) {
10 var axisTheme = deepMix({}, get(theme, ['components', 'axis', 'common']), get(theme, ['components', 'axis', direction]));
11 return get(axisTheme, ['grid'], {});
12}
13/**
14 * @ignore
15 * get axis grid items
16 * @param coordinate
17 * @param scale
18 * @param dim
19 * @return items
20 */
21export function getLineGridItems(coordinate, scale, dim, alignTick) {
22 var items = [];
23 var ticks = scale.getTicks();
24 if (coordinate.isPolar) {
25 // 补全 ticks
26 ticks.push({
27 value: 1,
28 text: '',
29 tickValue: '',
30 });
31 }
32 ticks.reduce(function (preTick, currentTick, currentIndex) {
33 var currentValue = currentTick.value;
34 if (alignTick) {
35 items.push({
36 points: [
37 coordinate.convert(dim === 'y' ? { x: 0, y: currentValue } : { x: currentValue, y: 0 }),
38 coordinate.convert(dim === 'y' ? { x: 1, y: currentValue } : { x: currentValue, y: 1 }),
39 ],
40 });
41 }
42 else {
43 if (currentIndex) {
44 var preValue = preTick.value;
45 var middleValue = (preValue + currentValue) / 2;
46 items.push({
47 points: [
48 coordinate.convert(dim === 'y' ? { x: 0, y: middleValue } : { x: middleValue, y: 0 }),
49 coordinate.convert(dim === 'y' ? { x: 1, y: middleValue } : { x: middleValue, y: 1 }),
50 ],
51 });
52 }
53 }
54 return currentTick;
55 }, ticks[0]);
56 return items;
57}
58/**
59 * @ignore
60 * get
61 * @param coordinate
62 * @param xScale
63 * @param yScale
64 * @param dim
65 * @returns items
66 */
67export function getCircleGridItems(coordinate, xScale, yScale, alignTick, dim) {
68 var count = xScale.values.length;
69 var items = [];
70 var ticks = yScale.getTicks();
71 ticks.reduce(function (preTick, currentTick) {
72 var preValue = preTick ? preTick.value : currentTick.value; // 只有一项数据时取当前值
73 var currentValue = currentTick.value;
74 var middleValue = (preValue + currentValue) / 2;
75 if (dim === 'x') {
76 // 如果是 x 轴作为半径轴,那么只需要取圆弧收尾两个即可
77 items.push({
78 points: [
79 coordinate.convert({
80 x: alignTick ? currentValue : middleValue,
81 y: 0,
82 }),
83 coordinate.convert({
84 x: alignTick ? currentValue : middleValue,
85 y: 1,
86 }),
87 ],
88 });
89 }
90 else {
91 items.push({
92 points: map(Array(count + 1), function (__, idx) {
93 return coordinate.convert({
94 x: idx / count,
95 y: alignTick ? currentValue : middleValue,
96 });
97 }),
98 });
99 }
100 return currentTick;
101 }, ticks[0]);
102 return items;
103}
104/**
105 * @ignore
106 * show grid or not
107 * @param axisTheme
108 * @param axisOption
109 */
110export function showGrid(axisTheme, axisOption) {
111 var userGrid = get(axisOption, 'grid');
112 if (userGrid === null) {
113 return false;
114 }
115 var themeGrid = get(axisTheme, 'grid');
116 return !(userGrid === undefined && themeGrid === null);
117}
118//# sourceMappingURL=grid.js.map
\No newline at end of file