Files
Reseaux-de-neurones-artific…/resources/js/components/PerceptronIterationsErrorsGraph.vue
Matthias Guillitte 83b7aa3f3a
Some checks failed
linter / quality (push) Failing after 7s
tests / ci (8.4) (push) Failing after 6s
tests / ci (8.5) (push) Failing after 5s
Added configuration panel datasets, back-end refactor and others
2026-03-12 16:38:50 +01:00

85 lines
2.4 KiB
Vue

<script setup lang="ts">
import type { ChartData } from 'chart.js';
import { Bar } from 'vue-chartjs';
import { colors } from '@/types/graphs';
import type { Iteration } from '@/types/perceptron';
const props = defineProps<{
iterations: Iteration[];
}>();
/**
* Return the datasets of the iterations with the form { label: `Exemple ${exampleIndex}`, data: [error for iteration 1, error for iteration 2, ...] }
*/
function getPerceptronErrorsPerIteration(): ChartData<
'bar',
(number | [number, number] | null)[]
>[] {
const datasets: ChartData<'bar', (number | [number, number] | null)[]>[] =
[];
const backgroundColors = colors;
props.iterations.forEach((iteration) => {
const exampleLabel = `Exemple ${iteration.exampleIndex}`;
let dataset = datasets.find((d) => d.label === exampleLabel);
if (!dataset) {
dataset = {
label: exampleLabel,
data: [],
backgroundColor:
backgroundColors[
iteration.exampleIndex % backgroundColors.length
],
};
datasets.push(dataset);
}
dataset.data.push(iteration.error);
});
// Sort dataset by label (Exemple 0, Exemple 1, ...)
datasets.sort((a, b) => {
const aIndex = parseInt(a.label.split(' ')[1]);
const bIndex = parseInt(b.label.split(' ')[1]);
return aIndex - bIndex;
});
return datasets;
}
</script>
<template>
<Bar
class="flex"
:options="{
responsive: true,
maintainAspectRatio: true,
plugins: {
title: {
display: true,
text: 'Nombre d\'erreurs par itération',
},
},
scales: {
x: {
stacked: true,
min: 0,
},
y: {
stacked: true,
beginAtZero: true,
},
},
}"
:data="{
labels: props.iterations.reduce((labels, iteration) => {
if (!labels.includes(`Itération ${iteration.iteration}`)) {
labels.push(`Itération ${iteration.iteration}`);
}
return labels;
}, [] as string[]),
datasets: getPerceptronErrorsPerIteration(),
}"
/>
</template>