teqo-backup/src/lib/electionFormat.ts
Francisco Ignácio Fontoura Solla 66feecd66b simplify(B13): corrige classe agregada, bolhas em pane proprio e registra debitos
O /simplify da escala relativa do mapa achou um bug semantico real em
computeAggregateTerritorialClass — somava o headroom dos slugs e comparava
contra a mediana de UMA unidade, classificando um grupo grande como expansao
quando ele e marginal. A mediana agora escala por slugs.length, com teste.

As bolhas sairam do centro do bounding box para o centroide real e ganharam
pane proprio (z-index 450), porque o bringToFront do hover as escondia atras
do poligono. Legenda e pintura passaram a compartilhar o mesmo predicado,
a copy dos quantis parou de prometer faixas de igual largura, e o subtitulo
do painel parou de dizer "em 2026" com 2022 selecionado (defeito do B11).

Fonte unica onde havia duas: NO_DATA_FILL, o raio das bolhas e
formatPlacementOrdinal (ex-formatMunicipalityVoteRank, agora client-safe em
electionFormat.ts).

Os quatro debitos maiores que o cleanup viraram o fill-in B13+
(docs/plans/escala-dry-pos-b13.md); a flakiness dos e2e, reproduzida em main
limpo, foi para o ledger com a causa afinada.
2026-07-26 05:12:37 -03:00

31 lines
1.4 KiB
TypeScript

/**
* Vote counts are whole votes, including the derived ones (E8's decomposed
* suggested goal and its deficit are fractional). Without pinning the fraction
* digits, pt-BR renders a goal of 100.968 votes as "100,968" — read as a
* hundred thousand by every human in the room.
*/
const numberFormatter = new Intl.NumberFormat('pt-BR', { maximumFractionDigits: 0 })
/** Shares and multiples: one decimal at most, never a forced trailing zero. */
export const oneDecimalFormatter = new Intl.NumberFormat('pt-BR', {
maximumFractionDigits: 1,
minimumFractionDigits: 0,
})
export const formatElectionNumber = (value: number): string => numberFormatter.format(value)
/**
* A ratio (0..1) as a share label with at most one decimal — the shape used
* for "% da própria votação estadual". Lives here, not next to the ranking it
* was written for, so client bundles can format a share without pulling the
* committed TSE artifact along with it.
*/
export const formatVoteSharePercent = (share: number): string =>
`${oneDecimalFormatter.format(share * 100)}%`
/**
* A placement as a pt-BR ordinal — "4º". Used for both rankings the product
* shows (a município among the 435, A11; the candidate among those votados
* num município, B13), and here for the same bundle reason as the share above.
*/
export const formatPlacementOrdinal = (rank: number): string => `${formatElectionNumber(rank)}º`