Page 1 of 1
Selecting an area of a TPolarSeries?
Posted: Fri Nov 14, 2014 12:02 pm
by 16567885
Imagine a user wants to select a certain range on a TLineSeries. With a TColorBandTool, it's easy to implement and easy to make look good (
like this).
Now what if we also have a polar series? The axis tools (like TColorLineTool or TColorBandTool) don't seem to work here. I fully understand that a polar chart is an entirely different kind. But I have no idea how one would best implement a "selection" of a portion (like "From 10° to 35°).
I tried adding a pie chart and moving the bits around but it didn't turn out well. I'm looking for ideas.
Anyone?
Re: Selecting an area of a TPolarSeries?
Posted: Fri Nov 14, 2014 2:37 pm
by yeray
Hi Jens,
I tried your idea of using a TPieSeries and it seems to work wonderfully for me here:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.View3D:=false;
with Chart1.AddSeries(TPolarSeries) as TPolarSeries do
begin
FillSampleValues;
end;
with Chart1.AddSeries(TPieSeries) as TPieSeries do
begin
ShowInLegend:=false;
Marks.Visible:=false;
Transparency:=50;
AddPie(10, '', clRed);
RotationAngle:=45;
AngleSize:=90;
end;
end;
- 2014-11-14_1535.png (81.71 KiB) Viewed 24457 times
Maybe you are doing something else that makes the TPieSeries not to fit correctly.
If you still find problems with it, please try to arrange a simple example project we can run as-is to reproduce the situation here.
An alternative would be using custom drawing techniques.
Re: Selecting an area of a TPolarSeries?
Posted: Mon Nov 17, 2014 9:43 am
by 16567885
It does indeed look flawless. I should have put more emphasis on the "
and moving the bits around": I'm a but clueless how to implement rotating the red selection pie around. Or even make it grow or shrink (greater/smaller angle selection).
It could easily be done by using additional components like trackbars and stuff. But
it would be even prettier (and more intuitive) if the user could just grab the red pie, move it around and maybe grow/shrink the selection range. For that, I'm looking for something already built into TeeChart.
Re: Selecting an area of a TPolarSeries?
Posted: Mon Nov 17, 2014 10:29 am
by yeray
Hi Jens,
I've improved the example above a little bit:
- 2014-11-17_1123.png (91.86 KiB) Viewed 24471 times
But as you say it could still be interesting if TColorBandTool would support TPolarSeries so I've added it to the public tracker:
http://bugs.teechart.net/show_bug.cgi?id=1014
Re: Selecting an area of a TPolarSeries?
Posted: Tue Dec 16, 2014 7:51 pm
by 16570767
I still haven't entirely given up on this idea. Is there any way to determine where the user clicks/taps? I know about GetCursorValues(..) and GetCursorValueIndex() method of TChartSeries but they seem to fail on a TPolarSeries and descendants. GetCursorValues outputs weird stuff whereas GetCursorValueIndex always returns -1 ("no point close to the mouse cursor position").
Any idea?
Re: Selecting an area of a TPolarSeries?
Posted: Thu Dec 18, 2014 12:12 pm
by yeray
Hi Jens,
The series OnClick event already gives you the index of the point the user has clicked. Ie:
Code: Select all
var polarSeries: TPolarSeries;
pieSeries: TPieSeries;
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.View3D:=false;
polarSeries:=Chart1.AddSeries(TPolarSeries) as TPolarSeries;
with polarSeries do
begin
FillSampleValues;
Brush.Style:=bsClear;
Pen.Visible:=false;
end;
//...
polarSeries.OnClick:=PolarSeriesOnClick;
end;
procedure TForm1.PolarSeriesOnClick(Sender: TChartSeries; ValueIndex: Integer;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
Caption:=IntToStr(ValueIndex);
end;
Re: Selecting an area of a TPolarSeries?
Posted: Fri Dec 19, 2014 11:04 am
by 16570767
Thank you for the suggestion. However, that only works when clicking some point exactly. Which almost impossible when used on a touch screen and/or there are many values (360 or 720).
So far, the closest match I was able to get was by using a TNearestTool which operates on
points, not on the axis.
- Form5_2014-12-19_11-57-15.png (74.9 KiB) Viewed 24336 times
This is still pretty inaccurate but probably better than nothing at all
Re: Selecting an area of a TPolarSeries?
Posted: Fri Dec 19, 2014 12:01 pm
by yeray
Hi Jens,
I'm not sure if this is what you are trying to do, but you can use OnMouseMove event to convert the XY coordinates into Angle&Radius as follows:
Code: Select all
procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var Angle, Radius: Double;
begin
Angle:=polarSeries.PointToAngle(X, Y)*HalfDivPi;
Radius:=polarSeries.PointToRadius(X, Y);
Caption:='Angle: ' + FormatFloat('#0.00', Angle) + ', Radius: ' + FormatFloat('#0.00', Radius);
end;
Re: Selecting an area of a TPolarSeries?
Posted: Fri Dec 19, 2014 12:08 pm
by 16570767
Another prime example of how I should read the documentation more carefully: I didn't know about
PointToAngle and
PointToRadius.
This is, once again, exactly what I was looking for. Awesome!
Now I will be able to move a transparent donut or pie around in order to "fake" a TColorBandTool for polar series. Thank you!
Re: Selecting an area of a TPolarSeries?
Posted: Fri Dec 19, 2014 1:45 pm
by yeray
Hi Jens,
jens.mertelmeyer wrote:Now I will be able to move a transparent donut or pie around in order to "fake" a TColorBandTool for polar series. Thank you!
You are welcome!
And don't hesitate to let us know if you find any other problem with it, or if you just want to share such an implementation.