mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-15 22:40:43 +01:00
TAChart: Extract TDrawFuncHelper.XRange helper function.
+ Fix GetNearestPoint for rotated function series. git-svn-id: trunk@38729 -
This commit is contained in:
parent
272eb740df
commit
cf75819f6e
@ -366,6 +366,7 @@ type
|
||||
strict private
|
||||
type
|
||||
TOnPoint = procedure (AXg, AXa: Double) of object;
|
||||
TImageToGraph = function (AX: Integer): Double of object;
|
||||
var
|
||||
FAxisToGraphXr, FAxisToGraphYr, FGraphToAxisXr: TTransformFunc;
|
||||
FCalc: TTransformFunc;
|
||||
@ -374,6 +375,7 @@ type
|
||||
FDrawer: IChartDrawer;
|
||||
FExtent: TDoubleRect;
|
||||
FGraphStep: Double;
|
||||
FImageToGraph: TImageToGraph;
|
||||
FNearestPointParams: ^TNearestPointParams;
|
||||
FNearestPointResults: ^TNearestPointResults;
|
||||
FMakeDP: TMakeDoublePoint;
|
||||
@ -386,6 +388,7 @@ type
|
||||
procedure ForEachPoint(AXg, AXMax: Double; AOnMoveTo, AOnLineTo: TOnPoint);
|
||||
procedure LineTo(AXg, AXa: Double);
|
||||
procedure MoveTo(AXg, AXa: Double);
|
||||
function XRange: TDoubleInterval;
|
||||
public
|
||||
constructor Create(
|
||||
ASeries: TCustomChartSeries; ADomainExclusions:
|
||||
@ -569,32 +572,24 @@ begin
|
||||
FAxisToGraphYr := @AxisToGraphX;
|
||||
FGraphToAxisXr := @GraphToAxisY;
|
||||
FMakeDP := @DoublePointRotated;
|
||||
FGraphStep := FChart.YImageToGraph(-AStep) - FChart.YImageToGraph(0);
|
||||
FImageToGraph := @FChart.YImageToGraph;
|
||||
AStep := -AStep;
|
||||
end
|
||||
else begin
|
||||
FAxisToGraphXr := @AxisToGraphX;
|
||||
FAxisToGraphYr := @AxisToGraphY;
|
||||
FGraphToAxisXr := @GraphToAxisX;
|
||||
FMakeDP := @DoublePoint;
|
||||
FGraphStep := FChart.XImageToGraph(AStep) - FChart.XImageToGraph(0);
|
||||
FImageToGraph := @FChart.XImageToGraph;
|
||||
end;
|
||||
FGraphStep := FImageToGraph(AStep) - FImageToGraph(0);
|
||||
end;
|
||||
|
||||
procedure TDrawFuncHelper.DrawFunction(ADrawer: IChartDrawer);
|
||||
var
|
||||
xg, xmax: Double;
|
||||
begin
|
||||
FDrawer := ADrawer;
|
||||
with FSeries do
|
||||
if IsRotated then begin
|
||||
xg := FExtent.a.Y;
|
||||
xmax := FExtent.b.Y;
|
||||
end
|
||||
else begin
|
||||
xg := FExtent.a.X;
|
||||
xmax := FExtent.b.X;
|
||||
end;
|
||||
ForEachPoint(xg, xmax, @MoveTo, @LineTo);
|
||||
with XRange do
|
||||
ForEachPoint(FStart, FEnd, @MoveTo, @LineTo);
|
||||
end;
|
||||
|
||||
procedure TDrawFuncHelper.ForEachPoint(
|
||||
@ -631,24 +626,20 @@ function TDrawFuncHelper.GetNearestPoint(
|
||||
const AParams: TNearestPointParams;
|
||||
out AResults: TNearestPointResults): Boolean;
|
||||
var
|
||||
xg, xmax: Double;
|
||||
x, r: Integer;
|
||||
begin
|
||||
AResults.FIndex := -1;
|
||||
AResults.FDist := Sqr(AParams.FRadius) + 1;
|
||||
|
||||
with AParams do
|
||||
if FSeries.IsRotated then begin
|
||||
xg := Max(FExtent.a.Y, FChart.YImageToGraph(FPoint.Y - FRadius));
|
||||
xmax := Min(FExtent.b.Y, FChart.YImageToGraph(FPoint.Y + FRadius));
|
||||
end
|
||||
else begin
|
||||
xg := Max(FExtent.a.X, FChart.XImageToGraph(FPoint.X - FRadius));
|
||||
xmax := Min(FExtent.b.X, FChart.XImageToGraph(FPoint.X + FRadius));
|
||||
end;
|
||||
|
||||
FNearestPointParams := @AParams;
|
||||
FNearestPointResults := @AResults;
|
||||
ForEachPoint(xg, xmax, @CheckForNearestPoint, @CheckForNearestPoint);
|
||||
|
||||
x := TPointBoolArr(AParams.FPoint)[FSeries.IsRotated];
|
||||
r := IfThen(FSeries.IsRotated, -1, 1) * AParams.FRadius;
|
||||
with XRange do
|
||||
ForEachPoint(
|
||||
Max(FImageToGraph(x - r), FStart),
|
||||
Min(FImageToGraph(x + r), FEnd),
|
||||
@CheckForNearestPoint, @CheckForNearestPoint);
|
||||
|
||||
Result := AResults.FDist < Sqr(AParams.FRadius) + 1;
|
||||
end;
|
||||
@ -677,6 +668,14 @@ begin
|
||||
FDrawer.MoveTo(FChart.GraphToImage(FPrev));
|
||||
end;
|
||||
|
||||
function TDrawFuncHelper.XRange: TDoubleInterval;
|
||||
begin
|
||||
if FSeries.IsRotated then
|
||||
Result := DoubleInterval(FExtent.a.Y, FExtent.b.Y)
|
||||
else
|
||||
Result := DoubleInterval(FExtent.a.X, FExtent.b.X);
|
||||
end;
|
||||
|
||||
{ TBasicFuncSeries }
|
||||
|
||||
procedure TBasicFuncSeries.AfterAdd;
|
||||
@ -791,9 +790,8 @@ function TFuncSeries.GetNearestPoint(
|
||||
const AParams: TNearestPointParams;
|
||||
out AResults: TNearestPointResults): Boolean;
|
||||
begin
|
||||
Result := false;
|
||||
AResults.FIndex := -1;
|
||||
if not Assigned(OnCalculate) then exit;
|
||||
if not Assigned(OnCalculate) then exit(false);
|
||||
|
||||
with TDrawFuncHelper.Create(Self, DomainExclusions, @DoCalculate, Step) do
|
||||
try
|
||||
|
||||
Loading…
Reference in New Issue
Block a user