2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
2024-02-13 16:50:11 +01:00
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
2023-07-27 07:31:52 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2018-06-11 04:24:29 +02:00
|
|
|
<template>
|
2018-06-11 05:52:47 +02:00
|
|
|
<svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`" style="overflow:visible">
|
2018-06-11 04:24:29 +02:00
|
|
|
<defs>
|
|
|
|
<linearGradient :id="gradientId" x1="0" x2="0" y1="1" y2="0">
|
2022-06-24 12:47:38 +02:00
|
|
|
<stop offset="0%" :stop-color="color" stop-opacity="0"></stop>
|
|
|
|
<stop offset="100%" :stop-color="color" stop-opacity="0.65"></stop>
|
2018-06-11 04:24:29 +02:00
|
|
|
</linearGradient>
|
|
|
|
</defs>
|
2022-06-24 12:47:38 +02:00
|
|
|
<polygon
|
|
|
|
:points="polygonPoints"
|
|
|
|
:style="`stroke: none; fill: url(#${ gradientId });`"
|
2022-06-21 07:39:23 +02:00
|
|
|
/>
|
2022-06-24 03:51:45 +02:00
|
|
|
<polyline
|
|
|
|
:points="polylinePoints"
|
|
|
|
fill="none"
|
|
|
|
:stroke="color"
|
|
|
|
stroke-width="2"
|
|
|
|
/>
|
|
|
|
<circle
|
2024-01-30 11:53:53 +01:00
|
|
|
:cx="headX ?? undefined"
|
|
|
|
:cy="headY ?? undefined"
|
2022-06-24 03:51:45 +02:00
|
|
|
r="3"
|
|
|
|
:fill="color"
|
|
|
|
/>
|
2018-06-11 04:24:29 +02:00
|
|
|
</svg>
|
|
|
|
</template>
|
|
|
|
|
2022-06-21 07:39:23 +02:00
|
|
|
<script lang="ts" setup>
|
2023-12-07 06:42:09 +01:00
|
|
|
import { watch, ref } from 'vue';
|
2019-08-18 05:42:58 +02:00
|
|
|
import { v4 as uuid } from 'uuid';
|
2022-06-24 03:51:45 +02:00
|
|
|
import tinycolor from 'tinycolor2';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { useInterval } from '@/scripts/use-interval.js';
|
2018-06-11 04:24:29 +02:00
|
|
|
|
2022-06-21 07:39:23 +02:00
|
|
|
const props = defineProps<{
|
|
|
|
src: number[];
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const viewBoxX = 50;
|
|
|
|
const viewBoxY = 50;
|
|
|
|
const gradientId = uuid();
|
2023-12-07 06:42:09 +01:00
|
|
|
const polylinePoints = ref('');
|
|
|
|
const polygonPoints = ref('');
|
|
|
|
const headX = ref<number | null>(null);
|
|
|
|
const headY = ref<number | null>(null);
|
|
|
|
const clock = ref<number | null>(null);
|
2022-06-24 03:51:45 +02:00
|
|
|
const accent = tinycolor(getComputedStyle(document.documentElement).getPropertyValue('--accent'));
|
|
|
|
const color = accent.toRgbString();
|
2022-06-21 07:39:23 +02:00
|
|
|
|
|
|
|
function draw(): void {
|
|
|
|
const stats = props.src.slice().reverse();
|
|
|
|
const peak = Math.max.apply(null, stats) || 1;
|
|
|
|
|
|
|
|
const _polylinePoints = stats.map((n, i) => [
|
|
|
|
i * (viewBoxX / (stats.length - 1)),
|
|
|
|
(1 - (n / peak)) * viewBoxY,
|
|
|
|
]);
|
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
polylinePoints.value = _polylinePoints.map(xy => `${xy[0]},${xy[1]}`).join(' ');
|
2018-06-11 19:18:29 +02:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
polygonPoints.value = `0,${ viewBoxY } ${ polylinePoints.value } ${ viewBoxX },${ viewBoxY }`;
|
2018-06-11 04:24:29 +02:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
headX.value = _polylinePoints.at(-1)![0];
|
|
|
|
headY.value = _polylinePoints.at(-1)![1];
|
2022-06-21 07:39:23 +02:00
|
|
|
}
|
2018-06-11 05:52:47 +02:00
|
|
|
|
2022-06-21 07:39:23 +02:00
|
|
|
watch(() => props.src, draw, { immediate: true });
|
2018-06-11 04:24:29 +02:00
|
|
|
|
2022-06-21 07:39:23 +02:00
|
|
|
// Vueが何故かWatchを発動させない場合があるので
|
2022-06-25 20:12:58 +02:00
|
|
|
useInterval(draw, 1000, {
|
|
|
|
immediate: false,
|
|
|
|
afterMounted: true,
|
2018-06-11 04:24:29 +02:00
|
|
|
});
|
|
|
|
</script>
|