Selecting an area of a TPolarSeries?

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
jens.mertelmeyer
Newbie
Newbie
Posts: 60
Joined: Fri Nov 22, 2013 12:00 am

Selecting an area of a TPolarSeries?

Post by jens.mertelmeyer » Fri Nov 14, 2014 12:02 pm

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? :)

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Selecting an area of a TPolarSeries?

Post by Yeray » Fri Nov 14, 2014 2:37 pm

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
2014-11-14_1535.png (81.71 KiB) Viewed 23714 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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

jens.mertelmeyer
Newbie
Newbie
Posts: 60
Joined: Fri Nov 22, 2013 12:00 am

Re: Selecting an area of a TPolarSeries?

Post by jens.mertelmeyer » Mon Nov 17, 2014 9:43 am

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 :D 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.

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Selecting an area of a TPolarSeries?

Post by Yeray » Mon Nov 17, 2014 10:29 am

Hi Jens,

I've improved the example above a little bit:
2014-11-17_1123.png
2014-11-17_1123.png (91.86 KiB) Viewed 23728 times
testPolarBand.zip
(1.97 KiB) Downloaded 1232 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
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

jens.mertelmeyer
Newbie
Newbie
Posts: 31
Joined: Fri Nov 21, 2014 12:00 am

Re: Selecting an area of a TPolarSeries?

Post by jens.mertelmeyer » Tue Dec 16, 2014 7:51 pm

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?

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Selecting an area of a TPolarSeries?

Post by Yeray » Thu Dec 18, 2014 12:12 pm

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;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

jens.mertelmeyer
Newbie
Newbie
Posts: 31
Joined: Fri Nov 21, 2014 12:00 am

Re: Selecting an area of a TPolarSeries?

Post by jens.mertelmeyer » Fri Dec 19, 2014 11:04 am

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
Form5_2014-12-19_11-57-15.png (74.9 KiB) Viewed 23593 times
This is still pretty inaccurate but probably better than nothing at all :roll:

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Selecting an area of a TPolarSeries?

Post by Yeray » Fri Dec 19, 2014 12:01 pm

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;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

jens.mertelmeyer
Newbie
Newbie
Posts: 31
Joined: Fri Nov 21, 2014 12:00 am

Re: Selecting an area of a TPolarSeries?

Post by jens.mertelmeyer » Fri Dec 19, 2014 12:08 pm

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! 8)

Now I will be able to move a transparent donut or pie around in order to "fake" a TColorBandTool for polar series. Thank you!

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Selecting an area of a TPolarSeries?

Post by Yeray » Fri Dec 19, 2014 1:45 pm

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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply