-
-
Notifications
You must be signed in to change notification settings - Fork 241
/
oh-trend.vue
63 lines (61 loc) · 1.7 KB
/
oh-trend.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
<template>
<trend :key="'trend' + config.item" v-if="showTrend" :style="config.style" :width="trendWidth" class="trend" :data="trendData" :gradient="trendGradient" :gradientDirection="trendGradientDirection" :stroke-width="trendStrokeWidth" auto-draw smooth />
</template>
<script>
import mixin from '../widget-mixin'
import { OhTrendDefinition } from '@/assets/definitions/widgets/system'
export default {
mixins: [mixin],
props: ['width'],
widget: OhTrendDefinition,
data () {
return {
trendData: [],
showTrend: false
}
},
computed: {
trendItem () {
return this.config.trendItem
},
trendWidth () {
return this.width || this.config.trendWidth
},
trendGradient () {
return this.config.trendGradient || ['#2196f3', '#5ac8fa']
},
trendGradientDirection () {
return this.config.trendGradientDirection || 'top'
},
trendStrokeWidth () {
return this.config.trendStrokeWidth || 3
}
},
mounted () {
this.buildTrend()
},
watch: {
trendItem (item) {
this.buildTrend()
}
},
methods: {
buildTrend () {
this.trendData = []
this.showTrend = false
if (!this.trendItem) return []
const sampling = typeof this.config.trendSampling === 'number' ? this.config.trendSampling : 60
return this.$oh.api.get('/rest/persistence/items/' + this.config.trendItem).then((resp) => {
if (resp.data && resp.data.length) {
let data = []
for (let i = resp.data.length - 1; i >= 0; i -= sampling) {
data.push(parseFloat(resp.data[i].state))
}
this.trendData = data.reverse()
this.showTrend = true
}
})
}
}
}
</script>