Dynamic TAnnotationTool Autosize=false makes text disappear?

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
swesty
Newbie
Newbie
Posts: 14
Joined: Tue Feb 17, 2009 12:00 am

Dynamic TAnnotationTool Autosize=false makes text disappear?

Post by swesty » Wed Mar 04, 2009 4:30 am

Hi Steema,

I am new to the TAnnotationTool but I have found an interesting problem. If I use the following code it works fine.

TMYForm.FormCreate ;
begin
SetLength(SieveAnnotation,12) ;
for i := 0 to 11 do
begin
SieveAnnotation := TAnnotationTool.Create(self) ;
SieveAnnotation.Brush.Color:=clWhite;
SieveAnnotation.Shape.Transparency:=0;
if i = 0 then
SieveAnnotation.Text:='COBBLES';
if i = 1 then
SieveAnnotation.Text:='COARSE GRAVEL';
if i = 2 then
SieveAnnotation.Text:='MEDIUM GRAVEL';
if i = 3 then
SieveAnnotation.Text:='FINE GRAVEL';
if i = 4 then
SieveAnnotation.Text:='COARSE SAND';
if i = 5 then
SieveAnnotation.Text:='MEDIUM SAND';
if i = 6 then
SieveAnnotation.Text:='FINE SAND';
if i = 7 then
SieveAnnotation[i].Text:='COARSE SILT';
if i = 8 then
SieveAnnotation[i].Text:='MEDIUM SILT';
if i = 9 then
SieveAnnotation[i].Text:='FINE SILT';
if i = 10 then
SieveAnnotation[i].Text:='CLAY';
end;

for i := 0 to 10 do
begin
SieveAnnotation[i].Active := true ;
chPSD1.Tools.Add(SieveAnnotation[i]);
end;

end;

TMyForm.chPSD1AfterDraw(Sender: TObject);
begin

With chPSD1 do
Begin
LeftVal := chPSD1.BottomAxis.CalcPosValue(60) ;
TopVal := chPSD1.LeftAxis.IStartPos - 15 ;
RightVal := chPSD1.BottomAxis.IEndPos;
BottomVal := chPSD1.LeftAxis.IStartPos ;

SieveAnnotation[0].PositionUnits:=muPixels;
// SieveAnnotation[0].Shape.AutoSize := false ;
SieveAnnotation[0].Shape.Left:=LeftVal;
SieveAnnotation[0].Shape.Top:=TopVal;
SieveAnnotation[0].Shape.Width:=RightVal-LeftVal;
SieveAnnotation[0].Shape.Height:=TopVal-BottomVal;

end;


If I use the code above then it works fine. However if I uncomment the line in the AfterDraw procedure then it only shows me blank boxes but they are the correct width. My bottomaxis is also Logarithmic if that helps.


Can you shed any light for me on what is going wrong here ?

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

Post by Yeray » Wed Mar 04, 2009 10:47 am

Hi swesty,

The problem is that you are setting a negative value to the annotation's Shape.Height so the rectangle is painted just above the text and the text without its rectangle isn't drawn.

You could correct your Shape.Height calculations in order to ensure that it has a positive value or you could call the TeCanvas OrientRectangle function that does the same:

Code: Select all

uses TeCanvas;
//...
Annotation.Shape.ShapeBounds := OrientRectangle(Annotation.Shape.ShapeBounds);
Finally I'd like to suggest you a pair of things:
1. You don't need to set some properties (PositionUnits, Shape.AutoSize) at OnAfterDraw event as they will be re-set again and again.

2. Chart's BottomAxis, LeftAxis,... properties are deprecated properties. I recommend you to use Chart's Axes.Bottom, Axes.Left,...
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

swesty
Newbie
Newbie
Posts: 14
Joined: Tue Feb 17, 2009 12:00 am

Post by swesty » Wed Mar 04, 2009 9:55 pm

Hi Yeray,

Thanks so much for the information.
I must admit with the first point you have noted I basically copied code from a previous forum article and that's why PositionUnits is in the AfterDraw because that is what was suggested. The forum article I am referring to is http://www.teechart.net/support/viewtopic.php?t=3502 which as you can see does it the way I have listed. But that's ok I can change to suit your recommendation.

Thanks for the tip on the Axes.....I have been using TChart for a long time and need to change my habits.

Cheers,
Steve

Post Reply