egirlskey/src/client/app/common/views/widgets/server.pie.vue

68 lines
1.1 KiB
Vue
Raw Normal View History

2018-02-19 22:56:39 +00:00
<template>
<svg viewBox="0 0 1 1" preserveAspectRatio="none">
<circle
:r="r"
cx="50%" cy="50%"
fill="none"
stroke-width="0.1"
2018-04-30 05:05:16 +00:00
stroke="rgba(0, 0, 0, 0.05)"/>
2018-02-19 22:56:39 +00:00
<circle
:r="r"
cx="50%" cy="50%"
:stroke-dasharray="Math.PI * (r * 2)"
:stroke-dashoffset="strokeDashoffset"
fill="none"
stroke-width="0.1"
:stroke="color"/>
2018-02-21 15:07:37 +00:00
<text x="50%" y="50%" dy="0.05" text-anchor="middle">{{ (value * 100).toFixed(0) }}%</text>
2018-02-19 22:56:39 +00:00
</svg>
</template>
<script lang="ts">
import Vue from 'vue';
export default Vue.extend({
props: {
value: {
type: Number,
required: true
}
},
data() {
return {
r: 0.4
};
},
computed: {
color(): string {
return `hsl(${180 - (this.value * 180)}, 80%, 70%)`;
},
strokeDashoffset(): number {
return (1 - this.value) * (Math.PI * (this.r * 2));
}
}
});
</script>
<style lang="stylus" scoped>
2018-04-19 22:50:49 +00:00
root(isDark)
2018-02-19 22:56:39 +00:00
display block
height 100%
> circle
transform-origin center
transform rotate(-90deg)
transition stroke-dashoffset 0.5s ease
> text
font-size 0.15px
2018-04-28 23:51:17 +00:00
fill isDark ? rgba(#fff, 0.6) : rgba(#000, 0.6)
2018-04-19 22:50:49 +00:00
svg[data-darkmode]
root(true)
svg:not([data-darkmode])
root(false)
2018-02-19 22:56:39 +00:00
</style>