Completed
Last Updated: 22 May 2015 14:35 by ADMIN
ADMIN
Stefan
Created on: 15 May 2015 13:02
Category: ChartView
Type: Bug Report
0
FIX. RadChartView - RadiusAspectRatio propety is not respected for PieDataPoint
To reproduce:
 protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            radChartView1 = new RadChartView();
            radChartView1.Parent = this;

            this.radChartView1.AreaType = ChartAreaType.Pie;
            PieSeries series = new PieSeries();
            series.DataPoints.Add(new PieDataPoint(50, "Germany"));
            series.DataPoints.Add(new PieDataPoint(70, "United States"));
            series.DataPoints.Add(new PieDataPoint(40, "France"));
            series.DataPoints.Add(new PieDataPoint(25, "United Kingdom"));
            series.ShowLabels = true;
            this.radChartView1.Series.Add(series);

            (series.Children[0] as PiePointElement).RadiusAspectRatio = 1.2f;
      }

Workaround:

  protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            radChartView1 = new RadChartView();
            radChartView1.Parent = this;

            this.radChartView1.AreaType = ChartAreaType.Pie;
            PieSeries series = new PieSeries();
            series.DataPoints.Add(new PieDataPoint(50, "Germany"));
            series.DataPoints.Add(new PieDataPoint(70, "United States"));
            series.DataPoints.Add(new PieDataPoint(40, "France"));
            series.DataPoints.Add(new PieDataPoint(25, "United Kingdom"));
            series.ShowLabels = true;
            this.radChartView1.Series.Add(series);

            (series.Children[0] as PiePointElement).RadiusAspectRatio = 1.2f;

            this.radChartView1.CreateRenderer += new ChartViewCreateRendererEventHandler(radChartView1_CreateRenderer);
        }

        void radChartView1_CreateRenderer(object sender, ChartViewCreateRendererEventArgs e)
        {
            e.Renderer = new CustomPieRenderer(e.Area as PieArea);
        }

        public class CustomPieRenderer : PieRenderer
        {
            public CustomPieRenderer(PieArea area)
                : base(area)
            { }

            protected override void Initialize()
            {
                base.Initialize();

                for (int i = 0; i < this.DrawParts.Count; i++)
                {
                    PieSeriesDrawPart piePart = this.DrawParts[i] as PieSeriesDrawPart;
                    if (piePart != null)
                    {
                        this.DrawParts[i] = new CustomPieSeriesDrawPart((PieSeries)piePart.Element, this);
                    }
                }
            }

        }

        class CustomPieSeriesDrawPart : PieSeriesDrawPart
        {
            public CustomPieSeriesDrawPart(PieSeries series, IChartRenderer renderer)
                : base(series, renderer)
            {

            }

            public override void DrawSeriesParts()
            {
                //base.DrawSeriesParts();

                PieSeriesModel model = this.Element.Model as PieSeriesModel;
                float diameter = CalculateDiameter();

                if (diameter > 0)
                {
                    DrawPieSegments(model, diameter);
                }
            }

            private float CalculateDiameter()
            {
                PieSeriesModel model = this.Element.Model as PieSeriesModel;
                double diameter = Math.Min((float)model.LayoutSlot.Width, (float)model.LayoutSlot.Height) * ((PieSeries)Element).RadiusFactor;

                return (float)diameter;
            }

            private void DrawPieSegments(PieSeriesModel model, float diameter)
            {
                Graphics gr = ((PieRenderer)this.Renderer).Graphics;
                RadGdiGraphics radGraphics = new RadGdiGraphics(gr);

                for (int i = 0; i < model.DataPoints.Count; i++)
                {
                    PiePointElement childElement = (PiePointElement)this.Element.Children[i];
                    PieDataPoint piePoint = (PieDataPoint)childElement.DataPoint;

                    float finalDiameter = diameter * childElement.RadiusAspectRatio;
                    GraphicsPath path = ConstructGraphicsPath(piePoint, model.LayoutSlot, finalDiameter);
                    UpdatePointPaths(piePoint, path);
                    System.Drawing.RectangleF rect = GetPieSectionRect(piePoint, model.LayoutSlot, finalDiameter);

                    childElement.GradientAngle = (float)(piePoint.StartAngle + piePoint.SweepAngle / 2);
                    FillPrimitiveImpl fill = new FillPrimitiveImpl(childElement, null);
                    fill.PaintFill(radGraphics, path, rect);

                    BorderPrimitiveImpl border = new BorderPrimitiveImpl(childElement, null);
                    border.PaintBorder(radGraphics, null, path, rect);
                }
            }

            protected System.Drawing.RectangleF GetPieSectionRect(PieDataPoint point, RadRect modelLayoutSlot, float diameter)
            {
                System.Drawing.RectangleF result;

                float x = (float)(modelLayoutSlot.X + (modelLayoutSlot.Width - diameter) / 2);
                float y = (float)(modelLayoutSlot.Y + (modelLayoutSlot.Height - diameter) / 2);

                result = new System.Drawing.RectangleF(x, y, Math.Max(diameter, 1f), Math.Max(diameter, 1f));

                if (point.OffsetFromCenter > 0)
                {
                    System.Drawing.PointF offset = GetOffset(point.StartAngle + (point.SweepAngle / 2), (diameter / 2) * (point.OffsetFromCenter));
                    result.X += offset.X;
                    result.Y += offset.Y;
                }

                return result;
            }

            private System.Drawing.PointF GetOffset(double angle, double radius)
            {
                double angleInRad = angle * RadMath.DegToRadFactor;

                double x = (Math.Cos(angleInRad) * radius);
                double y = (Math.Sin(angleInRad) * radius);

                return new System.Drawing.PointF((float)x, (float)y);
            }
        }
0 comments