Completed
Last Updated: 26 Jun 2018 06:55 by Dimitar
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 21 Jun 2018 06:50
Category: ChartView
Type: Bug Report
2
FIX. RadChartView - incorrect points are selected with the LassoSelectionController
To reproduce: please refer to the attached sample project and gif file.

Workaround: 
            CustomLassoSelectionController lassoSelectionController = new CustomLassoSelectionController(); 
            this.radChartView1.Controllers.Add(lassoSelectionController);

        public class CustomLassoSelectionController : LassoSelectionController
        {
            private IList<DataPoint> selectedPoints = null;

            public CustomLassoSelectionController()
            {
                this.selectedPoints = new List<DataPoint>();
            }

            private Point ClipLocation(Point point)
            {
                CartesianArea area = this.Area.View.GetArea<CartesianArea>();
                if (area != null)
                {
                    RectangleF clipRect = GetCartesianClipRect(area);

                    if (point.X < clipRect.X)
                    {
                        point = new Point((int)clipRect.X, point.Y);
                    }

                    if (point.X > clipRect.Width + clipRect.X)
                    {
                        point = new Point((int)clipRect.Width + (int)clipRect.X, point.Y);
                    }

                    if (point.Y < clipRect.Y)
                    {
                        point = new Point(point.X, (int)clipRect.Y);
                    }

                    if (point.Y > clipRect.Height + clipRect.Y)
                    {
                        point = new Point(point.X, (int)clipRect.Height + (int)clipRect.Y);
                    }
                }

                return point;
            }

            internal RectangleF GetCartesianClipRect(CartesianArea area)
            {
                float x1, x2, y1, y2;
                x1 = 0;
                y1 = 0;
                x2 = (float)area.View.Viewport.Right;
                y2 = (float)area.View.Viewport.Bottom;

                foreach (var axis in area.View.Axes)
                {
                    if (axis.AxisType == AxisType.First)
                    {
                        if (axis.Model.VerticalLocation == AxisVerticalLocation.Bottom)
                        {
                            y2 = Math.Min(y2, (float)axis.Model.LayoutSlot.Y);
                        }
                        else
                        {
                            y1 = Math.Max(y1, (float)axis.Model.LayoutSlot.Bottom);
                        }

                        x1 = Math.Min(x1, (float)axis.Model.LayoutSlot.X);
                        x2 = Math.Min(x2, (float)axis.Model.LayoutSlot.Right);
                    }
                    else
                    {
                        if (axis.Model.HorizontalLocation == AxisHorizontalLocation.Left)
                        {
                            x1 = Math.Max(x1, (float)axis.Model.LayoutSlot.Right);
                        }
                        else
                        {
                            x2 = Math.Min(x2, (float)axis.Model.LayoutSlot.X);
                        }

                        y1 = Math.Max(y1, (float)axis.Model.LayoutSlot.Y);
                        y2 = Math.Min(y2, (float)axis.Model.LayoutSlot.Bottom);
                    }
                }

                RectangleF result = new RectangleF((float)area.View.Viewport.X + x1, (float)area.View.Viewport.Y + y1, x2 - x1 + 1, y2 - y1 + 1);

                return result;
            }

            protected override ActionResult OnMouseUp(MouseEventArgs e)
            {
                if (e.Button != MouseButtons.Left || this.MouseDownLocation == Point.Empty || this.MouseMoveLocation == Point.Empty)
                {
                    return base.OnMouseUp(e);
                }

                if (MouseDownLocation != MouseMoveLocation)
                {
                    this.MouseMoveLocation = ClipLocation(e.Location);
                    CartesianArea area = this.Area.View.GetArea<CartesianArea>();

                    if (area != null)
                    {
                        this.selectedPoints.Clear();
                        RectangleF areaRect = RectangleF.Empty;
                        IChartView chartView = this.Area.View;
                        areaRect = GetCartesianClipRect(area);

                        Point topLeft = new Point(Math.Min(MouseDownLocation.X, e.X), Math.Min(MouseDownLocation.Y, e.Y));
                        Point lowerRight = new Point(Math.Max(MouseDownLocation.X, e.X), Math.Max(MouseDownLocation.Y, e.Y));
                        RectangleF lassoRect = new RectangleF(new PointF(topLeft.X - (float)chartView.PlotOriginX - area.View.Margin.Left, topLeft.Y - (float)chartView.PlotOriginY - area.View.Margin.Top), new SizeF(lowerRight.X - topLeft.X, lowerRight.Y - topLeft.Y));

                        foreach (var series in area.View.Series)
                        {
                            foreach (var dataPoint in series.DataPoints)
                            {
                                if (lassoRect.Contains(new PointF((float)dataPoint.LayoutSlot.Location.X, (float)dataPoint.LayoutSlot.Location.Y)))
                                {
                                    dataPoint.IsSelected = true;
                                    this.selectedPoints.Add(dataPoint);
                                }
                                else
                                {
                                    dataPoint.IsSelected = false;
                                }
                            }
                        }
                        
                        ChartDataPointsEventArgs changedArgs = new ChartDataPointsEventArgs(this.selectedPoints);
                        this.OnLassoSelectedPointsChanged(changedArgs);
                    }

                    MouseDownLocation = MouseMoveLocation = Point.Empty;
                }

                this.Result.ShouldInvalidate = true;
                return this.Result;
            }
        }
0 comments