Patch for TeeDatetime axis with too many labels

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
h.hasenack
Newbie
Newbie
Posts: 32
Joined: Tue Jul 21, 2009 12:00 am
Location: Nijmegen, Netherlands

Patch for TeeDatetime axis with too many labels

Post by h.hasenack » Fri Jul 24, 2009 11:23 am

The proposed patch influences the # of labels in an axis when very long periods are to be displayed. I have been using this patch since Tee6, i believe. Check the attachment to demonstrate the problem. (though de difference neems to be less obvious with Tee8).

Regards - Hans

Code: Select all

Procedure TeeDateTimeIncrement( IsDateTime:Boolean;
                                Increment:Boolean;
                                var Value:Double;
                                Const AnIncrement:Double;
                                tmpWhichDateTime:TDateTimeStep);
var Year  : Word;
    Month : Word;
    Day   : Word;

 Procedure DecMonths(HowMany:Word);
 begin
   Day:=1;
   if Month>HowMany then Dec(Month,HowMany)
   else
   begin
     Dec(Year);
     Month:=12-(HowMany-Month);
   end;
 end;

 Procedure IncMonths(HowMany:Word);
 begin
   Day:=1;
   Inc(Month,HowMany);
   if Month>12 then
   begin
     Inc(Year);
     Month:=Month-12;
   end;
 end;

 Procedure IncDecMonths(HowMany:Word);
 begin
   if Increment then IncMonths(HowMany)
                else DecMonths(HowMany);
 end;

{$ifdef HH_PATCH_TC_DATETIME}
VAR  MinNewValue:double;
{$endif}
begin
  if IsDateTime then
  begin
    DecodeDate(Value,year,month,day);
{$ifdef HH_PATCH_TC_DATETIME}
// This loop keeps adding the desired value until the
// AnIncrement value is reached. This avoids having too many
// date labels below a chart
    if Increment then MinNewValue:=Value+AnIncrement
                 else MinNewValue:=Value-AnIncrement;

    repeat
{$endif}
    Case tmpWhichDateTime of
       dtHalfMonth   : Begin
                         if Day>15 then Day:=15
                         else
                         if Day>1 then Day:=1
                         else
                         begin
                           IncDecMonths(1);
                           Day:=15;
                         end;
                       end;
       dtOneMonth    : IncDecMonths(1);
       dtTwoMonths   : IncDecMonths(2);
       dtThreeMonths : IncDecMonths(3);
       dtFourMonths  : IncDecMonths(4);
       dtSixMonths   : IncDecMonths(6);
       dtOneYear     : if Increment then Inc(year) else Dec(year);
    else
    begin
      if Increment then Value:=Value+AnIncrement
                   else Value:=Value-AnIncrement;
      Exit;
    end;
    end;
    Value:=EncodeDate(year,month,day);
{$ifdef HH_PATCH_TC_DATETIME}
    until (tmpWhichDateTime<dtOneYear)
          or (Increment and (Value>=MinNewValue))
          or (not Increment and (Value<=MinNewValue));
{$endif}
  end
  else
  begin
    if Increment then Value:=Value+AnIncrement
                 else Value:=Value-AnIncrement;
  end;
end;
Attachments
TestTChart.zip
Has a Date testing button on the main form
(6.08 KiB) Downloaded 213 times

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

Re: Patch for TeeDatetime axis with too many labels

Post by Yeray » Fri Jul 24, 2009 2:50 pm

Hi Hans,

I'm not sure to understand what is the exact problem you are noticing here. I see no difference in the result of pressing the btTestDates on your application before and after applying the changes you propose in TeeProcs.pas.
If the problem is that the labels before 1900 aren't shown, it's going to be solved with the next maintenance released as discussed here. If not, please, could you please try to explain the problem again? Maybe a picture would help us to understand it.

Thanks in advance.
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

h.hasenack
Newbie
Newbie
Posts: 32
Joined: Tue Jul 21, 2009 12:00 am
Location: Nijmegen, Netherlands

Re: Patch for TeeDatetime axis with too many labels

Post by h.hasenack » Mon Jul 27, 2009 7:52 am

Ah!

I had to find out how to let it go wrong...

1) Runn testapp from ZIP
2) click testYears
3) Edit chart, change bottom axis desired increment to eg one week. All labels on the bottom axis will overlap. With my patch, they wont.

Regards - Hans

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

Re: Patch for TeeDatetime axis with too many labels

Post by Yeray » Mon Jul 27, 2009 9:29 am

Hi Hans,

Thanks for the explanation. Now I could reproduce it and see how your code solves it. I'd like you to know that your code will be present in the next v8 maintenance release.

Thank you.
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