TAChart: Add TRandomChartSource.YNanPercent property

git-svn-id: trunk@41770 -
This commit is contained in:
ask 2013-06-20 00:39:58 +00:00
parent 26622f6def
commit f0b282dbd0
2 changed files with 17 additions and 2 deletions

View File

@ -57,6 +57,8 @@ type
TChartDistance = 0..MaxInt; TChartDistance = 0..MaxInt;
TPercent = 0..100;
TPointDistFunc = function (const A, B: TPoint): Integer; TPointDistFunc = function (const A, B: TPoint): Integer;
TTransformFunc = function (A: Double): Double of object; TTransformFunc = function (A: Double): Double of object;

View File

@ -96,6 +96,7 @@ type
FXMin: Double; FXMin: Double;
FYMax: Double; FYMax: Double;
FYMin: Double; FYMin: Double;
FYNanPercent: TPercent;
strict private strict private
FCurIndex: Integer; FCurIndex: Integer;
FCurItem: TChartDataItem; FCurItem: TChartDataItem;
@ -108,6 +109,7 @@ type
procedure SetXMin(AValue: Double); procedure SetXMin(AValue: Double);
procedure SetYMax(AValue: Double); procedure SetYMax(AValue: Double);
procedure SetYMin(AValue: Double); procedure SetYMin(AValue: Double);
procedure SetYNanPercent(AValue: TPercent);
protected protected
function GetCount: Integer; override; function GetCount: Integer; override;
function GetItem(AIndex: Integer): PChartDataItem; override; function GetItem(AIndex: Integer): PChartDataItem; override;
@ -127,6 +129,7 @@ type
property YCount; property YCount;
property YMax: Double read FYMax write SetYMax; property YMax: Double read FYMax write SetYMax;
property YMin: Double read FYMin write SetYMin; property YMin: Double read FYMin write SetYMin;
property YNanPercent: TPercent read FYNanPercent write SetYNanPercent default 0;
end; end;
TUserDefinedChartSource = class; TUserDefinedChartSource = class;
@ -740,7 +743,9 @@ function TRandomChartSource.GetItem(AIndex: Integer): PChartDataItem;
function GetRandomY: Double; function GetRandomY: Double;
begin begin
if YMax <= YMin then if (YNanPercent > 0) and (FRNG.GetInRange(0, 100) <= YNanPercent) then
Result := SafeNan
else if YMax <= YMin then
Result := YMin Result := YMin
else else
Result := FRNG.Get / High(LongWord) * (YMax - YMin) + YMin; Result := FRNG.Get / High(LongWord) * (YMax - YMin) + YMin;
@ -754,7 +759,7 @@ begin
FCurIndex := -1; FCurIndex := -1;
end; end;
while FCurIndex < AIndex do begin while FCurIndex < AIndex do begin
Inc(FCurIndex); FCurIndex += 1;
if XMax <= XMin then if XMax <= XMin then
FCurItem.X := XMin FCurItem.X := XMin
else begin else begin
@ -845,6 +850,14 @@ begin
Notify; Notify;
end; end;
procedure TRandomChartSource.SetYNanPercent(AValue: TPercent);
begin
if FYNanPercent = AValue then exit;
FYNanPercent := AValue;
InvalidateCaches;
Notify;
end;
{ TUserDefinedChartSource } { TUserDefinedChartSource }
procedure TUserDefinedChartSource.EndUpdate; procedure TUserDefinedChartSource.EndUpdate;