Skip to content

Commit

Permalink
Fix confusing appearance of voice chart
Browse files Browse the repository at this point in the history
Part of #86
  • Loading branch information
cheshire137 committed Feb 1, 2020
1 parent 6ec639a commit 7d315ad
Showing 1 changed file with 20 additions and 32 deletions.
52 changes: 20 additions & 32 deletions src/components/Charts/VoiceChatChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,31 @@ const options = {
responsive: true,
maintainAspectRatio: false,
scales: {
yAxes: [{ ticks: { callback: ChartUtils.wholeTicks } }]
yAxes: [{
ticks: {
callback: ChartUtils.wholeTicks,
beginAtZero: true
}
}]
}
};

const VoiceChatChart = ({ matches, season }: Props) => {
const getWins = () => {
let joinedVoiceCount = 0;
let didNotJoinVoiceCount = 0;
const wins = matches.filter(match => match.isWin());
const getCountsByVoiceStatus = (matches: Match[]) => {
let joinedVoiceCount = 0;
let didNotJoinVoiceCount = 0;

for (const match of wins) {
if (match.joinedVoice) {
joinedVoiceCount++;
} else {
didNotJoinVoiceCount++;
}
}

return [joinedVoiceCount, didNotJoinVoiceCount];
};

const getLosses = () => {
let joinedVoiceCount = 0;
let didNotJoinVoiceCount = 0;
const losses = matches.filter(match => match.isLoss());

for (const match of losses) {
if (match.joinedVoice) {
joinedVoiceCount++;
} else {
didNotJoinVoiceCount++;
}
for (const match of matches) {
if (match.joinedVoice) {
joinedVoiceCount++;
} else {
didNotJoinVoiceCount++;
}
}

return [joinedVoiceCount, didNotJoinVoiceCount];
};
return [joinedVoiceCount, didNotJoinVoiceCount];
};

const VoiceChatChart = ({ matches, season }: Props) => {
const data = {
labels: ["Joined Voice", "Did Not Join Voice"],
datasets: [
Expand All @@ -58,14 +46,14 @@ const VoiceChatChart = ({ matches, season }: Props) => {
borderColor: Color.win,
borderWidth: 2,
label: "Wins",
data: getWins()
data: getCountsByVoiceStatus(matches.filter(match => match.isWin()))
},
{
backgroundColor: Color.transparentLoss,
borderColor: Color.loss,
borderWidth: 2,
label: "Losses",
data: getLosses()
data: getCountsByVoiceStatus(matches.filter(match => match.isLoss()))
}
]
};
Expand Down

0 comments on commit 7d315ad

Please sign in to comment.