better traffic chart #120

This commit is contained in:
Alireza Ahmadi
2024-06-15 20:11:39 +02:00
parent ccbd591b39
commit 53ed86c373
+34 -10
View File
@@ -3,8 +3,8 @@
<v-card class="rounded-lg" :loading="loading" color="background"> <v-card class="rounded-lg" :loading="loading" color="background">
<v-card-title> <v-card-title>
<v-row> <v-row>
<v-col> <v-col cols="auto">
{{ $t('stats.graphTitle') + " - " + $t('objects.' + resource) + " : " + tag }} {{ $t('stats.graphTitle') }}
</v-col> </v-col>
<v-spacer></v-spacer> <v-spacer></v-spacer>
<v-col cols="auto"><v-icon icon="mdi-close" @click="$emit('close')"></v-icon></v-col> <v-col cols="auto"><v-icon icon="mdi-close" @click="$emit('close')"></v-icon></v-col>
@@ -12,7 +12,13 @@
</v-card-title> </v-card-title>
<v-divider></v-divider> <v-divider></v-divider>
<v-card-text style="padding: 0 16px;"> <v-card-text style="padding: 0 16px;">
<v-container id="container"> <div style="text-align: center; margin: 5px;">
{{ $t('objects.' + resource) + " : " + tag }}
</div>
<v-radio-group v-model="limit" @change="loadData" density="compact" :loading="loading" inline hide-details>
<v-radio v-for="p in periods" :label="p.title" :value="p.value"></v-radio>
</v-radio-group>
<v-container id="container" style="height:40vh;">
<v-alert :text="$t('noData')" type="warning" variant="outlined" v-if="alert"></v-alert> <v-alert :text="$t('noData')" type="warning" variant="outlined" v-if="alert"></v-alert>
<Line v-if="loaded" :data="usage" :options="<any>options" /> <Line v-if="loaded" :data="usage" :options="<any>options" />
</v-container> </v-container>
@@ -60,13 +66,29 @@ export default {
loaded: false, loaded: false,
alert: false, alert: false,
intervalId: <any>0, intervalId: <any>0,
limit: 1,
periods: [
{ value: 1, title: i18n.global.n(1) + i18n.global.t('date.h')},
{ value: 6, title: i18n.global.n(6) + i18n.global.t('date.h')},
{ value: 12, title: i18n.global.n(12) + i18n.global.t('date.h')},
{ value: 24, title: i18n.global.n(1) + i18n.global.t('date.d')},
{ value: 48, title: i18n.global.n(2) + i18n.global.t('date.d')},
{ value: 240, title: i18n.global.n(10) + i18n.global.t('date.d')},
{ value: 480, title: i18n.global.n(20) + i18n.global.t('date.d')},
{ value: 720, title: i18n.global.n(30) + i18n.global.t('date.d')},
{ value: 1440, title: i18n.global.n(60) + i18n.global.t('date.d')},
{ value: 2160, title: i18n.global.n(90) + i18n.global.t('date.d')},
],
options: { options: {
responsive: true, responsive: true,
maintainAspectRatio: true, maintainAspectRatio: false,
interaction: { interaction: {
intersect: false, intersect: false,
mode: 'index', mode: 'index',
}, },
elements: {
point: { pointStyle: 'crossRot' }
},
plugins: { plugins: {
tooltip: { tooltip: {
callbacks: { callbacks: {
@@ -99,13 +121,13 @@ export default {
} }
}, },
methods: { methods: {
async loadData(limit: number) { async loadData() {
this.loading = true this.loading = true
const data = await HttpUtils.get('api/stats', { resource: this.resource, tag: this.tag, limit: limit }) const data = await HttpUtils.get('api/stats', { resource: this.resource, tag: this.tag, limit: this.limit })
if (data.success && data.obj) { if (data.success && data.obj) {
const obj = <any[]>data.obj const obj = <any[]>data.obj
const l = String(i18n.global.locale) == 'fa' ? "fa-IR" : "en-US" const l = String(i18n.global.locale) == 'fa' ? "fa-IR" : "en-US"
const oneStep = limit * 3600 * 1000 / 360 // Each 10 sec const oneStep = this.limit * 3600 * 1000 / 360 // Each 10 sec
const now = new Date().getTime() const now = new Date().getTime()
const steps = <number[]>[] const steps = <number[]>[]
for (let i = 360; i >= 0; i--) { for (let i = 360; i >= 0; i--) {
@@ -145,8 +167,10 @@ export default {
], ],
} }
this.loaded = true this.loaded = true
this.alert = false
} else { } else {
this.alert = true this.alert = true
this.loaded = false
} }
this.loading = false this.loading = false
}, },
@@ -163,10 +187,10 @@ export default {
watch: { watch: {
visible(v) { visible(v) {
if (v) { if (v) {
const limit = 1 this.limit = 1
this.loadData(limit) this.loadData()
this.intervalId = setInterval(() => { this.intervalId = setInterval(() => {
this.loadData(limit) this.loadData()
}, 10000) }, 10000)
} else { } else {
this.loaded = false this.loaded = false