Page 1 of 1

Axis Labels not drawing

Posted: Wed Jul 16, 2025 12:14 am
by 16592490
TeeChart Axis labels seem to be too aggressive in NOT drawing even when there is space when using LabelsAlternate.

In particular, even if you set LabelSeparation to the minimum non-zero value (1) and set LabelsAlternate to true it stops drawing some labels even if they should fit. I took a quick look at the source code and I think it does not take into account if labels alternate. Here is an example attached.

Any thoughts on whether this might get fixed or has anyone hacked the source to address this?
LabelsShouldFit.png
LabelsShouldFit.png (19.16 KiB) Viewed 4280 times

Re: Axis Labels not drawing

Posted: Fri Jul 18, 2025 11:15 am
by yeray
Hello,

I've added it to the public tracker: #2775.
And already fixed it.
labelsalternate.png
labelsalternate.png (4.71 KiB) Viewed 3986 times
Here the diff if you want to apply it in your sources:

Code: Select all

--- a/TeEngine.pas
+++ b/TeEngine.pas
@@ -6963,11 +6963,11 @@ var
   var
     tmpLabelSize : Integer;
     tmpLabelW    : Boolean;
-    OldPosLabel  : Integer;
     tmp          : Integer;
-    OldSizeLabel : Integer;
+    OldPosLabel  : array [0..1] of Integer;
+    OldSizeLabel : array [0..1] of Integer;
 
-    function DoesLabelFit(const ALabel:String):Boolean;
+    function DoesLabelFit(const ALabel:String; const ARow:Integer):Boolean;
     var tmpNum : Integer;
     begin
       if tmpLabelW then
@@ -6978,15 +6978,15 @@ var
         tmpLabelSize:=ParentChart.Canvas.FontHeight*tmpNum;
       end;
 
-      if (FLabels.Separation<>0) and (OldPosLabel<>-1) then
+      if (FLabels.Separation<>0) and (OldPosLabel[ARow]<>-1) then
       begin
         Inc(tmpLabelSize,Trunc(0.02*tmpLabelSize*FLabels.Separation));
         tmpLabelSize:=tmpLabelSize div 2;
 
-        if tmp>=OldPosLabel then
-           result:=(tmp-tmpLabelSize)>=(OldPosLabel+OldSizeLabel)
+        if tmp>=OldPosLabel[ARow] then
+           result:=(tmp-tmpLabelSize)>=(OldPosLabel[ARow]+OldSizeLabel[ARow])
         else
-           result:=(tmp+tmpLabelSize)<=(OldPosLabel-OldSizeLabel);
+           result:=(tmp+tmpLabelSize)<=(OldPosLabel[ARow]-OldSizeLabel[ARow]);
       end
       else
         result:=True;
@@ -7032,6 +7032,7 @@ var
       tmpSt2       : String;
       tmpPicture   : TTeePicture;
       tmpDuplicated: Boolean;
+      tmpRow       : Integer;
   begin
     CalcAllSeries;
     CalcFirstLastAllSeries(tmpFirst,tmpLast);
@@ -7054,8 +7055,11 @@ var
 
       for s:=0 to ISeriesList.Count-1 do
       begin
-        OldPosLabel :=-1;
-        OldSizeLabel:= 0;
+        OldPosLabel[0] :=-1;
+        OldPosLabel[1] :=-1;
+        OldSizeLabel[0]:= 0;
+        OldSizeLabel[1]:= 0;
+        tmpRow:=0;
 
         t:=tmpFirst;
 
@@ -7073,9 +7077,9 @@ var
 
              if FLabels.Visible and (tmpSt<>'') then
              begin
-               tmpDraw:=DoesLabelFit(tmpSt);
+               tmpDraw:=DoesLabelFit(tmpSt, tmpRow);
 
-               if (FLabels.Separation<>0) and (OldPosLabel<>-1) then
+               if (FLabels.Separation<>0) and (OldPosLabel[tmpRow]<>-1) then
                begin
                  if (not tmpDraw) and Texts.Automatic.Trim then
                  begin
@@ -7084,7 +7088,7 @@ var
                    while tmpSt2<>'' do
                    begin
                      Delete(tmpSt2,Length(tmpSt2),1);
-                     tmpDraw:=DoesLabelFit(tmpSt2);
+                     tmpDraw:=DoesLabelFit(tmpSt2, tmpRow);
 
                      if tmpDraw then
                      begin
@@ -7099,8 +7103,11 @@ var
                    if not tmpDuplicated then
                      AddTickAndSaveLabel(tmpValue,tmp,tmpSt,tmpPicture);
 
-                   OldPosLabel:=tmp;
-                   OldSizeLabel:=tmpLabelSize;
+                   OldPosLabel[tmpRow]:=tmp;
+                   OldSizeLabel[tmpRow]:=tmpLabelSize;
+
+                   if LabelsAlternate then
+                      tmpRow:=(tmpRow+1) mod 2;
                  end;
                end
                else
@@ -7108,8 +7115,11 @@ var
                  if not tmpDuplicated then
                    AddTickAndSaveLabel(tmpValue,tmp,tmpSt,tmpPicture);
 
-                 OldPosLabel:=tmp;
-                 OldSizeLabel:=tmpLabelSize div 2;
+                 OldPosLabel[tmpRow]:=tmp;
+                 OldSizeLabel[tmpRow]:=tmpLabelSize div 2;
+
+                 if LabelsAlternate then
+                    tmpRow:=(tmpRow+1) mod 2;
                end;
              end;
            end;
-- 

Re: Axis Labels not drawing

Posted: Tue Jul 29, 2025 5:53 pm
by 16587558
Thanks!