sharkey/src/client/app/desktop/views/pages/admin/admin.users-chart.chart.vue

75 lines
1.3 KiB
Vue
Raw Normal View History

2018-08-18 03:52:24 +09:00
<template>
<div>
<a @click="span = 'day'">Per day</a> | <a @click="span = 'hour'">Per hour</a>
<svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`">
<polyline
:points="points"
fill="none"
stroke-width="0.3"
stroke="#555"/>
</svg>
</div>
2018-08-18 03:52:24 +09:00
</template>
<script lang="ts">
import Vue from 'vue';
export default Vue.extend({
props: {
2018-08-19 00:27:23 +09:00
chart: {
2018-08-18 03:52:24 +09:00
required: true
},
type: {
type: String,
required: true
}
},
data() {
return {
viewBoxX: 100,
viewBoxY: 30,
points: null,
span: 'day'
2018-08-18 03:52:24 +09:00
};
},
computed: {
stats(): any[] {
return (
this.span == 'day' ? this.chart.perDay :
this.span == 'hour' ? this.chart.perHour :
null
);
}
},
watch: {
stats() {
this.render();
}
},
mounted() {
this.render();
},
methods: {
render() {
const peak = Math.max.apply(null, this.stats.map(d => this.type == 'local' ? d.users.local.diff : d.users.remote.diff));
2018-08-18 03:52:24 +09:00
if (peak != 0) {
const data = this.stats.slice().reverse().map(x => ({
count: this.type == 'local' ? x.users.local.diff : x.users.remote.diff
}));
2018-08-19 00:27:23 +09:00
this.points = data.map((d, i) => `${(this.viewBoxX / data.length) * i},${(1 - (d.count / peak)) * this.viewBoxY}`).join(' ');
}
2018-08-18 03:52:24 +09:00
}
}
});
</script>
<style lang="stylus" scoped>
svg
display block
padding 10px
width 100%
</style>