mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-09 00:35:56 +02:00
TAChart: Improve TCubicSplineSeries by making its procedure GetSplineXRange a function and avoiding the IfThen calls. Issue #35268, modified patch by Marcin Wiazowski.
git-svn-id: trunk@60804 -
This commit is contained in:
parent
d0f6276d0c
commit
ff1abdbffb
@ -226,7 +226,7 @@ type
|
|||||||
var
|
var
|
||||||
FSplines: array of TSpline;
|
FSplines: array of TSpline;
|
||||||
procedure FreeSplines;
|
procedure FreeSplines;
|
||||||
procedure GetSplineXRange(ASpline: TSpline; out AXMin, AXMax: Double);
|
function GetSplineXRange(ASpline: TSpline; out AXMin, AXMax: Double): Boolean;
|
||||||
function IsUnorderedVisible: Boolean; inline;
|
function IsUnorderedVisible: Boolean; inline;
|
||||||
procedure PrepareCoeffs;
|
procedure PrepareCoeffs;
|
||||||
procedure SetBadDataPen(AValue: TBadDataChartPen);
|
procedure SetBadDataPen(AValue: TBadDataChartPen);
|
||||||
@ -1379,8 +1379,7 @@ procedure TCubicSplineSeries.Draw(ADrawer: IChartDrawer);
|
|||||||
if not Pen.EffVisible then exit;
|
if not Pen.EffVisible then exit;
|
||||||
ADrawer.Pen := Pen;
|
ADrawer.Pen := Pen;
|
||||||
end;
|
end;
|
||||||
GetSplineXRange(ASpline, xmin, xmax);
|
if not GetSplineXRange(ASpline, xmin, xmax) then
|
||||||
if xmin > xmax then
|
|
||||||
exit;
|
exit;
|
||||||
with TPointsDrawFuncHelper.Create(Self, xmin, xmax, ASpline.FStartIndex, @ASpline.Calculate, Step) do
|
with TPointsDrawFuncHelper.Create(Self, xmin, xmax, ASpline.FStartIndex, @ASpline.Calculate, Step) do
|
||||||
try
|
try
|
||||||
@ -1492,9 +1491,8 @@ begin
|
|||||||
if s.IsFewPoints or (s.FIsUnorderedX and not IsUnorderedVisible) then
|
if s.IsFewPoints or (s.FIsUnorderedX and not IsUnorderedVisible) then
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
GetSplineXRange(s, xmin, xmax);
|
if not GetSplineXRange(s, xmin, xmax) then
|
||||||
if xmax > xmin then
|
continue;
|
||||||
exit;
|
|
||||||
with TPointsDrawFuncHelper.Create(Self, xmin, xmax, s.FStartIndex, @s.Calculate, Step) do
|
with TPointsDrawFuncHelper.Create(Self, xmin, xmax, s.FStartIndex, @s.Calculate, Step) do
|
||||||
try
|
try
|
||||||
if not GetNearestPoint(AParams, r) or
|
if not GetNearestPoint(AParams, r) or
|
||||||
@ -1511,20 +1509,27 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCubicSplineSeries.GetSplineXRange(ASpline: TSpline;
|
function TCubicSplineSeries.GetSplineXRange(ASpline: TSpline;
|
||||||
out AXMin, AXMax: Double);
|
out AXMin, AXMax: Double): Boolean;
|
||||||
var
|
var
|
||||||
ext: TDoubleRect;
|
ext: TDoubleRect;
|
||||||
begin
|
begin
|
||||||
ext := FChart.CurrentExtent;
|
ext := FChart.CurrentExtent;
|
||||||
AXmin := IfThen(
|
|
||||||
(csoExtrapolateLeft in FOptions) and (ASpline = FSplines[0]),
|
if (csoExtrapolateLeft in FOptions) and (ASpline = FSplines[0]) then
|
||||||
ext.a.x, Max(ext.a.x, AxisToGraphX(ASpline.FX[0]))
|
AXmin := ext.a.x
|
||||||
);
|
else
|
||||||
AXmax := IfThen(
|
AXmin := Max(ext.a.x, AxisToGraphX(ASpline.FX[0]));
|
||||||
(csoExtrapolateRight in FOptions) and (ASpline = FSplines[High(FSplines)]),
|
|
||||||
ext.b.x, Min(ext.b.x, AxisToGraphX(ASpline.FX[High(ASpline.FX)]))
|
if AXmin > ext.b.x then
|
||||||
);
|
exit(false);
|
||||||
|
|
||||||
|
if (csoExtrapolateRight in FOptions) and (ASpline = FSplines[High(FSplines)]) then
|
||||||
|
AXmax := ext.b.x
|
||||||
|
else
|
||||||
|
AXmax := Min(ext.b.x, AxisToGraphX(ASpline.FX[High(ASpline.FX)]));
|
||||||
|
|
||||||
|
Result := AXMin <= AXMax;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCubicSplineSeries.IsUnorderedVisible: Boolean;
|
function TCubicSplineSeries.IsUnorderedVisible: Boolean;
|
||||||
@ -1541,7 +1546,6 @@ begin
|
|||||||
while i < Source.Count do begin
|
while i < Source.Count do begin
|
||||||
s := TSpline.Create(self);
|
s := TSpline.Create(self);
|
||||||
if s.PrepareCoeffs(Source, i) then begin
|
if s.PrepareCoeffs(Source, i) then begin
|
||||||
//s.PrepareIntervals;
|
|
||||||
SetLength(FSplines, Length(FSplines) + 1);
|
SetLength(FSplines, Length(FSplines) + 1);
|
||||||
FSplines[High(FSplines)] := s;
|
FSplines[High(FSplines)] := s;
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user