TCursorTool Drags Outside Chart

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
skassan
Newbie
Newbie
Posts: 27
Joined: Fri Sep 18, 2009 12:00 am

TCursorTool Drags Outside Chart

Post by skassan » Tue Sep 22, 2009 7:44 pm

I have vertical TCursorTool positioned near the left edge of a bottom axis. When I use the right mouse button to scroll the chart to the left, the cursor continues to be drawn, even after it leaves the edge of the chart. And even worse, if I continue to drag so that the cursor image makes it to the end of the window, I get an OnChange event telling me that the cursor has moved. It hasn't.

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

Re: TCursorTool Drags Outside Chart

Post by Yeray » Wed Sep 23, 2009 9:11 am

Hi skassan,

I think that activating/deactivating the cursor at OnChartScroll event should solve this:

Code: Select all

procedure TForm1.Chart1Scroll(Sender: TObject);
var CursorX: Integer;
begin
  CursorX := Chart1.Axes.Bottom.CalcPosValue(ChartTool1.XValue);
  if (CursorX >= Chart1.ChartRect.Left) and (CursorX <= Chart1.ChartRect.Right) then
    ChartTool1.Active := true
  else
    ChartTool1.Active := false;
end;
Note that this code would work if your cursor tool is the first tool and it is set as Vertical.
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

skassan
Newbie
Newbie
Posts: 27
Joined: Fri Sep 18, 2009 12:00 am

Re: TCursorTool Drags Outside Chart

Post by skassan » Wed Sep 23, 2009 1:06 pm

Thanks for the help. This works for scrolling, but using the same code for UndoZoom didn't work, for some reason. So I had to modify it as follows:

Code: Select all

void ClipCursorToChart(TCursorTool *Cursor)
{
  TChartSeries *Series = Cursor->Series;
  TCustomAxisPanel *Chart = Series->ParentChart;
  TChartAxis *Axis = Chart->BottomAxis;
  double CursorX = Cursor->XValue;
  Cursor->Active = CursorX >= Axis->Minimum &&
                   CursorX <= Axis->Maximum;
}

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

Re: TCursorTool Drags Outside Chart

Post by Yeray » Thu Oct 01, 2009 8:42 am

Hi skassan,

Thanks for the feedback. I'm happy to see that now it works as you expected.
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