Recent

Author Topic: [SOLVED] An issue with autosizing margins  (Read 3118 times)

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
[SOLVED] An issue with autosizing margins
« on: April 01, 2021, 02:14:17 pm »
There is some issue with the margins of TAChart, as it can be seen from this image https://wiki.lazarus.freepascal.org/images/8/80/TAChart_Margins.png, which is taken from https://wiki.lazarus.freepascal.org/TAChart_documentation#Extents_and_margins.

The size labelled as 7 is auto-sized. Maybe someday this could be made sizeable by the user/developer? If yes- should I create an entry in the bugtracker?
« Last Edit: April 13, 2021, 01:28:42 pm by CM630 »
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: An issue with autosizing margins
« Reply #1 on: April 01, 2021, 02:24:10 pm »
I do not see a real advantage in completely turning off autosizing because it puts all the burden of adjustments due to font size changes, wrapped axis title, html formatted axis title, rotated font of axis, adjustments needed when changing platforms and themes etc, on to the programmer who will have to repeat a lot of already existing code. What exactly do you have in mind that you want to achieve with this request?

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: An issue with autosizing margins
« Reply #2 on: April 01, 2021, 03:15:38 pm »
When several charts are placed over each other (vertically), if they have a variable number of lines in the Labels, they get misaligned - the plot area has different sizes, positions, values on the X axis, which hinders reading the data. IMHO, it is ugly, too. I have added an image to illustrate the issue.
Currently, I cycle all the charts, count the number of CrLf in their labels, and add CrLfs to the shorter lines. But the ability to set the size of all the margins will make life easier.



Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: An issue with autosizing margins
« Reply #3 on: April 01, 2021, 04:58:30 pm »
This should be possible with the TChartExtentLink using the AlignSides property. But as I can see now it does not respect the size of the axis title. Let me have a look...

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: An issue with autosizing margins
« Reply #4 on: April 02, 2021, 01:30:38 pm »
Also, I do not know if it related: I need to detect if it is clicked over the plot area itself, to make sure that it is not clicked on the margins.
Shall I know the size of the margins for that, or there is another way?
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: An issue with autosizing margins
« Reply #5 on: April 02, 2021, 01:44:38 pm »
Also, I do not know if it related: I need to detect if it is clicked over the plot area itself, to make sure that it is not clicked on the margins.
Just to make sure: "Plot area" is the rectangle spanned by the axes? What do you mean with "margins"? The axis lines and the axis frame?

Probably only losely related: There are new click tools in trunk: Axis click tool, header/footer click, legend click tool; they give you a HintInfo parameter which tells you which part of the axis, title etc has been clicked; they are applied in the charteditordemo in the demo folder of the TAChart installation.can't find it ATM...).

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: An issue with autosizing margins
« Reply #6 on: April 02, 2021, 04:49:15 pm »
Just to make sure: "Plot area" is the rectangle spanned by the axes? ...

I have shown it in the attached image. Maybe this area has an official name, which I do not know?

[/size]
...Probably only losely related: There are new click tools in trunk: Axis click tool, header/footer click, legend click tool; they give you a HintInfo parameter which tells you which part of the axis, title etc has been clicked; they are applied in the charteditordemo in the demo folder of the TAChart installation.can't find it ATM...).
I saw the Axis click tool, header/footer click, legend click tool etc. in Wikipedia today, before posting my previous comment, I think they will help me to improve a part of my code.
But I need to detect that the click is within the Plot Area.




Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: An issue with autosizing margins
« Reply #7 on: April 02, 2021, 05:28:04 pm »
Catching mouse events in TAChart is a bit unusual because the ChartTools will catch them before the standard OnMouse* events will see them.

The easiest way is to stay within the chart tools infrastructure. For your purpose you can add a TUserDefinedTool to the toolset, assign the left mouse key to it (Shift = [ssLeft]) and write a handler to the OnAfterMouseUp event of the tool which suites your needs, e.g.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.ChartToolset1UserDefinedTool1AfterMouseUp(ATool: TChartTool;
  2.   APoint: TPoint);
  3. var
  4.   R: TRect;
  5. begin
  6.   R := Chart1.ClipRect;
  7.   if (APoint.X > R.Left) and (APoint.X < R.Right) and (APoint.Y > R.Top) and (APoint.Y < R.Bottom) then
  8.      // or: if (PtInRect(ATool.Chart.ClipRect, APoint) then   // to accept also the borders
  9.     Caption := 'inside'
  10.   else
  11.     Caption := 'outside';
  12. end;  

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: An issue with autosizing margins
« Reply #8 on: April 02, 2021, 07:31:13 pm »
Thanks, so the plot area is named „ClipRect“, it seems to work perfectly.  :D

Hopefully,  the initial issue is solvable, too.



« Last Edit: April 03, 2021, 05:27:06 pm by CM630 »
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: An issue with autosizing margins
« Reply #9 on: April 03, 2021, 10:57:18 pm »
Hopefully,  the initial issue is solvable, too.
Please checkout the new revision - see also attached demo and screenshot:
  • Add a TChartExtentLink to the form
  • Using the LinkedCharts property define the charts which will be linked
  • Specify the sides of the charts meant to be at the same position in the AlignSides property.
  • Turn off Enabled if you don't want to link the axis labels of the charts
The current implementation is not perfect, it has some drawbacks which I should mention for completeness:
  • The chart sides are linked by adjusting the LabelSize property of the axes related. This means that manually provided LabelSize values will be lost, and in particular, the sides will not return to their old positions when the AlignSides property is cleared.
  • Normally there are no axes for the right and top sides of charts. And since there is no LabelSize property then, these sides will not align. As this is normally not desired I added a property AlignMissingAxes which automatically creates dummy right and top axes and formatted them to be invisible. But you must know that they exist, and they also are not removed when AlignMissingAxes is set to false later, or when the AlignSides set is cleared again.

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: An issue with autosizing margins
« Reply #10 on: April 06, 2021, 01:11:49 pm »
Thanks, I have forgotten how to build Lazarus from the SVN source (I am returning to a project abandoned for 4 or 5years). I have downloaded the entire Lazarus from SVN, then I replaced the TAchart only and rebuilt... still the old TAchart. It occurs that it will take me some longer to check and feedback.

This makes me worried, LabelSize was dedicated for the area of the values of the axises (scales), now it seems to be used for something else
Quote
The chart sides are linked by adjusting the LabelSize property of the axes related
, but I will check how it behaves first.
« Last Edit: April 06, 2021, 02:21:11 pm by CM630 »
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: An issue with autosizing margins
« Reply #11 on: April 06, 2021, 03:10:03 pm »
This makes me worried, LabelSize was dedicated for the area of the values of the axises (scales), now it seems to be used for something else
Just the same only that LabelSize is determined automatically

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: An issue with autosizing margins
« Reply #12 on: April 13, 2021, 01:28:30 pm »

Thanks, I succeeded to try it. It seems to work so far.

The current implementation is not perfect, it has some drawbacks which I should mention for completeness:

...and in particular, the sides will not return to their old positions when the AlignSides property is cleared.

This is not a drawback for me, because I will be able to spare for example 3 lines, align once and then disable the alignment.
This way some overlapping will occur, which is fine.
The little downside is that I will have to take care to realign when the .LeftAxis.Title.Caption is changed and to remove the remaining lines if they are more than 3 (for example).

The greater downside is that the excessive lines (more than 3) will have to be removed, instead of overlapping the plot area.
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

 

TinyPortal © 2005-2018