Meilleur affichage participation tour 1 + 2

This commit is contained in:
Emmy D'Anello 2024-06-21 00:14:19 +02:00
parent d75ab4d0f3
commit 0fef97dd82
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
4 changed files with 171 additions and 64 deletions

View File

@ -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 <>
<AppBar position="sticky">
@ -100,7 +100,7 @@ export default function ElectionsEuropeennes2024() {
blocs={blocs} nuances={nuances} siegesParBloc={siegesParBloc} siegesParNuance={siegesParNuance}
grouperParBloc={grouperParBloc} />
<TableauResultatsEuropeennes blocs={blocs} nuances={nuances} listes={listes} resultats={donnees} siegesParListe={siegesParListe} />
<TableauParticipation resultats={donnees} />
<TableauParticipation donnees_t1={donnees} />
<CarteResultats typeElection={"europeennes"} anneeElection={"2024"} typeResultats={typeResultats} zoneInfo={zoneInfo}
typeSousZone={typeSousZone} candidats={listes} blocs={blocs} nuances={nuances} tour={tour}
grouperParBloc={grouperParBloc} />

View File

@ -121,7 +121,7 @@ export default function ElectionsLegislatives2022() {
const tableauResultats = useMemo(() => {
if (typeResultats === "circonscription" || typeResultats === "bureau_vote")
return <TableauResultatsCandidatsLegislatives candidats={candidats} blocs={blocs} nuances={nuances} donnees={donnees} />
return <TableauResultatsCandidatsLegislatives candidats={candidats} blocs={blocs} nuances={nuances} donnees_t1={resultats.tour1} donnees_t2={resultats.tour2} />
else
return <TableauResultatsNuancesLegislatives blocs={blocs} nuances={nuances} donnees={donnees} />
}, [typeResultats, candidats, blocs, nuances, donnees])
@ -139,7 +139,7 @@ export default function ElectionsLegislatives2022() {
nomCategories={categoriesHistogramme} valeurParCategorie={valeursHistogramme}
totalExprimes={donnees.exprimes} couleurParCategorie={couleursHistogramme} />
{tableauResultats}
<TableauParticipation resultats={donnees} />
<TableauParticipation donnees_t1={resultats.tour1 ?? {}} donnees_t2={resultats.tour2 ?? {}} />
<CarteResultats typeElection={"legislatives"} anneeElection={"2022"} typeResultats={typeResultats} zoneInfo={zoneInfo}
typeSousZone={typeSousZone} candidats={candidats} blocs={blocs} nuances={nuances} tour={tour}
grouperParBloc={grouperParBloc} candidatKey={candidatKey} />

View File

@ -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 <TableRow>
<TableCell></TableCell>
<TableCell>Nombre tour 1</TableCell>
<TableCell>% Inscrites tour 1</TableCell>
<TableCell>% Votantes tour 1</TableCell>
<TableCell>Nombre tour 2</TableCell>
<TableCell>% Inscrites tour 2</TableCell>
<TableCell>% Votantes tour 2</TableCell>
</TableRow>
}
else {
return <TableRow>
<TableCell></TableCell>
<TableCell>Nombre</TableCell>
<TableCell>% Inscrites</TableCell>
<TableCell>% Votantes</TableCell>
</TableRow>
}
}, [donnees_t2])
const bodyRows = useMemo(() => {
if (donnees_t2) {
return <>
<TableRow key={"Inscrit⋅es"}>
<TableCell>Inscrites</TableCell>
<TableCell>{donnees_t1.inscrits}</TableCell>
<TableCell></TableCell>
<TableCell></TableCell>
<TableCell>{donnees_t2.inscrits}</TableCell>
<TableCell></TableCell>
<TableCell></TableCell>
</TableRow>
<TableRow key={"Abstentions"}>
<TableCell>Abstention</TableCell>
<TableCell>{donnees_t1.abstentions}</TableCell>
<TableCell>{(100 * donnees_t1.abstentions / donnees_t1.inscrits).toFixed(2)} %</TableCell>
<TableCell></TableCell>
<TableCell>{donnees_t2.abstentions}</TableCell>
<TableCell>{(100 * donnees_t2.abstentions / donnees_t2.inscrits).toFixed(2)} %</TableCell>
<TableCell></TableCell>
</TableRow>
<TableRow key={"Votant⋅es"}>
<TableCell>Votantes</TableCell>
<TableCell>{donnees_t1.votants}</TableCell>
<TableCell>{(100 * donnees_t1.votants / donnees_t1.inscrits).toFixed(2)} %</TableCell>
<TableCell></TableCell>
<TableCell>{donnees_t2.votants}</TableCell>
<TableCell>{(100 * donnees_t2.votants / donnees_t2.inscrits).toFixed(2)} %</TableCell>
<TableCell></TableCell>
</TableRow>
<TableRow key={"Blancs"}>
<TableCell>Blancs</TableCell>
<TableCell>{donnees_t1.blancs}</TableCell>
<TableCell>{(100 * donnees_t1.blancs / donnees_t1.inscrits).toFixed(2)} %</TableCell>
<TableCell>{(100 * donnees_t1.blancs / donnees_t1.votants).toFixed(2)} %</TableCell>
<TableCell>{donnees_t2.blancs}</TableCell>
<TableCell>{(100 * donnees_t2.blancs / donnees_t2.inscrits).toFixed(2)} %</TableCell>
<TableCell>{(100 * donnees_t2.blancs / donnees_t2.votants).toFixed(2)} %</TableCell>
</TableRow>
<TableRow key={"Nuls"}>
<TableCell>Nuls</TableCell>
<TableCell>{donnees_t1.nuls}</TableCell>
<TableCell>{(100 * donnees_t1.nuls / donnees_t1.inscrits).toFixed(2)} %</TableCell>
<TableCell>{(100 * donnees_t1.nuls / donnees_t1.votants).toFixed(2)} %</TableCell>
<TableCell>{donnees_t2.nuls}</TableCell>
<TableCell>{(100 * donnees_t2.nuls / donnees_t2.inscrits).toFixed(2)} %</TableCell>
<TableCell>{(100 * donnees_t2.nuls / donnees_t2.votants).toFixed(2)} %</TableCell>
</TableRow>
<TableRow key={"Exprimés"}>
<TableCell>Exprimés</TableCell>
<TableCell>{donnees_t1.exprimes}</TableCell>
<TableCell>{(100 * donnees_t1.exprimes / donnees_t1.inscrits).toFixed(2)} %</TableCell>
<TableCell>{(100 * donnees_t1.exprimes / donnees_t1.votants).toFixed(2)} %</TableCell>
<TableCell>{donnees_t2.exprimes}</TableCell>
<TableCell>{(100 * donnees_t2.exprimes / donnees_t2.inscrits).toFixed(2)} %</TableCell>
<TableCell>{(100 * donnees_t2.exprimes / donnees_t2.votants).toFixed(2)} %</TableCell>
</TableRow>
</>
} else {
return <>
<TableRow key={"Inscrit⋅es"}>
<TableCell>Inscrites</TableCell>
<TableCell>{donnees_t1.inscrits}</TableCell>
<TableCell></TableCell>
<TableCell></TableCell>
</TableRow>
<TableRow key={"Abstentions"}>
<TableCell>Abstention</TableCell>
<TableCell>{donnees_t1.abstentions}</TableCell>
<TableCell>{(100 * donnees_t1.abstentions / donnees_t1.inscrits).toFixed(2)} %</TableCell>
<TableCell></TableCell>
</TableRow>
<TableRow key={"Votant⋅es"}>
<TableCell>Votantes</TableCell>
<TableCell>{donnees_t1.votants}</TableCell>
<TableCell>{(100 * donnees_t1.votants / donnees_t1.inscrits).toFixed(2)} %</TableCell>
<TableCell></TableCell>
</TableRow>
<TableRow key={"Blancs"}>
<TableCell>Blancs</TableCell>
<TableCell>{donnees_t1.blancs}</TableCell>
<TableCell>{(100 * donnees_t1.blancs / donnees_t1.inscrits).toFixed(2)} %</TableCell>
<TableCell>{(100 * donnees_t1.blancs / donnees_t1.votants).toFixed(2)} %</TableCell>
</TableRow>
<TableRow key={"Nuls"}>
<TableCell>Nuls</TableCell>
<TableCell>{donnees_t1.nuls}</TableCell>
<TableCell>{(100 * donnees_t1.nuls / donnees_t1.inscrits).toFixed(2)} %</TableCell>
<TableCell>{(100 * donnees_t1.nuls / donnees_t1.votants).toFixed(2)} %</TableCell>
</TableRow>
<TableRow key={"Exprimés"}>
<TableCell>Exprimés</TableCell>
<TableCell>{donnees_t1.exprimes}</TableCell>
<TableCell>{(100 * donnees_t1.exprimes / donnees_t1.inscrits).toFixed(2)} %</TableCell>
<TableCell>{(100 * donnees_t1.exprimes / donnees_t1.votants).toFixed(2)} %</TableCell>
</TableRow>
</>
}
}, [donnees_t1, donnees_t2])
return <>
<TableContainer component={Paper}>
<Table sx={{ minWidth: 650 }} aria-label="simple table">
<TableHead>
<TableRow>
<TableCell></TableCell>
<TableCell>Nombre</TableCell>
<TableCell>% Inscrites</TableCell>
<TableCell>% Votantes</TableCell>
</TableRow>
{headerRow}
</TableHead>
<TableBody>
<TableRow key={"Inscrit⋅es"}>
<TableCell>Inscrites</TableCell>
<TableCell>{resultats.inscrits}</TableCell>
<TableCell></TableCell>
<TableCell></TableCell>
</TableRow>
<TableRow key={"Abstentions"}>
<TableCell>Abstention</TableCell>
<TableCell>{resultats.abstentions}</TableCell>
<TableCell>{(100 * resultats.abstentions / resultats.inscrits).toFixed(2)} %</TableCell>
<TableCell></TableCell>
</TableRow>
<TableRow key={"Votant⋅es"}>
<TableCell>Votantes</TableCell>
<TableCell>{resultats.votants}</TableCell>
<TableCell>{(100 * resultats.votants / resultats.inscrits).toFixed(2)} %</TableCell>
<TableCell></TableCell>
</TableRow>
<TableRow key={"Blancs"}>
<TableCell>Blancs</TableCell>
<TableCell>{resultats.blancs}</TableCell>
<TableCell>{(100 * resultats.blancs / resultats.inscrits).toFixed(2)} %</TableCell>
<TableCell>{(100 * resultats.blancs / resultats.votants).toFixed(2)} %</TableCell>
</TableRow>
<TableRow key={"Nuls"}>
<TableCell>Nuls</TableCell>
<TableCell>{resultats.nuls}</TableCell>
<TableCell>{(100 * resultats.nuls / resultats.inscrits).toFixed(2)} %</TableCell>
<TableCell>{(100 * resultats.nuls / resultats.votants).toFixed(2)} %</TableCell>
</TableRow>
<TableRow key={"Exprimés"}>
<TableCell>Exprimés</TableCell>
<TableCell>{resultats.exprimes}</TableCell>
<TableCell>{(100 * resultats.exprimes / resultats.inscrits).toFixed(2)} %</TableCell>
<TableCell>{(100 * resultats.exprimes / resultats.votants).toFixed(2)} %</TableCell>
</TableRow>
{bodyRows}
</TableBody>
</Table>
</TableContainer>

View File

@ -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 <>
<TableContainer component={Paper}>
@ -20,15 +21,21 @@ export function TableauResultatsCandidatsLegislatives({blocs, candidats, nuances
<TableCell>Candidat</TableCell>
<TableCell colSpan={2}>Nuance</TableCell>
<TableCell colSpan={2}>Bloc</TableCell>
<TableCell>Voix</TableCell>
<TableCell>% Inscrites</TableCell>
<TableCell>% Exprimées</TableCell>
<TableCell>Voix tour 1</TableCell>
<TableCell>% Inscrites tour 1</TableCell>
<TableCell>% Exprimées tour 1</TableCell>
<TableCell>Voix tour 2</TableCell>
<TableCell>% Inscrites tour 2</TableCell>
<TableCell>% Exprimées tour 2</TableCell>
</TableRow>
</TableHead>
<TableBody>
{candidatsTriees.map((candidat) => (
<LigneCandidat key={candidat.numero} candidat={candidat} voix={voixCandidats[candidat.numero] || 0}
donnees={donnees} nuances={nuances} blocs={blocs} />
<LigneCandidat key={candidat.numero} candidat={candidat}
voix_t1={voixCandidats_t1[candidat.numero] || 0}
voix_t2={voixCandidats_t2[candidat.numero] || 0}
donnees_t1={donnees_t1} donnees_t2={donnees_t2}
nuances={nuances} blocs={blocs} />
))}
</TableBody>
</Table>
@ -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 <TableRow key={candidat.numero}>
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 = <>
<TableCell>{voix_t1}</TableCell>
<TableCell>{(100 * voix_t1 / donnees_t1.inscrits).toFixed(2)} %</TableCell>
<TableCell>{(100 * voix_t1 / donnees_t1.exprimes).toFixed(2)} %</TableCell>
</>
const cellules_t2 = !voix_t2 ? <></> : <>
<TableCell>{voix_t2}</TableCell>
<TableCell>{(100 * voix_t2 / donnees_t2.inscrits).toFixed(2)} %</TableCell>
<TableCell>{(100 * voix_t2 / donnees_t2.exprimes).toFixed(2)} %</TableCell>
</>
return <TableRow sx={{backgroundColor: gagnant ? "#AAFFAA" : ""}} key={candidat.numero}>
<TableCell>{candidat.numero}</TableCell>
<TableCell>{candidat.prenom} {candidat.nom}</TableCell>
<TableCell sx={{backgroundColor: nuance.couleur, padding: "0.2em"}}></TableCell>
<TableCell>{nuance.nom} ({nuance.code})</TableCell>
<TableCell sx={{backgroundColor: bloc.couleur, padding: "0.2em"}}></TableCell>
<TableCell>{bloc.nom}</TableCell>
<TableCell>{voix}</TableCell>
<TableCell>{(100 * voix / donnees.inscrits).toFixed(2)} %</TableCell>
<TableCell>{(100 * voix / donnees.exprimes).toFixed(2)} %</TableCell>
{cellules_t1}
{cellules_t2}
</TableRow>
}