void ColorizeCountyItem(MapItem item, CountyVote results) { var maxVotes = results.Votes.Max(q => q.VotesCount); CandidateVote winnerVotes = maxVotes > 0 ? results.Votes.FirstOrDefault(q => q.VotesCount == maxVotes) : null; if (winnerVotes == null) { ColorizeItemAsUnknown(item); return; } ColorizeItemByWinner(item, results.TotalVotesCount, winnerVotes); }
bool GenerateVoteToolTipCore(SuperToolTip superTip, string titleText, List <CandidateVote> votes, int totalCount, bool allowElecotralInfo = true) { ToolTipTitleItem title = new ToolTipTitleItem() { Text = titleText }; superTip.Items.Add(title); superTip.Items.AddSeparator(); if (votes.Count == 0) { superTip.Items.Add(new ToolTipItem() { Text = "No information available yet" }); return(true); } CandidateVote eWinner = null; foreach (var vote in votes.OrderBy(q => q.CandidateType)) { ToolTipItem ti = new ToolTipItem(); ti.Image = colorizer.GenerateImage(vote.CandidateType); ti.Text = string.Format("{0} <b>{1:p}</b> ({2:n0})", GetNameByType(vote.CandidateType), Helpers.GetPercent(vote.VotesCount, totalCount), vote.VotesCount); superTip.Items.Add(ti); if (vote.ElectoralVotes > 0) { if (eWinner != null) { eWinner = null; } else { eWinner = vote; } } } if (eWinner != null && allowElecotralInfo) { superTip.Items.AddSeparator(); ToolTipItem winner = new ToolTipItem(); winner.Image = colorizer.GenerateImage(eWinner.CandidateType); winner.Text = string.Format("<b>{0}</b> electoral votes going to <b>{1}</b>", eWinner.ElectoralVotes, GetNameByType(eWinner.CandidateType)); superTip.Items.Add(winner); } return(true); }
void ColorizeStateItem(MapItem item, StateVote results) { var maxVotes = results.Votes.Max(q => q.VotesCount); var maxElectoral = results.Votes.Max(q => q.ElectoralVotes); CandidateVote winnerElectoral = maxElectoral > 0 ? results.Votes.FirstOrDefault(q => q.ElectoralVotes == maxElectoral) : null; CandidateVote winnerVotes = maxVotes > 0 ? results.Votes.FirstOrDefault(q => q.VotesCount == maxVotes) : null; if (IsColorByTotalVotes || winnerElectoral == null) { if (winnerVotes == null) { ColorizeItemAsUnknown(item); return; } ColorizeItemByWinner(item, results.TotalVotesCount, winnerVotes); return; } if (winnerElectoral != null) { ColorizeItemByWinner(item, results.TotalVotesCount, winnerVotes, true); } }
void ColorizeItemByWinner(MapItem item, int totalVotes, CandidateVote winnerVotes, bool ignoreGradient = false) { Color baseColor = ColorByType(winnerVotes.CandidateType); if (!ignoreGradient) { decimal percent = Helpers.GetPercent(winnerVotes.VotesCount, totalVotes); if (percent > 0.85m) { baseColor = HSLColor.Darken(baseColor, 0.5); } else { if (percent > 0.7m) { baseColor = HSLColor.Darken(baseColor, 0.8); } } } item.Fill = baseColor; item.HighlightedFill = baseColor; item.SelectedFill = baseColor; }