2022-12-11 19:52:36 +09:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import type { History } from 'masto'
|
|
|
|
import sparkline from '@fnando/sparkline'
|
|
|
|
|
|
|
|
const {
|
|
|
|
history,
|
2023-01-06 07:50:14 +09:00
|
|
|
width = 60,
|
|
|
|
height = 40,
|
2022-12-11 19:52:36 +09:00
|
|
|
} = $defineProps<{
|
|
|
|
history?: History[]
|
2023-01-06 07:50:14 +09:00
|
|
|
width?: number
|
|
|
|
height?: number
|
2022-12-11 19:52:36 +09:00
|
|
|
}>()
|
|
|
|
|
|
|
|
const historyNum = $computed(() => {
|
|
|
|
if (!history)
|
|
|
|
return [1, 1, 1, 1, 1, 1, 1]
|
|
|
|
return [...history].reverse().map(item => Number(item.accounts) || 0)
|
|
|
|
})
|
|
|
|
|
|
|
|
const sparklineEl = $ref<SVGSVGElement>()
|
|
|
|
|
|
|
|
watch([$$(historyNum), $$(sparklineEl)], ([historyNum, sparklineEl]) => {
|
|
|
|
if (!sparklineEl)
|
|
|
|
return
|
|
|
|
sparkline(sparklineEl, historyNum)
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2023-01-06 07:50:14 +09:00
|
|
|
<svg ref="sparklineEl" class="sparkline" :width="width" :height="height" stroke-width="3" />
|
2022-12-11 19:52:36 +09:00
|
|
|
</template>
|