-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLanguages.vue
27 lines (25 loc) · 1.06 KB
/
Languages.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<template>
<div class="h-1 rounded-full w-full bg-blue-500 relative my-4 flex-grow">
<div
v-for="(lang, index) of Object.keys(languages).sort((a, b) => languages[b] - languages[a])"
:key="lang"
class="absolute h-1"
:class="[index === 0 && 'rounded-tl-full rounded-bl-full', index === Object.keys(languages).length - 1 && 'rounded-tr-full rounded-br-full']"
:style="{
width: `${(languages[lang] / totalBytes) * 100}%`,
backgroundColor: `${langColors[lang]}`,
left: howFarLeft(index)
}"
></div>
</div>
</template>
<script setup lang="ts">
import { langColors } from '../statics'
const { languages } = defineProps<{ languages: { [key: string]: any }}>()
const totalBytes = Object.keys(languages).reduce((sum, key) => sum + parseFloat(languages[key] || 0), 0)
const howFarLeft = (index: number) => {
if (index === 0) return '0%'
const prevBytes = Object.keys(languages).splice(0, index).reduce((sum, key) => sum + parseFloat(languages[key] || 0), 0)
return `${(prevBytes / totalBytes) * 100}%`
}
</script>