/
SpeedGraph.vue
110 lines (107 loc) · 2.27 KB
/
SpeedGraph.vue
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
<template>
<div class="mt-4">
<apexcharts
ref="chart"
type="line"
:options="chartOptions"
:series="series"
/>
</div>
</template>
<script>
import VueApexCharts from 'vue-apexcharts'
import { mapGetters } from 'vuex'
import { getDataUnit, getDataValue } from '@/filters'
export default {
name: 'SpeedGraph',
components: {
apexcharts: VueApexCharts
},
data() {
return {
chartOptions: {
chart: {
sparkline: {
enabled: true
},
animations: {
enabled: false,
dynamicAnimation: {
speed: 1000
}
}
},
colors: [
this.$vuetify.theme.currentTheme.upload,
this.$vuetify.theme.currentTheme.download
],
stroke: {
show: true,
curve: 'smooth',
lineCap: 'round',
width: 4
},
fill: {
type: 'gradient',
gradient: {
shade: 'dark',
type: 'vertical',
shadeIntensity: 0.5,
opacityFrom: 0.6,
opacityTo: 0.5,
stops: [0, 50, 100]
}
},
tooltip: {
theme: 'light',
x: {
formatter: value => {
const val = 32 - value * 2
return val + ' seconds ago'
}
},
y: {
formatter: value => {
return `${getDataValue(value, 0)} ${getDataUnit(value)}`
}
}
}
}
}
},
computed: {
series() {
return [
{
name: 'upload',
type: 'area',
data: this.$store.state.upload_data
},
{
name: 'download',
type: 'area',
data: this.$store.state.download_data
}
]
},
...mapGetters(['getTheme']),
theme() {
return this.getTheme() ? 'Dark' : 'Light'
}
},
watch: {
theme(newValue) {
this.setChartTooltipTheme(newValue)
}
},
mounted() {
this.setChartTooltipTheme(this.theme)
},
methods: {
setChartTooltipTheme(theme) {
this.chartOptions.tooltip.theme = theme.toLowerCase()
this.$refs.chart.updateOptions(this.chartOptions)
}
}
}
</script>