scales and axes

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Fenichel
Newbie
Newbie
Posts: 15
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: 15
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: 9587
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 727 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 727 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: 15
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 727 times

Yeray
Site Admin
Site Admin
Posts: 9587
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 642 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: 15
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: 9587
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

Post Reply