mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-10-04 17:04:53 +02:00
bubble fraicheur des completions ajouté
This commit is contained in:
parent
cd8369d08c
commit
93086eba60
18 changed files with 179 additions and 66 deletions
|
@ -34,6 +34,12 @@ import {
|
|||
updateMapHeightForLargeScreens
|
||||
} from './utils.js';
|
||||
import Tablesort from 'tablesort';
|
||||
import TableSort from 'table-sort-js/table-sort.js';
|
||||
import $ from 'jquery';
|
||||
window.$ = $;
|
||||
window.jQuery = $;
|
||||
// Charger table-sortable (version non minifiée locale)
|
||||
import '../assets/js/table-sortable.js';
|
||||
|
||||
window.Chart = Chart;
|
||||
window.genererCouleurPastel = genererCouleurPastel;
|
||||
|
@ -44,6 +50,7 @@ window.ChartDataLabels = ChartDataLabels;
|
|||
window.maplibregl = maplibregl;
|
||||
window.toggleCompletionInfo = toggleCompletionInfo;
|
||||
window.updateMapHeightForLargeScreens = updateMapHeightForLargeScreens;
|
||||
window.Tablesort = Tablesort;
|
||||
|
||||
Chart.register(ChartDataLabels);
|
||||
|
||||
|
@ -112,11 +119,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
}
|
||||
updateCompletionProgress();
|
||||
|
||||
// Activer le tri sur tous les tableaux désignés
|
||||
document.querySelectorAll('.js-sort-table').forEach(table => {
|
||||
new Tablesort(table);
|
||||
});
|
||||
|
||||
// Focus sur le premier champ texte au chargement
|
||||
// const firstTextInput = document.querySelector('input.form-control');
|
||||
// if (firstTextInput) {
|
||||
|
@ -131,13 +133,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
|
||||
parseCuisine();
|
||||
|
||||
// Tri automatique des tableaux
|
||||
// const tables = document.querySelectorAll('table');
|
||||
// tables.forEach(table => {
|
||||
// table.classList.add('js-sort-table');
|
||||
// });
|
||||
|
||||
|
||||
// Modifier la fonction de recherche existante
|
||||
const searchInput = document.getElementById('app_admin_labourer');
|
||||
const suggestionList = document.getElementById('suggestionList');
|
||||
|
@ -201,4 +196,27 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
|
||||
enableLabourageForm();
|
||||
adjustListGroupFontSize('.list-group-item');
|
||||
|
||||
// Activer le tri naturel sur tous les tableaux avec la classe table-sort
|
||||
document.querySelectorAll('table.table-sort').forEach(table => {
|
||||
new TableSort(table);
|
||||
});
|
||||
|
||||
// Initialisation du tri et filtrage sur les tableaux du dashboard et de la page stats
|
||||
if (document.querySelector('#dashboard-table')) {
|
||||
$('#dashboard-table').tableSortable({
|
||||
pagination: false,
|
||||
showPaginationLabel: true,
|
||||
searchField: '#dashboard-table-search',
|
||||
responsive: false
|
||||
});
|
||||
}
|
||||
if (document.querySelector('#stats-table')) {
|
||||
$('#stats-table').tableSortable({
|
||||
pagination: false,
|
||||
showPaginationLabel: true,
|
||||
searchField: '#stats-table-search',
|
||||
responsive: false
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -47,16 +47,17 @@ function waitForChartAndDrawBubble() {
|
|||
}
|
||||
|
||||
// Calcul de la régression linéaire (moindres carrés)
|
||||
const validPoints = bubbleChartData.filter(d => d.x > 0 && d.y > 0);
|
||||
// On ne fait la régression que si on veut, mais l'axe X = fraicheur, Y = complétion
|
||||
const validPoints = bubbleChartData.filter(d => d.x !== null && d.y !== null);
|
||||
const n = validPoints.length;
|
||||
let regressionLine = null, slope = 0, intercept = 0;
|
||||
if (n >= 2) {
|
||||
let sumX = 0, sumY = 0, sumXY = 0, sumXX = 0;
|
||||
validPoints.forEach(d => {
|
||||
sumX += Math.log10(d.x);
|
||||
sumX += d.x;
|
||||
sumY += d.y;
|
||||
sumXY += Math.log10(d.x) * d.y;
|
||||
sumXX += Math.log10(d.x) * Math.log10(d.x);
|
||||
sumXY += d.x * d.y;
|
||||
sumXX += d.x * d.x;
|
||||
});
|
||||
const meanX = sumX / n;
|
||||
const meanY = sumY / n;
|
||||
|
@ -65,8 +66,8 @@ function waitForChartAndDrawBubble() {
|
|||
const xMin = Math.min(...validPoints.map(d => d.x));
|
||||
const xMax = Math.max(...validPoints.map(d => d.x));
|
||||
regressionLine = [
|
||||
{ x: xMin, y: slope * Math.log10(xMin) + intercept },
|
||||
{ x: xMax, y: slope * Math.log10(xMax) + intercept }
|
||||
{ x: xMin, y: slope * xMin + intercept },
|
||||
{ x: xMax, y: slope * xMax + intercept }
|
||||
];
|
||||
}
|
||||
window.Chart.register(window.ChartDataLabels);
|
||||
|
@ -105,10 +106,8 @@ function waitForChartAndDrawBubble() {
|
|||
].filter(Boolean)
|
||||
},
|
||||
options: {
|
||||
// responsive: true,
|
||||
plugins: {
|
||||
datalabels: {
|
||||
// Désactivé au niveau global, activé par dataset
|
||||
display: false
|
||||
},
|
||||
legend: { display: true },
|
||||
|
@ -117,14 +116,14 @@ function waitForChartAndDrawBubble() {
|
|||
label: (context) => {
|
||||
const d = context.raw;
|
||||
if (context.dataset.type === 'line') {
|
||||
return `Régression: y = ${slope.toFixed(2)} × log10(x) + ${intercept.toFixed(2)}`;
|
||||
return `Régression: y = ${slope.toFixed(2)} × x + ${intercept.toFixed(2)}`;
|
||||
}
|
||||
return [
|
||||
`${d.label}`,
|
||||
`Population: ${d.x.toLocaleString()}`,
|
||||
`Nombre de lieux: ${d.r.toFixed(2)}`,
|
||||
`Complétion: ${d.y.toFixed(2)}%`,
|
||||
`Fraîcheur moyenne: ${d.freshnessDays ? d.freshnessDays.toLocaleString() + ' jours' : 'N/A'}`,
|
||||
`Complétion: ${d.y.toFixed(2)}%`,
|
||||
`Population: ${d.population ? d.population.toLocaleString() : 'N/A'}`,
|
||||
`Nombre de lieux: ${d.r.toFixed(2)}`,
|
||||
`Budget: ${d.budget ? d.budget.toLocaleString() + ' €' : 'N/A'}`,
|
||||
`Budget/habitant: ${d.budgetParHabitant ? d.budgetParHabitant.toFixed(2) + ' €' : 'N/A'}`,
|
||||
`Budget/lieu: ${d.budgetParLieu ? d.budgetParLieu.toFixed(2) + ' €' : 'N/A'}`
|
||||
|
@ -135,11 +134,13 @@ function waitForChartAndDrawBubble() {
|
|||
},
|
||||
scales: {
|
||||
x: {
|
||||
type: 'logarithmic',
|
||||
title: { display: true, text: 'Population (échelle log)' }
|
||||
type: 'linear',
|
||||
title: { display: true, text: 'Fraîcheur moyenne (jours, plus petit = plus récent)' }
|
||||
},
|
||||
y: {
|
||||
title: { display: true, text: 'Completion' }
|
||||
title: { display: true, text: 'Taux de complétion (%)' },
|
||||
min: 0,
|
||||
max: 100
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
8
assets/js/table-sortable.js
Normal file
8
assets/js/table-sortable.js
Normal file
File diff suppressed because one or more lines are too long
0
assets/js/table-sortable.min.js
vendored
Normal file
0
assets/js/table-sortable.min.js
vendored
Normal file
|
@ -1,11 +1,7 @@
|
|||
// Gestion du tri des tableaux
|
||||
import Tablesort from 'tablesort';
|
||||
// import Tablesort from 'tablesort';
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.querySelectorAll('.js-sort-table').forEach(table => {
|
||||
new Tablesort(table);
|
||||
});
|
||||
|
||||
// Gestion du toggle gouttes/ronds sur la carte
|
||||
const toggle = document.getElementById('toggleMarkers');
|
||||
if (toggle && window.updateMarkers) {
|
||||
|
@ -18,6 +14,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
// Exposer une fonction pour (ré)appliquer le tri si besoin
|
||||
export function applyTableSort() {
|
||||
document.querySelectorAll('.js-sort-table').forEach(table => {
|
||||
new Tablesort(table);
|
||||
new window.Tablesort(table);
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue