Recent

Author Topic: The best way to have lineseries with snapping cursors (pointers)?  (Read 20651 times)

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: The best way to have lineseries with snapping cursors (pointers)?
« Reply #30 on: October 12, 2012, 02:43:44 pm »
I do understand you. You are trying to call SetYValue from the inside of OnDrag event handler. It does work (if you call GetYValue immediately, you will see the effect).
However, just after return from the handler, point position is moved to the value determined by AGraphPoint.

CM630

  • Hero Member
  • *****
  • Posts: 1088
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: The best way to have lineseries with snapping cursors (pointers)?
« Reply #31 on: October 12, 2012, 03:03:31 pm »
So right after return from the handler, point position is moved to the value determined by AGraphPoint and this is okay.
But shouldn't GetYValue return the value, set by AGraphPoint?
I'll check again on Monday, if it really behaves so, maybe I got confused by the synchronization.
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: The best way to have lineseries with snapping cursors (pointers)?
« Reply #32 on: October 12, 2012, 03:43:51 pm »
Quote
shouldn't GetYValue return the value, set by AGraphPoint?
Yes, it should, but (1) you should check it after the handler, not inside of it and (2) if you active have axis transformations, they will of course affect the Y value.

CM630

  • Hero Member
  • *****
  • Posts: 1088
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: The best way to have lineseries with snapping cursors (pointers)?
« Reply #33 on: October 15, 2012, 08:23:06 am »
So here it is:

Code: [Select]
procedure TForm1.ChartToolset1DataPointDragTool1Drag( ASender: TDataPointDragTool; var AGraphPoint: TDoublePoint);
var
  p: TNearestPointParams;
  r: TNearestPointResults;
begin
  p.FDistFunc := @PointDistX;
  p.FOptimizeX := true;
  p.FPoint := Chart1.GraphToImage(AGraphPoint);
  p.FRadius := 15;
  Cursor1.SetYValue(0,7);
  if Wavedata.GetNearestPoint(p, r) then AGraphPoint := Wavedata.AxisToGraph(r.FValue);
  Cursor1.SetText(0,'U='+ FloatToStrF(Cursor1.GetYValue(0),ffFixed,3,3) + ' V') ; //Comment this line, if you are using Lazarus build less than  38732.
  Label2.Caption:= FloatToStrf(Cursor1.GetYValue(0),ffFixed,3,3) + '     ' + FloatToStrf(Cursor2.GetYValue(0),ffFixed,3,3);
end;

If the code is run this way, both label2.caption and the cursor caption show „7“.
But if I do Cursor1.GetYValue(0) in a procedure run after procedure TForm1.ChartToolset1DataPointDragTool1Drag( ASender: TDataPointDragTool; var AGraphPoint: TDoublePoint); then I get the exact Y value.
If I get you right, the idea is that the behaviour shall be exactly this?
Couldn't and shouldn't running AGraphPoint := Wavedata.AxisToGraph(r.FValue); change the result of GetYValue immediately, instead of waiting the whole procedure to finish? Or probably the concept is that with the current implementation the designer will know both the values in the beginning and during the execution process (current value) of the procedure. It is sure, that breaking compatibility with Delphi is unwanted.
« Last Edit: October 15, 2012, 08:24:54 am by paskal »
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: The best way to have lineseries with snapping cursors (pointers)?
« Reply #34 on: October 15, 2012, 09:08:47 am »
Quote
If I get you right, the idea is that the behaviour shall be exactly this?
Yes.

Quote
Couldn't and shouldn't running AGraphPoint := Wavedata.AxisToGraph(r.FValue); change the result of GetYValue immediately, instead of waiting the whole procedure to finish?
That is a simple variable assignment, it can not immediately change value of another variable.
Also, note the point I made in the previous post about axis transformation -- AGraphPoint is in graph coordinates, but GetYValue returns axis coordinates.

 

TinyPortal © 2005-2018