TRectangleTool - Some questions ...

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
moelski
Advanced
Posts: 212
Joined: Mon Apr 23, 2007 12:00 am
Location: Germany
Contact:

TRectangleTool - Some questions ...

Post by moelski » Mon Jul 30, 2007 12:49 pm

Hi !

I want to implement TRectangleTool in my application.
Creating the the tool is easy:

Code: Select all

  RectTool := TRectangleTool.Create(self);
  RectTool.Text := 'Test';
  Chart1.Tools.Add(RectTool);
But then the problems getting bigger and bigger :wink:
1) How can I recognize that the mouse is over a TRectangleTool if the user clicks with the right mouse button? I want to show a special popupmenu for editing the TRectangleTool (text, font, callout, ...).
2) Normally the zoom don´t work for TRectangleTool. How can I change this? It would be great if the tool get´s the new correct position after zoom.

Did you have some example code for me?

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

Post by Narcís » Mon Jul 30, 2007 1:34 pm

Hi Dominik,

1. You can use OnMouseDown event and tool's Clicked method like this:

Code: Select all

procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if ((Button=mbRight) and (ChartTool1.Clicked(X,Y)))then
  begin
    //Write your code here.
  end;
end;
2. For this to work fine you should set the TRectangleTool position to a relative element in the chart (series, axes, legend, ...) and update this position every time the chart is being zoomed or scrolled, for example:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  SetRectPos;
end;

procedure TForm1.SetRectPos;
begin
  Chart1.Draw;
  ChartTool1.Shape.CustomPosition:=true;
  ChartTool1.Shape.Left:=Series1.CalcXPos(5);
  ChartTool1.Shape.Top:=Series1.CalcYPos(5);
end;

procedure TForm1.Chart1Zoom(Sender: TObject);
begin
  SetRectPos;
end;

procedure TForm1.Chart1UndoZoom(Sender: TObject);
begin
  SetRectPos;
end;

procedure TForm1.Chart1Scroll(Sender: TObject);
begin
  SetRectPos;
end;
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

moelski
Advanced
Posts: 212
Joined: Mon Apr 23, 2007 12:00 am
Location: Germany
Contact:

Post by moelski » Tue Jul 31, 2007 4:57 am

Hi Narcis,

ChartTool1.Shape.Left:=Series1.CalcXPos(5);
ChartTool1.Shape.Top:=Series1.CalcYPos(5);


Well this seems to be tricky ....
Would it be possible to do calculate the new position a little bit more dynamically? Here are my problems:
1) What will happend if series1 isn´t visible?
2) What will happen if no series is visible?

I have tried to use your code in this way:

Code: Select all

  TRectangleTool(Chart1.Tools[1]).Shape.Left           := Series1.CalcXPos(TRectangleTool(Chart1.Tools[1]).Shape.Left);
  TRectangleTool(Chart1.Tools[1]).Shape.Top            := Series1.CalcYPos(TRectangleTool(Chart1.Tools[1]).Shape.Top);
But this won´t work for me.

So could you please add a small piece of code which changes the position of the rectangle tool against it´s actual position.
And what about the Callouts. Must I recalculate the endpoint, too?

btw: Clicking on a rectangle tool works fine for me now !

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

Post by Narcís » Tue Jul 31, 2007 9:17 am

Hi moelski,
Well this seems to be tricky ....
Would it be possible to do calculate the new position a little bit more dynamically? Here are my problems:
1) What will happend if series1 isn´t visible?
2) What will happen if no series is visible?
This is dynamic because whenever the chart is zoomed or scrolled the rectangle position is changed accordingly as well. However this is just an example. If you don't relate rectangle's position to series you can make it relative to chart axes for example:

Code: Select all

procedure TForm1.SetRectPos;
begin
  Chart1.Draw;
  ChartTool1.Shape.CustomPosition:=true;
  ChartTool1.Shape.Left:=Chart1.Axes.Left.PosAxis + 10;
  ChartTool1.Shape.Top:=Chart1.Axes.Bottom.PosAxis - 10;
end;
I have tried to use your code in this way:
Code:
TRectangleTool(Chart1.Tools[1]).Shape.Left := Series1.CalcXPos(TRectangleTool(Chart1.Tools[1]).Shape.Left);
TRectangleTool(Chart1.Tools[1]).Shape.Top := Series1.CalcYPos(TRectangleTool(Chart1.Tools[1]).Shape.Top);

But this won´t work for me.
CalcXPos and CalcYPos methods doesn't work that way. Those methods return a pixel screen position from given series point ValueIndex. Look at the different methods provided for calculating from chart values to pixel screen coordinates and viceversa.

So could you please add a small piece of code which changes the position of the rectangle tool against it´s actual position.

A simple example would be something like this:

Code: Select all

procedure TForm1.SetRectPos;
begin
  Chart1.Draw;
  ChartTool1.Shape.CustomPosition:=true;
  ChartTool1.Shape.Left:=ChartTool1.Shape.Left + 10;
  ChartTool1.Shape.Top:=ChartTool1.Shape.Top - 10;
end;
Don't forget the Draw call in the SetRectPos method in all the examples I posted.
And what about the Callouts. Must I recalculate the endpoint, too?


Yes, the same for the callout needs to be done.
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

moelski
Advanced
Posts: 212
Joined: Mon Apr 23, 2007 12:00 am
Location: Germany
Contact:

Post by moelski » Tue Jul 31, 2007 9:52 am

Hi Narcis,

thx for your answer but I won´t get it working :cry:

So could you please make a small demo application with the following features:
1) the RectangleTool has always the same width / heigth if you do zooming or panning.
2) the tool will be placed at the correct position after zooming / scrolling and don´t stay at the position before zooming / scrolling.

This would solve my problems. With that code I can implament the callout option by myself.

Thx in advance !!

moelski
Advanced
Posts: 212
Joined: Mon Apr 23, 2007 12:00 am
Location: Germany
Contact:

Post by moelski » Wed Aug 01, 2007 5:47 am

Hi Narcis,

I spend a pro support mail. I think this is a bigger problem (for me).

Greetz Dominik

Post Reply