Page 1 of 1

Patch for TeeDatetime axis with too many labels

Posted: Fri Jul 24, 2009 11:23 am
by 10553957
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;

Re: Patch for TeeDatetime axis with too many labels

Posted: Fri Jul 24, 2009 2:50 pm
by yeray
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.

Re: Patch for TeeDatetime axis with too many labels

Posted: Mon Jul 27, 2009 7:52 am
by 10553957
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

Re: Patch for TeeDatetime axis with too many labels

Posted: Mon Jul 27, 2009 9:29 am
by yeray
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.