UNPKG

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