Skip to content

Commit

Permalink
Merge pull request #70 from code4romania/update_stacked_bar
Browse files Browse the repository at this point in the history
Update stacked bar for Referendum
  • Loading branch information
RaduCStefanescu authored Sep 26, 2020
2 parents c31155f + 47adc1a commit bfa2e92
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@code4ro/reusable-components",
"version": "0.1.26",
"version": "0.1.27",
"description": "Component library for code4ro",
"keywords": [
"code4ro",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo } from "react";
import { ElectionResults } from "../../types/Election";
import { ElectionBallotMeta, ElectionResults } from "../../types/Election";
import { themable } from "../../hooks/theme";
import { HorizontalStackedBar, HorizontalStackedBarItem } from "../HorizontalStackedBar/HorizontalStackedBar";
import { PartyResultCard } from "../PartyResultCard/PartyResultCard";
Expand All @@ -10,6 +10,7 @@ import cssClasses from "./ElectionResultsStackedBar.module.scss";

type Props = {
results: ElectionResults;
meta?: ElectionBallotMeta | null;
};

const defaultConstants = {
Expand All @@ -24,7 +25,7 @@ export const ElectionResultsStackedBar = themable<Props>(
"ElectionResultsStackedBar",
cssClasses,
defaultConstants,
)(({ classes, results, constants }) => {
)(({ classes, results, constants, meta }) => {
const { candidates } = results;
const { neutralColor, maxStackedBarItems, breakpoint1, breakpoint2, breakpoint3 } = constants;

Expand All @@ -41,7 +42,11 @@ export const ElectionResultsStackedBar = themable<Props>(
const candidate = candidates[i];
if (candidate) {
const color = electionCandidateColor(candidate);
const percent = fractionOf(candidate.votes, results.validVotes);
let percent = fractionOf(candidate.votes, results.validVotes);
if (meta && meta.type === "referendum" && candidate.name === "NU AU VOTAT" && results.eligibleVoters) {
const eligibleVoters = results.eligibleVoters;
percent = fractionOf(candidate.votes, eligibleVoters);
}
items.push({
name: candidate.shortName ?? candidate.name,
color,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const ElectionResultsSummarySection = themable<Props>(
fie câștigătorii pentru această unitate au fost aleși în primul tur de scrutin.
</DivBodyHuge>
))}
{results && <ElectionResultsStackedBar className={classes.stackedBar} results={results} />}
{results && <ElectionResultsStackedBar className={classes.stackedBar} results={results} meta={meta} />}
<div style={{ width: "100%" }} ref={measureRef} />
{results && !mobileMap && separator}
{!mobileMap && (
Expand Down

1 comment on commit bfa2e92

@vercel
Copy link

@vercel vercel bot commented on bfa2e92 Sep 26, 2020

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.