Completed
Last Updated: 20 Mar 2015 14:25 by ADMIN
ADMIN
Dimitar
Created on: 19 Mar 2015 12:37
Category: ChartView
Type: Bug Report
0
FIX. RadChartView - The axis labels are clipped when the text has specific length.
To reproduce:
BarSeries barSeries = new BarSeries("Performance", "RepresentativeName");
barSeries.Name = "Q1";
barSeries.DataPoints.Add(new CategoricalDataPoint(1000000, "Harley Harley Harley Harley Smith"));
barSeries.DataPoints.Add(new CategoricalDataPoint(2000000, "White"));
barSeries.DataPoints.Add(new CategoricalDataPoint(3000000, "Smith Smith Smith Smith Smith mith Smith Harley"));
barSeries.DataPoints.Add(new CategoricalDataPoint(4000000, "Jones"));
barSeries.DataPoints.Add(new CategoricalDataPoint(5000000, "Marshall"));
this.radChartView1.Series.Add(barSeries);

this.radChartView1.GetArea<CartesianArea>().Orientation = Orientation.Horizontal;

LinearAxis horizontalAxis = radChartView1.Axes.Get<LinearAxis>(1);
horizontalAxis.ClipLabels = false;


Workaround:
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++)
        {
            AxisLabelDrawPart part = this.DrawParts[i] as AxisLabelDrawPart;
            if (part != null)
            {
                this.DrawParts[i] = new CustomDrawPart((Axis)part.Element, this);
            }
        }
    }
}
public class CustomDrawPart : AxisLabelDrawPart
{
    public CustomDrawPart(Axis axis, IChartRenderer renderer) :base( axis,  renderer)
    {}
    protected override void DrawNoneAndMultiLineLabelElements()
    {
        //base.DrawNoneAndMultiLineLabelElements();
        if (!this.Element.ShowLabels || this.Element.Children.Count == 0)
        {
            return;
        }

        Graphics graphics = this.Renderer.Surface as Graphics;
        RadGdiGraphics radGraphics = new RadGdiGraphics(graphics);

        RadRect plotRect = this.Element.Model.LayoutSlot;
        plotRect.X += this.ViewportOffsetX;
        plotRect.Y += this.ViewportOffsetY;

        CartesianAxis axis = this.Element as CartesianAxis;
        SizeF offset = SizeF.Empty;

        if (axis != null)
        {
            offset = ((CartesianRenderer)this.Renderer).GetAxisOffset(axis);

            if (axis.ClipLabels)
            {
                SizeF size = graphics.MeasureString("W", this.Element.Font);

                RectangleF clipRect = ChartRenderer.ToRectangleF(plotRect);
                clipRect.Y -= size.Height / 2f;
                clipRect.Height += size.Height;
                clipRect.X -= size.Width;
                clipRect.Width += size.Width * 2f;
                clipRect.Offset(offset.ToPointF());

                graphics.SetClip(clipRect);
            }
        }

        using (SolidBrush brush = new SolidBrush(Color.Empty))
        {
            foreach (UIChartElement element in this.Element.Children)
            {
                AxisLabelElement labelElement = element as AxisLabelElement;

                if (labelElement == null || !labelElement.IsVisible)
                {
                    continue;
                }

                string text = labelElement.Text;

                if (string.IsNullOrEmpty(text))
                {
                    continue;
                }

                labelElement.OnAxisLabelFormatting(new ChartAxisLabelFormattingEventArgs(labelElement));
                RadRect slot = labelElement.GetLayoutSlot();

                if (this.Element is CartesianAxis)
                {
                    slot.X += this.ViewportOffsetX;
                    slot.Y += this.ViewportOffsetY;
                }

                if (this.Element.AxisType == AxisType.First)
                {
                    slot.X += (float)((IChartView)this.Element.View).PlotOriginX;
                }
                else
                {
                    slot.Y += (float)((IChartView)this.Element.View).PlotOriginY;
                }

                RectangleF rect = ChartRenderer.ToRectangleF(slot);

                if (axis != null)
                {
                    rect.Offset(offset.ToPointF());
                }

                if (labelElement.BackgroundShape != null)
                {
                    labelElement.BackgroundShape.Paint((Graphics)radGraphics.UnderlayGraphics, rect);
                }

                FillPrimitiveImpl fill = new FillPrimitiveImpl(labelElement, null);
                fill.PaintFill(radGraphics, 0, Size.Empty, rect);

                BorderPrimitiveImpl border = new BorderPrimitiveImpl(labelElement, null);
                border.PaintBorder(radGraphics, 0, Size.Empty, rect);

                if (brush.Color != labelElement.ForeColor)
                {
                    brush.Color = labelElement.ForeColor;
                }

                StringFormat sf = StringFormat.GenericTypographic;
                sf.Alignment = StringAlignment.Near;

                graphics.DrawString(text, labelElement.Font, Brushes.Black, rect.Location, sf);
            }
        }
    }
}
0 comments