1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.showGrid = exports.getCircleGridItems = exports.getLineGridItems = exports.getGridThemeCfg = void 0;
|
4 | var util_1 = require("@antv/util");
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | function 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 | }
|
16 | exports.getGridThemeCfg = getGridThemeCfg;
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | function getLineGridItems(coordinate, scale, dim, alignTick) {
|
26 | var items = [];
|
27 | var ticks = scale.getTicks();
|
28 | if (coordinate.isPolar) {
|
29 |
|
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 | }
|
62 | exports.getLineGridItems = getLineGridItems;
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | function 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 |
|
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 | }
|
109 | exports.getCircleGridItems = getCircleGridItems;
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 | function 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 | }
|
124 | exports.showGrid = showGrid;
|
125 |
|
\ | No newline at end of file |