monkeeShark/packages/frontend/src/widgets/server-metric/pie.vue

55 lines
1.1 KiB
Vue
Raw Normal View History

2021-01-03 13:38:32 +00:00
<template>
2023-05-24 08:33:31 +00:00
<svg :class="$style.root" viewBox="0 0 1 1" preserveAspectRatio="none">
2021-01-03 13:38:32 +00:00
<circle
:r="r"
cx="50%" cy="50%"
fill="none"
stroke-width="0.1"
stroke="rgba(0, 0, 0, 0.05)"
2023-05-24 08:33:31 +00:00
:class="$style.circle"
2021-01-03 13:38:32 +00:00
/>
<circle
:r="r"
cx="50%" cy="50%"
:stroke-dasharray="Math.PI * (r * 2)"
:stroke-dashoffset="strokeDashoffset"
fill="none"
stroke-width="0.1"
:class="$style.circle"
2021-01-03 13:38:32 +00:00
:stroke="color"
/>
2023-05-24 08:33:31 +00:00
<text x="50%" y="50%" dy="0.05" text-anchor="middle" :class="$style.text">{{ (value * 100).toFixed(0) }}%</text>
2021-01-03 13:38:32 +00:00
</svg>
</template>
<script lang="ts" setup>
import { } from 'vue';
2021-01-03 13:38:32 +00:00
const props = defineProps<{
value: number;
}>();
const r = 0.45;
const color = $computed(() => `hsl(${180 - (props.value * 180)}, 80%, 70%)`);
const strokeDashoffset = $computed(() => (1 - props.value) * (Math.PI * (r * 2)));
2021-01-03 13:38:32 +00:00
</script>
2023-05-24 08:33:31 +00:00
<style lang="scss" module>
.root {
2021-01-03 13:38:32 +00:00
display: block;
height: 100%;
2023-05-24 08:33:31 +00:00
}
2021-01-03 13:38:32 +00:00
2023-05-24 08:33:31 +00:00
.circle {
transform-origin: center;
transform: rotate(-90deg);
transition: stroke-dashoffset 0.5s ease;
}
2021-01-03 13:38:32 +00:00
2023-05-24 08:33:31 +00:00
.text {
font-size: 0.15px;
fill: currentColor;
2021-01-03 13:38:32 +00:00
}
</style>