TAChart: Add new property RandomColors to TRandomChartSource.

This commit is contained in:
wp_xyz 2022-01-30 13:52:31 +01:00
parent 5b7387ddd5
commit 34f156c0b9

View File

@ -149,6 +149,7 @@ type
TRandomChartSource = class(TCustomChartSource)
strict private
FPointsNumber: Integer;
FRandomColors: Boolean;
FRandomX: Boolean;
FRandSeed: Integer;
FXMax: Double;
@ -163,6 +164,7 @@ type
procedure Reset;
procedure SetPointsNumber(AValue: Integer);
procedure SetRandomColors(AValue: Boolean);
procedure SetRandomX(AValue: Boolean);
procedure SetRandSeed(AValue: Integer);
procedure SetXMax(const AValue: Double);
@ -182,8 +184,8 @@ type
public
function IsSorted: Boolean; override;
published
property PointsNumber: Integer
read FPointsNumber write SetPointsNumber default 0;
property PointsNumber: Integer read FPointsNumber write SetPointsNumber default 0;
property RandomColors: Boolean read FRandomColors write SetRandomColors default false;
property RandomX: Boolean read FRandomX write SetRandomX default false;
property RandSeed: Integer read FRandSeed write SetRandSeed;
property XCount;
@ -1262,6 +1264,11 @@ end;
function TRandomChartSource.GetItem(AIndex: Integer): PChartDataItem;
function GetRandomColor: TChartColor;
begin
Result := FRNG.Get and $00FFFFFF;
end;
function GetRandomX: Double;
begin
Result := FRNG.Get / High(LongWord) * (XMax - XMin) + XMin;
@ -1329,6 +1336,8 @@ begin
end;
end;
end;
if FRandomColors then
FCurItem.Color := GetRandomColor;;
end;
Result := @FCurItem;
end;
@ -1352,6 +1361,13 @@ begin
Reset;
end;
procedure TRandomChartSource.SetRandomColors(AValue: Boolean);
begin
if FRandomColors = AValue then exit;
FRandomColors := AValue;
Reset;
end;
procedure TRandomChartSource.SetRandomX(AValue: Boolean);
begin
if FRandomX = AValue then exit;