Skip to content

Commit

Permalink
feat: charts animation
Browse files Browse the repository at this point in the history
  • Loading branch information
Zephyruso committed Dec 5, 2024
1 parent cd5c03d commit e7e555d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/components/sidebar/SpeedCharts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ onMounted(() => {
},
splitLine: { show: false },
},
animation: false,
series: [
{
name: t('upload'),
Expand Down
21 changes: 15 additions & 6 deletions src/store/statistics.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { fetchMemoryAPI, fetchTrafficAPI } from '@/api'
import { ref, watch } from 'vue'

const initValue = new Array(60).fill(0).map((v, i) => ({ name: i, value: v }))

export const memory = ref<number>(0)
export const downloadSpeed = ref<number>(0)
export const uploadSpeed = ref<number>(0)
export const downloadSpeedHistory = ref<number[]>(new Array(60).fill(0))
export const uploadSpeedHistory = ref<number[]>(new Array(60).fill(0))
export const downloadSpeedHistory = ref([...initValue])
export const uploadSpeedHistory = ref([...initValue])

let cancel: () => void

export const initSatistic = () => {
cancel?.()

downloadSpeedHistory.value = new Array(60).fill(0)
uploadSpeedHistory.value = new Array(60).fill(0)
downloadSpeedHistory.value = [...initValue]
uploadSpeedHistory.value = [...initValue]

const memoryWs = fetchMemoryAPI<string>()
const unwatchMemory = watch(memoryWs.data, (data) => {
Expand All @@ -34,12 +36,19 @@ export const initSatistic = () => {
up: number
down: number
}
const timestamp = Date.now().valueOf()

downloadSpeed.value = parsedData.down
uploadSpeed.value = parsedData.up

downloadSpeedHistory.value.push(parsedData.down)
uploadSpeedHistory.value.push(parsedData.up)
downloadSpeedHistory.value.push({
value: parsedData.down,
name: timestamp,
})
uploadSpeedHistory.value.push({
value: parsedData.up,
name: timestamp,
})

downloadSpeedHistory.value = downloadSpeedHistory.value.slice(-60)
uploadSpeedHistory.value = uploadSpeedHistory.value.slice(-60)
Expand Down

0 comments on commit e7e555d

Please sign in to comment.