summaryrefslogtreecommitdiff
path: root/src/client/app/desktop/views/pages/admin/admin.users-chart.chart.vue
blob: 45ecc1392949d1427215d3aa2da6f330b9f95ebc (plain)
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
<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>
</template>

<script lang="ts">
import Vue from 'vue';

export default Vue.extend({
	props: {
		chart: {
			required: true
		},
		type: {
			type: String,
			required: true
		}
	},
	data() {
		return {
			viewBoxX: 100,
			viewBoxY: 30,
			points: null,
			span: 'day'
		};
	},
	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));

			if (peak != 0) {
				const data = this.stats.slice().reverse().map(x => ({
					count: this.type == 'local' ? x.users.local.diff : x.users.remote.diff
				}));

				this.points = data.map((d, i) => `${(this.viewBoxX / data.length) * i},${(1 - (d.count / peak)) * this.viewBoxY}`).join(' ');
			}
		}
	}
});
</script>

<style lang="stylus" scoped>
svg
	display block
	padding 10px
	width 100%

</style>