1 | import { 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 | */
|
9 | export 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 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | export function getLineGridItems(coordinate, scale, dim, alignTick) {
|
22 | var items = [];
|
23 | var ticks = scale.getTicks();
|
24 | if (coordinate.isPolar) {
|
25 |
|
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 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | export 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 |
|
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 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | export 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 |