Approved
Last Updated: 07 Apr 2017 10:12 by ADMIN
ADMIN
Hristo
Created on: 16 Oct 2015 08:37
Category: RangeSelector
Type: Bug Report
5
FIX. RadRangeSelector - if it is associated with a chart and the height of the range selector is decreased, the hosted in the RadRangeSelector chart is cropped
How to reproduce:
public partial class Form1 : Form
    {
        private RangeSelectorViewElement chartElement;

        public Form1()
        {
            InitializeComponent();

            new RadControlSpyForm().Show();

            this.SetupChart();

            this.radRangeSelector1.AssociatedControl = this.radChartView1;
            this.chartElement = this.radRangeSelector1.RangeSelectorElement.AssociatedElement as RangeSelectorViewElement;
            this.chartElement.SeriesInitializing += new SeriesInitializingEventHandler(chartElement_SeriesInitializing);
        }

        private void chartElement_SeriesInitializing(object sender, SeriesInitializingEventArgs e)
        {
            e.SeriesType = typeof(LineSeries);
        }

        private void SetupChart()
        {
            LineSeries lineSeries = new LineSeries();
            lineSeries.DataPoints.Add(new CategoricalDataPoint(20, "Jan"));
            lineSeries.DataPoints.Add(new CategoricalDataPoint(22, "Apr"));
            lineSeries.DataPoints.Add(new CategoricalDataPoint(12, "Jul"));
            lineSeries.DataPoints.Add(new CategoricalDataPoint(19, "Oct"));
            this.radChartView1.Series.Add(lineSeries);

            LineSeries lineSeries2 = new LineSeries();
            lineSeries2.DataPoints.Add(new CategoricalDataPoint(3, "Jan"));
            lineSeries2.DataPoints.Add(new CategoricalDataPoint(1, "Apr"));
            lineSeries2.DataPoints.Add(new CategoricalDataPoint(5, "Jul"));
            lineSeries2.DataPoints.Add(new CategoricalDataPoint(2, "Oct"));
            this.radChartView1.Series.Add(lineSeries2);
        }

        private void radButton1_Click(object sender, EventArgs e)
        {
            this.radRangeSelector1.Height = 100;
            //this.ScaleVerticallyChart(this.chartElement.View, .55);
        }
}

Workaround: zoom out along the Y axis the hosted chart element and pan the view so that all series are visible
private void radButton1_Click(object sender, EventArgs e)
        {
            this.radRangeSelector1.Height = 100;
            this.ScaleVerticallyChart(this.chartElement.View, this.radRangeSelector1.Height / (float)150);
        }

        private void ScaleVerticallyChart(ChartView view, double verticalScaleFactor)
        {
            FieldInfo fiPan = view.GetType().GetField("pan", BindingFlags.NonPublic | BindingFlags.Instance);
            RadPoint pan = (RadPoint)fiPan.GetValue(view);
            FieldInfo fiZoom = view.GetType().GetField("zoom", BindingFlags.NonPublic | BindingFlags.Instance);
            RadSize zoom = (RadSize)fiZoom.GetValue(view);

            double verticalPan = pan.Y * verticalScaleFactor / zoom.Height;
            CartesianArea area = view.GetArea<CartesianArea>();
            if (area != null)
            {
                MethodInfo mi = area.GetType().GetMethod("GetCartesianClipRect", BindingFlags.NonPublic | BindingFlags.Instance);
                RectangleF rect = (RectangleF)mi.Invoke(area, new object[] { });
                SizeF areaSize = rect.Size;
                verticalPan += areaSize.Height - (areaSize.Height * verticalScaleFactor + verticalPan);
            }

            zoom = new RadSize(1, verticalScaleFactor);
            fiZoom.SetValue(view, zoom);
            view.Layout();
        }
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
0 comments