This is a migrated thread and some comments may be shown as answers.

Custom selection behavior HitTestPoints off when zoomed in

1 Answer 59 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Seth
Top achievements
Rank 1
Seth asked on 02 Jul 2018, 09:13 PM

Hello,

I've written a custom selection behavior in order to support un-selecting points when clicking on an empty (non-Data Point) area of the chart. This behavior works pretty nicely. However, as soon as the chart is zoomed or panned in any direction, the click ends up selecting a point to the upper-left of where I actually clicked. The main algorithm of the click selection is below. Is there a specific pan/zoom offset that I'm supposed to take into account?

var rect = new Rect((myMouseButtonEventArgs.GetPosition(this.Chart as IInputElement), new Size(myHitTestMargin));
if(this.Chart is RadCartesianChart)
{
    var chart = this.Chart as RadCartesianChart;
    var points = chart.Series.SelectMany(s => s.HitTestDataPoints(rect)); //-- this returns the wrong set of points when zoomed or panned
    //-- Create a new arguments object with these points and invoke a custom event with those args
}

1 Answer, 1 is accepted

Sort by
0
Seth
Top achievements
Rank 1
answered on 02 Jul 2018, 09:31 PM
Just needed to get the Zoom and PanOffset properties from the chart and apply them:

var zoom = Chart.Zoom;
var panOffset = Chart.PanOffset;

rect.X -= panOffset.X;
rect.Y -= panOffset.Y;
rect.Height *= zoom.Height;
rect.Width *= zoom.Width;

Thanks!
Tags
Chart
Asked by
Seth
Top achievements
Rank 1
Answers by
Seth
Top achievements
Rank 1
Share this question
or