mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-10-09 17:02:46 +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
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue