Page 1 of 1

TCursorTool Drags Outside Chart

Posted: Tue Sep 22, 2009 7:44 pm
by 10054271
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.

Re: TCursorTool Drags Outside Chart

Posted: Wed Sep 23, 2009 9:11 am
by yeray
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.

Re: TCursorTool Drags Outside Chart

Posted: Wed Sep 23, 2009 1:06 pm
by 10054271
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;
}

Re: TCursorTool Drags Outside Chart

Posted: Thu Oct 01, 2009 8:42 am
by yeray
Hi skassan,

Thanks for the feedback. I'm happy to see that now it works as you expected.