summaryrefslogtreecommitdiff
path: root/src/client/app/desktop/views/pages/admin/admin.drive-chart.chart.vue
blob: 3c537d8d6da2d4b5f6bd112086f1f0b88dfb4bcb (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
<template>
<svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`">
	<polyline
		:points="points"
		fill="none"
		stroke-width="1"
		stroke="#555"/>
</svg>
</template>

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

export default Vue.extend({
	props: {
		chart: {
			required: true
		},
		type: {
			type: String,
			required: true
		}
	},
	data() {
		return {
			viewBoxX: 365,
			viewBoxY: 70,
			points: null
		};
	},
	created() {
		const peak = Math.max.apply(null, this.chart.map(d => this.type == 'local' ? d.drive.local.totalSize : d.drive.remote.totalSize));

		if (peak != 0) {
			const data = this.chart.slice().reverse().map(x => ({
				size: this.type == 'local' ? x.drive.local.totalSize : x.drive.remote.totalSize
			}));

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

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

</style>