private void CalculateData() { SumVotes = 0; decimal sumVote = 0; for (int i = 0; i < CountVotes.Count; i++) { sumVote += ((decimal)CountVotes[i] * (i + 1) / Split); SumVotes += CountVotes[i]; } AverageRate = SumVotes == 0 ? 0 : Math.Round(sumVote / SumVotes, 2); PercentageVotes.Clear(); foreach (var i in CountVotes) { PercentageVotes.Add(sumVote == 0 ? 0 : Math.Round(((decimal)i / SumVotes) * 100, 2)); } HoverPanelData.Clear(); if (EnableGrouping) { var actualIdx = 0; var actualGroup = 0; var sumvote = 0; while ((actualGroup * Split) + actualIdx < CountVotes.Count) { sumvote += CountVotes[(actualGroup * Split) + actualIdx++]; if (actualIdx == Split) { actualGroup++; actualIdx = 0; HoverPanelData.Add(new HoverPanelDataItem { Index = actualGroup, Value = SumVotes > 0 ? Math.Round(((decimal)sumvote / SumVotes) * 100, 2) : 0 }); sumvote = 0; } } } else { for (int i = 0; i < PercentageVotes.Count; i++) { HoverPanelData.Add(new HoverPanelDataItem { Index = i + 1, Value = PercentageVotes[i] }); } } }
public void OnHover(HoverPanelData data) { m_Holder.SetActive(true); m_Title.text = data.title; m_Description.text = data.description; }