Get Points Index from Rect

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
GoToXY
Newbie
Newbie
Posts: 81
Joined: Thu Apr 03, 2008 12:00 am

Get Points Index from Rect

Post by GoToXY » Fri Jul 23, 2010 1:10 pm

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.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Get Points Index from Rect

Post by Narcís » Fri Jul 23, 2010 1:30 pm

Hi GotoXY,

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

http://www.teechart.net/support/viewtopic.php?t=5385
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

GoToXY
Newbie
Newbie
Posts: 81
Joined: Thu Apr 03, 2008 12:00 am

Re: Get Points Index from Rect

Post by GoToXY » Fri Jul 23, 2010 1:39 pm

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

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Get Points Index from Rect

Post by Yeray » Fri Jul 23, 2010 2:26 pm

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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

GoToXY
Newbie
Newbie
Posts: 81
Joined: Thu Apr 03, 2008 12:00 am

Re: Get Points Index from Rect

Post by GoToXY » Fri Jul 23, 2010 2:32 pm

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!

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Get Points Index from Rect

Post by Yeray » Fri Jul 23, 2010 4:02 pm

Hi GoToXY,

Thanks to your for your comments and for sharing!
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply