TAChart: Fix early crash of new ChartLiveView

git-svn-id: trunk@63762 -
This commit is contained in:
wp 2020-08-16 17:03:16 +00:00
parent 57d9bae48d
commit 14ce141c40

View File

@ -20,6 +20,7 @@ type
procedure FullExtentChanged(Sender: TObject); procedure FullExtentChanged(Sender: TObject);
procedure SetActive(const AValue: Boolean); procedure SetActive(const AValue: Boolean);
procedure SetChart(const AValue: TChart); procedure SetChart(const AValue: TChart);
procedure SetExtentY(const AValue: TChartLiveViewExtentY);
procedure SetViewportSize(const AValue: Double); procedure SetViewportSize(const AValue: Double);
procedure UpdateViewport; procedure UpdateViewport;
public public
@ -28,7 +29,7 @@ type
published published
property Active: Boolean read FActive write SetActive default false; property Active: Boolean read FActive write SetActive default false;
property Chart: TChart read FChart write SetChart default nil; property Chart: TChart read FChart write SetChart default nil;
property ExtentY: TChartLiveViewExtentY read FExtentY write FExtentY default lveAuto; property ExtentY: TChartLiveViewExtentY read FExtentY write SetExtentY default lveAuto;
property ViewportSize: double read FViewportSize write SetViewportSize; property ViewportSize: double read FViewportSize write SetViewportSize;
end; end;
@ -38,7 +39,7 @@ procedure Register;
implementation implementation
uses uses
TACustomSeries, TAEnumerators; Math, TACustomSeries, TAEnumerators;
constructor TChartLiveView.Create(AOwner: TComponent); constructor TChartLiveView.Create(AOwner: TComponent);
begin begin
@ -79,6 +80,13 @@ begin
FullExtentChanged(Self); FullExtentChanged(Self);
end; end;
procedure TChartLiveview.SetExtentY(const AValue: TChartLiveViewExtentY);
begin
if FExtentY = AValue then exit;
FExtentY := AValue;
FullExtentChanged(nil);
end;
procedure TChartLiveView.SetViewportSize(const AValue: Double); procedure TChartLiveView.SetViewportSize(const AValue: Double);
begin begin
if FViewportSize = AValue then exit; if FViewportSize = AValue then exit;
@ -94,6 +102,9 @@ var
i: Integer; i: Integer;
ymin, ymax: Double; ymin, ymax: Double;
begin begin
if not FChart.ScalingValid then
exit;
fext := FChart.GetFullExtent(); fext := FChart.GetFullExtent();
lext := FChart.LogicalExtent; lext := FChart.LogicalExtent;
w := lext.b.x - lext.a.x; w := lext.b.x - lext.a.x;
@ -110,12 +121,12 @@ begin
case FExtentY of case FExtentY of
lveAuto: lveAuto:
begin begin
ymin := 1E308; ymin := Infinity;
ymax := -1E308; ymax := -Infinity;
for i := 0 to FChart.SeriesCount-1 do for i := 0 to FChart.SeriesCount-1 do
if FChart.Series[i] is TChartSeries then if FChart.Series[i] is TChartSeries then
TChartSeries(FChart.Series[i]).FindYRange(lext.a.x, lext.b.x, ymin, ymax); TChartSeries(FChart.Series[i]).FindYRange(lext.a.x, lext.b.x, ymin, ymax);
if (ymin < 1E308) and (ymax > -1E308) then if (ymin <> Infinity) and (ymax <> -Infinity) then
begin begin
lext.a.y := ymin; lext.a.y := ymin;
lext.b.y := ymax; lext.b.y := ymax;