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