scales and axes

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Fenichel
Newbie
Newbie
Posts: 28
Joined: Fri Jul 19, 2024 12:00 am

Re: scales and axes

Post by Fenichel » Fri Sep 13, 2024 8:53 pm

Here's yet another related issue. When I create a new axis to be an auxiliary scale on the right, it looks strange, because
  • As previously discussed, the title appears to the left of the scale, when it should be to the right. This will be fixable by using your new Distance parameter.
  • The ticks and labels are to the left of the axis, when they should be to the right. I don't think any existing user-accessible parameter controls this.
What might be good is to add a Side property to tChartAxis, with values [Left, Right, Top, Bottom]. Then when a user created a new axis with Side=Right, the axis's ticks & labels would automatically be on the right of the axis, and the default position of the axis title would be to the right of the labels. I wouldn't make such an axis have the PositionPercent behavior of RightAxis, but I suppose you might feel obligated to do that for a sort of consistency.

I'll put my latest demo code up on my site in the next few minutes.

Fenichel
Newbie
Newbie
Posts: 28
Joined: Fri Jul 19, 2024 12:00 am

Re: scales and axes

Post by Fenichel » Fri Sep 13, 2024 9:23 pm

Oops. I seem to have sent this twice. Delete whichever version you choose.

Here is another related issue. Your new Distance parameter will allow the title of right-sided auxiliary axes to be moved to the right of those axes, but the ticks and labels of those new axes will still come out on the left. As my latest demo (at https://www.fenichel.net/programs/ScaleTest.zip) shows, that doesn't look right.
What might be good is a new tChartAxis.Side parameter, with values {Left, Right, Top, Bottom}. Then a new axis with Side=Right could automatically get its title, ticks, and labels all to the right of the axis, with the title's horizontal position still tunable with Distance.

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

Re: scales and axes

Post by Yeray » Mon Sep 16, 2024 6:28 am

Hello,

I believe I haven't correctly understood the initial issue.
This is what I see with your example:
axes_scales.png
axes_scales.png (32.72 KiB) Viewed 59991 times
So I don't see any axis at the right.

If you want an axis to be at the right side of the chart, you may want to set its OtherSide property to true. This way, the labels and title related to it will also change their side:
mstsc_dE7DnYtLv9.gif
mstsc_dE7DnYtLv9.gif (108.07 KiB) Viewed 59991 times
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

Fenichel
Newbie
Newbie
Posts: 28
Joined: Fri Jul 19, 2024 12:00 am

Re: scales and axes

Post by Fenichel » Mon Sep 16, 2024 6:45 am

I think you are not looking at the latest version of my demo. When I run it I seeImage

But you're right; I hadn't noticed the OtherSide parameter. Should it be mentioned in the Axis chapter of the tutorial?
Attachments
Screenshot 2024-09-15 233822.jpg
Screenshot 2024-09-15 233822.jpg (216.15 KiB) Viewed 59991 times

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

Re: scales and axes

Post by Yeray » Mon Sep 16, 2024 9:58 am

Hello,

Indeed I'm afraid I was looking at the wrong version of your project.
Adding a boolean property (ie OthSide) to your tScale and mapping it to the Axis OtherSice property seems to solve it for me here. Note I also had to modify your OuterPercent peorperty, which maps to PositionPercent:

Code: Select all

             sideRight: begin (* right *)
                          //...
                          OuterPercent       := -20;
                          //...
                          OthSide            := true;
                        end   (* right *);
axes_scales.png
axes_scales.png (28.5 KiB) Viewed 59906 times
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

Fenichel
Newbie
Newbie
Posts: 28
Joined: Fri Jul 19, 2024 12:00 am

Re: scales and axes

Post by Fenichel » Mon Sep 16, 2024 6:28 pm

The solution is even simpler than that. Once OtherSide is in play, no OthSide is needed. Since my tScale is a descendant of tChartAxis, I can just set

Code: Select all

              OtherSide        := TheParentAxis.OtherSide;
around the same time as I set

Code: Select all

              Horizontal       := TheParentAxis.Horizontal;

inside tScale's constructor.
My old ToggleGrid went through various hoops to move the RightAxis and any right-sided tScale around, but now it is straightforward. As you can see from the latest version of my demo (same location), all it needs now is Distance.

Thanks for your responsiveness. This level of user support is appreciated.

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

Re: scales and axes

Post by Yeray » Wed Sep 18, 2024 1:36 pm

Hello,

We've just implemented the new Distance property, closing the ticket #2740.

Since you own the sources, you can apply the main changes to your copy of the sources, at TeEngine.pas and rebuild&reinstall the sources with TeeRecompile.

Code: Select all

diff --git a/TeEngine.pas b/TeEngine.pas
index cffb80a4..64525987 100644
--- a/TeEngine.pas
+++ b/TeEngine.pas
@@ -435,17 +435,19 @@ type
 
   TAxisTitlePosition=(tpStart, tpCenter, tpEnd);
 
   TChartAxisTitle=class(TCustomTextShape)
   private
+    FDistance     : Integer;
     FPosition     : TAxisTitlePosition;
 
     IDefaultAngle : Integer;
 
     function GetCaption:String;
     Function IsAngleStored:Boolean;
     Procedure SetCaption(Const Value:String);
+    Procedure SetDistance(Const Value:Integer);
     Procedure SetPosition(Const Value:TAxisTitlePosition);
   public
     Constructor Create(const AOwner: TCustomTeePanel); override;
 
     Procedure Assign(Source:TPersistent); override;

@@ -453,10 +455,11 @@ type
     function Clicked(x,y:Integer):Boolean; overload;
     Function Clicked(const P:TPoint):Boolean; overload;
   published
     property Angle stored IsAngleStored nodefault;
     property Caption:String read GetCaption write SetCaption;
+    property Distance:Integer read FDistance write SetDistance default 0;
     property Font;
     property Position:TAxisTitlePosition read FPosition write SetPosition default tpCenter;
     property TextAlignment default taCenter;
     property Visible default True;
 
@@ -3508,10 +3511,11 @@ end;
 Procedure TChartAxisTitle.Assign(Source:TPersistent);
 Begin
   if Source is TChartAxisTitle then
   With TChartAxisTitle(Source) do
   Begin
+    Self.FDistance:=FDistance;
     Self.FPosition:=FPosition;
   end;
 
   inherited;
 end;
 
@@ -3549,10 +3553,19 @@ end;
 function TChartAxisTitle.Clicked(x,y:Integer):Boolean;
 begin
   result:=Visible and (Caption<>'') and ClickedShape(TeePoint(x,y),ShapeBounds);
 end;
 
+Procedure TChartAxisTitle.SetDistance(Const Value:Integer);
+begin
+  if FDistance<>Value then
+  begin
+    FDistance:=Value;
+    Repaint;
+  end;
+end;
+
 { TChartAxisPen }
 
 Constructor TChartAxisPen.Create(const OnChangeEvent:TNotifyEvent);
 Begin
   inherited;
   
@@ -7802,10 +7815,11 @@ Procedure TChartAxis.CalcRect(var R:TRect; InflateChartRectangle:Boolean);
 var tmp : Integer;
     t   : Integer;
     tmpMargin : Integer;
     tmpTitleSize : Integer;
     tmpHasTitle : Boolean;
+    tmpDistance : Integer;
 begin
   // If this axis has any child subaxes, process them first:
 
   if Assigned(FSubAxes) then
   for t:=0 to FSubAxes.Count-1 do
   
@@ -7829,11 +7843,28 @@ begin
     if tmpHasTitle then
     begin
       with FAxisTitle do
            tmpTitleSize:=InternalCalcSize(FAxisTitle,Angle,Caption,FTitleSize);
 
-      FPosTitle:=CalcLabelsRect(tmpTitleSize);
+      tmpDistance:=0;
+      if FAxisTitle.Distance<>0 then
+      begin
+        if Horizontal then
+          if OtherSide then
+             tmpDistance:=-FAxisTitle.Distance
+          else
+             tmpDistance:=FAxisTitle.Distance
+        else
+          if OtherSide then
+             tmpDistance:=FAxisTitle.Distance
+          else
+             tmpDistance:=-FAxisTitle.Distance;
+
+        InflateAxisRect(R,FAxisTitle.Distance);
+      end;
+
+      FPosTitle:=CalcLabelsRect(tmpTitleSize)+tmpDistance;
     end;
 
     if FLabels.Visible then
     begin
       // Reset to zero, to force recalculation at SizeLabels
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

Fenichel
Newbie
Newbie
Posts: 28
Joined: Fri Jul 19, 2024 12:00 am

Re: scales and axes

Post by Fenichel » Thu Sep 19, 2024 8:25 pm

Are there instructions somewhere for TeeRecompile? I tried to run it naively, and I got various errors. I can post the error messages here, but maybe pointing me to some instructions would take less of your time.

Fenichel
Newbie
Newbie
Posts: 28
Joined: Fri Jul 19, 2024 12:00 am

Re: scales and axes

Post by Fenichel » Thu Sep 19, 2024 8:43 pm

Here is a screenshot of errors from TeeRecompile:
Image
Attachments
TeeRecompile failure.jpg
TeeRecompile failure.jpg (199.43 KiB) Viewed 59245 times

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

Re: scales and axes

Post by Yeray » Fri Sep 20, 2024 7:09 am

Hello,

According to the error message (Tee97.dpk), you seem to be compiling TeeChart Standard v2024.40 for Delphi 7.
I've just tried it here and worked fine:
TeeRecompile_TeeChartStd_2024.40_D7.png
TeeRecompile_TeeChartStd_2024.40_D7.png (42.54 KiB) Viewed 59057 times

Have you modified those sources to add the new Distance property? Make sure the changes are correct.
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

Fenichel
Newbie
Newbie
Posts: 28
Joined: Fri Jul 19, 2024 12:00 am

Re: scales and axes

Post by Fenichel » Fri Sep 20, 2024 4:51 pm

I can't tell what the problem is.
  • I can successfully run TeeRecompile with TeEngine.pas unmodified.
  • As carefully as I could, I re-edited TeEngine.pas to incorporate the changes you list in your post, and I get the same error messages.
  • That Repaint is undeclared is especially weird, since that is such a core Controls method.
  • Could I be checking the wrong boxes when I run TeeRecompile? Before I click Begin it looks likeImage
Could you put a copy of the correctly-edited TeEngine.pas somewhere for me to download?
Incidentally, in TChartAxis.CalcRect,

Code: Select all

              if Horizontal then
                if OtherSide then
                   tmpDistance:=-FAxisTitle.Distance   // H+O+
                else
                   tmpDistance:=FAxisTitle.Distance    // H+O-
              else
                if OtherSide then
                   tmpDistance:=FAxisTitle.Distance   // H-O+
                else
                   tmpDistance:=-FAxisTitle.Distance;  // H-O-

could be simplified to

Code: Select all

if OtherSide = Horizontal then
  tmpDistance := -FAxisTitle.Distance
else
  tmpDistance := FAxisTitle.Distance
Attachments
TeeRecompile config.jpg
TeeRecompile config.jpg (127.99 KiB) Viewed 58935 times

Fenichel
Newbie
Newbie
Posts: 28
Joined: Fri Jul 19, 2024 12:00 am

Re: scales and axes

Post by Fenichel » Sat Sep 21, 2024 8:00 pm

TeeRecompile now works for me. I must have been making some stupid transcription error in editing TeEngine.pas.

Distance works imperfectly for me.
  • It does fine with LeftAxis and RightAxis.
  • I haven't tried it on the top or bottom axes.
  • It seems to be ignored by auxiliary axes (my tScales).
As usual, my demo code is on my Web site at https://www.fenichel.net/programs/ScaleTest.zip.

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

Re: scales and axes

Post by Yeray » Mon Sep 23, 2024 9:23 am

Hello,

Manually created axes do have their ResizeChart property set to false by default.
However, setting it to true will cause other side effects.
I'll investigate if there's anything else we can do.
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

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

Re: scales and axes

Post by Yeray » Mon Sep 23, 2024 9:29 am

By the way,
Fenichel wrote:
Fri Sep 20, 2024 4:51 pm
could be simplified to

Code: Select all

if OtherSide = Horizontal then
  tmpDistance := -FAxisTitle.Distance
else
  tmpDistance := FAxisTitle.Distance
I've just simplified that to:

Code: Select all

        tmpDistance:=InflateAxisPos(0,FAxisTitle.Distance);
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

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

Re: scales and axes

Post by Yeray » Mon Sep 23, 2024 10:51 am

Hello,
Yeray wrote:
Mon Sep 23, 2024 9:23 am
Manually created axes do have their ResizeChart property set to false by default.
However, setting it to true will cause other side effects.
I'll investigate if there's anything else we can do.
After setting ResizeChart property to true for a custom axis, you can play with the Texts.MarginToAxis as well as the already mentioned Title.Distance and PostionPercent properties to adjust them as you wish:
mstsc_PjpJJ9G8ns.gif
mstsc_PjpJJ9G8ns.gif (427.1 KiB) Viewed 57233 times
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