Completed
Last Updated: 16 Apr 2018 11:03 by Dimitar
ADMIN
Dimitar
Created on: 11 Apr 2018 10:06
Category: ChartView
Type: Bug Report
1
FIX. RadChartView - the CartesianGridLineAnnotation is not clipped when zoom and pan is performed.
Use attached to reproduce. 

Workaround:
Use custom renderer: 

private void RadChartView1_CreateRenderer(object sender, ChartViewCreateRendererEventArgs e)
{
    e.Renderer = new CustomCartesianRenderer(e.Area as CartesianArea);
}

public class CustomCartesianRenderer : CartesianRenderer
{
    public CustomCartesianRenderer(CartesianArea area)
        : base(area)
    { }
    protected override void Initialize()
    {
        base.Initialize();
        for (int i = 0; i < this.DrawParts.Count; i++)
        {
            CartesianGridLineAnnotationDrawPart linePart = this.DrawParts[i] as CartesianGridLineAnnotationDrawPart;
            if (linePart != null)
            {
                this.DrawParts[i] = new MyCartesianGridLineAnnotationDrawPart((CartesianGridLineAnnotation)linePart.Element, this);
            }
        }
    }
}
class MyCartesianGridLineAnnotationDrawPart : CartesianGridLineAnnotationDrawPart
{
    public MyCartesianGridLineAnnotationDrawPart(CartesianGridLineAnnotation element, CartesianRenderer renderer)
       : base(element, renderer)
    { }
    public override void Draw()
    {
      
        PropertyInfo modelProperty = typeof(CartesianGridLineAnnotation).GetProperty("Model",
        System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
        object model = modelProperty.GetValue(this.Element);
        PropertyInfo layoutProperty = model.GetType().GetProperty("LayoutSlot", BindingFlags.Public | BindingFlags.Instance);
        RadRect radRect = (RadRect)layoutProperty.GetValue(model);
        RectangleF rect = ChartRenderer.ToRectangleF(radRect);


        rect.Offset(this.ViewportOffsetX, this.ViewportOffsetY);

        Graphics graphics = this.Renderer.Surface as Graphics;
       
        RadGdiGraphics radGraphics = new RadGdiGraphics(graphics);
        
        var clipRect = ChartRenderer.ToRectangle(this.Element.View.GetArea<CartesianArea>().AreaModel.PlotArea.LayoutSlot);
        clipRect.Offset((int)this.ViewportOffsetX,(int) this.ViewportOffsetY);

        graphics.SetClip(clipRect);
     

        GraphicsPath path = new GraphicsPath();
        path.AddLine(rect.Location, new PointF(rect.Right, rect.Bottom));

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

        rect.Size = graphics.MeasureString(this.Element.Label, this.Element.Font);
        rect.Offset(this.Element.PositonOffset.Width + 1, this.Element.PositonOffset.Height + 1);

        TextParams tp = new TextParams();
        tp.font = this.Element.Font;
        tp.foreColor = this.Element.ForeColor;
        tp.paintingRectangle = rect;
        tp.text = this.Element.Label;

        TextPrimitiveHtmlImpl text = new TextPrimitiveHtmlImpl();
        text.PaintPrimitive(radGraphics, 0f, new SizeF(1f, 1f), tp);
    }
}


Attached Files:
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
0 comments