Recent

Author Topic: How to fix the size of the plot area?  (Read 34100 times)

CM630

  • Hero Member
  • *****
  • Posts: 1616
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
How to fix the size of the plot area?
« on: August 13, 2012, 10:43:23 am »
Here is the problem:
I use a chart with line series.
When I zoom vertically the number of the characters in the Y axis scale varies (i.e 10, 100, 1000).
As a result since the total width of the Chart stays the same the size of the plot area changes (it gets narrower when I have bigger Y values and wider, when the Y values are smaller).
I tried Margins, MarginsExternal and Margins of the LeftScale itself, etc.
In fact, I could not find the size of the plot area as separate property?

Maybe I could ask another question in the same thread- how am I to force the cart to write the values for the beginning and the end of the scales (for example, if the values between -1 and +1 are shown, I need to have -1 written in the beginning of the scale and 1 in the end.
« Last Edit: August 13, 2012, 10:48:08 am by paskal »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13353
Re: How to fix the size of the plot area?
« Reply #1 on: August 13, 2012, 12:01:03 pm »
Quote
I could not find the size of the plot area as separate property?
I'm not quite sure but I think there is none, you cannot fix the size of the plot area. But maybe we should wait until Ask is online.

Quote
how am I to force the chart to write the values for the beginning and the end of the scales
Chart.Extent allows to freeze axis scaling. If you want the y axis to go from -1 to +1 set Chart.Extent.YMin=-1, Chart.Extent.YMax=1, Chart.Extent.UseYMin and UseYMin = true.

CM630

  • Hero Member
  • *****
  • Posts: 1616
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: How to fix the size of the plot area?
« Reply #2 on: August 13, 2012, 12:16:13 pm »
Quote
how am I to force the chart to write the values for the beginning and the end of the scales
Chart.Extent allows to freeze axis scaling. If you want the y axis to go from -1 to +1 set Chart.Extent.YMin=-1, Chart.Extent.YMax=1, Chart.Extent.UseYMin and UseYMin = true.
That's not what I mean. For example I have a chart with X values between 0 and 12, but on the scale it is written 2;6 and 10. I need to know how to have the first visible value displayed on the chart (i.e. 0) and the last one (i.e. 12) to be shown.
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13353
Re: How to fix the size of the plot area?
« Reply #3 on: August 13, 2012, 12:31:46 pm »
To get the labels correct you should play around with the BottomAxis.Intervals properties. Have a look at the documentation (http://wiki.lazarus.freepascal.org/TAChart_documentation#Axis_intervals) for a description of what the properties mean.

Are the labels 2,6,12 the only labels that you see? Do you have a very small window? If the data are not too exotic and if you're not using weird transformations TChart normally does a nice job in label finding. If your data start at 0 the first label normally always is at 0. The last one may become 10 if the chart gets smaller, but you can correct that with the Intervals settings.

Or maybe your first x value is slightly larger than 0, say, 0.001. Then the zero is skipped and the next interval is labeled. You can get the zero by forcing the axis extent to begin at 0, by setting Chart.Extent.XMin = 0 and Chart.Extent.UseXMin = true.

If this still is not what you mean you should post a small project which demonstrates your question.
« Last Edit: August 13, 2012, 01:02:13 pm by wp »

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: How to fix the size of the plot area?
« Reply #4 on: August 13, 2012, 01:50:59 pm »
Quote
the size of the plot area as separate property
See http://wiki.lazarus.freepascal.org/TAChart_documentation#Extents
and the "extent" demo.
However, I feel I do not fully understand your request --
of "plot area change" is essentially a definition of zooming,
so why do you want to zoom without changing the area?

Quote
force the chart to write the values for the beginning and the end of the scales
If the scale is fixed (i.e. you allow no zooming or panning and your data has fixed range), you can manually set axis marks by using your own data source.
If the scale is dynamic, however, then the question becomes very complex:
what is the beginning and end of scales? Do you mean the bounds of the current chart extent? If so, they are very unlikely to be exactly +1 and -1.
You can try to set BottomAxis.Intervals.Options=[aipUseCount], which should
give what your want (first and last marks exactly at chart bounds, other marks equidistant between them). However, of course, the resulting labels will not be round unless you carefully select extent, margins and Intervals.Count.
Additionally, I have encountered a tricky corner case of rounding error during the mark value calculations -- this is the reason I answer so late. It is hopefully fixed in r38233. I wonder whether this problem is common enough to merit back-porting.


CM630

  • Hero Member
  • *****
  • Posts: 1616
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: How to fix the size of the plot area?
« Reply #5 on: August 13, 2012, 02:42:06 pm »
A have attached two screenshots, I think they will make everything clear.
On the first one there is nothing on the oscillogram, so you can see that they are exactly the same.
On the second one there two processes- one with amplitude ±10 and the second one- with ±1000.
As you can see, the plot area (the white field) on the lower one is narrower, I think I do not have to explain the negative aspects of that behaviour. Increasing Marginsexternal.Left makes enough space for the scale marks, but still the plot area is decreased when the number is bigger.
Also, you can see, that on the ±10 chart the displayed values are ±8., it would be much better if the highest values were show, but anyway this is not such a big problem as the first one.
« Last Edit: August 13, 2012, 03:27:41 pm by paskal »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13353
Re: How to fix the size of the plot area?
« Reply #6 on: August 13, 2012, 03:41:56 pm »
You could force the labels to the same widths and pad with spaces. This can be easily done by changing LeftAxis.Marks.Format in both charts to something like "%n.9g" where n is the number of characters of your longest label (the "9" is the maximum number of decimal places displayed, but is normally not used to its limits with reasonably selected labels). To be exact you should select a monospaced font, like Courier, for the Marks.LabelFont, but my Lazarus crashes when I do this...

Of course, you must be aware that same empty space will appear between labels and axis title if you have short labels.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: How to fix the size of the plot area?
« Reply #7 on: August 13, 2012, 03:45:32 pm »
Quote
As you can see, the plot area (the white field) on the lower one is narrower
Ah, yes, now I understand.

Quote
I think I do not have to explain the negative aspects of that behaviour.
Actually, please explain -- TAChart makes a serious effort to calculate axis sizes automatically, and I did not yet encounter any case where it is not desirable.

I can implement some kind of manual override of the axis labels' size,
but I need a good reason and design for that.

Meanwhile, you can use fixed-size font and format to make your labels identical in size. Alternatively, rotate Y labels 90 degrees counterclockwise and set Marks.Clipped = true.

Quote
on the ±10 chart the displayed values are ±8., it would be much better if the highest values were show
This looks very much like the problem I just fixed -- try r38233.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12645
  • FPC developer.
Re: How to fix the size of the plot area?
« Reply #8 on: August 13, 2012, 03:56:49 pm »
Quote
As you can see, the plot area (the white field) on the lower one is narrower
Ah, yes, now I understand.

Quote
I think I do not have to explain the negative aspects of that behaviour.
Actually, please explain -- TAChart makes a serious effort to calculate axis sizes automatically, and I did not yet encounter any case where it is not desirable.

I can imagine this very well:-)   The reason is if both charts depict the same events but with different units or timelines.  Different units can have slightly wider labels, but the X coordinates have meaning and should align.

Think of action and result diagrams, signal transformation etc.
« Last Edit: August 13, 2012, 04:07:37 pm by marcov »

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: How to fix the size of the plot area?
« Reply #9 on: August 13, 2012, 04:28:44 pm »
you should select a monospaced font, like Courier, for the Marks.LabelFont, but my Lazarus crashes when I do this...
Should be fixed in r38234. Note that you might have to fully recompile TAChart to see the effect
(for example, by clearing "lib" directory). This is because FPC sometimes misses unit dependencies when generics are involved.

The reason is if both charts depict the same events but with different units or timelines.  Different units can have slightly wider labels, but the X coordinates have meaning and should align.
Think of action and result diagrams, signal transformation etc.
To display such such charts, TAChart supports multiple axises, axis groups and axis transformations.
See http://wiki.lazarus.freepascal.org/TAChart_documentation#Coordinates_and_axises for docs,
"axis", "panes", "axistransf" demos and "Oscilloscope" page of the "line" demo for examples.

Perhaps an additional feature to TChartExtentLink allowing to synchronize not only extents, but also drawing areas,
may be useful. However, it will by quite tricky to implement.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12645
  • FPC developer.
Re: How to fix the size of the plot area?
« Reply #10 on: August 13, 2012, 05:53:27 pm »
To display such such charts, TAChart supports multiple axises, axis groups and axis transformations.

Signal and response diagrams are generally plotted in different diagrams in literature.

wp

  • Hero Member
  • *****
  • Posts: 13353
Re: How to fix the size of the plot area?
« Reply #11 on: August 13, 2012, 10:27:57 pm »
Code: [Select]
[quote]
Should be fixed in r38234
@Ask: Yes, I can change the font now - thank you.

CM630

  • Hero Member
  • *****
  • Posts: 1616
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: How to fix the size of the plot area?
« Reply #12 on: August 14, 2012, 07:24:57 am »
Quote
I think I do not have to explain the negative aspects of that behaviour.
Actually, please explain -- TAChart makes a serious effort to calculate axis sizes automatically, and I did not yet encounter any case where it is not desirable.[/quote]
You have to trust me- I raised two threads about TAChart and you have two bugs down (the second one due to WP) ;)
Marcov explained it quite well, but as you said:

To display such such charts, TAChart supports multiple axises, axis groups and axis transformations.
If I understand you properly, you mean to put all the items on a single chart?
I have attached an example- just imagine how these would like on a single chart with eight scales.
All these curves show processes that go simultaneously and you have to determine when each one starts and ends, compared with the others.
I'll give you another real life example- you have an oscillogram on which a process starts on the 35ms and end on 47ms, which is easy to determine, since you have a thick on every millisecond. On another oscillogram there is a process, that starts on 32ms and ends on 44ms. How do people determine if both processes have the same duration? They print them on two separate pages, put the sheets one over another and watch them agaionst the light on a window pane. Don't laugh, that's life.

I will try WP's solution when builds of r38234 are available for download - I have been using it with another development environment, but in it things kept messing, hopefully here it won't be this way.
« Last Edit: August 14, 2012, 08:21:12 am by paskal »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13353
Re: How to fix the size of the plot area?
« Reply #13 on: August 14, 2012, 09:04:19 am »
@Ask: What about a third "Margins" property, like "MarginToPlot", which fixes the distances between chart border and plot rect? By default, it should be (-1,-1,-1,-1) saying that every distance is floating. If the user wants a specific margin it would be in his responsibility to select an appropriate value that does not truncate labels, overwrites the axis title, or truncates other axes.

@paskal: Maybe I am too sensible, but I hear some kind of arrogance in your posting. You are not working with TeeChart which is a commercial product, but with software that is written and maintained volontarily by people in their spare time.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: How to fix the size of the plot area?
« Reply #14 on: August 14, 2012, 10:20:04 am »
Quote
I have attached an example- just imagine how these would like on a single chart with eight scales.
I think these would like exactly the same -- try it :)

Quote
You have to trust me- I raised two threads about TAChart and you have two bugs down
Yes, thanks for your reports. I do trust you about the results you want,
however, you should trust me about the method to get them.

@Ask: What about a third "Margins" property, like "MarginToPlot", which fixes the distances between chart border and plot rect?
This is one method. I was thinking about "FixedSize" property of axis.
Your way is probably better because it can override things like first/last mark and arrow margins from orthogonal axises.
As I said, IMO the best option would be to leave margins dynamic,
but synchronize them automatically between linked charts.
But this option is also hardest to implement.

@paskal: What do you think?

 

TinyPortal © 2005-2018