mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 17:52:59 +02:00
TAChart: Add TeeChart-compatible TChartAxis.Logarithmic property
git-svn-id: trunk@36926 -
This commit is contained in:
parent
362e4674d2
commit
b6b8f83df3
@ -25,7 +25,7 @@ interface
|
|||||||
uses
|
uses
|
||||||
Classes, SysUtils,
|
Classes, SysUtils,
|
||||||
TAGraph, TAChartAxis, TAChartAxisUtils, TAChartUtils, TACustomSeries,
|
TAGraph, TAChartAxis, TAChartAxisUtils, TAChartUtils, TACustomSeries,
|
||||||
TASeries;
|
TASeries, TATransformations;
|
||||||
|
|
||||||
type
|
type
|
||||||
TChartTeeChart = class helper for TChart
|
TChartTeeChart = class helper for TChart
|
||||||
@ -54,7 +54,8 @@ type
|
|||||||
public
|
public
|
||||||
// Swap X and Y as TeeChart does.
|
// Swap X and Y as TeeChart does.
|
||||||
function AddXY(
|
function AddXY(
|
||||||
AX, AY: Double; AXLabel: String = ''; AColor: TChartColor = clTAColor): Integer; overload; inline;
|
AX, AY: Double; AXLabel: String = '';
|
||||||
|
AColor: TChartColor = clTAColor): Integer; overload; inline;
|
||||||
published
|
published
|
||||||
property AxisIndexX default 0;
|
property AxisIndexX default 0;
|
||||||
property AxisIndexY default 1;
|
property AxisIndexY default 1;
|
||||||
@ -73,8 +74,92 @@ type
|
|||||||
property Style: TChartSeriesStyle read GetStyle write SetStyle default [];
|
property Style: TChartSeriesStyle read GetStyle write SetStyle default [];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TChartAxisTeeChart = class helper for TChartAxis
|
||||||
|
strict private
|
||||||
|
function GetLogarithmic: Boolean;
|
||||||
|
procedure SetLogarithmic(AValue: Boolean);
|
||||||
|
published
|
||||||
|
property Logarithmic: Boolean
|
||||||
|
read GetLogarithmic write SetLogarithmic default false;
|
||||||
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
uses
|
||||||
|
Math;
|
||||||
|
|
||||||
|
type
|
||||||
|
TLogTransformEnumerator = class(TAxisTransformEnumerator)
|
||||||
|
function GetCurrent: TLogarithmAxisTransform;
|
||||||
|
function MoveNext: Boolean;
|
||||||
|
property Current: TLogarithmAxisTransform read GetCurrent;
|
||||||
|
function GetEnumerator: TLogTransformEnumerator;
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
VLogTransforms: array of TChartAxisTransformations;
|
||||||
|
|
||||||
|
function AddLogTransforms: TChartAxisTransformations;
|
||||||
|
begin
|
||||||
|
Result := TChartAxisTransformations.Create(nil);
|
||||||
|
TLogarithmAxisTransform.Create(nil).Transformations := Result;
|
||||||
|
SetLength(VLogTransforms, Length(VLogTransforms) + 1);
|
||||||
|
VLogTransforms[High(VLogTransforms)] := Result;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure FreeLogTransforms;
|
||||||
|
var
|
||||||
|
t: TChartAxisTransformations;
|
||||||
|
begin
|
||||||
|
for t in VLogTransforms do
|
||||||
|
t.Free;
|
||||||
|
VLogTransforms := nil;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TLogTransformEnumerator }
|
||||||
|
|
||||||
|
function TLogTransformEnumerator.GetCurrent: TLogarithmAxisTransform;
|
||||||
|
begin
|
||||||
|
Result := inherited GetCurrent as TLogarithmAxisTransform;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TLogTransformEnumerator.GetEnumerator: TLogTransformEnumerator;
|
||||||
|
begin
|
||||||
|
Result := Self;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TLogTransformEnumerator.MoveNext: Boolean;
|
||||||
|
begin
|
||||||
|
repeat
|
||||||
|
Result := inherited MoveNext;
|
||||||
|
until Result and (inherited GetCurrent is TLogarithmAxisTransform);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TChartAxisTeeChart }
|
||||||
|
|
||||||
|
function TChartAxisTeeChart.GetLogarithmic: Boolean;
|
||||||
|
var
|
||||||
|
t: TLogarithmAxisTransform;
|
||||||
|
begin
|
||||||
|
if Transformations <> nil then
|
||||||
|
for t in TLogTransformEnumerator.Create(Transformations.List) do
|
||||||
|
if t.Enabled then
|
||||||
|
exit(true);
|
||||||
|
Result := false;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TChartAxisTeeChart.SetLogarithmic(AValue: Boolean);
|
||||||
|
var
|
||||||
|
t: TLogarithmAxisTransform;
|
||||||
|
begin
|
||||||
|
Intervals.Tolerance := IfThen(AValue, 2, 0);
|
||||||
|
if Transformations <> nil then
|
||||||
|
for t in TLogTransformEnumerator.Create(Transformations.List) do
|
||||||
|
t.Enabled := AValue
|
||||||
|
else if AValue then
|
||||||
|
Transformations := AddLogTransforms;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TCustomChartSeriesTeeChart }
|
{ TCustomChartSeriesTeeChart }
|
||||||
|
|
||||||
function TCustomChartSeriesTeeChart.GetStyle: TChartSeriesStyle;
|
function TCustomChartSeriesTeeChart.GetStyle: TChartSeriesStyle;
|
||||||
@ -119,8 +204,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
|
|
||||||
Dummy;
|
Dummy;
|
||||||
|
|
||||||
|
finalization
|
||||||
|
FreeLogTransforms;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user