widgetHeatmap.vue
9.31 KB
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<template>
<div :style="styleObj">
<v-chart :options="options" autoresize/>
</div>
</template>
<script>
export default {
name: "widgetHeatmap",
components: {},
props: {
value: Object,
ispreview: Boolean,
},
data() {
return {
options: {
title: {
text: "",
left: "center",
textStyle: {
color: "#fff",
},
},
tooltip: {
position: "top",
show: true,
textStyle: {},
},
grid: {
height: "90%",
width: "90%",
top: 10,
left: 20,
},
xAxis: {
name: "",
type: "category",
axisLabel: {
show: true,
color: "#0f0",
},
data: [],
splitArea: {
show: false,
},
nameTextStyle: {
color: "",
fontSize: 14,
},
},
yAxis: {
name: "",
type: "category",
axisLabel: {
show: true,
color: "#0f0",
},
data: [],
splitArea: {
show: false,
},
nameTextStyle: {
color: "",
fontSize: 14,
},
},
visualMap: {
show: true,
min: 0,
max: 5000,
calculable: true,
orient: "horizontal",
left: "center",
bottom: 0,
inRange: {
color: [],
},
textStyle: {
fontSize: 14,
color: "#fff",
},
},
series: [
{
name: "",
type: "heatmap",
data: [],
label: {
show: false,
fontSize: 16,
},
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowColor: "rgba(0, 0, 0, 0.5)",
},
},
},
],
},
optionsStyle: {}, // 样式
optionsData: {}, // 数据
optionsCollapse: {}, // 图标属性
optionsSetup: {},
};
},
computed: {
styleObj() {
return {
position: this.ispreview ? "absolute" : "static",
width: this.optionsStyle.width + "px",
height: this.optionsStyle.height + "px",
left: this.optionsStyle.left + "px",
top: this.optionsStyle.top + "px",
background: this.optionsSetup.background,
};
},
},
watch: {
value: {
handler(val) {
this.optionsStyle = val.position;
this.optionsData = val.data;
this.optionsCollapse = val.collapse;
this.optionsSetup = val.setup;
this.editorOptions();
},
deep: true,
},
},
created() {
this.optionsStyle = this.value.position;
this.optionsData = this.value.data;
this.optionsCollapse = this.value.collapse;
this.optionsSetup = this.value.setup;
this.editorOptions();
},
methods: {
// 修改图标options属性
editorOptions() {
this.setOptionsTitle();
this.setOptionsX();
this.setOptionsY();
this.setOptionsSeries();
this.setOptionsMargin();
this.setOptionsVisualMap();
this.setOptionsData();
},
// 标题修改
setOptionsTitle() {
const optionsSetup = this.optionsSetup;
const title = {
text: optionsSetup.titleText,
show: optionsSetup.isNoTitle,
left: optionsSetup.textAlign,
textStyle: {
color: optionsSetup.textColor,
fontSize: optionsSetup.textFontSize,
fontWeight: optionsSetup.textFontWeight
},
subtext: optionsSetup.subText,
subtextStyle: {
color: optionsSetup.subTextColor,
fontWeight: optionsSetup.subTextFontWeight,
fontSize: optionsSetup.subTextFontSize
},
};
this.options.title = title;
},
// X轴设置
setOptionsX() {
const optionsSetup = this.optionsSetup;
const xAxis = {
type: "category",
// 坐标轴是否显示
show: optionsSetup.hideX,
// 坐标轴名称
name: optionsSetup.xName,
nameTextStyle: {
color: optionsSetup.xNameColor,
fontSize: optionsSetup.xNameFontSize
},
// 轴反转
inverse: optionsSetup.reversalX,
axisLabel: {
show: true,
// 文字间隔
interval: optionsSetup.textInterval,
// 文字角度
rotate: optionsSetup.textAngleX,
textStyle: {
// 坐标文字颜色
color: optionsSetup.Xcolor,
fontSize: optionsSetup.fontSizeX
}
},
axisLine: {
show: true,
lineStyle: {
color: optionsSetup.lineColorX
}
},
splitArea: {
show: false,
},
};
this.options.xAxis = xAxis;
},
// Y轴设置
setOptionsY() {
const optionsSetup = this.optionsSetup;
const yAxis = {
type: "category",
// 坐标轴是否显示
show: optionsSetup.isShowY,
// 坐标轴名称
name: optionsSetup.textNameY,
nameTextStyle: {
color: optionsSetup.NameColorY,
fontSize: optionsSetup.NameFontSizeY
},
// y轴反转
inverse: optionsSetup.reversalY,
axisLabel: {
show: true,
// 文字角度
rotate: optionsSetup.textAngleY,
textStyle: {
// 坐标文字颜色
color: optionsSetup.colorY,
fontSize: optionsSetup.fontSizeY
}
},
axisLine: {
show: true,
lineStyle: {
color: optionsSetup.lineColorY
}
},
splitArea: {
show: false,
},
};
this.options.yAxis = yAxis;
},
// 数值设定
setOptionsSeries() {
const optionsSetup = this.optionsSetup;
const lable = {
show: optionsSetup.isShow,
textStyle: {
fontSize: optionsSetup.fontSize,
color: optionsSetup.subTextColor,
fontWeight: optionsSetup.fontWeight
}
}
this.options.series[0].label = lable;
},
// 边距设置
setOptionsMargin() {
const optionsSetup = this.optionsSetup;
const grid = {
left: optionsSetup.marginLeft,
right: optionsSetup.marginRight,
bottom: optionsSetup.marginBottom,
top: optionsSetup.marginTop,
containLabel: true
};
this.options.grid = grid;
},
// tooltip 设置
setOptionsTooltip() {
const optionsSetup = this.optionsSetup;
const tooltip = {
trigger: "item",
position: "top",
show: true,
textStyle: {
color: optionsSetup.lineColor,
fontSize: optionsSetup.tipsLineColor
}
};
this.options.tooltip = tooltip;
},
// 图设置
setOptionsVisualMap() {
const optionsSetup = this.optionsSetup;
const visualMap = this.options.visualMap;
visualMap.show = optionsSetup.isShowLegend;
visualMap.min = optionsSetup.dataMin;
visualMap.max = optionsSetup.dataMax;
visualMap.textStyle = {
fontSize : optionsSetup.lengedFontSize,
color : optionsSetup.lengedColor
};
visualMap.inRange.color = optionsSetup.lengedColorList.map((x) => {
return x.color;
});
visualMap.left = optionsSetup.lateralPosition;
visualMap.top = optionsSetup.longitudinalPosition;
visualMap.bottom = optionsSetup.longitudinalPosition;
visualMap.orient = optionsSetup.layoutFront;
visualMap.itemWidth = optionsSetup.lengedWidth;
},
setOptionsData() {
const optionsData = this.optionsData; // 数据类型 静态 or 动态
optionsData.dataType == "staticData"
? this.staticDataFn(optionsData.staticData)
: this.dynamicDataFn(optionsData.dynamicData, optionsData.refreshTime);
},
//去重
setUnique(arr) {
let newArr = [];
arr.forEach(item => {
return newArr.includes(item) ? '' : newArr.push(item);
});
return newArr;
},
staticDataFn(val) {
const data = [];
let xAxisList = [];
let yAxisList = [];
for (const i in val) {
xAxisList[i] = val[i].axis;
yAxisList[i] = val[i].yaxis;
data[i] = [val[i].axis,val[i].yaxis,val[i].num]
}
xAxisList = this.setUnique(xAxisList);
yAxisList = this.setUnique(yAxisList);
this.options.xAxis.data = xAxisList;
this.options.yAxis.data = yAxisList;
this.options.series[0].data = data;
},
dynamicDataFn(val, refreshTime) {
if (!val) return;
if (this.ispreview) {
this.getEchartData(val);
this.flagInter = setInterval(() => {
this.getEchartData(val);
}, refreshTime);
} else {
this.getEchartData(val);
}
},
getEchartData(val) {
const data = this.queryEchartsData(val);
data.then((res) => {
this.renderingFn(res);
});
},
renderingFn(val) {
this.options.xAxis.data = val.xAxis;
this.options.yAxis.data = val.yAxis;
this.options.series[0].data = val.series;
},
},
};
</script>
<style scoped lang="scss">
.echarts {
width: 100%;
height: 100%;
overflow: hidden;
}
</style>