Files
vote-front/components/QuestionResult.vue
T
2025-05-31 21:05:58 +02:00

81 lines
1.8 KiB
Vue

<template>
<div class="emphased">
<div v-for="(amount, val) in filtered_results" :id="`${questionId}-${val}`" :key="val"
:style="{ width: `${(amount / total) * 100}%` }">
<span>({{ amount }}){{ val }}</span>
</div>
</div>
</template>
<script setup lang="ts">
interface Props {
values?: string[]
results: { [question_id: string]: { [values: string]: number } }
questionId: string
}
const { values = ["Très bien", "Bien", "Passable", "Insuffisant", "À rejeter"], 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) ?? 1)
</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: -1;
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>