Restricting TCursorTool Range

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

Restricting TCursorTool Range

Post by skassan » Mon Sep 21, 2009 4:23 pm

Is there a way to restrict the range of a TCursorTool? I'm using two cursors to mark the beginning and end of a range. I'd like to restrict the movement such that the beginning is always before the end. Currently, I'm intercepting the OnCursorChange events, and redrawing the cursor where I want it if it's out of bounds. But that's not a very visually pleasing effect.

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

Re: Restricting TCursorTool Range

Post by Yeray » Tue Sep 22, 2009 8:10 am

Hi skassan,

Maybe you could consider using ColorLine tool that seems to look better with the following example:

Code: Select all

procedure TForm1.ChartTool1DragLine(Sender: TColorLineTool);
begin
  if ChartTool1.Value > 20 then ChartTool1.Value := 20;
  if ChartTool1.Value < 10 then ChartTool1.Value := 10;
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

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

Re: Restricting TCursorTool Range

Post by skassan » Tue Sep 22, 2009 1:06 pm

Agreed, that's much better visually. But I think it's more important to give the user the feedback during the drag so they can have better precision with their placement. The cursor is also much easier to use from my perspective, with snap and the ability to know which point the cursor is over without having to iterate through the whole series.

What I've decided to go with is this. Instead of repositioning the cursor the user is dragging, I let that cursor "push" the other cursor if necessary to keep their relative positions.

Code: Select all

void __fastcall TMDIChild::BeginCursorChange(TCursorTool *Sender,
      int x, int y, const double XValue, const double YValue,
      TChartSeries *Series, int ValueIndex)
{
  // Don't allow the beginning to move after the end.
  if (XValue >= EndCursor->XValue &&
      ValueIndex < Series->Count() - 1)
  {
    EndCursor->XValue = Series->XValues->Value[ValueIndex + 1];
  }
}
//---------------------------------------------------------------------------

void __fastcall TMDIChild::EndCursorChange(TCursorTool *Sender,
      int x, int y, const double XValue, const double YValue,
      TChartSeries *Series, int ValueIndex)
{
  // Don't allow the end to move before the beginning.
  if (XValue <= BeginCursor->XValue &&
      ValueIndex > 0)
  {
    BeginCursor->XValue = Series->XValues->Value[ValueIndex - 1];
  }
}
//---------------------------------------------------------------------------

Post Reply