public void Render(IVisio.Page page) { this.TotalMarginWidth = this.Rectangle.Width * (0.10); int num_points = this.DataPoints.Count; double bar_spacing = num_points > 1 ? (this.Rectangle.Width - this.TotalBarWidth) / num_points : 0.0; // Calculate min & max which will be used many times later double max = this.DataPoints.Select(i => i.Value).Max(); double min = this.DataPoints.Select(i => i.Value).Min(); var range = ChartUtil.GetValueRangeDistance(min, max); // Determine the leftmost part of the drawing area double base_x = this.Rectangle.Left + (this.TotalMarginWidth / 2.0); // Determine the baseline height a.k.a the y axis location double base_y = this.Rectangle.Bottom; if (min < 0.0) { // if the min value is negative then we have to "raise" the baseline to accomodate it base_y += System.Math.Abs(this.Rectangle.Height * (min / range)); } var category_axis_start_point = new Geometry.Point(this.Rectangle.Left, base_y); var category_axis_end_point = new Geometry.Point(this.Rectangle.Right, base_y); var category_axis_shape = page.DrawLine(category_axis_start_point, category_axis_end_point); double cur_x = base_x; var points = new List <Geometry.Point>(); for (int i = 0; i < this.DataPoints.Count; i++) { if (i == 0) { points.Add(new Geometry.Point(cur_x, base_y)); } var p = this.DataPoints[i]; var value_height = System.Math.Abs(this.Rectangle.Height * (p.Value / range)); if (p.Value >= 0.0) { points.Add(new Geometry.Point(cur_x, base_y + value_height)); } else { points.Add(new Geometry.Point(cur_x, base_y - value_height)); } if (i == this.DataPoints.Count - 1) { points.Add(new Geometry.Point(cur_x, base_y)); } cur_x += bar_spacing; } points.Add(new Geometry.Point(base_x, base_y)); var area_shape = page.DrawPolyline(points); var allshapes = this.DataPoints.Select(dp => dp.VisioShape).Where(s => s != null).ToList(); allshapes.Add(category_axis_shape); ChartUtil.GroupShapesIfNeeded(page, allshapes); }
public void Render(IVisio.Page page) { this.TotalMarginWidth = this.Rectangle.Width * (0.10); this.TotalBarSpacingWidth = this.Rectangle.Width * (0.10); this.TotalBarWidth = this.Rectangle.Width * (0.80); int num_points = this.DataPoints.Count; double bar_spacing = num_points > 1 ? this.TotalBarSpacingWidth / num_points : 0.0; double bar_width = num_points > 0 ? this.TotalBarWidth / num_points : this.TotalBarWidth; double cur_x = this.Rectangle.Left + (this.TotalMarginWidth / 2.0); double max = this.DataPoints.Select(i => i.Value).Max(); double min = this.DataPoints.Select(i => i.Value).Min(); var range = ChartUtil.GetValueRangeDistance(min, max); double base_y = this.Rectangle.Bottom; if (min < 0.0) { base_y += System.Math.Abs(this.Rectangle.Height * (min / range)); } var category_axis_start_point = new Geometry.Point(this.Rectangle.Left, base_y); var category_axis_end_point = new Geometry.Point(this.Rectangle.Right, base_y); var category_axis_shape = page.DrawLine(category_axis_start_point, category_axis_end_point); foreach (var p in this.DataPoints) { var value_height = System.Math.Abs(this.Rectangle.Height * (p.Value / range)); Geometry.Point bar_p0; Geometry.Point bar_p1; if (p.Value >= 0.0) { bar_p0 = new Geometry.Point(cur_x, base_y); bar_p1 = new Geometry.Point(cur_x + bar_width, base_y + value_height); } else { bar_p0 = new Geometry.Point(cur_x, base_y - value_height); bar_p1 = new Geometry.Point(cur_x + bar_width, base_y); } var bar_rect = new Geometry.Rectangle(bar_p0, bar_p1); var shape = page.DrawRectangle(bar_rect); p.VisioShape = shape; if (p.Label != null) { shape.Text = p.Label; } cur_x += bar_width + bar_spacing; } var allshapes = this.DataPoints.Select(dp => dp.VisioShape).Where(s => s != null).ToList(); allshapes.Add(category_axis_shape); ChartUtil.GroupShapesIfNeeded(page, allshapes); }