Recent

Author Topic: Anchor question  (Read 1357 times)

AL

  • Sr. Member
  • ****
  • Posts: 261
Anchor question
« on: April 06, 2020, 06:34:26 pm »
If I have a chart on a form, anchoring all sides to the form will make the chart expand as I expand the form. That is simple.

If I have 2 charts or even better 3 charts stacked vertically on a form.  How do I set the anchors so that when I expand the form, all charts expand proportionnally.
For the x axis this is simple, anchor both sides of the charts to the form sides.
But for the height ( Y axis) I have been playing with all kinds fo combinations for the last hours and cannot find one that does what I want.
Is this possible?
Thanks
Laz 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: Anchor question
« Reply #1 on: April 06, 2020, 06:52:48 pm »
Will the stacked charts have the same size?

AL

  • Sr. Member
  • ****
  • Posts: 261
Re: Anchor question
« Reply #2 on: April 06, 2020, 09:05:23 pm »
Yes same size
In fact I have 5 all together.
Laz 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: Anchor question
« Reply #3 on: April 06, 2020, 10:00:03 pm »
Then it's easy:
  • Put the charts into a panel (or a form, but all the space will be covered by the charts in this solution)
  • Important: Do not anchor the charts. Every chart must have Anchors = [alLeft, alTop], no AnchorSides set
  • Go to the panel's ChildSizing
  • Set Panel.ChildSizing.ControlsPerLine = 1
  • Panel.ChildSizing.EnlargeHorizontal = crsScaleChilds
  • Panel.ChildSizing.EnlargeVertical = crsScaleChilds
  • Panel-ChildSizing.Layout = cclLeftToRightThenTopToBottom
  • Voila
This results in equally sized charts. Use the LeftRightSpacing/TopLeftSpacing properties to add an additional margin at the outer sides and VerticalSpacing between the charts.

I thought that there is a way also to scale the charts in proportion to their original size, but don't get it to work ATM...

AL

  • Sr. Member
  • ****
  • Posts: 261
Re: Anchor question
« Reply #4 on: April 06, 2020, 10:42:19 pm »
OK thank you.  I have not used panels until now, but I see it seems a good practice to put a panel in the form.

So there is no solution with anchors only. This makes me feel less dumb  :D
Laz 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Anchor question
« Reply #5 on: April 06, 2020, 11:33:09 pm »
Would the TFLowPanel be a good control for this ?
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: Anchor question
« Reply #6 on: April 07, 2020, 12:06:01 am »
Here is another solution in which you can freely change the size of the individual charts, even at runtime:
  • Add three charts to the form or a panel. Reduze their size for the moment to get access to the form/panel.
  • Add a splitter. Set its Align to alTop in order to get a horizontal orientation. The splitter must be freely floating - therefore you must remove the alTop Anchor and switch Align to alNone. When the container is resized the splitter changes both top and bottom distances to the container.
  • Select the splitter, copy it to the clipboard and paste it back into the panel/form. (Or repeat the previous step)
  • Now use the AnchorEditor to anchor the left and right sides of all charts to the left and right sides of the panel/form
  • Anchor the top side of the top chart to the top side of the panel/form, and its bottom side to the top side of the upper splitter.
  • Anchor top side of the center chart to the bottom side of the upper splitter, and its bottom side to the top side of the lower splitter
  • Anchor the top side of the bottom chart to the bottom side of the lower splitter, and its bottom side to bottom side of the panel/form
  • Now the charts are fully anchored - they cannot be dragged by the mouse any more. But you can drag the splitters.
  • At runtime all chart heights change in proportion to their original heights with the panel/form height.
  • Additionally you have the splitters to change the height of an individual chart.
Of course you can extend this to four, five, any number of charts.

AL

  • Sr. Member
  • ****
  • Posts: 261
Re: Anchor question
« Reply #7 on: April 08, 2020, 12:34:01 am »
2 good options.
I have implemented the panel option, works very well.  Thank you.

I have added a charttoolset.(One set for all charts)  When I use the distance tool the measure is displayed in the last chart I clicked in.  The distance tool is using right-click.
So if I measure a distance in the chart 1 it works Ok
Then I go to chart 2 and the distance is still displayed in chart 1.
If I click in the chart2 first before measuring then is measuring correctly.
I think it is more a problem of focus than a problem with the tool.
All charts have autofocus property set to true.
Any suggestions?
Laz 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: Anchor question
« Reply #8 on: April 08, 2020, 01:28:08 am »
Look at the source code of TBasicChartTool (unit TAGraph) which is the most fundamental chart tool:
Code: Pascal  [Select][+][-]
  1. type
  2.   TBasicChartTool = class(TIndexedComponent)
  3.   strict protected
  4.     FChart: TChart;
  5.      ...
  6.   public
  7.     property Chart: TChart read FChart;
  8.   end;
There is a property Chart which tells on which chart the tool operates. This is set when the ToolSet is assigned to the chart. For this reason a tool does not work with a second chart, and you cannot share the same toolset with two charts. Therefore, you simply copy the current toolset to the clipboard and paste it back into the form. Then make sure that the second chart uses the second toolset.

AL

  • Sr. Member
  • ****
  • Posts: 261
Re: Anchor question
« Reply #9 on: April 08, 2020, 02:07:41 am »
OK. but strangely, the zoom and pan tools from the toolset works in all charts.
No problem I will make one toolset per chart.
Thank you
Laz 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: Anchor question
« Reply #10 on: April 08, 2020, 03:17:37 pm »
OK. but strangely, the zoom and pan tools from the toolset works in all charts.
It is the same issue, with a bit different behaviour though. When I add ONE ZoomDragTool to a form with two charts and assign it to BOTH charts and drag the zoom rect in the chart which was assigned last then the zoom rect is drawn in the other chart but the zoom occurs in the same chart. Quite crazy!

Yes, without an extra zoomdrag tool the behavior is correct because every chart has a built-in toolset with zoomdrag and pandrag tools. so, we have the situation like when you added two separate toolsets.

 

TinyPortal © 2005-2018