protected void RefreshChart(DateTime?snapshotTime) { Console.WriteLine("Refresh chart in chart view"); var moods = ReportManager.GetMoodBreakdownForSnapshot(this.currentSnapshot).ToList(); SnapshotBarView last = null; var w = labelW; for (int i = 0; i < moods.Count(); i++) { var bar = this.bars [i]; var m = moods [i]; bar.Update(m.Name, (float)m.ResponsePercentage, m.ResponseCount); last = bar; if (bar.Frame.Width > w) { w = bar.Frame.Width; } } this.totalLabel.Text = string.Format("Total responders = {0}", moods.Sum(m => m.ResponseCount)); this.Frame = new RectangleF(this.Frame.Location, new SizeF(this.Frame.Width, totalLabel.Frame.Y + totalLabel.Frame.Height + margin * 2)); this.background.Frame = new RectangleF(this.background.Frame.Location, this.Frame.Size); // this.title.Frame = new RectangleF(this.title.Frame.Location, new SizeF(this.Frame.Width, this.title.Frame.Height)); this.Center = new PointF(this.Center.X, this.Superview.Bounds.Height / 2); this.chart.Center = new PointF(this.Frame.Width / 2, this.chart.Center.Y); this.chart.Hidden = false; this.Hidden = false; }
protected void BuildChart(DateTime?snapshotTime) { Console.WriteLine("Build chart in chart view"); if (chart != null) { chart.RemoveFromSuperview(); chart = null; } chart = new UIView(this.Bounds); chart.ContentMode = UIViewContentMode.Left; var snapshot = this.currentSnapshot; if (title == null) { BuildTitle(snapshotTime); } var moods = ReportManager.GetMoodBreakdownForSnapshot(snapshot); var y = labelH + title.Frame.Y + margin; var w = labelW; bars = new List <SnapshotBarView> (); foreach (var m in moods) { var bar = new SnapshotBarView(new RectangleF(0f, y, labelW, labelH), m.Name, (float)m.ResponsePercentage, m.ResponseCount, m.DisplayColor); chart.Add(bar); this.bars.Add(bar); if (bar.Frame.Width > w) { w = bar.Frame.Width; } y += labelH + margin; } this.totalLabel = new UILabel(new RectangleF(5f, y + 10f, this.chart.Bounds.Width, labelH)); this.totalLabel.Text = string.Format("Total responders = {0}", moods.Sum(m => m.ResponseCount)); this.totalLabel.Font = UIFont.FromName("HelveticaNeue-CondensedBold", 12.0f); this.totalLabel.TextColor = UIColor.Gray; this.totalLabel.TextAlignment = UITextAlignment.Center; this.totalLabel.BackgroundColor = UIColor.Clear; this.chart.Add(this.totalLabel); y += labelH + margin; this.Add(chart); this.Frame = new RectangleF(this.Frame.Location, new SizeF(this.Frame.Width, y + margin * 2)); this.background.Frame = new RectangleF(this.background.Frame.Location, this.Frame.Size); // this.title.Frame = new RectangleF(this.title.Frame.Location, new SizeF(this.Frame.Width, this.title.Frame.Height)); this.chart.Center = new PointF(this.Frame.Width / 2, this.chart.Center.Y); this.Center = new PointF(this.Center.X, this.Superview.Bounds.Height / 2); this.chart.Hidden = false; this.Hidden = false; }