From 7599b98959da5bb5d87adf4e0547f8db1dfdcdf3 Mon Sep 17 00:00:00 2001 From: bolbol Date: Fri, 21 Aug 2026 22:35:46 +0100 Subject: [PATCH] =?UTF-8?q?fix(ticker/pdf):=20ralentissement=20ticker=20?= =?UTF-8?q?=C3=A0=2018=20car/s=20et=20correction=20troncature=20table=20PD?= =?UTF-8?q?F=20via=20truncateToWidth?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 2 +- services/export-pdf.js | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 6cfac27..9b83ae1 100644 --- a/index.html +++ b/index.html @@ -1684,7 +1684,7 @@ function updateTicker() { `⚠ ${x.r.region} — ${x.r.id_marche} : ${x.delai} jours restants` ).join(' • '); content.textContent = text; - const duration = Math.min(70, Math.max(25, Math.ceil(text.length / 14))); + const duration = Math.min(100, Math.max(30, Math.ceil(text.length / 18))); content.style.animationDuration = `${duration}s`; ticker.classList.add('active'); document.body.classList.add('has-ticker'); diff --git a/services/export-pdf.js b/services/export-pdf.js index a8d6ebe..007b1de 100644 --- a/services/export-pdf.js +++ b/services/export-pdf.js @@ -91,6 +91,13 @@ function kpiBox(doc, x, y, w, h, label, value, color) { // ─── Table ──────────────────────────────────────────────────────────────────── +function truncateToWidth(doc, text, maxWidth) { + if (doc.widthOfString(text) <= maxWidth) return text; + let t = text; + while (t.length > 1 && doc.widthOfString(t + '…') > maxWidth) t = t.slice(0, -1); + return t + '…'; +} + function table(doc, { title, headers, rows, colWidths }) { const pageW = doc.page.width - 80; const totalW = colWidths.reduce((a, b) => a + b, 0); @@ -111,7 +118,7 @@ function table(doc, { title, headers, rows, colWidths }) { doc.fontSize(7.5).font('Helvetica-Bold'); let x = 40; for (let i = 0; i < headers.length; i++) { - doc.text(headers[i], x + 3, y + 4, { width: widths[i] - 6, height: 11, ellipsis: true }); + doc.text(truncateToWidth(doc, headers[i], widths[i] - 6), x + 3, y + 4, { width: widths[i] - 6, lineBreak: false }); x += widths[i]; } y += 17; @@ -134,7 +141,7 @@ function table(doc, { title, headers, rows, colWidths }) { doc.fontSize(7).font('Helvetica'); let x = 40; for (let i = 0; i < row.length; i++) { - doc.text(String(row[i] ?? '—'), x + 3, y + 4, { width: widths[i] - 6, height: rowH - 4, ellipsis: true }); + doc.text(truncateToWidth(doc, String(row[i] ?? '—'), widths[i] - 6), x + 3, y + 4, { width: widths[i] - 6, lineBreak: false }); x += widths[i]; } stroke(doc, C.border);