diff --git a/src/Controller/FraicheurController.php b/src/Controller/FraicheurController.php index ef16fa86..fca887a2 100644 --- a/src/Controller/FraicheurController.php +++ b/src/Controller/FraicheurController.php @@ -213,8 +213,8 @@ class FraicheurController extends AbstractController } foreach ($ecartsMoyenne as $ville) { - // Histogramme écart à la moyenne (pas de 10%) - $binEcart = (string)(ceil($ville['ecart_moyenne_pourcent'] / 10) * 10); + // Histogramme écart à la moyenne (pas de 3%) + $binEcart = (string)(ceil($ville['ecart_moyenne_pourcent'] / 3) * 3); if (!isset($histogramEcartMoyenne[$binEcart])) { $histogramEcartMoyenne[$binEcart] = 0; } diff --git a/templates/admin/stats.html.twig b/templates/admin/stats.html.twig index d04dc71f..655223a7 100644 --- a/templates/admin/stats.html.twig +++ b/templates/admin/stats.html.twig @@ -249,6 +249,7 @@
{% include 'admin/stats_history.html.twig' %}
+
@@ -656,7 +657,52 @@ if(dc ){ }else{ console.log('pas de distribution_completion') } - + +// === Distribution du budget par habitant (écart à la moyenne, pas de 3%) === +const budgetEcartData = []; +{% for commerce in stats.places %} + {% if commerce.getBudgetParHabitantEcartPourcent is defined %} + budgetEcartData.push({{ commerce.getBudgetParHabitantEcartPourcent()|default(0) }}); + {% endif %} +{% endfor %} +const budgetEcartDistribution = {}; +budgetEcartData.forEach(ecart => { + const range = Math.floor(ecart / 3) * 3; + const key = `${range}% à ${range + 3}%`; + budgetEcartDistribution[key] = (budgetEcartDistribution[key] || 0) + 1; +}); +const budgetEcartLabels = Object.keys(budgetEcartDistribution).sort((a, b) => parseInt(a) - parseInt(b)); +const budgetEcartValues = budgetEcartLabels.map(label => budgetEcartDistribution[label]); +const dbh = document.getElementById('distribution_budget_habitant'); +if(dbh){ + const budgetEcartCtx = dbh.getContext ? dbh.getContext('2d') : null; + if(!budgetEcartCtx){ + console.log('pas de budgetEcartCtx'); + } else { + new Chart(budgetEcartCtx, { + type: 'bar', + data: { + labels: budgetEcartLabels, + datasets: [{ + label: 'Distribution des villes selon l\'écart à la moyenne du budget par habitant (pas 3%)', + data: budgetEcartValues, + backgroundColor: 'rgba(255, 206, 86, 0.5)', + borderColor: 'rgba(255, 206, 86, 1)', + borderWidth: 1 + }] + }, + options: { + scales: { + y: { + beginAtZero: true + } + }, + responsive: true, + maintainAspectRatio: false + } + }); + } +} });