TAChart: Add TChartAxisIntervalParams.Tolerance property

git-svn-id: trunk@34818 -
This commit is contained in:
ask 2012-01-20 11:37:38 +00:00
parent eee642144f
commit f917cbd144
3 changed files with 25 additions and 9 deletions

View File

@ -45,6 +45,7 @@ type
FOptions: TAxisIntervalParamOptions; FOptions: TAxisIntervalParamOptions;
FOwner: TPersistent; FOwner: TPersistent;
FStepValues: TDoubleDynArray; FStepValues: TDoubleDynArray;
FTolerance: Cardinal;
function NiceStepsIsStored: Boolean; function NiceStepsIsStored: Boolean;
procedure ParseNiceSteps; procedure ParseNiceSteps;
procedure SetCount(AValue: Integer); procedure SetCount(AValue: Integer);
@ -52,6 +53,7 @@ type
procedure SetMinLength(AValue: Integer); procedure SetMinLength(AValue: Integer);
procedure SetNiceSteps(const AValue: String); procedure SetNiceSteps(const AValue: String);
procedure SetOptions(AValue: TAxisIntervalParamOptions); procedure SetOptions(AValue: TAxisIntervalParamOptions);
procedure SetTolerance(AValue: Cardinal);
strict protected strict protected
procedure Changed; virtual; procedure Changed; virtual;
protected protected
@ -68,6 +70,7 @@ type
read FNiceSteps write SetNiceSteps stored NiceStepsIsStored; read FNiceSteps write SetNiceSteps stored NiceStepsIsStored;
property Options: TAxisIntervalParamOptions property Options: TAxisIntervalParamOptions
read FOptions write SetOptions default DEF_INTERVAL_OPTIONS; read FOptions write SetOptions default DEF_INTERVAL_OPTIONS;
property Tolerance: Cardinal read FTolerance write SetTolerance default 0;
end; end;
type type
@ -360,6 +363,13 @@ begin
Changed; Changed;
end; end;
procedure TChartAxisIntervalParams.SetTolerance(AValue: Cardinal);
begin
if FTolerance = AValue then exit;
FTolerance := AValue;
Changed;
end;
{ TChartDataItem } { TChartDataItem }
function TChartDataItem.GetY(AIndex: Integer): Double; function TChartDataItem.GetY(AIndex: Integer): Double;

View File

@ -32,7 +32,7 @@ type
strict private strict private
FParams: TChartAxisIntervalParams; FParams: TChartAxisIntervalParams;
procedure RoundToImage( procedure RoundToImage(
AParams: TValuesInRangeParams; var AValues: TChartValueTextArray); const AParams: TValuesInRangeParams; var AValues: TChartValueTextArray);
procedure SetParams(AValue: TChartAxisIntervalParams); procedure SetParams(AValue: TChartAxisIntervalParams);
strict protected strict protected
procedure CalculateIntervals( procedure CalculateIntervals(
@ -274,21 +274,26 @@ begin
end; end;
procedure TIntervalChartSource.RoundToImage( procedure TIntervalChartSource.RoundToImage(
AParams: TValuesInRangeParams; var AValues: TChartValueTextArray); const AParams: TValuesInRangeParams; var AValues: TChartValueTextArray);
const
MAX_DIGITS = 17; function A2I(AX: Double): Integer; inline;
begin
Result := AParams.FGraphToImage(AParams.FAxisToGraph(AX));
end;
var var
i, x, d: Integer; i, x: Integer;
v, p, rv: Double; v, p, rv: Double;
begin begin
if AParams.FIntervals.Tolerance = 0 then exit;
for i := 0 to High(AValues) do begin for i := 0 to High(AValues) do begin
v := AValues[i].FValue; v := AValues[i].FValue;
if v = 0 then continue; if v = 0 then continue;
x := AParams.ToImage(v); x := A2I(v);
p := Power(10, Floor(Log10(Abs(v))) - MAX_DIGITS); p := Power(10, Floor(Log10(Abs(v)) - Log10(High(Int64)) + 1));
for d := 1 to MAX_DIGITS do begin while true do begin
rv := Round(v / p) * p; rv := Round(v / p) * p;
if AParams.ToImage(rv) <> x then break; if Cardinal(Abs(A2I(rv) - x)) >= AParams.FIntervals.Tolerance then break;
v := rv; v := rv;
p *= 10; p *= 10;
end; end;

View File

@ -457,6 +457,7 @@ begin
AssertValueEquals([20, 30, 40, 50, 60, 70], r); AssertValueEquals([20, 30, 40, 50, 60, 70], r);
src.Params.Options := [aipUseCount]; src.Params.Options := [aipUseCount];
src.Params.Count := 7; src.Params.Count := 7;
src.Params.Tolerance := 1;
src.ValuesInRange(p, r); src.ValuesInRange(p, r);
AssertValueEquals([24, 30, 36, 41, 47, 52, 58, 63, 69, 75], r); AssertValueEquals([24, 30, 36, 41, 47, 52, 58, 63, 69, 75], r);
finally finally