mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-11 13:56:05 +02:00
TAChart: Convert Series.UpdateBounds methods to Series.GetBounds.
The logic for updating centralized in Graph.UpdateExtent procedure. git-svn-id: trunk@23211 -
This commit is contained in:
parent
c95dd96212
commit
e63e1febd5
@ -68,7 +68,7 @@ type
|
||||
function GetGraphPointX(AIndex: Integer): Double;
|
||||
function GetSeriesColor: TColor; virtual;
|
||||
function GetXMaxVal: Integer;
|
||||
procedure UpdateBounds(var ABounds: TDoubleRect); override;
|
||||
procedure GetBounds(out ABounds: TDoubleRect); override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
@ -301,6 +301,12 @@ begin
|
||||
Result := DefaultFormattedMark(AIndex);
|
||||
end;
|
||||
|
||||
procedure TChartSeries.GetBounds(out ABounds: TDoubleRect);
|
||||
begin
|
||||
if not Active or (Count = 0) then exit;
|
||||
ABounds := Extent;
|
||||
end;
|
||||
|
||||
function TChartSeries.GetColor(AIndex: Integer): TColor;
|
||||
begin
|
||||
Result := ColorOrDefault(Source[AIndex]^.Color);
|
||||
@ -447,16 +453,5 @@ begin
|
||||
ListSource.SetYValue(AIndex, AValue);
|
||||
end;
|
||||
|
||||
procedure TChartSeries.UpdateBounds(var ABounds: TDoubleRect);
|
||||
begin
|
||||
if not Active or (Count = 0) then exit;
|
||||
with Extent do begin
|
||||
if a.X < ABounds.a.X then ABounds.a.X := a.X;
|
||||
if a.Y < ABounds.a.Y then ABounds.a.Y := a.Y;
|
||||
if b.X > ABounds.b.X then ABounds.b.X := b.X;
|
||||
if b.Y > ABounds.b.Y then ABounds.b.Y := b.Y;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
@ -64,7 +64,7 @@ type
|
||||
procedure SetDepth(AValue: TChartDistance); virtual; abstract;
|
||||
procedure SetShowInLegend(AValue: Boolean); virtual; abstract;
|
||||
procedure SetZPosition(AValue: TChartDistance); virtual; abstract;
|
||||
procedure UpdateBounds(var ABounds: TDoubleRect); virtual; abstract;
|
||||
procedure GetBounds(out ABounds: TDoubleRect); virtual; abstract;
|
||||
procedure UpdateMargins(ACanvas: TCanvas; var AMargins: TRect); virtual;
|
||||
|
||||
protected
|
||||
@ -1068,6 +1068,7 @@ procedure TChart.UpdateExtent;
|
||||
|
||||
var
|
||||
i: Integer;
|
||||
seriesBounds: TDoubleRect;
|
||||
begin
|
||||
if FIsZoomed then begin
|
||||
FCurrentExtent := FZoomExtent;
|
||||
@ -1076,10 +1077,18 @@ begin
|
||||
Extent.CheckBoundsOrder;
|
||||
|
||||
FCurrentExtent := EmptyExtent;
|
||||
for i := 0 to SeriesCount - 1 do
|
||||
with Series[i] do
|
||||
if Active then
|
||||
UpdateBounds(FCurrentExtent);
|
||||
for i := 0 to SeriesCount - 1 do begin
|
||||
if Series[i].Active then begin
|
||||
seriesBounds := EmptyExtent;
|
||||
Series[i].GetBounds(seriesBounds);
|
||||
with FCurrentExtent do begin
|
||||
a.X := Min(a.X, seriesBounds.a.X);
|
||||
b.X := Max(b.X, seriesBounds.b.X);
|
||||
a.Y := Min(a.Y, seriesBounds.a.Y);
|
||||
b.Y := Max(b.Y, seriesBounds.b.Y);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
with FCurrentExtent, Extent do begin
|
||||
SetBounds(a.X, b.X, XMin, XMax, UseXMin, UseXMax);
|
||||
SetBounds(a.Y, b.Y, YMin, YMax, UseYMin, UseYMax);
|
||||
|
@ -224,7 +224,7 @@ type
|
||||
procedure SetUseBounds(AValue: Boolean);
|
||||
protected
|
||||
procedure GetLegendItems(AItems: TChartLegendItems); override;
|
||||
procedure UpdateBounds(var ABounds: TDoubleRect); override;
|
||||
procedure GetBounds(out ABounds: TDoubleRect); override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
@ -265,7 +265,7 @@ type
|
||||
procedure SetStep(AValue: TFuncSeriesStep);
|
||||
protected
|
||||
procedure GetLegendItems(AItems: TChartLegendItems); override;
|
||||
procedure UpdateBounds(var ABounds: TDoubleRect); override;
|
||||
procedure GetBounds(out ABounds: TDoubleRect); override;
|
||||
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
@ -287,19 +287,19 @@ type
|
||||
end;
|
||||
|
||||
TSeriesDrawEvent = procedure (ACanvas: TCanvas; const ARect: TRect) of object;
|
||||
TSeriesUpdateBoundsEvent = procedure (var ABounds: TDoubleRect) of object;
|
||||
TSeriesGetBoundsEvent = procedure (out ABounds: TDoubleRect) of object;
|
||||
|
||||
{ TUserDrawnSeries }
|
||||
|
||||
TUserDrawnSeries = class(TCustomChartSeries)
|
||||
private
|
||||
FOnDraw: TSeriesDrawEvent;
|
||||
FOnUpdateBounds: TSeriesUpdateBoundsEvent;
|
||||
FOnGetBounds: TSeriesGetBoundsEvent;
|
||||
procedure SetOnDraw(AValue: TSeriesDrawEvent);
|
||||
procedure SetOnUpdateBounds(AValue: TSeriesUpdateBoundsEvent);
|
||||
procedure SetOnGetBounds(AValue: TSeriesGetBoundsEvent);
|
||||
protected
|
||||
procedure GetBounds(out ABounds: TDoubleRect); override;
|
||||
procedure GetLegendItems(AItems: TChartLegendItems); override;
|
||||
procedure UpdateBounds(var ABounds: TDoubleRect); override;
|
||||
public
|
||||
procedure Draw(ACanvas: TCanvas); override;
|
||||
function IsEmpty: Boolean; override;
|
||||
@ -308,8 +308,8 @@ type
|
||||
property ZPosition;
|
||||
published
|
||||
property OnDraw: TSeriesDrawEvent read FOnDraw write SetOnDraw;
|
||||
property OnUpdateBounds: TSeriesUpdateBoundsEvent
|
||||
read FOnUpdateBounds write SetOnUpdateBounds;
|
||||
property OnGetBounds: TSeriesGetBoundsEvent
|
||||
read FOnGetBounds write SetOnGetBounds;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@ -488,6 +488,21 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TLine.GetBounds(out ABounds: TDoubleRect);
|
||||
begin
|
||||
if not UseBounds then exit;
|
||||
case LineStyle of
|
||||
lsHorizontal: begin
|
||||
ABounds.a.Y := FPosGraph;
|
||||
ABounds.b.Y := FPosGraph;
|
||||
end;
|
||||
lsVertical: begin
|
||||
ABounds.a.X := FPosGraph;
|
||||
ABounds.b.X := FPosGraph;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TLine.GetLegendItems(AItems: TChartLegendItems);
|
||||
begin
|
||||
AItems.Add(TLegendItemLine.Create(Pen, Title));
|
||||
@ -530,15 +545,6 @@ begin
|
||||
UpdateParentChart;
|
||||
end;
|
||||
|
||||
procedure TLine.UpdateBounds(var ABounds: TDoubleRect);
|
||||
begin
|
||||
if not UseBounds then exit;
|
||||
case LineStyle of
|
||||
lsHorizontal: UpdateMinMax(FPosGraph, ABounds.a.Y, ABounds.b.Y);
|
||||
lsVertical: UpdateMinMax(FPosGraph, ABounds.a.X, ABounds.b.X);
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TBasicPointSeries }
|
||||
|
||||
procedure TBasicPointSeries.DrawLabel(
|
||||
@ -1102,6 +1108,16 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TFuncSeries.GetBounds(out ABounds: TDoubleRect);
|
||||
begin
|
||||
with Extent do begin
|
||||
if UseXMin then ABounds.a.X := XMin;
|
||||
if UseYMin then ABounds.a.Y := YMin;
|
||||
if UseXMax then ABounds.b.X := XMax;
|
||||
if UseYMax then ABounds.b.Y := YMax;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TFuncSeries.GetLegendItems(AItems: TChartLegendItems);
|
||||
begin
|
||||
AItems.Add(TLegendItemLine.Create(Pen, Title));
|
||||
@ -1140,16 +1156,6 @@ begin
|
||||
UpdateParentChart;
|
||||
end;
|
||||
|
||||
procedure TFuncSeries.UpdateBounds(var ABounds: TDoubleRect);
|
||||
begin
|
||||
with Extent do begin
|
||||
if UseXMin and (XMin < ABounds.a.X) then ABounds.a.X := XMin;
|
||||
if UseYMin and (YMin < ABounds.a.Y) then ABounds.a.Y := YMin;
|
||||
if UseXMax and (XMax > ABounds.b.X) then ABounds.b.X := XMax;
|
||||
if UseYMax and (YMax > ABounds.b.Y) then ABounds.b.Y := YMax;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TUserDrawnSeries }
|
||||
|
||||
procedure TUserDrawnSeries.Draw(ACanvas: TCanvas);
|
||||
@ -1158,6 +1164,12 @@ begin
|
||||
FOnDraw(ACanvas, FChart.ClipRect);
|
||||
end;
|
||||
|
||||
procedure TUserDrawnSeries.GetBounds(out ABounds: TDoubleRect);
|
||||
begin
|
||||
if Assigned(FOnGetBounds) then
|
||||
FOnGetBounds(ABounds);
|
||||
end;
|
||||
|
||||
procedure TUserDrawnSeries.GetLegendItems(AItems: TChartLegendItems);
|
||||
begin
|
||||
Unused(AItems);
|
||||
@ -1175,19 +1187,13 @@ begin
|
||||
UpdateParentChart;
|
||||
end;
|
||||
|
||||
procedure TUserDrawnSeries.SetOnUpdateBounds(AValue: TSeriesUpdateBoundsEvent);
|
||||
procedure TUserDrawnSeries.SetOnGetBounds(AValue: TSeriesGetBoundsEvent);
|
||||
begin
|
||||
if FOnUpdateBounds = AValue then exit;
|
||||
FOnUpdateBounds := AValue;
|
||||
if TMethod(FOnGetBounds) = TMethod(AValue) then exit;
|
||||
FOnGetBounds := AValue;
|
||||
UpdateParentChart;
|
||||
end;
|
||||
|
||||
procedure TUserDrawnSeries.UpdateBounds(var ABounds: TDoubleRect);
|
||||
begin
|
||||
if Assigned(FOnUpdateBounds) then
|
||||
FOnUpdateBounds(ABounds);
|
||||
end;
|
||||
|
||||
initialization
|
||||
RegisterSeriesClass(TLineSeries, 'Line series');
|
||||
RegisterSeriesClass(TAreaSeries, 'Area series');
|
||||
|
Loading…
Reference in New Issue
Block a user