/
style-parser.ts
89 lines (83 loc) · 2.23 KB
/
style-parser.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import * as _ from '@antv/util';
function AxisStyleParser(axisCfg, axis) {
if (axis.line) {
if (axis.line.visible === false) {
axisCfg.line = null;
} else if (axis.line.style) {
axisCfg.line = _.clone(axis.line.style);
}
}
if (axis.title) {
if (axis.title.visible === false) {
axisCfg.showTitle = false;
} else {
if (axis.title.visible === true) {
axisCfg.showTitle = true;
}
if (axisCfg.autoRotate) {
axisCfg.autoRotateTitle = axisCfg.autoRotate;
}
axisCfg.title = _.clone(axis.title);
if (axisCfg.title.style) {
axisCfg.title.textStyle = axisCfg.title.style;
delete axisCfg.title.style;
}
}
}
if (axis.tickLine) {
if (axis.tickLine.visible === false) {
axisCfg.tickLine = null;
} else if (axis.tickLine.style) {
axisCfg.tickLine = _.clone(axis.tickLine.style);
}
}
if (Object.prototype.hasOwnProperty.call(axis, 'autoHideLabel')) {
axisCfg.autoHideLabel = axis.autoHideLabel;
}
if (Object.prototype.hasOwnProperty.call(axis, 'autoRotateLabel')) {
axisCfg.autoRotateLabel = axis.autoRotateLabel;
}
if (axis.label) {
if (axis.label.visible === false) {
axisCfg.label = null;
} else {
const newLabel = _.clone(axis.label);
if (newLabel.style) {
newLabel.textStyle = newLabel.style;
delete newLabel.style;
}
if (axis.label.formatter) {
const textFormatter = axis.label.formatter;
axisCfg.label = (text) => {
newLabel.text = textFormatter(text);
return newLabel;
};
} else {
axisCfg.label = newLabel;
}
}
}
if (axis.grid) {
if (axis.grid.visible === false) {
axisCfg.grid = null;
} else {
axisCfg.grid = _.clone(axis.grid);
if (axis.grid.style) {
axisCfg.grid = _.clone(axis.grid.style);
}
}
}
}
function TooltipStyleParser() {}
function LabelStyleParser(theme, style) {
const labelCfg = theme.label;
labelCfg.textStyle = style;
}
function AnnotationStyleParser() {}
function checkNull(cfg) {
if (cfg === null) {
return {};
}
return cfg;
}
export { AxisStyleParser, TooltipStyleParser, LabelStyleParser, AnnotationStyleParser };