TAChart: Fix AreaSeries drawing inverted area if it extends down to -Inf.

git-svn-id: branches/fixes_2_0@60181 -
This commit is contained in:
mattias 2019-01-24 09:44:08 +00:00
parent 7bba9a748a
commit 651746a306
2 changed files with 31 additions and 4 deletions

View File

@ -35,6 +35,10 @@ const
DEFAULT_FONT_SIZE = 10;
DEFAULT_EPSILON = 1e-6;
// Replacement for +INF, Canvas does not work correctly when MaxInt is used.
// Any screen coordinates are clipped to range -MAX_COORD ... MAX_COORD.
MAX_COORD = 100*1000*1000;
type
EChartError = class(Exception);
EChartIntervalError = class(EChartError);
@ -331,6 +335,7 @@ procedure Exchange(var A, B: String); overload; inline;
function FormatIfNotEmpty(AFormat, AStr: String): String; inline;
function IfThen(ACond: Boolean; ATrue, AFalse: TObject): TObject; overload;
function ImgRoundChecked(A: Double): Integer; inline;
function InterpolateRGB(AColor1, AColor2: Integer; ACoeff: Double): Integer;
function IntToColorHex(AColor: Integer): String; inline;
function IsEquivalent(const A1, A2: Double): Boolean; inline;
@ -444,6 +449,11 @@ begin
Result := AFalse;
end;
function ImgRoundChecked(A: Double): Integer;
begin
Result := Round(EnsureRange(A, -MAX_COORD, MAX_COORD));
end;
function InterpolateRGB(AColor1, AColor2: Integer; ACoeff: Double): Integer;
type
TBytes = packed array [1..4] of Byte;

View File

@ -1847,24 +1847,41 @@ begin
s.VisitSources(AVisitor, AAxis, AData);
end;
function SgnInt(X: Double): Integer;
begin
if X > 0 then Result := +1
else if X < 0 then Result := -1
else Result := 0;
end;
function TChart.XGraphToImage(AX: Double): Integer;
begin
Result := RoundChecked(FScale.X * AX + FOffset.X);
Result := ImgRoundChecked(FScale.X * AX + FOffset.X);
end;
function TChart.XImageToGraph(AX: Integer): Double;
begin
Result := (AX - FOffset.X) / FScale.X;
if AX >= MAX_COORD then
Result := Infinity * SgnInt(FScale.X)
else if AX <= -MAX_COORD then
Result := -Infinity * SgnInt(FScale.X)
else
Result := (AX - FOffset.X) / FScale.X;
end;
function TChart.YGraphToImage(AY: Double): Integer;
begin
Result := RoundChecked(FScale.Y * AY + FOffset.Y);
Result := ImgRoundChecked(FScale.Y * AY + FOffset.Y);
end;
function TChart.YImageToGraph(AY: Integer): Double;
begin
Result := (AY - FOffset.Y) / FScale.Y;
if AY >= MAX_COORD then
Result := Infinity * SgnInt(FScale.Y)
else if AY <= -MAX_COORD then
Result := +Infinity * SgnInt(FScale.Y)
else
Result := (AY - FOffset.Y) / FScale.Y;
end;
procedure TChart.ZoomFull(AImmediateRecalc: Boolean);