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 » Mon Sep 23, 2024 7:07 pm

I don't understand the sequence that uses an axis's PositionPercent, Texts.MarginToAxis, and Title.Distance to determine the displayed positions of the axis, its ticks & labels, and its title. I had expected the sequence to be
  • fix the axis using PositionPercent,
  • fix the ticks & labels by using MarginToAxis,
  • fix the title by using Distance
, but that is not correct. For example, I can get the axis, ticks, and labels just where I want them, with the only remaining issue being that the title is a little too far away. If I now decrease Distance, the title doesn't move, but the ticks and labels move out to be near the title. It seems that the master object here is the title, not the axis.
Can a user program obtain the position (in pixels or in muPercent units) of an axis title? If that were possible, then a reasonable (but ugly) strategy might be to
  • set MarginToAxis to taste
  • set Distance and PositionPercent to 0,
  • see where that left the title,
  • set Distance to pull the ticks & labels into position, and finally
  • reset PositionPercent (or MarginToAxis?) to get the axis close to the ticks & labels.
At least some of these maneuvers would presumably need to be redone whenever the chart is resized. Ugh.

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 25, 2024 10:41 am

Hello,
Fenichel wrote:
Mon Sep 23, 2024 7:07 pm
If I now decrease Distance, the title doesn't move, but the ticks and labels move out to be near the title. It seems that the master object here is the title, not the axis.
Yes that's the effect of the "axis rect inflation" (call to InflateAxisRect). We decided the new Distance property should "inflate" the axis rect to accommodate the rest of the elements when ResizeChart property is true as we already do with the Texts.MarginToAxis property.
Fenichel wrote:
Mon Sep 23, 2024 7:07 pm
Can a user program obtain the position (in pixels or in muPercent units) of an axis title? If that were possible, then a reasonable (but ugly) strategy might be to
  • set MarginToAxis to taste
  • set Distance and PositionPercent to 0,
  • see where that left the title,
  • set Distance to pull the ticks & labels into position, and finally
  • reset PositionPercent (or MarginToAxis?) to get the axis close to the ticks & labels.
At least some of these maneuvers would presumably need to be redone whenever the chart is resized. Ugh.
Maybe we need to make both properties to also work when ResizeChart is false to give more options.
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 » Wed Sep 25, 2024 5:25 pm

I have to think more about this, but I think I'm going to end up
  • not using Distance, and
  • returning to my strategy of having two axes wherever there used to be one, with one carrying the title and the other carrying the axis proper, ticks, and labels.
That strategy uses a lot of apparatus, but then resizing is brainless, since all of the important dimensions are in muPercent units, not pixels.

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 » Thu Sep 26, 2024 7:22 am

Hello,
Yeray wrote:
Wed Sep 25, 2024 10:41 am
Maybe we need to make both properties to also work when ResizeChart is false to give more options.
We've done some extra changes so the Axis Labels and Title are moved according to the Texts.MarginToAxis and Title.Distance properties when the Axis has ResizeChart property set to false.

Code: Select all

---
 TeEngine.pas | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/TeEngine.pas b/TeEngine.pas
index 395ac92b..94dcbbe6 100644
--- a/TeEngine.pas
+++ b/TeEngine.pas
@@ -7827,6 +7827,9 @@ begin
 
   IAxisDateTime:=IsDateTime;
 
+  // Calculate labels position applying a % margin from axis
+  tmpMargin:=Round(ParentChart.Canvas.FontHeight*FLabels.FMargin*0.01);
+
   if InflateChartRectangle then
   begin
     // See TeeTools TAxisScrollBar
@@ -7872,8 +7875,6 @@ begin
       if Assigned(CalcPosLabels) then
          tmp:=CalcPosLabels(Self,tmp);
 
-      // Calculate labels position applying a % margin from axis
-      tmpMargin:=Round(ParentChart.Canvas.FontHeight*FLabels.FMargin*0.01);
       FPosLabels:=InflateAxisPos(CalcLabelsRect(tmp),tmpMargin);
     end;
 
@@ -7887,8 +7888,8 @@ begin
   else
   begin
     FPosAxis:=ApplyPosition(GetRectangleEdge(R),R);
-    FPosLabels:=InflateAxisPos(FPosAxis,SizeTickAxis);
-    FPosTitle:=InflateAxisPos(FPosLabels,SizeLabels);
+    FPosLabels:=InflateAxisPos(FPosAxis,SizeTickAxis+tmpMargin);
+    FPosTitle:=InflateAxisPos(FPosAxis,SizeTickAxis+SizeLabels+Title.Distance);
   end;
 end;
So, with these changes, you can set ResizeChart property to false and you'll see how Texts.MarginToAxis and Title.Distance properties modify Labels and Title positions without resizing the chart:
mstsc_Ekf0nzLeRu.gif
mstsc_Ekf0nzLeRu.gif (368.29 KiB) Viewed 35621 times
Note that, when ResizeChart property is set to true, Texts.MarginToAxis moves the Labels, and PositionPercent moves the Axis, but they don't resize the chart. I think we should improve that.
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 » Thu Sep 26, 2024 8:28 am

Hello,
Yeray wrote:
Thu Sep 26, 2024 7:22 am
Note that, when ResizeChart property is set to true, Texts.MarginToAxis moves the Labels, and PositionPercent moves the Axis, but they don't resize the chart. I think we should improve that.
Improved with this change:

Code: Select all

---
 TeEngine.pas | 1 +
 1 file changed, 1 insertion(+)

diff --git a/TeEngine.pas b/TeEngine.pas
index 94dcbbe6..c5ccf6e6 100644
--- a/TeEngine.pas
+++ b/TeEngine.pas
@@ -7875,6 +7875,7 @@ begin
       if Assigned(CalcPosLabels) then
          tmp:=CalcPosLabels(Self,tmp);
 
+      InflateAxisRect(R,tmpMargin);
       FPosLabels:=InflateAxisPos(CalcLabelsRect(tmp),tmpMargin);
     end;
 
-- 
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 26, 2024 8:48 pm

Those are good changes. Looking at the latest version of my demo (on my site in the usual place), everything works well. There is a mildly irritating left-right asymmetry of spacing (Is Distance always counting from the same side of the labels column, instead of an OtherSide-dependent side?), but it doesn't matter. I now realize that my graphs will want to fiddle with Distance in data-dependent ways, to keep the titles and labels of high precision from colliding.

Thanks again for all your support.

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 30, 2024 8:29 am

Hello,
Fenichel wrote:
Thu Sep 26, 2024 8:48 pm
There is a mildly irritating left-right asymmetry of spacing (Is Distance always counting from the same side of the labels column, instead of an OtherSide-dependent side?),
When Title.Distance is 0 we place the Title where it was before adding this new property to prevent breaking old charts. This is at the left of the labels for the Left axis (Horizontal=false and OtherSide=false), at the right of the Right axis (Horizontal=false and OtherSide=true), at the bottom of the labels for the Bottom axis (Horizontal=true and OtherSide=false) or at the top of the Top axis (Horizontal=true and OtherSide=true)
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 » Wed Oct 02, 2024 9:51 pm

Thanks for your clarification.

I've taken this development as far as I want to for now. My final demo code is at the usual place (https://www.fenichel.net/programs/ScaleTest.zip), and I'll leave it there for anyone who might want to see how to set up parallel scales to existing axes.

Post Reply