Skip to content

Commit

Permalink
Merge pull request #26 from Petrosdevri/25-change-party-priority
Browse files Browse the repository at this point in the history
Changed party priority
  • Loading branch information
Petrosdevri authored Jan 25, 2024
2 parents 7cb6116 + 0895f3a commit 05d604d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/pages/Home/Ballot.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default function PartyBallot({ nd, syriza, pasok, kke, el, niki, pe, mera
<Party color='#CC1C24' name='ΣΥΡΙΖΑ' votes={syriza} setVotes={setSYRIZA} />
<Party color='#00793A' name='ΠΑΣΟΚ' votes={pasok} setVotes={setPASOK} />
<Party color='#DF251C' name='ΚΚΕ' votes={kke} setVotes={setKKE} />
<Party color='#E4B365' name='Σπαρτιάτες' votes={spartiates} setVotes={setSpartiates} />
<Party color='#8DBEE2' name='Ελληνική Λύση' votes={el} setVotes={setEL} />
<Party color='#BD552C' name='Νίκη' votes={niki} setVotes={setNIKI} />
<Party color='#972490' name='Πλεύση Ελευθερίας' votes={pe} setVotes={setPE} />
Expand All @@ -20,7 +21,6 @@ export default function PartyBallot({ nd, syriza, pasok, kke, el, niki, pe, mera
<Party color='#D82F33' name='ΑΝΤΑΡΣΥΑ' votes={antarsya} setVotes={setANTARSYA} />
<Party color='#F2D308' name='Ένωση Κεντρώων' votes={ek} setVotes={setEK} />
<Party color='#D7062C' name='ΚΚΕ(μ-λ)' votes={kkeml} setVotes={setKKEML} />
<Party color='#E4B365' name='Σπαρτιάτες' votes={spartiates} setVotes={setSpartiates} />
</div>
</div>
)
Expand Down
10 changes: 5 additions & 5 deletions src/pages/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { apliAnalogiki, enisximeniAnalogiki } from '@poliverse/greek-electoral-s
import { Button, Stack } from 'react-bootstrap';
import Ballot from './Ballot';

export default function Home({nd, syriza, pasok, kke, el, niki, pe, mera25, epam, ed, op, ps, antarsya, ek, kkeml, spartiates, electoralSystem, electoralThreshold, seatDistribution, showResults, setND, setSYRIZA, setPASOK, setKKE, setEL, setNIKI, setPE, setMeRA25, setEPAM, setED, setOP, setPS, setANTARSYA, setEK, setKKEML, setSpartiates, setElectoralSystem, setElectoralThreshold, setSeatDistribution, setShowResults}) {
export default function Home({nd, syriza, pasok, kke, spartiates, el, niki, pe, mera25, epam, ed, op, ps, antarsya, ek, kkeml, electoralSystem, electoralThreshold, seatDistribution, showResults, setND, setSYRIZA, setPASOK, setKKE, setSpartiates, setEL, setNIKI, setPE, setMeRA25, setEPAM, setED, setOP, setPS, setANTARSYA, setEK, setKKEML, setElectoralSystem, setElectoralThreshold, setSeatDistribution, setShowResults}) {
const navigate = useNavigate();

function isMobileDevice() {
Expand All @@ -16,6 +16,7 @@ export default function Home({nd, syriza, pasok, kke, el, niki, pe, mera25, epam
const syrizaPercentage = parseFloat(syriza);
const pasokPercentage = parseFloat(pasok);
const kkePercentage = parseFloat(kke);
const spartiatesPercentage = parseFloat(spartiates);
const elPercentage = parseFloat(el);
const nikiPercentage = parseFloat(niki);
const pePercentage = parseFloat(pe);
Expand All @@ -27,14 +28,13 @@ export default function Home({nd, syriza, pasok, kke, el, niki, pe, mera25, epam
const antarsyaPercentage = parseFloat(antarsya);
const ekPercentage = parseFloat(ek);
const kkemlPercentage = parseFloat(kkeml);
const spartiatesPercentage = parseFloat(spartiates);

if(isNaN(ndPercentage) || isNaN(syrizaPercentage) || isNaN(pasokPercentage) || isNaN(kkePercentage) || isNaN(elPercentage) || isNaN(nikiPercentage) || isNaN(pePercentage) || isNaN(mera25Percentage) || isNaN(epamPercentage) || isNaN(edPercentage) || isNaN(opPercentage) || isNaN(psPercentage) || isNaN(antarsyaPercentage) || isNaN(ekPercentage) || isNaN(kkemlPercentage) || isNaN(spartiatesPercentage)) {
if(isNaN(ndPercentage) || isNaN(syrizaPercentage) || isNaN(pasokPercentage) || isNaN(kkePercentage) || isNaN(spartiatesPercentage) || isNaN(elPercentage) || isNaN(nikiPercentage) || isNaN(pePercentage) || isNaN(mera25Percentage) || isNaN(epamPercentage) || isNaN(edPercentage) || isNaN(opPercentage) || isNaN(psPercentage) || isNaN(antarsyaPercentage) || isNaN(ekPercentage) || isNaN(kkemlPercentage)) {
alert('Παρακαλώ εισάγετε έγκυρα ποσοστά ψήφων για κάθε κόμμα.');
return;
}

const percentages = [ndPercentage, syrizaPercentage, pasokPercentage, kkePercentage, elPercentage, nikiPercentage, pePercentage, mera25Percentage, epamPercentage, edPercentage, opPercentage, psPercentage, antarsyaPercentage, ekPercentage, kkemlPercentage, spartiatesPercentage];
const percentages = [ndPercentage, syrizaPercentage, pasokPercentage, kkePercentage, spartiatesPercentage, elPercentage, nikiPercentage, pePercentage, mera25Percentage, epamPercentage, edPercentage, opPercentage, psPercentage, antarsyaPercentage, ekPercentage, kkemlPercentage];
let newSeatDistribution;
if (electoralSystem === "apliAnalogiki") {
newSeatDistribution = apliAnalogiki(percentages, electoralThreshold);
Expand Down Expand Up @@ -65,7 +65,7 @@ export default function Home({nd, syriza, pasok, kke, el, niki, pe, mera25, epam
</div>
</div>
<p>Η σειρά των κομμάτων βασίζεται στα αποτελέσματά τους στις προηγούμενες εκλογές.</p>
<Ballot nd={nd} syriza={syriza} pasok={pasok} kke={kke} el={el} niki={niki} pe={pe} mera25={mera25} epam={epam} ed={ed} op={op} ps={ps} antarsya={antarsya} ek={ek} kkeml={kkeml} spartiates={spartiates} showResults={showResults} setND={setND} setSYRIZA={setSYRIZA} setPASOK={setPASOK} setKKE={setKKE} setEL={setEL} setNIKI={setNIKI} setPE={setPE} setMeRA25={setMeRA25} setEPAM={setEPAM} setED={setED} setOP={setOP} setPS={setPS} setANTARSYA={setANTARSYA} setEK={setEK} setKKEML={setKKEML} setSpartiates={setSpartiates} setShowResults={setShowResults} />
<Ballot nd={nd} syriza={syriza} pasok={pasok} kke={kke} spartiates={spartiates} el={el} niki={niki} pe={pe} mera25={mera25} epam={epam} ed={ed} op={op} ps={ps} antarsya={antarsya} ek={ek} kkeml={kkeml} showResults={showResults} setND={setND} setSYRIZA={setSYRIZA} setPASOK={setPASOK} setKKE={setKKE} setSpartiates={setSpartiates} setEL={setEL} setNIKI={setNIKI} setPE={setPE} setMeRA25={setMeRA25} setEPAM={setEPAM} setED={setED} setOP={setOP} setPS={setPS} setANTARSYA={setANTARSYA} setEK={setEK} setKKEML={setKKEML} setShowResults={setShowResults} />
{isMobileDevice() ? <Button className='submit-btn' onClick={() => { setShowResults(true); handleResults(); }}>Υποβολή</Button> :
<Button className='submit-btn' onClick={() => { setShowResults(true); handleResults(); }}>Υποβολή</Button> }
</Stack>
Expand Down
54 changes: 27 additions & 27 deletions src/pages/Results/Results.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,47 @@ import './Results.css';
import { useLocation } from 'react-router-dom';
import ResultsCharts from './ResultsCharts';

export default function Results({nd, syriza, pasok, kke, el, niki, pe, mera25, epam, ed, op, ps, antarsya, ek, kkeml, spartiates}) {
export default function Results({nd, syriza, pasok, kke, spartiates, el, niki, pe, mera25, epam, ed, op, ps, antarsya, ek, kkeml}) {
const location = useLocation();
const seatDistribution = location.state.seatDistribution;
const partyColors = ['#1D6EC8', '#CC1C24', '#00793A', '#DF251C', '#8DBEE2', '#BD552C', '#972490', '#EB4326', '#16459A', '#EB8C1E', '#509E2F', '#1B395A', '#D82F33', '#F2D308', '#D7062C', '#E4B365'];
const partyColors = ['#1D6EC8', '#CC1C24', '#00793A', '#DF251C', '#E4B365', '#8DBEE2', '#BD552C', '#972490', '#EB4326', '#16459A', '#EB8C1E', '#509E2F', '#1B395A', '#D82F33', '#F2D308', '#D7062C'];

const barData = [{party: 'ΝΔ', percentage: nd, fill: partyColors[0]},
{party: 'ΣΥΡΙΖΑ', percentage: syriza, fill: partyColors[1]},
{party: 'ΠΑΣΟΚ', percentage: pasok, fill: partyColors[2]},
{party: 'ΚΚΕ', percentage: kke, fill: partyColors[3]},
{party: 'ΕΛ', percentage: el, fill: partyColors[4]},
{party: 'ΝΙΚΗ', percentage: niki, fill: partyColors[5]},
{party: 'ΠΕ', percentage: pe, fill: partyColors[6]},
{party: 'ΜΕΡΑ25', percentage: mera25, fill: partyColors[7]},
{party: 'ΕΠΑΜ', percentage: epam, fill: partyColors[8]},
{party: 'ΕΔ', percentage: ed, fill: partyColors[9]},
{party: 'ΟΠ', percentage: op, fill: partyColors[10]},
{party: 'ΠΣ', percentage: ps, fill: partyColors[11]},
{party: 'ΑΝΤΑΡΣΥΑ', percentage: antarsya, fill: partyColors[12]},
{party: 'ΕΚ', percentage: ek, fill: partyColors[13]},
{party: 'ΚΚΕ Μ-Λ', percentage: kkeml, fill: partyColors[14]},
{party: 'ΣΠ', percentage: spartiates, fill: partyColors[15]}];
{party: 'ΣΠ', percentage: spartiates, fill: partyColors[4]},
{party: 'ΕΛ', percentage: el, fill: partyColors[5]},
{party: 'ΝΙΚΗ', percentage: niki, fill: partyColors[6]},
{party: 'ΠΕ', percentage: pe, fill: partyColors[7]},
{party: 'ΜΕΡΑ25', percentage: mera25, fill: partyColors[8]},
{party: 'ΕΠΑΜ', percentage: epam, fill: partyColors[9]},
{party: 'ΕΔ', percentage: ed, fill: partyColors[10]},
{party: 'ΟΠ', percentage: op, fill: partyColors[11]},
{party: 'ΠΣ', percentage: ps, fill: partyColors[12]},
{party: 'ΑΝΤΑΡΣΥΑ', percentage: antarsya, fill: partyColors[13]},
{party: 'ΕΚ', percentage: ek, fill: partyColors[14]},
{party: 'ΚΚΕ Μ-Λ', percentage: kkeml, fill: partyColors[15]}];

const maxPercentage = Math.max(...barData.map(entry => entry.percentage));
const upperHeight = Math.ceil(maxPercentage / 5) * 5;

const pieData = [{party: 'ΝΔ', seats: seatDistribution[0], fill: partyColors[0]},
{party: 'ΣΥΡΙΖΑ', seats: seatDistribution[1], fill: partyColors[1]},
{party: 'ΠΑΣΟΚ', seats: seatDistribution[2], fill: partyColors[2]},
{party: 'ΚΚΕ', seats: seatDistribution[3], fill: partyColors[3]},
{party: 'ΕΛ', seats: seatDistribution[4], fill: partyColors[4]},
{party: 'ΝΙΚΗ', seats: seatDistribution[5], fill: partyColors[5]},
{party: 'ΠΕ', seats: seatDistribution[6], fill: partyColors[6]},
{party: 'ΜΕΡΑ25', seats: seatDistribution[7], fill: partyColors[7]},
{party: 'ΕΠΑΜ', seats: seatDistribution[8], fill: partyColors[8]},
{party: 'ΕΔ', seats: seatDistribution[9], fill: partyColors[9]},
{party: 'ΟΠ', seats: seatDistribution[10], fill: partyColors[10]},
{party: 'ΠΣ', seats: seatDistribution[11], fill: partyColors[11]},
{party: 'ΑΝΤΑΡΣΥΑ', seats: seatDistribution[12], fill: partyColors[12]},
{party: 'ΕΚ', seats: seatDistribution[13], fill: partyColors[13]},
{party: 'ΚΚΕ Μ-Λ', seats: seatDistribution[14], fill: partyColors[14]},
{party: 'ΣΠ', seats: seatDistribution[15], fill: partyColors[15]}];
{party: 'ΚΚΕ', seats: seatDistribution[3], fill: partyColors[3]},
{party: 'ΣΠ', seats: seatDistribution[4], fill: partyColors[4]},
{party: 'ΕΛ', seats: seatDistribution[5], fill: partyColors[5]},
{party: 'ΝΙΚΗ', seats: seatDistribution[6], fill: partyColors[6]},
{party: 'ΠΕ', seats: seatDistribution[7], fill: partyColors[7]},
{party: 'ΜΕΡΑ25', seats: seatDistribution[8], fill: partyColors[8]},
{party: 'ΕΠΑΜ', seats: seatDistribution[9], fill: partyColors[9]},
{party: 'ΕΔ', seats: seatDistribution[10], fill: partyColors[10]},
{party: 'ΟΠ', seats: seatDistribution[11], fill: partyColors[11]},
{party: 'ΠΣ', seats: seatDistribution[12], fill: partyColors[12]},
{party: 'ΑΝΤΑΡΣΥΑ', seats: seatDistribution[13], fill: partyColors[13]},
{party: 'ΕΚ', seats: seatDistribution[14], fill: partyColors[14]},
{party: 'ΚΚΕ Μ-Λ', seats: seatDistribution[15], fill: partyColors[15]}];

return (
<div className='results'>
Expand Down

1 comment on commit 05d604d

@vercel
Copy link

@vercel vercel bot commented on 05d604d Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.