diff --git a/components/tachart/tachartutils.pas b/components/tachart/tachartutils.pas index 26bb0e5401..84f78ad401 100644 --- a/components/tachart/tachartutils.pas +++ b/components/tachart/tachartutils.pas @@ -138,6 +138,8 @@ function PointDistY(const A, B: TPoint): Integer; inline; procedure Unused(const A1); procedure Unused(const A1, A2); +procedure UpdateMinMax(AValue: Double; var AMin, AMax: Double); + operator +(const A: TPoint; B: TSize): TPoint; implementation @@ -300,6 +302,14 @@ begin end; {$HINTS ON} +procedure UpdateMinMax(AValue: Double; var AMin, AMax: Double); +begin + if AValue < AMin then + AMin := AValue + else if AValue > AMax then + AMax := AValue; +end; + operator + (const A: TPoint; B: TSize): TPoint; begin Result.X := A.X + B.cx; diff --git a/components/tachart/taseries.pas b/components/tachart/taseries.pas index 31e36cf827..fc048a60dd 100644 --- a/components/tachart/taseries.pas +++ b/components/tachart/taseries.pas @@ -704,8 +704,7 @@ begin Result := inherited AddXY(X, Y, XLabel, Color); // Update max - if X > XGraphMax then XGraphMax := X; - if X < XGraphMin then XGraphMin := X; + UpdateMinMax(X, FXGraphMin, FXGraphMax); if Y > YGraphMax then begin YGraphMax := Y; XOfYGraphMax := X; @@ -915,16 +914,14 @@ begin XGraphMin := MaxDouble; for i := 0 to Count - 1 do begin Val := PChartCoord(FCoordList.Items[i])^.x; - if Val > XGraphMax then XGraphMax := Val; - if Val < XGraphMin then XGraphMin := Val; + UpdateMinMax(Val, FXGraphMin, FXGraphMax); end; YGraphMax := MinDouble; YGraphMin := MaxDouble; for i:=0 to Count-1 do begin Val := PChartCoord(FCoordList.Items[i])^.y; - if Val > YGraphMax then YGraphMax := Val; - if Val < YGraphMin then YGraphMin := Val; + UpdateMinMax(Val, FYGraphMin, FYGraphMax); end; UpdateParentChart; @@ -1437,10 +1434,8 @@ begin Result := inherited AddXY(X, Y, XLabel, Color); // Update max - if X > XGraphMax then XGraphMax := X; - if X < XGraphMin then XGraphMin := X; - if Y > YGraphMax then YGraphMax := Y; - if Y < YGraphMin then YGraphMin := Y; + UpdateMinMax(X, FXGraphMin, FXGraphMax); + UpdateMinMax(Y, FYGraphMin, FYGraphMax); UpdateParentChart; end;