clicked part for axis

TeeChart FireMonkey (Windows,OSX,iOS & Android) for Embarcadero RAD Studio, Delphi and C++ Builder (XE5+)
Post Reply
n2n
Newbie
Newbie
Posts: 19
Joined: Mon Nov 23, 2015 12:00 am

clicked part for axis

Post by n2n » Thu Jan 14, 2016 2:22 am

im trying to get the clicked part for axis, im using CalcClickedPart function, it works but if i click on axis labels it wont trigger. also protected AxisRect function is returning rect excluding the label part, if you look at my screenshot, it will only work if i click on the axis line but it doesnt work when clicked on labels.
Attachments
Capture.PNG
Capture.PNG (1.51 KiB) Viewed 2198 times

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

Re: clicked part for axis

Post by Yeray » Thu Jan 14, 2016 5:01 pm

Hello,

This should allow you to determine when an axis label has been clicked:

Code: Select all

uses TeCanvas;

procedure TForm1.Chart1Click(Sender: TObject);

  function RectOf(AAxis: TChartAxis; Index:Integer):TRect;
  var tmpItem : TAxisItem;
    tmp,
    tmpW,
    tmpH : Integer;
    tmpP : TPoint;
  begin
    tmpItem:=AAxis.Items[Index];

    tmp:=tmpItem.LabelPos;
    tmpW:=AAxis.ParentChart.Canvas.TextWidth(tmpItem.Text);
    tmpH:=AAxis.ParentChart.Canvas.FontHeight;

    if AAxis.Horizontal then
    begin
      if AAxis.OtherSide then
      begin
        result.Bottom:=AAxis.PosLabels;
        result.Top:=result.Bottom-tmpH;
      end
      else
      begin
        result.Top:=AAxis.PosLabels;
        result.Bottom:=result.Top+tmpH;
      end;
    end
    else
    begin
      if AAxis.OtherSide then
         result.Left:=AAxis.PosLabels
      else
         result.Right:=AAxis.PosLabels;
    end;

    if AAxis.Horizontal then
    begin
      result.Left:=tmp-(tmpW div 2);
      result.Right:=result.Left+tmpW;
    end
    else
    begin
      result.Top:=tmp-(tmpH div 2);
      result.Bottom:=result.Top+tmpH;

      if AAxis.OtherSide then
         result.Right:=result.Left+tmpW
      else
         result.Left:=result.Right-tmpW
    end;

    if AAxis.ParentChart.View3D then
    begin
      tmpP:=AAxis.ParentChart.Canvas.Calculate3DPosition(result.TopLeft.X,result.TopLeft.Y,Round(AAxis.ParentChart.Width3D*AAxis.ZPosition*0.01));
      OffsetRect(result,tmpP.X-result.Left,tmpP.Y-result.Top);
    end;
  end;

var i: Integer;
begin
  with Chart1.Axes.Bottom do
  begin
    ParentChart.Canvas.AssignFont(Texts.Font);

    for i:=0 to Items.Count-1 do
      if PointInRect(RectOf(Chart1.Axes.Bottom, i), Chart1.GetCursorPos) then
        ShowMessage('clicked label');
  end;
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

n2n
Newbie
Newbie
Posts: 19
Joined: Mon Nov 23, 2015 12:00 am

Re: clicked part for axis

Post by n2n » Fri Jan 15, 2016 2:52 am

That method will get me the rect of each label, but i need to get the rect of Axis, just as shown below, if i use this method it will not trigger when user click on the gap between labels.
Attachments
Capture.png
Capture.png (1.77 KiB) Viewed 2157 times

n2n
Newbie
Newbie
Posts: 19
Joined: Mon Nov 23, 2015 12:00 am

Re: clicked part for axis

Post by n2n » Fri Jan 15, 2016 6:13 am

nevermind, i have managed to get the full rect based on first items left and last items right. thanks

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

Re: clicked part for axis

Post by Yeray » Fri Jan 15, 2016 9:27 am

Hello,

I'm glad to hear you found how to achieve it.
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