elk/components/common/CommonTrendingCharts.vue

33 lines
730 B
Vue
Raw Normal View History

2022-12-11 13:52:36 +03:00
<script lang="ts" setup>
2023-01-08 09:21:09 +03:00
import type { mastodon } from 'masto'
2022-12-11 13:52:36 +03:00
import sparkline from '@fnando/sparkline'
const {
history,
2023-01-06 01:50:14 +03:00
width = 60,
height = 40,
2022-12-11 13:52:36 +03:00
} = $defineProps<{
2023-01-08 09:21:09 +03:00
history?: mastodon.v1.TagHistory[]
2023-01-06 01:50:14 +03:00
width?: number
height?: number
2022-12-11 13:52:36 +03: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 01:50:14 +03:00
<svg ref="sparklineEl" class="sparkline" :width="width" :height="height" stroke-width="3" />
2022-12-11 13:52:36 +03:00
</template>