-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
260 lines (209 loc) · 4.29 KB
/
index.js
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
const ALLOWED_DATA_TYPES = ["string", "number", "boolean"];
class Options {
#options = {};
export() {
return { ...this.options, ...this.#options };
}
add(optionsToAdd) {
this.#options = { ...this.#options, ...optionsToAdd };
}
get options() {
const options = {};
const keys = Object.keys(this);
keys
.filter((key) => {
const valueType = typeof this[key];
return ALLOWED_DATA_TYPES.some((DATA_TYPE) => valueType === DATA_TYPE);
})
.forEach((key) => (options[key] = this[key]));
return options;
}
}
class TitleOptions extends Options {
show;
zlevel;
text;
subtext;
// styling
backgroundColor;
// shadow
shadowColor;
shadowBlur;
shadowOffsetX;
shadowOffsetY;
// border
borderColor;
borderWidth;
borderRadius;
// spacing
textAlign;
textVerticalAlign;
padding;
itemGap;
// poisitioning
top;
left;
bottom;
right;
/**
* Extend the title text horizontally, by applying padding to each side
* @param {number} amountOfPadding The amount of padding to apply, to each side,
* where each unit is one space " ".
*/
extendHorizontally(amountOfPadding) {
let padding = "";
for (var i = 0; i < amountOfPadding; i++) {
padding = padding.concat(" ");
}
this.text = `${padding}${this.text}${padding}`;
}
}
class LegendOptions extends Options {
show;
zlevel;
type;
selectedMode;
// styling
icon;
inactiveColor;
inactiveBorderColor;
inactiveBorderWidth;
backgroundColor;
// shadow
shadowBlur;
shadowColor;
shadowOffsetX;
shadowOffsetY;
// border
borderColor;
borderWidth;
borderRadius; // can use arrays, which is not supported
// orientation
orient;
align;
symbolRotate;
// spacing
padding;
itemGap;
itemWidth;
itemHeight;
// sizing
width;
height;
// positioning
top;
left;
bottom;
right;
}
class GridOptions extends Options {
show;
zlevel;
containLabel;
// styling
backgroundColor;
// border
borderWidth;
borderColor;
// shadow
shadowBlur;
shadowColor;
shadowOffsetX;
shadowOffsetY;
// sizing
width;
height;
// positioning
top;
left;
bottom;
right;
}
class AxisOptions extends Options {
show;
zlevel;
type;
scale; // requires (type === 'value') && (min and max not set)
alignTicks;
inverse;
silent;
// Intervals
min; // can use funcitions, which are not supported
max; // can use funcitions, which are not supported
splitNumber;
minInterval; // requries (type === 'value') || (type === 'time')
maxInterval; // requries (type === 'value') || (type === 'time')
interval;
logBase; // requires (type === 'log');
// naming
name;
nameLocation;
nameGap;
nameRotate;
// positioning => requires (xAxis.axisLine.onZero === false)
position;
offset;
}
class AxisPointerOptions extends Options {
show;
zlevel;
type;
value;
status;
snap;
// Triggers
triggerOn;
triggerTooltip;
}
class GraphOptions extends Options {
zlevel;
type;
name;
seriesLayoutBy;
/**
* @param {string} type The type of graph e.g "bar"
* @param {string} name Series name used for displaying in tooltip and filtering with legend, or updating data and configuration with setOption.
*/
constructor(type, name) {
super();
this.type = type;
this.name = name;
}
}
class SeriesOptions extends Options {
backgroundColor;
#data = [];
/**
* @param {Array.<GraphOptions>} data An array of GraphOptions objects, each one representing a graph.
*/
setData(data) {
this.#data = data;
}
export() {
return this.#data.map((data) => data.export());
}
}
class EchartsOptions extends Options {
title = new TitleOptions();
grid = new GridOptions();
legend = new LegendOptions();
yAxis = new AxisOptions();
xAxis = new AxisOptions();
axisPointer = new AxisPointerOptions();
series = new SeriesOptions();
export = () => {
const options = super.export();
return {
grid: this.grid.export(),
title: this.title.export(),
legend: this.legend.export(),
yAxis: this.yAxis.export(),
xAxis: this.xAxis.export(),
axisPointer: this.axisPointer.export(),
series: this.series.export(),
...options,
};
};
}
export { GraphOptions };
export default EchartsOptions;