Annotation position on resize

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Bob Yeatman
Newbie
Newbie
Posts: 18
Joined: Fri Nov 15, 2002 12:00 am

Annotation position on resize

Post by Bob Yeatman » Tue May 12, 2009 9:33 am

Hi, I have Delphi 6 and Teechart. I add an annotation to the chart and set its custom position. This work well. However, when I resize the chart the position of the annotation (relative to other chart components) moves.

For example: I add an annotation and place it next to the chart’s title. Then, when I resize the chart the annotation moves relative to the title.

Is there a way to automatically “adjust” the position of the annotation (to fix the annotation position relative to the chart) so that the position of the annotation does not move when the chart is resized?

Thanks
Bob

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

Post by Yeray » Tue May 12, 2009 11:24 am

Hi Bob,

I'm not sure to understand what you exactly want. If you want the annotation not to move at all, simply set its position with absolute values:

Code: Select all

uses series, TeeTools;

var FDragging: boolean;
    DifX, DifY: Integer;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.AllowZoom := False;
  Chart1.View3D := False;
  Chart1.Align := alClient;

  Chart1.AddSeries(TPointSeries.Create(self));
  Chart1[0].FillSampleValues(25);

  Chart1.Tools.Add(TAnnotationTool.Create(self));
  (Chart1.Tools[0] as TAnnotationTool).Text := 'My annotation';
  (Chart1.Tools[0] as TAnnotationTool).Shape.CustomPosition := True;

  Chart1.OnMouseDown := ChartMouseDown;
  Chart1.OnMouseMove := ChartMouseMove;
  Chart1.OnMouseUp := ChartMouseUp;
end;

procedure TForm1.ChartMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  with (Chart1.Tools[0] as TAnnotationTool) do
    if Clicked(X,Y) then
    begin
      DifX := X-Shape.Left;
      DifY := Y-Shape.Top;
      FDragging := True;
    end;
end;

procedure TForm1.ChartMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  if FDragging then
  begin
    with Chart1.Tools[0] as TAnnotationTool do
    begin
      Shape.Left := X-DifX;
      Shape.Top := Y-DifY;
    end;
  end;
end;

procedure TForm1.ChartMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  FDragging := False;
end;
If you are trying to move it relative to another chart part (axes, a series point,...) tell us and we'll try to give you some tips.
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

Bob Yeatman
Newbie
Newbie
Posts: 18
Joined: Fri Nov 15, 2002 12:00 am

Position of Annotation

Post by Bob Yeatman » Tue May 12, 2009 12:49 pm

Hi,
Thanks for the fast response.

The annotation example in the TeeChartPro8 All Features program shows the problem. This example has 3 annotations on a chart.

Click the example's edit button, select the 1st annotation (default) and go to the position tab.
Next, set the position for annotation 1 to: Custom=True, Scaling=Percent, Top=5, Left=45 -> you may need to use slightly different values to center the annotation1 over the title.

Finally, resize the chart (maximize the window or make the window small).

You will see that annotation1 does not stay over the title (it moves when the window is resized).

Note: The position for Annotation2 is set to pixels. Would it be better to set the annotation position using pixels and then make a relationship between the window size (in pixels) and the annotation position (also in pixels) so the annotation moves appropriately when the window size is changed?

I would like the annotation not to move relative to the title or axes or chart's frame. Is this possible?

Thanks again,
Bob

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

Post by Yeray » Tue May 12, 2009 1:35 pm

Hi Bob,
Bob Yeatman wrote:Click the example's edit button, select the 1st annotation (default) and go to the position tab.
Next, set the position for annotation 1 to: Custom=True, Scaling=Percent, Top=5, Left=45 -> you may need to use slightly different values to center the annotation1 over the title.

Finally, resize the chart (maximize the window or make the window small).

You will see that annotation1 does not stay over the title (it moves when the window is resized).
I've tested it with 2 different computers and annotation 1 always follows the title. Let me explain how it should work:

- Setting annotation position units as percent, it should move with chart resizes. It is a relative position.

- Setting annotation position units as pixels, it should not move with chart resizes. It is an absolute position.

- You still could use relative positions with pixels, but you should use OnAfterdraw event in order to reposition the tool manually each time. For example, relative to the chart title:

Code: Select all

procedure TForm1.Chart1Resize(Sender: TObject);
begin
  Chart1.Draw;
  ChartTool1.PositionUnits := muPixels;
  ChartTool1.Left := Chart1.Title.Left;
  ChartTool1.Top := Chart1.Title.Top;
end;
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

Bob Yeatman
Newbie
Newbie
Posts: 18
Joined: Fri Nov 15, 2002 12:00 am

Annotation position shift

Post by Bob Yeatman » Tue May 12, 2009 3:38 pm

Hi,
If I make the program window very small and then full screen I can clearly see that the annotation moves relative to the chart frame and the chart title. Hmmm the movement is not huge but it is there. Try covering the title with the annotation and when you make the window small or maximize it you should see different parts of title appear. I could send you some jpeg showing this. I'll try doing a "better" positioning of the annotations in the Afterdraw event.
Thanks,Bob

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

Post by Yeray » Wed May 13, 2009 8:29 am

Hi Bob,

Probably using percentages the annotation seems to move a little bit due to internal roundings.
Yes, I recommend you to use OnAfterDraw event to recalculate the tool position. Something like:

Code: Select all

uses teetools;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.Tools.Add(TAnnotationTool.Create(self));

  with (Chart1.Tools[0] as TAnnotationTool) do
  begin
    Text := 'my annotation text';
    PositionUnits := muPixels;
  end;

  Chart1.Draw;
end;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
begin
  with (Chart1.Tools[0] as TAnnotationTool) do
  begin
    Left := Chart1.Title.Left;
    Top := Chart1.Title.Top;
  end;
end;
Also note that Chart1.Title is fully configurable.
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

Bob Yeatman
Newbie
Newbie
Posts: 18
Joined: Fri Nov 15, 2002 12:00 am

Exact annotation positions

Post by Bob Yeatman » Wed May 13, 2009 11:08 am

Hi,
I think internal rounding of the percentage is the problem. I'll give your suggestion a try.
Thanks much!
Bob

Post Reply