Page 1 of 1

Get Points Index from Rect

Posted: Fri Jul 23, 2010 1:10 pm
by 10548769
I wonder if there is a function from TChartSeries that return a list a points Index from a TRect (Selection using mouse).

I did a lil search on the forum and i havent found anything about that.

Thanks.

Re: Get Points Index from Rect

Posted: Fri Jul 23, 2010 1:30 pm
by narcis
Hi GotoXY,

You could do the same as the examples discussed on this thread:

http://www.teechart.net/support/viewtopic.php?t=5385

Re: Get Points Index from Rect

Posted: Fri Jul 23, 2010 1:39 pm
by 10548769
Looks like what im trying to do but in reverse. We have series with over 2m values so i think it would be more optimized my way.

What i do is convert my TRect values to values from the axis then vérified if (X >= X1) AND (X <= X2) etc..

From my point of view, converting the TRect will be less CPU usage since i do that only 1 time but i dont know if comparing Double will cost me more than comparing integer + the conversion

Re: Get Points Index from Rect

Posted: Fri Jul 23, 2010 2:26 pm
by yeray
Hi GoToXY,

I also think your method would be more optimized.
(A) Transform the Rect coordinates (pixels) to doubles (values) and, in the loop, compare doubles (Rect coordinates and Series Values).
(B) In the loop, transform Series Values to integers (pixels) and compare integers.

Note that in (B) "transform Series Values to integers (pixels)", the call to CalcXPos means some operations, concretely two sums of doubles, a product and a Round.
I don't think the difference between comparing integers and comparing doubles would compensate these extra operations.

Re: Get Points Index from Rect

Posted: Fri Jul 23, 2010 2:32 pm
by 10548769
It seems to be working great enought for me.

There is my code so if others want to used it, be free to do so.

Code: Select all

Function GetPointsFromRect(AChart: TChart; ASerie: TChartSeries; ARect: TRect): TIntegerArray;
Var
 Left, Right, Top, Bottom: Double;
 Ctr: Integer;

Begin
If (ARect.Left > ARect.Right) Then Begin
 Ctr := ARect.Left;
 ARect.Left := ARect.Right;
 ARect.Right := Ctr;
 End;
If (ARect.Top > ARect.Bottom) Then Begin
 Ctr := ARect.Top;
 ARect.Top := ARect.Bottom;
 ARect.Bottom := Ctr;
 End;

//I assume that the serie is on the bottom and left axis.
Left := AChart.BottomAxis.CalcPosPoint(ARect.Left);
Right := AChart.BottomAxis.CalcPosPoint(ARect.Right);
Top := AChart.LeftAxis.CalcPosPoint(ARect.Top);
Bottom := AChart.LeftAxis.CalcPosPoint(ARect.Bottom);

SetLength(Result, 0);
For Ctr := 0 To ASerie.Count - 1 Do
 If ((ASerie.XValues[Ctr] >= Left) AND (ASerie.XValues[Ctr] <= Right) AND (ASerie.YValues[Ctr] >= Bottom) AND (ASerie.YValues[Ctr] <= Top)) Then Begin
  SetLength(Result, Length(Result) + 1);
  Result[Length(Result) - 1] := Ctr;
  End;
End;
Thanks a lot again, i really appreciate your SuperFast Support!

Re: Get Points Index from Rect

Posted: Fri Jul 23, 2010 4:02 pm
by yeray
Hi GoToXY,

Thanks to your for your comments and for sharing!