2024-09-07 16:38:18 +09:00
|
|
|
<script setup lang="ts">
|
2023-01-08 15:21:09 +09:00
|
|
|
import type { mastodon } from 'masto'
|
2022-12-11 19:52:36 +09:00
|
|
|
import sparkline from '@fnando/sparkline'
|
|
|
|
|
|
|
|
const {
|
|
|
|
history,
|
2023-01-06 07:50:14 +09:00
|
|
|
width = 60,
|
|
|
|
height = 40,
|
2024-02-22 00:20:08 +09:00
|
|
|
} = defineProps<{
|
2023-01-08 15:21:09 +09:00
|
|
|
history?: mastodon.v1.TagHistory[]
|
2023-01-06 07:50:14 +09:00
|
|
|
width?: number
|
|
|
|
height?: number
|
2022-12-11 19:52:36 +09:00
|
|
|
}>()
|
|
|
|
|
2024-02-22 00:20:08 +09:00
|
|
|
const historyNum = computed(() => {
|
2022-12-11 19:52:36 +09:00
|
|
|
if (!history)
|
|
|
|
return [1, 1, 1, 1, 1, 1, 1]
|
|
|
|
return [...history].reverse().map(item => Number(item.accounts) || 0)
|
|
|
|
})
|
|
|
|
|
2024-02-22 00:20:08 +09:00
|
|
|
const sparklineEl = ref<SVGSVGElement>()
|
2023-01-13 06:19:20 +09:00
|
|
|
const sparklineFn = typeof sparkline !== 'function' ? (sparkline as any).default : sparkline
|
2022-12-11 19:52:36 +09:00
|
|
|
|
2024-02-22 00:20:08 +09:00
|
|
|
watch([historyNum, sparklineEl], ([historyNum, sparklineEl]) => {
|
2022-12-11 19:52:36 +09:00
|
|
|
if (!sparklineEl)
|
|
|
|
return
|
2023-01-13 06:19:20 +09:00
|
|
|
sparklineFn(sparklineEl, historyNum)
|
2022-12-11 19:52:36 +09:00
|
|
|
})
|
|
|
|
</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>
|