82 lines
1.9 KiB
Vue
82 lines
1.9 KiB
Vue
<template>
|
|
<div class="emphased">
|
|
<div v-for="(amount, val) in filtered_results" :id="`${questionId}-${val}`" :key="val"
|
|
:style="{ width: (total ? `${(amount / total) * 100}%` : '100%'), background: colors[values.indexOf(String(val))] }">
|
|
<span>({{ amount }}){{ val }}</span>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
interface Props {
|
|
values?: string[]
|
|
colors?: string[]
|
|
results: { [question_id: string]: { [values: string]: number } }
|
|
questionId: string
|
|
}
|
|
|
|
const { values = ["Très bien", "Bien", "Passable", "Insuffisant", "À rejeter"], colors = ["#4DB544", "#87E169", "#FFC33C", "#FF824B", "#E94A4D"], results, questionId } = defineProps<Props>()
|
|
|
|
const filtered_results = computed(() => {
|
|
if (!(questionId in results)) {
|
|
return values.reduce((acc, val) => {
|
|
acc[val] = 0
|
|
return acc
|
|
}, {} as { [key: string]: number })
|
|
}
|
|
|
|
const relevant = results[questionId]
|
|
|
|
return values.reduce((acc, val) => {
|
|
if (!(val in relevant)) {
|
|
acc[val] = 0
|
|
} else {
|
|
acc[val] = relevant[val]
|
|
}
|
|
return acc
|
|
}, {} as { [key: string]: number })
|
|
|
|
})
|
|
|
|
const total = computed(() => (Object.values(filtered_results.value).reduce((acc, v) => v + acc, 0) || 0))
|
|
</script>
|
|
|
|
|
|
<style scoped="true" lang="css">
|
|
.emphased {
|
|
position: relative;
|
|
margin-top: 2em;
|
|
margin-bottom: 2em;
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
display: inline-flex;
|
|
flex-wrap: nowrap;
|
|
}
|
|
|
|
.emphased:after {
|
|
content: "";
|
|
position: absolute;
|
|
z-index: 100;
|
|
top: -10px;
|
|
bottom: -10px;
|
|
left: 50%;
|
|
border-left: 4px solid #444;
|
|
transform: translate(-50%);
|
|
|
|
}
|
|
|
|
.emphased div {
|
|
padding: 3px;
|
|
border: 1px solid #444;
|
|
border-right: none;
|
|
text-overflow: ellipsis;
|
|
overflow: hidden;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.emphased div:last-child {
|
|
border-right: 1px solid #444;
|
|
}
|
|
</style> |