mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-02 19:24:46 +01:00
TAChart: Add TIntervalChartSource class. Use it as the default source for axis marks.
git-svn-id: trunk@24574 -
This commit is contained in:
parent
d0954af332
commit
3eeaff3825
@ -84,6 +84,7 @@ type
|
||||
TChartAxisMarks = class(
|
||||
specialize TGenericChartMarks<TChartAxisBrush, TChartPen, TChartAxisFramePen>)
|
||||
private
|
||||
FDefaultSource: TIntervalChartSource;
|
||||
FListener: TListener;
|
||||
FSource: TCustomChartSource;
|
||||
function IsFormatStored: Boolean;
|
||||
@ -91,6 +92,8 @@ type
|
||||
public
|
||||
constructor Create(AOwner: TCustomChart);
|
||||
destructor Destroy; override;
|
||||
|
||||
function SourceDef: TCustomChartSource;
|
||||
published
|
||||
property Distance default 1;
|
||||
property Format stored IsFormatStored;
|
||||
@ -277,6 +280,7 @@ end;
|
||||
constructor TChartAxisMarks.Create(AOwner: TCustomChart);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FDefaultSource := TIntervalChartSource.Create(AOwner);
|
||||
FDistance := 1;
|
||||
FFrame.Style := psClear;
|
||||
FLabelBrush.Style := bsClear;
|
||||
@ -288,6 +292,7 @@ end;
|
||||
destructor TChartAxisMarks.Destroy;
|
||||
begin
|
||||
FListener.Free;
|
||||
FDefaultSource.Free;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
@ -307,6 +312,13 @@ begin
|
||||
StyleChanged(Self);
|
||||
end;
|
||||
|
||||
function TChartAxisMarks.SourceDef: TCustomChartSource;
|
||||
begin
|
||||
Result := FSource;
|
||||
if Result = nil then
|
||||
Result := FDefaultSource;
|
||||
end;
|
||||
|
||||
{ TChartAxis }
|
||||
|
||||
procedure TChartAxis.Assign(Source: TPersistent);
|
||||
@ -484,15 +496,8 @@ begin
|
||||
AMax := GetTransform.GraphToAxis(AMax);
|
||||
if AMin > AMax then
|
||||
Exchange(AMin, AMax);
|
||||
if Marks.Source = nil then begin
|
||||
FMarkValues := GetIntervals(AMin, AMax, false);
|
||||
SetLength(FMarkTexts, Length(FMarkValues));
|
||||
for i := 0 to High(FMarkValues) do
|
||||
FMarkTexts[i] := Format(Marks.Format, [FMarkValues[i]]);
|
||||
end
|
||||
else
|
||||
Marks.Source.ValuesInInterval(
|
||||
AMin, AMax, Marks.Format, IsVertical, FMarkValues, FMarkTexts);
|
||||
Marks.SourceDef.ValuesInInterval(
|
||||
AMin, AMax, Marks.Format, IsVertical, FMarkValues, FMarkTexts);
|
||||
if Inverted then
|
||||
for i := 0 to High(FMarkValues) div 2 do begin
|
||||
Exchange(FMarkValues[i], FMarkValues[High(FMarkValues) - i]);
|
||||
|
||||
@ -63,7 +63,7 @@ type
|
||||
function FormatItem(const AFormat: String; AIndex: Integer): String;
|
||||
procedure ValuesInInterval(
|
||||
AMin, AMax: Double; const AFormat: String; AUseY: Boolean;
|
||||
out AValues: TDoubleDynArray; out ATexts: TStringDynArray);
|
||||
out AValues: TDoubleDynArray; out ATexts: TStringDynArray); virtual;
|
||||
function ValuesTotal: Double; virtual;
|
||||
function XOfMax: Double;
|
||||
function XOfMin: Double;
|
||||
@ -157,6 +157,18 @@ type
|
||||
property YMin: Double read FYMin write SetYMin;
|
||||
end;
|
||||
|
||||
{ TIntervalChartSource }
|
||||
|
||||
TIntervalChartSource = class(TCustomChartSource)
|
||||
protected
|
||||
function GetCount: Integer; override;
|
||||
function GetItem(AIndex: Integer): PChartDataItem; override;
|
||||
public
|
||||
procedure ValuesInInterval(
|
||||
AMin, AMax: Double; const AFormat: String; AUseY: Boolean;
|
||||
out AValues: TDoubleDynArray; out ATexts: TStringDynArray); override;
|
||||
end;
|
||||
|
||||
TUserDefinedChartSource = class;
|
||||
|
||||
TGetChartDataItemEvent = procedure (
|
||||
@ -751,6 +763,33 @@ begin
|
||||
Notify;
|
||||
end;
|
||||
|
||||
{ TIntervalChartSource }
|
||||
|
||||
function TIntervalChartSource.GetCount: Integer;
|
||||
begin
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
function TIntervalChartSource.GetItem(AIndex: Integer): PChartDataItem;
|
||||
begin
|
||||
Unused(AIndex);
|
||||
Result := nil;
|
||||
end;
|
||||
|
||||
procedure TIntervalChartSource.ValuesInInterval(
|
||||
AMin, AMax: Double; const AFormat: String; AUseY: Boolean;
|
||||
out AValues: TDoubleDynArray; out ATexts: TStringDynArray);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
Unused(AUseY);
|
||||
AValues := GetIntervals(AMin, AMax, false);
|
||||
SetLength(ATexts, Length(AValues));
|
||||
for i := 0 to High(AValues) do
|
||||
// Extra format arguments for compatibility with FormatItem.
|
||||
ATexts[i] := Format(AFormat, [AValues[i], 0.0, '', 0.0, 0.0]);
|
||||
end;
|
||||
|
||||
{ TUserDefinedChartSource }
|
||||
|
||||
function TUserDefinedChartSource.GetCount: Integer;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user