Ejemplo n.º 1
0
        protected override void DrawArea()
        {
            CartesianRenderer renderer    = (CartesianRenderer)this.Renderer;
            AreaSeries        area        = this.Element as AreaSeries;
            Graphics          graphics    = renderer.Graphics;
            RadGdiGraphics    radGraphics = new RadGdiGraphics(graphics);

            RectangleF rect     = ChartRenderer.ToRectangleF(this.Element.Model.LayoutSlot);
            RectangleF clipRect = (RectangleF)renderer.Area
                                  .GetType()
                                  .GetMethod("GetCartesianClipRect", BindingFlags.Instance | BindingFlags.NonPublic)
                                  .Invoke(renderer.Area, new object[] { });

            PointF topLeft  = new PointF(clipRect.X, clipRect.Y);
            PointF topRight = new PointF(clipRect.Right - 1, clipRect.Y);

            PointF lowerRight = new PointF(clipRect.Right - 1, clipRect.Bottom - 1);
            PointF lowerLeft  = new PointF(clipRect.X, clipRect.Bottom - 1);

            List <PointF[]> allPoints = GetPointsPositionsArrays();

            float zeroOnTheYAxis = (float)this.GetLocationOfValue(0, (NumericalAxis)area.VerticalAxis);

            lowerLeft.Y  = zeroOnTheYAxis;
            lowerRight.Y = zeroOnTheYAxis;

            foreach (PointF[] points in allPoints)
            {
                if (points.Length < 2)
                {
                    continue;
                }

                GraphicsPath fillPath = this.GetLinePaths(points);

                if (fillPath == null)
                {
                    continue;
                }

                if (this.Element.View.GetArea <CartesianArea>().Orientation == System.Windows.Forms.Orientation.Vertical)
                {
                    if (area.VerticalAxis.IsInverse)
                    {
                        fillPath.AddLine(points[points.Length - 1], new PointF(points[points.Length - 1].X, topRight.Y));
                        fillPath.AddLine(topRight, topLeft);
                        fillPath.AddLine(new PointF(points[0].X, topLeft.Y), points[0]);
                    }
                    else
                    {
                        fillPath.AddLine(points[points.Length - 1], new PointF(points[points.Length - 1].X, lowerRight.Y));
                        fillPath.AddLine(lowerRight, lowerLeft);
                        fillPath.AddLine(new PointF(points[0].X, lowerLeft.Y), points[0]);
                    }
                }
                else
                {
                    if (area.HorizontalAxis.IsInverse)
                    {
                        fillPath.AddLine(points[points.Length - 1], topRight);
                        fillPath.AddLine(topRight, lowerRight);
                        fillPath.AddLine(lowerRight, points[0]);
                    }
                    else
                    {
                        fillPath.AddLine(points[points.Length - 1], topLeft);
                        fillPath.AddLine(topLeft, lowerLeft);
                        fillPath.AddLine(lowerLeft, points[0]);
                    }
                }

                FillPrimitiveImpl fill = new FillPrimitiveImpl(this.Element, null);
                fill.PaintFill(radGraphics, fillPath, clipRect);

                GraphicsPath borderPath = new GraphicsPath();
                AreaSeries   series     = (AreaSeries)this.Element;

                borderPath = new GraphicsPath();

                if (series.StrokeMode == AreaSeriesStrokeMode.All ||
                    series.StrokeMode == AreaSeriesStrokeMode.AllButPlotLine ||
                    series.StrokeMode == AreaSeriesStrokeMode.LeftAndPoints ||
                    series.StrokeMode == AreaSeriesStrokeMode.LeftLine)
                {
                    if (this.Element.View.GetArea <CartesianArea>().Orientation == System.Windows.Forms.Orientation.Vertical)
                    {
                        if (area.VerticalAxis.IsInverse)
                        {
                            borderPath.AddLine(topLeft, points[0]);
                        }
                        else
                        {
                            borderPath.AddLine(lowerLeft, points[0]);
                        }
                    }
                    else
                    {
                        if (area.HorizontalAxis.IsInverse)
                        {
                            borderPath.AddLine(lowerRight, points[0]);
                        }
                        else
                        {
                            borderPath.AddLine(lowerLeft, points[0]);
                        }
                    }
                }

                if (series.StrokeMode == AreaSeriesStrokeMode.All ||
                    series.StrokeMode == AreaSeriesStrokeMode.AllButPlotLine ||
                    series.StrokeMode == AreaSeriesStrokeMode.LeftAndPoints ||
                    series.StrokeMode == AreaSeriesStrokeMode.Points ||
                    series.StrokeMode == AreaSeriesStrokeMode.RightAndPoints)
                {
                    GraphicsPath path = GetLinePaths(points);

                    if (path != null)
                    {
                        borderPath.AddPath(path, true);
                    }
                }

                if (series.StrokeMode == AreaSeriesStrokeMode.All ||
                    series.StrokeMode == AreaSeriesStrokeMode.AllButPlotLine ||
                    series.StrokeMode == AreaSeriesStrokeMode.RightAndPoints ||
                    series.StrokeMode == AreaSeriesStrokeMode.RightLine)
                {
                    if (this.Element.View.GetArea <CartesianArea>().Orientation == System.Windows.Forms.Orientation.Vertical)
                    {
                        if (area.VerticalAxis.IsInverse)
                        {
                            borderPath.AddLine(points[points.Length - 1], topRight);
                        }
                        else
                        {
                            borderPath.AddLine(points[points.Length - 1], lowerRight);
                        }
                    }
                    else
                    {
                        if (area.HorizontalAxis.IsInverse)
                        {
                            borderPath.AddLine(points[points.Length - 1], topRight);
                        }
                        else
                        {
                            borderPath.AddLine(points[points.Length - 1], topLeft);
                        }
                    }
                }

                if (series.StrokeMode == AreaSeriesStrokeMode.All ||
                    series.StrokeMode == AreaSeriesStrokeMode.PlotLine)
                {
                    if (this.Element.View.GetArea <CartesianArea>().Orientation == System.Windows.Forms.Orientation.Vertical)
                    {
                        if (area.VerticalAxis.IsInverse)
                        {
                            borderPath.AddLine(topRight, topLeft);
                        }
                        else
                        {
                            borderPath.AddLine(lowerRight, lowerLeft);
                        }
                    }
                    else
                    {
                        if (area.HorizontalAxis.IsInverse)
                        {
                            borderPath.AddLine(topRight, lowerRight);
                        }
                        else
                        {
                            borderPath.AddLine(lowerLeft, topLeft);
                        }
                    }
                }

                BorderPrimitiveImpl border = new BorderPrimitiveImpl(this.Element, null);
                border.PaintBorder(radGraphics, null, borderPath, rect);

                if (series.Image != null)
                {
                    graphics.SetClip(fillPath);
                    ImagePrimitiveImpl image = new ImagePrimitiveImpl(series);
                    image.PaintImage(radGraphics, series.Image, clipRect, series.ImageLayout, series.ImageAlignment, series.ImageOpacity, false);
                    graphics.ResetClip();
                }
            }
        }
        public override void DrawSeriesParts()
        {
            CustomCartesianRenderer customRenderer = this.Renderer as CustomCartesianRenderer;
            Graphics       graphics    = customRenderer.Graphics;
            RadGdiGraphics radGraphics = new RadGdiGraphics(graphics);

            for (int j = 0; j < this.Element.DataPoints.Count; j++)
            {
                DataPoint dataPoint = this.Element.DataPoints[j];
                RadRect   slot      = dataPoint.LayoutSlot;

                if ((bool)dataPoint.GetType().GetField("isEmpty", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(dataPoint))
                {
                    continue;
                }

                RectangleF barBounds      = new RectangleF((float)(this.OffsetX + slot.X), (float)(this.OffsetY + slot.Y), (float)slot.Width, (float)slot.Height);
                bool       isAreaVertical = (((CartesianSeries)this.Element).Parent as CartesianArea).Orientation == System.Windows.Forms.Orientation.Vertical;

                DataPointElement childElement = (DataPointElement)this.Element.Children[j];

                if (isAreaVertical)
                {
                    float realHeight = barBounds.Height * childElement.HeightAspectRatio;
                    barBounds.Y     += barBounds.Height - realHeight;
                    barBounds.Height = realHeight;
                }
                else
                {
                    float realWidth = barBounds.Width * childElement.HeightAspectRatio;
                    barBounds.Width = realWidth;
                }

                barBounds = AdjustBarDataPointBounds(childElement, barBounds);

                if (isAreaVertical)
                {
                    barBounds.Width = Math.Max(barBounds.Width, 1f);
                }
                else
                {
                    barBounds.Height = Math.Max(barBounds.Height, 1f);
                }

                RadImageShape background = childElement.BackgroundShape;

                if (background != null)
                {
                    background.Paint(graphics, barBounds);
                }

                FillPrimitiveImpl fill = new FillPrimitiveImpl(childElement, null);
                fill.PaintFill(radGraphics, 0, new SizeF(1, 1), barBounds);

                BorderPrimitiveImpl border = new BorderPrimitiveImpl(childElement, null);
                border.PaintBorder(radGraphics, 0, new SizeF(1, 1), barBounds);

                if (childElement.Image != null)
                {
                    graphics.SetClip(barBounds);
                    ImagePrimitiveImpl pointImage = new ImagePrimitiveImpl(childElement);
                    pointImage.PaintImage(radGraphics, childElement.Image, barBounds, childElement.ImageLayout, childElement.ImageAlignment, childElement.ImageOpacity, false);
                    graphics.ResetClip();
                }

                float xOffset = 20;
                float yOffset = 20;

                GraphicsPath  path  = new GraphicsPath();
                List <PointF> lines = new List <PointF>();
                lines.Add(new PointF(barBounds.Right, barBounds.Y));
                lines.Add(new PointF(barBounds.Right + xOffset, barBounds.Y - yOffset));
                lines.Add(new PointF(barBounds.Right + xOffset, barBounds.Bottom - yOffset));
                lines.Add(new PointF(barBounds.Right, barBounds.Bottom));
                path.AddLines(lines.ToArray());
                path.CloseFigure();

                using (Pen pen = new Pen(this.Element.BorderColor), pen2 = new Pen(Color.FromArgb(100, Color.Black)))
                {
                    graphics.DrawPath(pen, path);
                    graphics.DrawPath(pen2, path);
                }

                using (Brush brush = new SolidBrush(this.Element.BackColor), brush2 = new SolidBrush(Color.FromArgb(100, Color.Black)))
                {
                    graphics.FillPath(brush, path);
                    graphics.FillPath(brush2, path);
                }

                if (this.DrawCap)
                {
                    path  = new GraphicsPath();
                    lines = new List <PointF>();
                    lines.Add(new PointF(barBounds.X, barBounds.Y));
                    lines.Add(new PointF(barBounds.X + xOffset, barBounds.Y - yOffset));
                    lines.Add(new PointF(barBounds.Right + xOffset, barBounds.Y - yOffset));
                    lines.Add(new PointF(barBounds.Right, barBounds.Y));
                    path.AddLines(lines.ToArray());
                    path.CloseFigure();

                    using (Pen pen = new Pen(this.Element.BorderColor), pen2 = new Pen(Color.FromArgb(100, Color.White)))
                    {
                        graphics.DrawPath(pen, path);
                        graphics.DrawPath(pen2, path);
                    }

                    using (Brush brush = new SolidBrush(this.Element.BackColor), brush2 = new SolidBrush(Color.FromArgb(100, Color.White)))
                    {
                        graphics.FillPath(brush, path);
                        graphics.FillPath(brush2, path);
                    }

                    using (StringFormat sf = new StringFormat(StringFormat.GenericTypographic))
                    {
                        object category = ((CategoricalDataPoint)dataPoint).Category;
                        string text     = customRenderer.Summaries[category].ToString();
                        SizeF  textSize = graphics.MeasureString(text, this.summaryFont);

                        RectangleF rect = ChartRenderer.ToRectangleF(slot);
                        rect.Offset(this.Element.View.Margin.Right + (rect.Width - textSize.Width) / 2, this.Element.View.Margin.Top + textSize.Height - 10);
                        radGraphics.DrawString(text, rect, this.summaryFont, Color.Black, sf, System.Windows.Forms.Orientation.Horizontal, false);
                    }
                }
            }
        }