mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-10 08:16:04 +02:00
TAChart: Initial implementation of TChartAxisIntervalParams.
Does not do anything useful yet. git-svn-id: trunk@31836 -
This commit is contained in:
parent
cf6ddb9fb0
commit
c52dc587e2
@ -24,6 +24,49 @@ interface
|
||||
uses
|
||||
Classes, Types, TAChartUtils;
|
||||
|
||||
|
||||
const
|
||||
DEF_INTERVAL_STEPS = '0.2|0.5|1.0';
|
||||
|
||||
type
|
||||
TAxisIntervalParamOption = (
|
||||
aipUseCount, aipUseMaxLength, aipUseMinLength, aipUseNiceSteps);
|
||||
|
||||
TAxisIntervalParamOptions = set of TAxisIntervalParamOption;
|
||||
|
||||
TChartAxisIntervalParams = class(TPersistent)
|
||||
strict private
|
||||
FCount: Integer;
|
||||
FMaxLength: Integer;
|
||||
FMinLength: Integer;
|
||||
FNiceSteps: String;
|
||||
FStepValues: TDoubleDynArray;
|
||||
FOptions: TAxisIntervalParamOptions;
|
||||
FOwner: TPersistent;
|
||||
function NiceStepsIsStored: Boolean;
|
||||
procedure ParseNiceSteps;
|
||||
procedure SetCount(AValue: Integer);
|
||||
procedure SetMaxLength(AValue: Integer);
|
||||
procedure SetMinLength(AValue: Integer);
|
||||
procedure SetNiceSteps(const AValue: String);
|
||||
procedure SetOptions(AValue: TAxisIntervalParamOptions);
|
||||
strict protected
|
||||
procedure Changed; virtual;
|
||||
protected
|
||||
function GetOwner: TPersistent; override;
|
||||
public
|
||||
constructor Create(AOwner: TPersistent);
|
||||
property StepValues: TDoubleDynArray read FStepValues;
|
||||
published
|
||||
property Count: Integer read FCount write SetCount default 5;
|
||||
property MaxLength: Integer read FMaxLength write SetMaxLength default 100;
|
||||
property MinLength: Integer read FMinLength write SetMinLength default 5;
|
||||
property NiceSteps: String
|
||||
read FNiceSteps write SetNiceSteps stored NiceStepsIsStored;
|
||||
property Options: TAxisIntervalParamOptions
|
||||
read FOptions write SetOptions default [];
|
||||
end;
|
||||
|
||||
type
|
||||
EBufferError = class(EChartError);
|
||||
EEditableSourceRequired = class(EChartError);
|
||||
@ -125,7 +168,7 @@ procedure SetDataItemDefaults(var AItem: TChartDataItem);
|
||||
implementation
|
||||
|
||||
uses
|
||||
Math, SysUtils;
|
||||
Math, StrUtils, SysUtils;
|
||||
|
||||
procedure SetDataItemDefaults(var AItem: TChartDataItem);
|
||||
var
|
||||
@ -139,6 +182,86 @@ begin
|
||||
AItem.YList[i] := 0;
|
||||
end;
|
||||
|
||||
{ TChartAxisIntervalParams }
|
||||
|
||||
procedure TChartAxisIntervalParams.Changed;
|
||||
begin
|
||||
// Empty.
|
||||
end;
|
||||
|
||||
constructor TChartAxisIntervalParams.Create(AOwner: TPersistent);
|
||||
begin
|
||||
FOwner := AOwner;
|
||||
SetPropDefaults(Self, ['Count', 'MaxLength', 'MinLength', 'Options']);
|
||||
FNiceSteps := DEF_INTERVAL_STEPS;
|
||||
ParseNiceSteps;
|
||||
end;
|
||||
|
||||
function TChartAxisIntervalParams.GetOwner: TPersistent;
|
||||
begin
|
||||
Result := FOwner;
|
||||
end;
|
||||
|
||||
function TChartAxisIntervalParams.NiceStepsIsStored: Boolean;
|
||||
begin
|
||||
Result := NiceSteps <> DEF_INTERVAL_STEPS;
|
||||
end;
|
||||
|
||||
procedure TChartAxisIntervalParams.ParseNiceSteps;
|
||||
var
|
||||
parts: TStringList;
|
||||
i: Integer;
|
||||
begin
|
||||
parts := TStringList.Create;
|
||||
try
|
||||
parts.Delimiter := '|';
|
||||
parts.StrictDelimiter := true;
|
||||
parts.DelimitedText := IfThen(NiceSteps = '', DEF_INTERVAL_STEPS, NiceSteps);
|
||||
SetLength(FStepValues, parts.Count);
|
||||
for i := 0 to parts.Count - 1 do
|
||||
FStepValues[i] := StrToFloatDefSep(parts[i]);
|
||||
finally
|
||||
parts.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TChartAxisIntervalParams.SetCount(AValue: Integer);
|
||||
begin
|
||||
if FCount = AValue then exit;
|
||||
FCount := AValue;
|
||||
Changed;
|
||||
end;
|
||||
|
||||
procedure TChartAxisIntervalParams.SetMaxLength(AValue: Integer);
|
||||
begin
|
||||
if FMaxLength = AValue then exit;
|
||||
FMaxLength := AValue;
|
||||
Changed;
|
||||
end;
|
||||
|
||||
procedure TChartAxisIntervalParams.SetMinLength(AValue: Integer);
|
||||
begin
|
||||
if FMinLength = AValue then exit;
|
||||
FMinLength := AValue;
|
||||
Changed;
|
||||
end;
|
||||
|
||||
procedure TChartAxisIntervalParams.SetNiceSteps(const AValue: String);
|
||||
begin
|
||||
if FNiceSteps = AValue then exit;
|
||||
FNiceSteps := AValue;
|
||||
ParseNiceSteps;
|
||||
Changed;
|
||||
end;
|
||||
|
||||
procedure TChartAxisIntervalParams.SetOptions(
|
||||
AValue: TAxisIntervalParamOptions);
|
||||
begin
|
||||
if FOptions = AValue then exit;
|
||||
FOptions := AValue;
|
||||
Changed;
|
||||
end;
|
||||
|
||||
{ TChartDataItem }
|
||||
|
||||
function TChartDataItem.GetY(AIndex: Integer): Double;
|
||||
|
@ -28,14 +28,22 @@ type
|
||||
{ TIntervalChartSource }
|
||||
|
||||
TIntervalChartSource = class(TCustomChartSource)
|
||||
strict private
|
||||
FParams: TChartAxisIntervalParams;
|
||||
procedure SetParams(AValue: TChartAxisIntervalParams);
|
||||
protected
|
||||
function GetCount: Integer; override;
|
||||
function GetItem(AIndex: Integer): PChartDataItem; override;
|
||||
procedure SetYCount(AValue: Cardinal); override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
|
||||
procedure ValuesInRange(
|
||||
AMin, AMax: Double; const AFormat: String; AUseY: Boolean;
|
||||
var AValues: TChartValueTextArray); override;
|
||||
published
|
||||
property Params: TChartAxisIntervalParams read FParams write SetParams;
|
||||
end;
|
||||
|
||||
TDateTimeStep = (
|
||||
@ -52,7 +60,7 @@ type
|
||||
{ TDateTimeIntervalChartSource }
|
||||
|
||||
TDateTimeIntervalChartSource = class(TIntervalChartSource)
|
||||
private
|
||||
strict private
|
||||
FDateTimeFormat: String;
|
||||
FSteps: TDateTimeSteps;
|
||||
public
|
||||
@ -74,6 +82,12 @@ implementation
|
||||
uses
|
||||
DateUtils, Math, StrUtils, SysUtils;
|
||||
|
||||
type
|
||||
TSourceIntervalParams = class(TChartAxisIntervalParams)
|
||||
strict protected
|
||||
procedure Changed; override;
|
||||
end;
|
||||
|
||||
procedure CalculateIntervals(
|
||||
AMin, AMax: Double; AxisScale: TAxisScale; out AStart, AStep: Double);
|
||||
var
|
||||
@ -186,8 +200,30 @@ begin
|
||||
]);
|
||||
end;
|
||||
|
||||
{ TSourceIntervalParams }
|
||||
|
||||
procedure TSourceIntervalParams.Changed;
|
||||
begin
|
||||
with GetOwner as TCustomChartSource do begin
|
||||
BeginUpdate;
|
||||
EndUpdate;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TIntervalChartSource }
|
||||
|
||||
constructor TIntervalChartSource.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FParams := TChartAxisIntervalParams.Create(Self);
|
||||
end;
|
||||
|
||||
destructor TIntervalChartSource.Destroy;
|
||||
begin
|
||||
FreeAndNil(FParams);
|
||||
inherited;
|
||||
end;
|
||||
|
||||
function TIntervalChartSource.GetCount: Integer;
|
||||
begin
|
||||
Result := 0;
|
||||
@ -199,6 +235,12 @@ begin
|
||||
Result := nil;
|
||||
end;
|
||||
|
||||
procedure TIntervalChartSource.SetParams(AValue: TChartAxisIntervalParams);
|
||||
begin
|
||||
if FParams = AValue then exit;
|
||||
FParams.Assign(AValue);
|
||||
end;
|
||||
|
||||
procedure TIntervalChartSource.SetYCount(AValue: Cardinal);
|
||||
begin
|
||||
Unused(AValue);
|
||||
|
Loading…
Reference in New Issue
Block a user