-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5dd69e5
commit d80973c
Showing
8 changed files
with
98 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/frontend/src/components/Election/Results/components/ScoreRangeWidget.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import useAnonymizedBallots from "~/components/AnonymizedBallotsContextProvider"; | ||
import Widget from "./Widget"; | ||
import useRace from "~/components/RaceContextProvider"; | ||
import { Divider, Typography } from "@mui/material"; | ||
import ResultsBarChart from "./ResultsBarChart"; | ||
import useFeatureFlags from "~/components/FeatureFlagContextProvider"; | ||
|
||
// candidates helps define the order | ||
export default () => { | ||
const {ballotsForRace} = useAnonymizedBallots(); | ||
const {t, race} = useRace(); | ||
|
||
const flags = useFeatureFlags(); | ||
if(!flags.isSet('ALL_STATS')) return <></> | ||
|
||
let numAtDiff = []; | ||
|
||
const incIndex = (arr, index) => { | ||
while(index >= arr.length){ | ||
arr.push({ | ||
name: arr.length, | ||
count: 0 | ||
}); | ||
} | ||
arr[index].count++; | ||
} | ||
|
||
ballotsForRace().forEach((scores) => { | ||
incIndex(numAtDiff, | ||
scores.reduce((prev,score) => Math.max(prev, score.score), 0) - | ||
scores.reduce((prev,score) => Math.min(prev, score.score), 20) | ||
) | ||
}) | ||
|
||
return <Widget title={t(`results.score_range_title`)}> | ||
<Typography variant='h6'>{t(`results.score_range_sub_title`)}</Typography> | ||
<ResultsBarChart data={numAtDiff.reverse()} xKey='count' percentage={true} sortFunc={false}/> | ||
<Typography sx={{'textAlign': 'left'}}>{t(`results.score_range_warning`)}</Typography> | ||
</Widget> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters