mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 08:43:14 +02:00
TAChart: Split off TCustomFuncSeries from TFuncSeries as ancestor without the OnCalculate event.
git-svn-id: trunk@56335 -
This commit is contained in:
parent
d3268fe1b4
commit
ddef3a32fd
@ -34,21 +34,19 @@ type
|
|||||||
|
|
||||||
TFuncSeriesStep = 1..MaxInt;
|
TFuncSeriesStep = 1..MaxInt;
|
||||||
|
|
||||||
TFuncSeries = class(TBasicFuncSeries)
|
TCustomFuncSeries = class(TBasicFuncSeries)
|
||||||
strict private
|
strict private
|
||||||
FDomainExclusions: TIntervalList;
|
FDomainExclusions: TIntervalList;
|
||||||
FExtentAutoY: Boolean;
|
FExtentAutoY: Boolean;
|
||||||
FOnCalculate: TFuncCalculateEvent;
|
|
||||||
FPen: TChartPen;
|
FPen: TChartPen;
|
||||||
FStep: TFuncSeriesStep;
|
FStep: TFuncSeriesStep;
|
||||||
|
|
||||||
function DoCalcIdentity(AX: Double): Double;
|
|
||||||
function DoCalculate(AX: Double): Double;
|
|
||||||
procedure SetExtentAutoY(AValue: Boolean);
|
procedure SetExtentAutoY(AValue: Boolean);
|
||||||
procedure SetOnCalculate(AValue: TFuncCalculateEvent);
|
|
||||||
procedure SetPen(AValue: TChartPen);
|
procedure SetPen(AValue: TChartPen);
|
||||||
procedure SetStep(AValue: TFuncSeriesStep);
|
procedure SetStep(AValue: TFuncSeriesStep);
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
function DoCalculate(AX: Double): Double; virtual; abstract;
|
||||||
procedure GetBounds(var ABounds: TDoubleRect); override;
|
procedure GetBounds(var ABounds: TDoubleRect); override;
|
||||||
procedure GetLegendItems(AItems: TChartLegendItems); override;
|
procedure GetLegendItems(AItems: TChartLegendItems); override;
|
||||||
|
|
||||||
@ -61,14 +59,11 @@ type
|
|||||||
function GetNearestPoint(
|
function GetNearestPoint(
|
||||||
const AParams: TNearestPointParams;
|
const AParams: TNearestPointParams;
|
||||||
out AResults: TNearestPointResults): Boolean; override;
|
out AResults: TNearestPointResults): Boolean; override;
|
||||||
function IsEmpty: Boolean; override;
|
|
||||||
public
|
public
|
||||||
property DomainExclusions: TIntervalList read FDomainExclusions;
|
property DomainExclusions: TIntervalList read FDomainExclusions;
|
||||||
published
|
published
|
||||||
property AxisIndexX;
|
property AxisIndexX;
|
||||||
property AxisIndexY;
|
property AxisIndexY;
|
||||||
property OnCalculate: TFuncCalculateEvent
|
|
||||||
read FOnCalculate write SetOnCalculate;
|
|
||||||
property ExtentAutoY: Boolean
|
property ExtentAutoY: Boolean
|
||||||
read FExtentAutoY write SetExtentAutoY default false;
|
read FExtentAutoY write SetExtentAutoY default false;
|
||||||
property Pen: TChartPen read FPen write SetPen;
|
property Pen: TChartPen read FPen write SetPen;
|
||||||
@ -76,6 +71,26 @@ type
|
|||||||
read FStep write SetStep default DEF_FUNC_STEP;
|
read FStep write SetStep default DEF_FUNC_STEP;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TFuncSeries = class(TCustomFuncSeries)
|
||||||
|
strict private
|
||||||
|
FOnCalculate: TFuncCalculateEvent;
|
||||||
|
procedure SetOnCalculate(AValue: TFuncCalculateEvent);
|
||||||
|
protected
|
||||||
|
function DoCalcIdentity(AX: Double): Double;
|
||||||
|
function DoCalculate(AX: Double): Double; override;
|
||||||
|
procedure GetBounds(var ABounds: TDoubleRect); override;
|
||||||
|
public
|
||||||
|
procedure Assign(ASource: TPersistent); override;
|
||||||
|
procedure Draw(ADrawer: IChartDrawer); override;
|
||||||
|
function GetNearestPoint(
|
||||||
|
const AParams: TNearestPointParams;
|
||||||
|
out AResults: TNearestPointResults): Boolean; override;
|
||||||
|
function IsEmpty: Boolean; override;
|
||||||
|
published
|
||||||
|
property OnCalculate: TFuncCalculateEvent
|
||||||
|
read FOnCalculate write SetOnCalculate;
|
||||||
|
end;
|
||||||
|
|
||||||
TParametricCurveCalculateEvent = procedure (
|
TParametricCurveCalculateEvent = procedure (
|
||||||
const AT: Double; out AX, AY: Double) of object;
|
const AT: Double; out AX, AY: Double) of object;
|
||||||
|
|
||||||
@ -477,22 +492,22 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TFuncSeries }
|
|
||||||
|
|
||||||
procedure TFuncSeries.Assign(ASource: TPersistent);
|
{ TCustomFuncSeries }
|
||||||
|
|
||||||
|
procedure TCustomFuncSeries.Assign(ASource: TPersistent);
|
||||||
begin
|
begin
|
||||||
if ASource is TFuncSeries then
|
if ASource is TCustomFuncSeries then
|
||||||
with TFuncSeries(ASource) do begin
|
with TFuncSeries(ASource) do begin
|
||||||
Self.FDomainExclusions.Assign(FDomainExclusions);
|
Self.FDomainExclusions.Assign(FDomainExclusions);
|
||||||
Self.FExtentAutoY := FExtentAutoY;
|
Self.FExtentAutoY := FExtentAutoY;
|
||||||
Self.FOnCalculate := FOnCalculate;
|
|
||||||
Self.Pen := FPen;
|
Self.Pen := FPen;
|
||||||
Self.FStep := FStep;
|
Self.FStep := FStep;
|
||||||
end;
|
end;
|
||||||
inherited Assign(ASource);
|
inherited Assign(ASource);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TFuncSeries.Create(AOwner: TComponent);
|
constructor TCustomFuncSeries.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
FDomainExclusions := TIntervalList.Create;
|
FDomainExclusions := TIntervalList.Create;
|
||||||
@ -502,13 +517,96 @@ begin
|
|||||||
FStep := DEF_FUNC_STEP;
|
FStep := DEF_FUNC_STEP;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TFuncSeries.Destroy;
|
destructor TCustomFuncSeries.Destroy;
|
||||||
begin
|
begin
|
||||||
FreeAndNil(FDomainExclusions);
|
FreeAndNil(FDomainExclusions);
|
||||||
FreeAndNil(FPen);
|
FreeAndNil(FPen);
|
||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomFuncSeries.Draw(ADrawer: IChartDrawer);
|
||||||
|
begin
|
||||||
|
ADrawer.SetBrushParams(bsClear, clTAColor);
|
||||||
|
ADrawer.Pen := Pen;
|
||||||
|
with TDrawFuncHelper.Create(Self, DomainExclusions, @DoCalculate, Step) do
|
||||||
|
try
|
||||||
|
DrawFunction(ADrawer);
|
||||||
|
finally
|
||||||
|
Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomFuncSeries.GetBounds(var ABounds: TDoubleRect);
|
||||||
|
var
|
||||||
|
ymin, ymax: Double;
|
||||||
|
begin
|
||||||
|
inherited GetBounds(ABounds);
|
||||||
|
if not Extent.UseXMin or not Extent.UseXMax or not ExtentAutoY then
|
||||||
|
exit;
|
||||||
|
ymin := SafeInfinity;
|
||||||
|
ymax := NegInfinity;
|
||||||
|
with TDrawFuncHelper.Create(Self, DomainExclusions, @DoCalculate, Step) do
|
||||||
|
try
|
||||||
|
CalcAxisExtentY(ABounds.a.X, ABounds.b.X, ymin, ymax);
|
||||||
|
if not Extent.UseYMin or (ymin > Extent.YMin) then
|
||||||
|
ABounds.a.Y := ymin;
|
||||||
|
if not Extent.UseYMax or (ymax < Extent.YMax) then
|
||||||
|
ABounds.b.Y := ymax;
|
||||||
|
finally
|
||||||
|
Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomFuncSeries.GetLegendItems(AItems: TChartLegendItems);
|
||||||
|
begin
|
||||||
|
AItems.Add(TLegendItemLine.Create(Pen, LegendTextSingle));
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TCustomFuncSeries.GetNearestPoint(
|
||||||
|
const AParams: TNearestPointParams;
|
||||||
|
out AResults: TNearestPointResults): Boolean;
|
||||||
|
begin
|
||||||
|
with TDrawFuncHelper.Create(Self, DomainExclusions, @DoCalculate, Step) do
|
||||||
|
try
|
||||||
|
Result := GetNearestPoint(AParams, AResults);
|
||||||
|
finally
|
||||||
|
Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomFuncSeries.SetExtentAutoY(AValue: Boolean);
|
||||||
|
begin
|
||||||
|
if FExtentAutoY = AValue then exit;
|
||||||
|
FExtentAutoY := AValue;
|
||||||
|
UpdateParentChart;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomFuncSeries.SetPen(AValue: TChartPen);
|
||||||
|
begin
|
||||||
|
if FPen = AValue then exit;
|
||||||
|
FPen.Assign(AValue);
|
||||||
|
UpdateParentChart;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCustomFuncSeries.SetStep(AValue: TFuncSeriesStep);
|
||||||
|
begin
|
||||||
|
if FStep = AValue then exit;
|
||||||
|
FStep := AValue;
|
||||||
|
UpdateParentChart;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{ TFuncSeries }
|
||||||
|
|
||||||
|
procedure TFuncSeries.Assign(ASource: TPersistent);
|
||||||
|
begin
|
||||||
|
if ASource is TFuncSeries then
|
||||||
|
with TFuncSeries(ASource) do begin
|
||||||
|
Self.FOnCalculate := FOnCalculate;
|
||||||
|
end;
|
||||||
|
inherited Assign(ASource);
|
||||||
|
end;
|
||||||
|
|
||||||
function TFuncSeries.DoCalcIdentity(AX: Double): Double;
|
function TFuncSeries.DoCalcIdentity(AX: Double): Double;
|
||||||
begin
|
begin
|
||||||
Result := AX;
|
Result := AX;
|
||||||
@ -544,28 +642,8 @@ var
|
|||||||
ymin, ymax: Double;
|
ymin, ymax: Double;
|
||||||
begin
|
begin
|
||||||
inherited GetBounds(ABounds);
|
inherited GetBounds(ABounds);
|
||||||
if
|
if Assigned(OnCalculate) then
|
||||||
not Extent.UseXMin or not Extent.UseXMax or not ExtentAutoY
|
|
||||||
or not Assigned(OnCalculate)
|
|
||||||
then
|
|
||||||
exit;
|
exit;
|
||||||
ymin := SafeInfinity;
|
|
||||||
ymax := NegInfinity;
|
|
||||||
with TDrawFuncHelper.Create(Self, DomainExclusions, @DoCalculate, Step) do
|
|
||||||
try
|
|
||||||
CalcAxisExtentY(ABounds.a.X, ABounds.b.X, ymin, ymax);
|
|
||||||
if not Extent.UseYMin or (ymin > Extent.YMin) then
|
|
||||||
ABounds.a.Y := ymin;
|
|
||||||
if not Extent.UseYMax or (ymax < Extent.YMax) then
|
|
||||||
ABounds.b.Y := ymax;
|
|
||||||
finally
|
|
||||||
Free;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TFuncSeries.GetLegendItems(AItems: TChartLegendItems);
|
|
||||||
begin
|
|
||||||
AItems.Add(TLegendItemLine.Create(Pen, LegendTextSingle));
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TFuncSeries.GetNearestPoint(
|
function TFuncSeries.GetNearestPoint(
|
||||||
@ -573,14 +651,9 @@ function TFuncSeries.GetNearestPoint(
|
|||||||
out AResults: TNearestPointResults): Boolean;
|
out AResults: TNearestPointResults): Boolean;
|
||||||
begin
|
begin
|
||||||
AResults.FIndex := -1;
|
AResults.FIndex := -1;
|
||||||
if not Assigned(OnCalculate) then exit(false);
|
if not Assigned(OnCalculate) then
|
||||||
|
exit(false);
|
||||||
with TDrawFuncHelper.Create(Self, DomainExclusions, @DoCalculate, Step) do
|
Result := inherited;
|
||||||
try
|
|
||||||
Result := GetNearestPoint(AParams, AResults);
|
|
||||||
finally
|
|
||||||
Free;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TFuncSeries.IsEmpty: Boolean;
|
function TFuncSeries.IsEmpty: Boolean;
|
||||||
@ -588,13 +661,6 @@ begin
|
|||||||
Result := not Assigned(OnCalculate);
|
Result := not Assigned(OnCalculate);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFuncSeries.SetExtentAutoY(AValue: Boolean);
|
|
||||||
begin
|
|
||||||
if FExtentAutoY = AValue then exit;
|
|
||||||
FExtentAutoY := AValue;
|
|
||||||
UpdateParentChart;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TFuncSeries.SetOnCalculate(AValue: TFuncCalculateEvent);
|
procedure TFuncSeries.SetOnCalculate(AValue: TFuncCalculateEvent);
|
||||||
begin
|
begin
|
||||||
if TMethod(FOnCalculate) = TMethod(AValue) then exit;
|
if TMethod(FOnCalculate) = TMethod(AValue) then exit;
|
||||||
@ -602,19 +668,6 @@ begin
|
|||||||
UpdateParentChart;
|
UpdateParentChart;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFuncSeries.SetPen(AValue: TChartPen);
|
|
||||||
begin
|
|
||||||
if FPen = AValue then exit;
|
|
||||||
FPen.Assign(AValue);
|
|
||||||
UpdateParentChart;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TFuncSeries.SetStep(AValue: TFuncSeriesStep);
|
|
||||||
begin
|
|
||||||
if FStep = AValue then exit;
|
|
||||||
FStep := AValue;
|
|
||||||
UpdateParentChart;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TParametricCurveSeries }
|
{ TParametricCurveSeries }
|
||||||
|
|
||||||
|
@ -469,7 +469,6 @@ implementation
|
|||||||
{$R tagraph.res}
|
{$R tagraph.res}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
lazlogger,
|
|
||||||
Clipbrd, Dialogs, GraphMath, LCLProc, LResources, Math, Types,
|
Clipbrd, Dialogs, GraphMath, LCLProc, LResources, Math, Types,
|
||||||
TADrawerCanvas, TAGeometry, TAMath, TAStyles;
|
TADrawerCanvas, TAGeometry, TAMath, TAStyles;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user