diff --git a/web/components/visualization/results-section.js b/web/components/visualization/results-section.js index cba58a740e8b08cd55568192937cf8258f2ff9dd..6a2cb5758a8c7592f65907e5b4ac371c0755e7e7 100644 --- a/web/components/visualization/results-section.js +++ b/web/components/visualization/results-section.js @@ -99,8 +99,8 @@ class ResultComponent { </button> </header> <div class="card-content"> - <div id="round-list" class="content"> - Résultats détaillés du tour + <div id="detailed-results" class="content"> + <h5 class="title is-5">Résultats détaillés du tour</h5> </div> </div> </div> @@ -121,12 +121,11 @@ class ResultComponent { </div>`; } - async progressBarTemplate(candidateList) { - let party = await this.PartyModel.getParty(candidateList.PartyID); + progressBarTemplate(candidateList, color) { return /* HTML */ `<div class="progressBar"> <div class="progressBarValue" - style="background-color : ${party.Color}; width : ${candidateList.Percentage}%" + style="background-color : ${color}; width : ${candidateList.Percentage}%" > ${candidateList.Name + " (" + @@ -236,33 +235,37 @@ class ResultComponent { } displayResults() { - console.log(this.results); document.getElementById("news-flow").innerHTML = ""; if (this.zone === "areas") { this.displayFlowAreas(); } else if (this.zone === "sections") { this.displayFlowSections(); } - let scroller = Scroller.scrollInit("news-flow"); + this.displayRoundResults(); + Scroller.scrollInit("news-flow"); } async displayFlowAreas() { - let resultHandler = this; this.results.areasResults.sort(function (a, b) { return b.DateCompletion - a.DateCompletion; }); for (let j in this.results.areasResults) { let area = this.results.areasResults[j]; - if (area.status === resultHandler.filter) { + if (area.status === this.filter) { document.getElementById( "news-flow" ).innerHTML += this.resultFlowTemplate(area); for (let i in area.candidateLists) { + let party = await this.PartyModel.getParty( + area.candidateLists[i].PartyID + ); + document.getElementById( "flow-content-" + area.ID - ).innerHTML += await resultHandler.progressBarTemplate( - area.candidateLists[i] + ).innerHTML += await this.progressBarTemplate( + area.candidateLists[i], + party.Color ); } } @@ -270,7 +273,6 @@ class ResultComponent { } async displayFlowSections() { - let resultHandler = this; let sections = []; this.results.areasResults.forEach((area) => { sections = sections.concat(area.Sections); @@ -281,19 +283,36 @@ class ResultComponent { for (let j in sections) { let section = sections[j]; - if (section.status === resultHandler.filter) { + if (section.status === this.filter) { document.getElementById( "news-flow" ).innerHTML += this.resultFlowTemplate(section); for (let i in section.candidateLists) { + let party = await this.PartyModel.getParty( + section.candidateLists[i].PartyID + ); + document.getElementById( "flow-content-" + section.ID - ).innerHTML += await resultHandler.progressBarTemplate( - section.candidateLists[i] + ).innerHTML += await this.progressBarTemplate( + section.candidateLists[i], + party.Color ); } } } } + + displayRoundResults() { + document.getElementById("detailed-results").innerHTML = `<h5 class="title is-5">Résultats détaillés du tour</h5>`; + for (let i in this.results.roundResults) { + document.getElementById( + "detailed-results" + ).innerHTML += this.progressBarTemplate( + this.results.roundResults[i], + this.results.roundResults[i].Color + ); + } + } } diff --git a/web/services/election/calculate-election-generic.js b/web/services/election/calculate-election-generic.js index f35ff0fd7fca3a83984363e1e77a3ca7fa84a060..9ce1a53b29ee888c390b2c1c0af5402647e4d883 100644 --- a/web/services/election/calculate-election-generic.js +++ b/web/services/election/calculate-election-generic.js @@ -123,6 +123,9 @@ class DirectMetropolitanCalculator { }, currentParty.VoiceNumber ); + currentParty.Percentage = Number( + (currentParty.VoiceNumber / this.stats.VotesExpressed) * 100 + ).toFixed(2); } }); party = currentParty; @@ -226,8 +229,9 @@ class DirectMetropolitanCalculator { }, 0 ); - candidateList.Percentage = - Number((candidateList.VoiceNumber / area.stats.VotesExpressed) * 100).toFixed(2); + candidateList.Percentage = Number( + (candidateList.VoiceNumber / area.stats.VotesExpressed) * 100 + ).toFixed(2); }); area.candidateLists = candidateListToKeep; area.candidateLists.sort((a, b) => { @@ -291,7 +295,7 @@ class DirectMetropolitanCalculator { section.status = "validated"; } else { section.status = "not validated"; - return section ; + return section; } } @@ -307,8 +311,9 @@ class DirectMetropolitanCalculator { }, 0 ); - candidateList.Percentage = - Number((candidateList.VoiceNumber / section.stats.VotesExpressed) * 100).toFixed(2); + candidateList.Percentage = Number( + (candidateList.VoiceNumber / section.stats.VotesExpressed) * 100 + ).toFixed(2); }); section.candidateLists = candidateLists; section.candidateLists.sort((a, b) => {