feat : graphique trafic global 14j (v1.6.27)

This commit is contained in:
2026-05-19 19:33:46 +02:00
parent 868e68fa85
commit d729e943a3
2 changed files with 51 additions and 1 deletions
+50 -1
View File
@@ -50,6 +50,47 @@
+ '</svg>';
}
function trendChart(totals) {
var trendEl = document.getElementById('stats-trend-container');
if (!trendEl || !totals.length) { return; }
var days = totals.length;
var maxV = Math.max.apply(null, totals) || 1;
var W = 1000; // viewBox, s'adapte en CSS
var H = 80;
var padX = 4;
var padY = 8;
var barW = Math.floor((W - 2 * padX) / days) - 2;
// Dates des jours (index 0 = il y a 13 jours)
var now = new Date();
var labels = totals.map(function (_, i) {
var d = new Date(now);
d.setDate(d.getDate() - (days - 1 - i));
return d.toLocaleDateString('fr-FR', { day: 'numeric', month: 'short' });
});
var bars = totals.map(function (v, i) {
var x = padX + i * (W - 2 * padX) / days + 1;
var bh = Math.max(2, (v / maxV) * (H - padY - 16));
var y = H - padY - bh;
var lx = x + barW / 2;
var label = labels[i];
var showLabel = (i === 0 || i === days - 1 || i === Math.floor(days / 2));
return '<rect x="' + x.toFixed(1) + '" y="' + y.toFixed(1) + '" width="' + barW + '" height="' + bh.toFixed(1) + '"'
+ ' fill="var(--bs-primary,#0d6efd)" opacity="0.75" rx="2"/>'
+ '<title>' + label + ' : ' + v + ' vis.</title>'
+ (showLabel
? '<text x="' + lx.toFixed(1) + '" y="' + (H - 1) + '" text-anchor="middle"'
+ ' font-size="10" fill="var(--bs-secondary-color,#6c757d)">' + label + '</text>'
: '');
}).join('');
trendEl.innerHTML = '<p class="small text-muted mb-2 fw-semibold">Trafic total — 14 derniers jours</p>'
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ' + W + ' ' + H + '"'
+ ' style="width:100%;height:80px;display:block">' + bars + '</svg>';
}
fetch('/trending?period=14d')
.then(function (r) { return r.ok ? r.text() : Promise.reject(); })
.then(function (xml) {
@@ -70,7 +111,15 @@
var daily = pm ? (pagesByDay[pm[0]] || null) : null;
return { title: title, link: link, slug: slug, vis: vis, daily: daily };
});
var maxV = Math.max.apply(null, rows.map(function (r) { return r.vis; })) || 1;
// Graphique global : somme de tous les articles par jour
var nDays = 14;
var totals = new Array(nDays).fill(0);
Object.values(pagesByDay).forEach(function (arr) {
arr.forEach(function (v, i) { if (i < nDays) { totals[i] += v; } });
});
trendChart(totals);
var html = '<div class="table-responsive"><table class="table table-sm table-hover mb-0 small w-100"><tbody>';
rows.forEach(function (row, i) {
var vis = row.vis.toLocaleString('fr-FR');
+1
View File
@@ -35,6 +35,7 @@ $_activeGroup = trim($_GET['group'] ?? '');
<div class="card-body p-0" id="stats-pages-container">
<p class="text-muted p-3 mb-0">Chargement…</p>
</div>
<div class="card-footer bg-transparent border-top px-3 pt-3 pb-2" id="stats-trend-container"></div>
</div>
<div class="row g-4">