From 0fef97dd8294954161815353d115432af5bdb70d Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Fri, 21 Jun 2024 00:14:19 +0200 Subject: [PATCH] Meilleur affichage participation tour 1 + 2 --- .../src/ElectionsEuropeennes2024.js | 4 +- .../src/ElectionsLegislatives2022.js | 4 +- .../src/includes/composants_elections.js | 179 +++++++++++++----- .../composants_elections_legislatives.js | 48 +++-- 4 files changed, 171 insertions(+), 64 deletions(-) diff --git a/nupes-elections-front/src/ElectionsEuropeennes2024.js b/nupes-elections-front/src/ElectionsEuropeennes2024.js index 6e9651e..e0b6772 100644 --- a/nupes-elections-front/src/ElectionsEuropeennes2024.js +++ b/nupes-elections-front/src/ElectionsEuropeennes2024.js @@ -82,7 +82,7 @@ export default function ElectionsEuropeennes2024() { } return [categories, voixParNuance, couleurs] } - }, [typeResultats, nuances, blocs, donnees, voixParNuance, voixParBloc, grouperParBloc]) + }, [nuances, blocs, voixParNuance, voixParBloc, grouperParBloc]) return <> @@ -100,7 +100,7 @@ export default function ElectionsEuropeennes2024() { blocs={blocs} nuances={nuances} siegesParBloc={siegesParBloc} siegesParNuance={siegesParNuance} grouperParBloc={grouperParBloc} /> - + diff --git a/nupes-elections-front/src/ElectionsLegislatives2022.js b/nupes-elections-front/src/ElectionsLegislatives2022.js index 5bdca16..30fed63 100644 --- a/nupes-elections-front/src/ElectionsLegislatives2022.js +++ b/nupes-elections-front/src/ElectionsLegislatives2022.js @@ -121,7 +121,7 @@ export default function ElectionsLegislatives2022() { const tableauResultats = useMemo(() => { if (typeResultats === "circonscription" || typeResultats === "bureau_vote") - return + return else return }, [typeResultats, candidats, blocs, nuances, donnees]) @@ -139,7 +139,7 @@ export default function ElectionsLegislatives2022() { nomCategories={categoriesHistogramme} valeurParCategorie={valeursHistogramme} totalExprimes={donnees.exprimes} couleurParCategorie={couleursHistogramme} /> {tableauResultats} - + diff --git a/nupes-elections-front/src/includes/composants_elections.js b/nupes-elections-front/src/includes/composants_elections.js index c3b689d..f5cebb9 100644 --- a/nupes-elections-front/src/includes/composants_elections.js +++ b/nupes-elections-front/src/includes/composants_elections.js @@ -22,9 +22,11 @@ export function HistogrammeVoix({titre, nomCategories, valeurParCategorie, total const data = [] for (let categorie of Object.keys(nomCategories)) { - categories.push(nomCategories[categorie]) - data.push([nomCategories[categorie], valeurParCategorie[categorie], couleurParCategorie[categorie], - nomCategories[categorie]]) + if (valeurParCategorie[categorie] !== 0) { + categories.push(nomCategories[categorie]) + data.push([nomCategories[categorie], valeurParCategorie[categorie], couleurParCategorie[categorie], + nomCategories[categorie]]) + } } return [categories, data] @@ -109,59 +111,142 @@ export function CompositionHemicycle({titre, blocs, nuances, siegesParBloc, sieg /** * Tableau de participation de l'élection dans la zone concernée - * @param resultats + * @param donnees_t1 + * @param donnees_t2 * @return {JSX.Element} * @constructor */ -export function TableauParticipation({resultats}) { +export function TableauParticipation({donnees_t1, donnees_t2 = null}) { + const headerRow = useMemo(() => { + if (donnees_t2) { + return + + Nombre tour 1 + % Inscrit⋅es tour 1 + % Votant⋅es tour 1 + Nombre tour 2 + % Inscrit⋅es tour 2 + % Votant⋅es tour 2 + + } + else { + return + + Nombre + % Inscrit⋅es + % Votant⋅es + + } + }, [donnees_t2]) + + const bodyRows = useMemo(() => { + if (donnees_t2) { + return <> + + Inscrit⋅es + {donnees_t1.inscrits} + + + {donnees_t2.inscrits} + + + + + Abstention + {donnees_t1.abstentions} + {(100 * donnees_t1.abstentions / donnees_t1.inscrits).toFixed(2)} % + + {donnees_t2.abstentions} + {(100 * donnees_t2.abstentions / donnees_t2.inscrits).toFixed(2)} % + + + + Votant⋅es + {donnees_t1.votants} + {(100 * donnees_t1.votants / donnees_t1.inscrits).toFixed(2)} % + + {donnees_t2.votants} + {(100 * donnees_t2.votants / donnees_t2.inscrits).toFixed(2)} % + + + + Blancs + {donnees_t1.blancs} + {(100 * donnees_t1.blancs / donnees_t1.inscrits).toFixed(2)} % + {(100 * donnees_t1.blancs / donnees_t1.votants).toFixed(2)} % + {donnees_t2.blancs} + {(100 * donnees_t2.blancs / donnees_t2.inscrits).toFixed(2)} % + {(100 * donnees_t2.blancs / donnees_t2.votants).toFixed(2)} % + + + Nuls + {donnees_t1.nuls} + {(100 * donnees_t1.nuls / donnees_t1.inscrits).toFixed(2)} % + {(100 * donnees_t1.nuls / donnees_t1.votants).toFixed(2)} % + {donnees_t2.nuls} + {(100 * donnees_t2.nuls / donnees_t2.inscrits).toFixed(2)} % + {(100 * donnees_t2.nuls / donnees_t2.votants).toFixed(2)} % + + + Exprimés + {donnees_t1.exprimes} + {(100 * donnees_t1.exprimes / donnees_t1.inscrits).toFixed(2)} % + {(100 * donnees_t1.exprimes / donnees_t1.votants).toFixed(2)} % + {donnees_t2.exprimes} + {(100 * donnees_t2.exprimes / donnees_t2.inscrits).toFixed(2)} % + {(100 * donnees_t2.exprimes / donnees_t2.votants).toFixed(2)} % + + + } else { + return <> + + Inscrit⋅es + {donnees_t1.inscrits} + + + + + Abstention + {donnees_t1.abstentions} + {(100 * donnees_t1.abstentions / donnees_t1.inscrits).toFixed(2)} % + + + + Votant⋅es + {donnees_t1.votants} + {(100 * donnees_t1.votants / donnees_t1.inscrits).toFixed(2)} % + + + + Blancs + {donnees_t1.blancs} + {(100 * donnees_t1.blancs / donnees_t1.inscrits).toFixed(2)} % + {(100 * donnees_t1.blancs / donnees_t1.votants).toFixed(2)} % + + + Nuls + {donnees_t1.nuls} + {(100 * donnees_t1.nuls / donnees_t1.inscrits).toFixed(2)} % + {(100 * donnees_t1.nuls / donnees_t1.votants).toFixed(2)} % + + + Exprimés + {donnees_t1.exprimes} + {(100 * donnees_t1.exprimes / donnees_t1.inscrits).toFixed(2)} % + {(100 * donnees_t1.exprimes / donnees_t1.votants).toFixed(2)} % + + + } + }, [donnees_t1, donnees_t2]) + return <> - - - Nombre - % Inscrit⋅es - % Votant⋅es - + {headerRow} - - Inscrit⋅es - {resultats.inscrits} - - - - - Abstention - {resultats.abstentions} - {(100 * resultats.abstentions / resultats.inscrits).toFixed(2)} % - - - - Votant⋅es - {resultats.votants} - {(100 * resultats.votants / resultats.inscrits).toFixed(2)} % - - - - Blancs - {resultats.blancs} - {(100 * resultats.blancs / resultats.inscrits).toFixed(2)} % - {(100 * resultats.blancs / resultats.votants).toFixed(2)} % - - - Nuls - {resultats.nuls} - {(100 * resultats.nuls / resultats.inscrits).toFixed(2)} % - {(100 * resultats.nuls / resultats.votants).toFixed(2)} % - - - Exprimés - {resultats.exprimes} - {(100 * resultats.exprimes / resultats.inscrits).toFixed(2)} % - {(100 * resultats.exprimes / resultats.votants).toFixed(2)} % - + {bodyRows}
diff --git a/nupes-elections-front/src/includes/composants_elections_legislatives.js b/nupes-elections-front/src/includes/composants_elections_legislatives.js index f12b752..743d7c2 100644 --- a/nupes-elections-front/src/includes/composants_elections_legislatives.js +++ b/nupes-elections-front/src/includes/composants_elections_legislatives.js @@ -7,9 +7,10 @@ import TableRow from "@mui/material/TableRow" import TableCell from "@mui/material/TableCell" import TableBody from "@mui/material/TableBody" -export function TableauResultatsCandidatsLegislatives({blocs, candidats, nuances, donnees}) { - const voixCandidats = donnees?.voix ?? {} - const candidatsTriees = trierCandidats(candidats, voixCandidats) +export function TableauResultatsCandidatsLegislatives({blocs, candidats, nuances, donnees_t1, donnees_t2}) { + const voixCandidats_t1 = donnees_t1?.voix ?? {} + const voixCandidats_t2 = donnees_t2?.voix ?? {} + const candidatsTriees = trierCandidats(candidats, voixCandidats_t1) return <> @@ -20,15 +21,21 @@ export function TableauResultatsCandidatsLegislatives({blocs, candidats, nuances Candidat Nuance Bloc - Voix - % Inscrit⋅es - % Exprimé⋅es + Voix tour 1 + % Inscrit⋅es tour 1 + % Exprimé⋅es tour 1 + Voix tour 2 + % Inscrit⋅es tour 2 + % Exprimé⋅es tour 2 {candidatsTriees.map((candidat) => ( - + ))} @@ -36,20 +43,35 @@ export function TableauResultatsCandidatsLegislatives({blocs, candidats, nuances } -function LigneCandidat({candidat, voix, donnees, nuances, blocs}) { +function LigneCandidat({candidat, voix_t1, voix_t2, donnees_t1, donnees_t2, nuances, blocs}) { const nuance = nuances.filter(nuance => nuance.code === candidat.nuance)[0] const bloc = blocs.filter(bloc => bloc.nom === candidat.bloc)[0] - return + const gagnant = voix_t2 === Math.max(...Object.values(donnees_t2.voix)) + || (voix_t1 === Math.max(...Object.values(donnees_t1.voix)) + && voix_t1 / donnees_t1.exprimes >= 0.5 && voix_t1 / donnees_t1.inscrits >= 0.25) + + const cellules_t1 = <> + {voix_t1} + {(100 * voix_t1 / donnees_t1.inscrits).toFixed(2)} % + {(100 * voix_t1 / donnees_t1.exprimes).toFixed(2)} % + + + const cellules_t2 = !voix_t2 ? <> : <> + {voix_t2} + {(100 * voix_t2 / donnees_t2.inscrits).toFixed(2)} % + {(100 * voix_t2 / donnees_t2.exprimes).toFixed(2)} % + + + return {candidat.numero} {candidat.prenom} {candidat.nom} {nuance.nom} ({nuance.code}) {bloc.nom} - {voix} - {(100 * voix / donnees.inscrits).toFixed(2)} % - {(100 * voix / donnees.exprimes).toFixed(2)} % + {cellules_t1} + {cellules_t2} }