Size the legend's compact population to its fixed column in every locale

Intl compact forms are longer than the old '12.3M': with one decimal
everywhere, German reached '123,5 Mio.' (10 chars) on the region rows,
past both the 60px mobile and 70px desktop Population column. One
decimal now only below 10 million; whole units above. Worst case over
all 11 locales: 8 Latin chars (de/ro/ru '123 Mio.').
This commit is contained in:
Doxa Maps 2026-09-29 08:24:08 +00:00
parent a3e58ac7ca
commit 64a15f4a03

View file

@ -642,12 +642,15 @@ function numLocale() {
}
// ★ COMPACT IN THE READER'S NOTATION. This was `toFixed(1) + 'M'` / `+ 'k'`: English abbreviations with
// an English decimal point on every Population cell in every locale. Intl's compact notation writes each
// language's own form (ru "12,3 млн", de "12,3 Mio.", ar "12.3 مليون", zh "1234.6万") at the same
// precision as before: one decimal for millions, whole thousands.
// language's own form (ru "1,2 млн", de "1,2 Mio.", ar "1.2 مليون", zh "123.5万").
// ⚠ SIZED TO THE COLUMN, which is fixed (--stl-num-w: 60px at 10.5px mono, 70px at 13px). The local forms are
// longer than "12.3M": with one decimal everywhere de reached "123,5 Mio." (10 chars) — past both widths on
// the region rows, whose sums run to hundreds of millions. So one decimal only below 10 million, where it
// carries real information; whole units above. Worst case measured over all 11 locales: 8 Latin chars.
function fmtPop(n) {
if (!n) return '—'
if (n >= 1e3) {
return new Intl.NumberFormat(numLocale(), { notation: 'compact', maximumFractionDigits: n >= 1e6 ? 1 : 0 }).format(n)
return new Intl.NumberFormat(numLocale(), { notation: 'compact', maximumFractionDigits: n >= 1e6 && n < 1e7 ? 1 : 0 }).format(n)
}
return n.toLocaleString(numLocale())
}