Recent

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

CM630

  • Hero Member
  • *****
  • Posts: 1579
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: How to fix the size of the plot area?
« Reply #15 on: August 14, 2012, 10:29:12 am »
@wp, that's it, you are too sensitive, I have no idea why you got such an impression.
I  do not expect anyone to make any improvements, but I am very happy that they do.
Indeed, I am impressed by the possibilities that Lazarus have and the progress that it have made in comparison with the previous release.
In fact, that is the problem with commercial products- they might fix something, but you have to pay for the next release, being in the position, that you have already paid for something that you cannot use.
Here it is simple- if you do not like something, and there is no one to do it- then you can try fixing it yourself. Well, half a year ago I had no idea how to declare vars in Pascal, so my time for that have not come yet. Still, I think that finding and which is more important- reporting bugs is a help.
So, let's go to the point- I like your idea for Margins to plot, still I am not sure if having PlotHeight ; PlotWidth; PlotTop and PlotLeft are not more standard solutions?
I do not understand why MarginsExternal calculates the distance between the scale values, instead from the plot, but anyway I do not ask, because I do not care, and there is a good reason why- changing it now will cause backward compatibility problems.

@paskal: What do you think?
First I'll spend some time trying
I think these would like exactly the same -- try it :)
Then I'll think. As we say- I sat thinking, I sat things until I finally realized, that I was only sitting.
You have posted, while I was writing this post, so there is something above.
But I am quite confident about one thing- it is the user of the TAChart, who shall take care to have enough space for writing the scales values.

BTW, maybe somethink like the attached image could be useful for the wiki.
« Last Edit: August 14, 2012, 11:00:10 am by paskal »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13328
Re: How to fix the size of the plot area?
« Reply #16 on: August 14, 2012, 11:21:33 am »
Now that it is possible to modify the label font I tried my idea with the Marks.Format specifier a few postings above. Here is a screen shot. I used LeftAxis.Marks.Format = '%6.9g'. The Courier labels do look a bit outdated, though. The only requirement is that the x axis has the same labels in all charts.

Quote
when builds of r38234 are available for download
It seems that snapshots have not been updated for a long time. You have to use svn or download the source.zip snapshot which is at r38235 today, and compile Lazarus. If you never did that before there is an item in the "Tools" menu. As Ask mentioned above delete the tachart\lib folder before you do that.

CM630

  • Hero Member
  • *****
  • Posts: 1579
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: How to fix the size of the plot area?
« Reply #17 on: August 14, 2012, 01:49:51 pm »
Screenshots look perfect. There is also a little trick- the namings (so far I could not find where you wrote y axis and what is the exact name of this element)  of the left axis of all the charts must have the same line length, because if you have
Quote
Phase A
on one of the charts and
Quote
Phase
B
on the other, the plot areas will probably get different widths, again. Maybe that is what you meant by „The only requirement is that the x axis has the same labels in all charts.“?
Probably this week I won't have more time for that, so meanwhile there shall be new snapshots.

I noticed something else: the Y values of your first chart are between 0 and 1, but you do not have a 0 value written on the left axis. It is the same case with the Y scales of the other 2 charts. I would not pay attention, but ask said:
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.
Probably Ask meant something else?
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13328
Re: How to fix the size of the plot area?
« Reply #18 on: August 14, 2012, 02:34:57 pm »
Quote
I could not find where you wrote y axis and what is the exact name of this element
This is the title of the left axis (Chart1.LeftAxis.Title.Caption := 'y axis') - maybe you should have a look at my recent tutorial on getting started (http://wiki.lazarus.freepascal.org/TAChart_tutorial:_Getting_started).

Quote
Quote
    Phase A
on one of the charts and
Quote
    Phase
    B
on the other,
I thinks that's not possible, the axis title can only be single-lined in TAChart.

Quote
the Y values of your first chart are between 0 and 1, but you do not have a 0 value written on the left axis
I am beginning to see what you mean: you have varying data, sometimes all greater than 0, sometimes some negative, and you always want to see the 0 at the axis. I think you will have to do some progamming to achieve this effect. You could try to call the following procedure whenever the data range changes:

Code: [Select]
procedure DisplayAxisZero(Chart:TChart);
var
  ex: TDoubleRect;
begin
  ex := Chart.GetFullExtent;
  Chart.Extent.UseYMin := ex.a.y > 0;
end;

GetFullExtent returns the range in which the data vary; the point a is the left-bottom corner, b the top-right corner of the chart, i.e. a.y is the lowest y value. If that is > 0 then Chart.Extent.UseYMin is turned on, this will show the 0. If the y minimum < 0 UseYMin is turned off because the 0 is already shown and the negative values would be truncated. The condition that all y values are negative is not handled - I am leaving it for you as an exercise... You should also consider the case of zooming if your application allows that. The Extent is documented here: http://wiki.lazarus.freepascal.org/TAChart_documentation#Extents

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: How to fix the size of the plot area?
« Reply #19 on: August 14, 2012, 03:19:20 pm »
Quote from: wp
axis title can only be single-lined in TAChart.
Not so, see http://wiki.lazarus.freepascal.org/TAChart_documentation#Multi-line_marks and "Multiline" page of the "labels" demo.

Quote from: paskal
Probably Ask meant something else?
There is some subtlety here: when TAChart decides which marks to display,
it takes into account the actual range of data values.
There may be two reasons for the "boundary" marks to be invisible -- either they are outside of the clipping range, in which case it is as expected,
or they are *exactly" on the edge, which is the case I fixed.
The latter case is rare and is most easily triggered by the workaround I suggested in the previous posts.

Quote from: wp
you have varying data, sometimes all greater than 0, sometimes some negative, and you always want to see the 0 at the axis. I think you will have to do some programming to achieve this effect
Hm, I was under the impression that the ranges are actually known beforehand,
and can thus be simply pre-set. If the problem is indeed as you describe, then I can propose a couple of tricks:
1) If the actual ranges are always close to the desired ones, simply increase
  Chart.ExpandPercentage property
2) Otherwise, add a point with X=NaN, Y=0 to the source of each series.

wp

  • Hero Member
  • *****
  • Posts: 13328
Re: How to fix the size of the plot area?
« Reply #20 on: August 14, 2012, 03:31:26 pm »
Quote
Not so, see http://wiki.lazarus.freepascal.org/TAChart_documentation#Multi-line_marks and "Multiline" page of the "labels" demo.
Ah - never stop learning... My sentence was motivated by the fact that the Axis.Text.Caption does not have the same property editor as the Chart.Title.Text.

Quote
add a point with X=NaN, Y=0 to the source of each series.
That's nice!

CM630

  • Hero Member
  • *****
  • Posts: 1579
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: How to fix the size of the plot area?
« Reply #21 on: August 15, 2012, 07:02:15 am »
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?
If I understand you correctly, you mean, that there might be for example 5 separate charts, and that they might have a common property, which will set the size of each of them simultaneously?
I think that will be both hard to implement and probably hard to use. If someone wants to make such a synchronization,  this one could probably do it by calculating the numbers of the digits in the longest axis values. In fact, for myself, if I have tens or hundreds of sets oscillograms, I would like all of them to look all the same (with the same plot area size).
I think that MarginToPlot is a good solution, with only one proposal- instead of using -1 values to disable, UseLeft/UseTo... etc could be used, like it is in the Extents. This will make it more consistent with the overall style of TACharts.

Quote
the Y values of your first chart are between 0 and 1, but you do not have a 0 value written on the left axis
I am beginning to see what you mean: you have varying data, sometimes all greater than 0, sometimes some negative, and you always want to see the 0 at the axis. I think you will have to do some progamming to achieve this effect. You could try to call the following procedure whenever the data range changes:
No, I do not always want to see the 0 (though when you said it, I do want, it would be useful to find DC components).
What I wanted is shown on the picture- I have added the values that I miss on your screenshot with red colour.
Maybe some of you already explained how to do it, still I have to reread all the posts.

Quote
I could not find where you wrote y axis and what is the exact name of this element
This is the title of the left axis (Chart1.LeftAxis.Title.Caption := 'y axis') - maybe you should have a look at my recent tutorial on getting started (http://wiki.lazarus.freepascal.org/TAChart_tutorial:_Getting_started).
That was close but as you've said in your tutorial- Don't forget to set Visible to true.. ;) BTW, I'had read it at least once.
« Last Edit: August 15, 2012, 07:32:52 am by paskal »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 13328
Re: How to fix the size of the plot area?
« Reply #22 on: August 15, 2012, 10:09:35 am »
Quote
What I wanted is shown on the picture
In other words, you want some kind of "AutoExpandToLabel" feature which expands the axis such that it always begins and ends with a label? That would be nice, I agree.

« Last Edit: August 15, 2012, 10:25:21 am by wp »

wp

  • Hero Member
  • *****
  • Posts: 13328
Re: How to fix the size of the plot area?
« Reply #23 on: August 17, 2012, 11:29:25 pm »
Quote
I do not always want to see the 0 (though when you said it, I do want, it would be useful to find DC components)
Another way to force the 0 on the y axis is to add a TConstantLineSeries with LineStyle lsHorizontal and Position 0. This also draws a line at y=0 even you have grid turned off.

CM630

  • Hero Member
  • *****
  • Posts: 1579
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: How to fix the size of the plot area?
« Reply #24 on: August 21, 2012, 10:57:23 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 :)
*Ask, do you mean that I can have several vertically shifted Y axises, like on the image, attached to the post?
I made the image with an image editor, the line example does not have such a thing, at least I did not find it.
BTW, in the line example, what should checking Sorted do? It does nothing for me.
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: How to fix the size of the plot area?
« Reply #25 on: August 21, 2012, 11:35:58 am »
"axis", "panes", "axistransf" demos and "Oscilloscope" page of the "line" demo for examples.
*Ask, do you mean that I can have several vertically shifted Y axises, like on the image, attached to the post?
I made the image with an image editor, the line example does not have such a thing, at least I did not find it.
Yes. Note that I suggested several demo programs, exhibiting various aspects.
In particular, see "Axis groups" page of the "axis" demo and "Transform" page of the "panes" demo.

BTW, in the line example, what should checking Sorted do? It does nothing for me.
The "Fast drawing" page of the "line" demo is dedicated to measuring speed of drawing line series
with extremely many points. Line series has many optimizations for this case,
which are partially documented here: http://wiki.lazarus.freepascal.org/TAChart_documentation#Fast_lines.
To see the effect of "Sorted" toggle, do the following:
1) Press "Add" button several times
2) Zoom to a relatively small part of series by drawing tall but narrow rectangle while holding "Shift".
3) Press "Timed refresh"
4) Toggle "Sorted"
5) Press "Timed refresh" again

CM630

  • Hero Member
  • *****
  • Posts: 1579
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: How to fix the size of the plot area?
« Reply #26 on: August 21, 2012, 01:09:49 pm »
"axis", "panes", "axistransf" demos and "Oscilloscope" page of the "line" demo for examples.
*Ask, do you mean that I can have several vertically shifted Y axises, like on the image, attached to the post?
I made the image with an image editor, the line example does not have such a thing, at least I did not find it.
Yes. Note that I suggested several demo programs, exhibiting various aspects.
In particular, see "Axis groups" page of the "axis" demo and "Transform" page of the "panes" demo.
Yes, on the first sight axis group seems really so fine.
Here is another question, maybe not so much related with the topic.
Here is what is needed: when clicking on the highest/lowest  value of a scale (or one of the many on a chart) a edit field to appear, so I can edit the maximum/ minimum values. For example, I have a scale with from -10 to +10. I want to make it from -10 to +20. My idea is to click on +10 and to change the value to +20.
So probably TAChart doe not have this as an inbuilt feature, but it is not necessary.
The question is what is the best way to detect a mouse click on the scales. Shall I watch the mouse position and calculate if the click is over a scale or there is some other solution?
P.S. I just found out that if AllowZoom= true then mouse down works only on the scales, but not on the plot area. Anyway, dealing with the mouse location seems simple enough.
« Last Edit: August 21, 2012, 01:53:18 pm by paskal »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: How to fix the size of the plot area?
« Reply #27 on: August 21, 2012, 03:59:18 pm »
Quote
Shall I watch the mouse position and calculate if the click is over a scale or there is some other solution?
For now -- yes, you have to do it yourself.
It would be a useful addition to TAChart, but not easy to implement.

Quote
if AllowZoom= true then mouse down works only on the scales, but not on the plot area
This is by design, see event processing order at
http://wiki.lazarus.freepascal.org/TAChart_documentation#Tools

CM630

  • Hero Member
  • *****
  • Posts: 1579
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: How to fix the size of the plot area?
« Reply #28 on: August 23, 2012, 08:43:01 am »
So, how am I to find the real minimum and maximum values dispayed for a series of graphics?
I crated a chart. In left axis I set range.min=-10 and range.min= +10. UseMax and UsdeMin stay False.
I run this code:
Code: [Select]
procedure TForm1.Chart1Click(Sender: TObject);
begin
 ShowMessage (FloatToStr(Chart1.LeftAxis.Range.Min) +'   '+ FloatToStr(Chart1.LeftAxis.Range.max) + #13 + #10+ FloatToStr(chart1.Extent.Ymin) +'  '+ FloatToStr(chart1.Extent.YMax));
end;
It shows
Quote
-10  10
0 0
, but in fact the displayed values on the left scale are from -1 to +1. How am I go get them?
I looked in the series properties, but I did not find a property for the +- values, displayed on the chart.
Or should I make some tricks with the tools + zoom?

Maybe I am not explaining the question clearly?

« Last Edit: August 23, 2012, 08:49:28 am by paskal »
Лазар 4,4 32 bit (sometimes 64 bit); FPC3,2,2

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: How to fix the size of the plot area?
« Reply #29 on: August 23, 2012, 09:48:21 am »
Quote
I set range.min=-10 and range.min= +10. UseMax and UseMin stay False.
Range and Extent, like most published properties, are declarative -- that is,
it indicates the developer's intent as opposed to the actual state.
Besides that, when UseMax = UseMin = False, Range.Min and Range.Max are ignored.

To get the chart extent in graph coordinates, use CurrentExtent or LogicalExtent.
See http://wiki.lazarus.freepascal.org/TAChart_documentation#Extents
To Convert those into axis coordinates, use GraphToAxis functions
of the appropriate axis.

Edit: Since r38349, you can use TChartAxis.IsPointInside function to determine
if the mouse position falls inside of marks area of the given axis.
« Last Edit: August 24, 2012, 06:25:04 am by Ask »

 

TinyPortal © 2005-2018