mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 20:44:03 +02:00
TAChart: Activate new transformations code
git-svn-id: trunk@24435 -
This commit is contained in:
parent
08149cef06
commit
e2f5ade37d
@ -24,7 +24,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, Graphics, SysUtils, Types,
|
Classes, Graphics, SysUtils, Types,
|
||||||
TAChartUtils, TASources, TATypes;
|
TAChartUtils, TASources, TATransformations, TATypes;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -69,44 +69,6 @@ type
|
|||||||
property Style default psDot;
|
property Style default psDot;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TChartAxisTransformation }
|
|
||||||
|
|
||||||
TChartAxisTransformation = class(TPersistent)
|
|
||||||
private
|
|
||||||
FOnChanged: TNotifyEvent;
|
|
||||||
procedure SetOnChanged(const AValue: TNotifyEvent);
|
|
||||||
protected
|
|
||||||
procedure Changed;
|
|
||||||
public
|
|
||||||
function AxisToGraph(AX: Double): Double; virtual;
|
|
||||||
function GraphToAxis(AX: Double): Double; virtual;
|
|
||||||
|
|
||||||
property OnChanged: TNotifyEvent read FOnChanged write SetOnChanged;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TChartAxisLogLinearTransformation }
|
|
||||||
|
|
||||||
TChartAxisLogLinearTransformation = class(TChartAxisTransformation)
|
|
||||||
private
|
|
||||||
FLogarithmic: Boolean;
|
|
||||||
FOffset: Double;
|
|
||||||
FScale: Double;
|
|
||||||
procedure SetLogarithmic(AValue: Boolean);
|
|
||||||
procedure SetOffset(AValue: Double);
|
|
||||||
procedure SetScale(AValue: Double);
|
|
||||||
public
|
|
||||||
constructor Create;
|
|
||||||
public
|
|
||||||
procedure Assign(Source: TPersistent); override;
|
|
||||||
|
|
||||||
function AxisToGraph(AX: Double): Double; override;
|
|
||||||
function GraphToAxis(AX: Double): Double; override;
|
|
||||||
published
|
|
||||||
property Logarithmic: Boolean read FLogarithmic write SetLogarithmic default false;
|
|
||||||
property Offset: Double read FOffset write SetOffset;
|
|
||||||
property Scale: Double read FScale write SetScale;
|
|
||||||
end;
|
|
||||||
|
|
||||||
TChartAxisBrush = class(TBrush)
|
TChartAxisBrush = class(TBrush)
|
||||||
published
|
published
|
||||||
property Style default bsClear;
|
property Style default bsClear;
|
||||||
@ -140,6 +102,7 @@ type
|
|||||||
|
|
||||||
TChartAxis = class(TCollectionItem)
|
TChartAxis = class(TCollectionItem)
|
||||||
private
|
private
|
||||||
|
FDefaultTransformations: TChartAxisTransformations;
|
||||||
FMarkTexts: TStringDynArray;
|
FMarkTexts: TStringDynArray;
|
||||||
FMarkValues: TDoubleDynArray;
|
FMarkValues: TDoubleDynArray;
|
||||||
FSize: Integer;
|
FSize: Integer;
|
||||||
@ -155,9 +118,10 @@ type
|
|||||||
FTickColor: TColor;
|
FTickColor: TColor;
|
||||||
FTickLength: Integer;
|
FTickLength: Integer;
|
||||||
FTitle: TChartAxisTitle;
|
FTitle: TChartAxisTitle;
|
||||||
FTransformation: TChartAxisLogLinearTransformation;
|
FTransformations: TChartAxisTransformations;
|
||||||
FVisible: Boolean;
|
FVisible: Boolean;
|
||||||
|
|
||||||
|
function GetTransform: TChartAxisTransformations;
|
||||||
procedure SetAlignment(AValue: TChartAxisAlignment);
|
procedure SetAlignment(AValue: TChartAxisAlignment);
|
||||||
procedure SetGrid(AValue: TChartAxisPen);
|
procedure SetGrid(AValue: TChartAxisPen);
|
||||||
procedure SetInverted(AValue: Boolean);
|
procedure SetInverted(AValue: Boolean);
|
||||||
@ -166,7 +130,7 @@ type
|
|||||||
procedure SetTickColor(AValue: TColor);
|
procedure SetTickColor(AValue: TColor);
|
||||||
procedure SetTickLength(AValue: Integer);
|
procedure SetTickLength(AValue: Integer);
|
||||||
procedure SetTitle(AValue: TChartAxisTitle);
|
procedure SetTitle(AValue: TChartAxisTitle);
|
||||||
procedure SetTransformation(AValue: TChartAxisLogLinearTransformation);
|
procedure SetTransformations(AValue: TChartAxisTransformations);
|
||||||
procedure SetVisible(const AValue: Boolean);
|
procedure SetVisible(const AValue: Boolean);
|
||||||
|
|
||||||
procedure StyleChanged(ASender: TObject);
|
procedure StyleChanged(ASender: TObject);
|
||||||
@ -197,8 +161,8 @@ type
|
|||||||
property TickLength: Integer
|
property TickLength: Integer
|
||||||
read FTickLength write SetTickLength default DEF_TICK_LENGTH;
|
read FTickLength write SetTickLength default DEF_TICK_LENGTH;
|
||||||
property Title: TChartAxisTitle read FTitle write SetTitle;
|
property Title: TChartAxisTitle read FTitle write SetTitle;
|
||||||
property Transformation: TChartAxisLogLinearTransformation
|
property Transformations: TChartAxisTransformations
|
||||||
read FTransformation write SetTransformation;
|
read FTransformations write SetTransformations;
|
||||||
property Visible: Boolean read FVisible write SetVisible default true;
|
property Visible: Boolean read FVisible write SetVisible default true;
|
||||||
published
|
published
|
||||||
property OnMarkToText: TChartAxisMarkToTextEvent
|
property OnMarkToText: TChartAxisMarkToTextEvent
|
||||||
@ -331,6 +295,7 @@ end;
|
|||||||
constructor TChartAxis.Create(ACollection: TCollection);
|
constructor TChartAxis.Create(ACollection: TCollection);
|
||||||
begin
|
begin
|
||||||
inherited Create(ACollection);
|
inherited Create(ACollection);
|
||||||
|
FDefaultTransformations := TChartAxisTransformations.Create(nil);
|
||||||
FGrid := TChartAxisPen.Create;
|
FGrid := TChartAxisPen.Create;
|
||||||
FGrid.OnChange := @StyleChanged;
|
FGrid.OnChange := @StyleChanged;
|
||||||
FGrid.Style := psDot;
|
FGrid.Style := psDot;
|
||||||
@ -338,17 +303,16 @@ begin
|
|||||||
FTickColor := clBlack;
|
FTickColor := clBlack;
|
||||||
FTickLength := DEF_TICK_LENGTH;
|
FTickLength := DEF_TICK_LENGTH;
|
||||||
FTitle := TChartAxisTitle.Create(ACollection.Owner as TCustomChart);
|
FTitle := TChartAxisTitle.Create(ACollection.Owner as TCustomChart);
|
||||||
FTransformation := TChartAxisLogLinearTransformation.Create;
|
//FTransformation.OnChanged := @StyleChanged;
|
||||||
FTransformation.OnChanged := @StyleChanged;
|
|
||||||
FVisible := true;
|
FVisible := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TChartAxis.Destroy;
|
destructor TChartAxis.Destroy;
|
||||||
begin
|
begin
|
||||||
FTransformation.Free;
|
|
||||||
FTitle.Free;
|
FTitle.Free;
|
||||||
FMarks.Free;
|
FMarks.Free;
|
||||||
FGrid.Free;
|
FGrid.Free;
|
||||||
|
FDefaultTransformations.Free;
|
||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -420,7 +384,7 @@ procedure TChartAxis.Draw(
|
|||||||
if AMin = AMax then exit;
|
if AMin = AMax then exit;
|
||||||
coord := SideByAlignment(ARect, Alignment, FSize);
|
coord := SideByAlignment(ARect, Alignment, FSize);
|
||||||
for i := 0 to High(FMarkValues) do begin
|
for i := 0 to High(FMarkValues) do begin
|
||||||
v := Transformation.AxisToGraph(FMarkValues[i]);
|
v := GetTransform.AxisToGraph(FMarkValues[i]);
|
||||||
if IsVertical then
|
if IsVertical then
|
||||||
DrawYMark(coord, v, FMarkTexts[i])
|
DrawYMark(coord, v, FMarkTexts[i])
|
||||||
else
|
else
|
||||||
@ -489,8 +453,8 @@ var
|
|||||||
i, count: Integer;
|
i, count: Integer;
|
||||||
v: Double;
|
v: Double;
|
||||||
begin
|
begin
|
||||||
AMin := Transformation.GraphToAxis(AMin);
|
AMin := GetTransform.GraphToAxis(AMin);
|
||||||
AMax := Transformation.GraphToAxis(AMax);
|
AMax := GetTransform.GraphToAxis(AMax);
|
||||||
if AMin > AMax then
|
if AMin > AMax then
|
||||||
Exchange(AMin, AMax);
|
Exchange(AMin, AMax);
|
||||||
if Marks.Source = nil then begin
|
if Marks.Source = nil then begin
|
||||||
@ -520,6 +484,13 @@ begin
|
|||||||
FOnMarkToText(FMarkTexts[i], FMarkValues[i]);
|
FOnMarkToText(FMarkTexts[i], FMarkValues[i]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TChartAxis.GetTransform: TChartAxisTransformations;
|
||||||
|
begin
|
||||||
|
Result := Transformations;
|
||||||
|
if Result = nil then
|
||||||
|
Result := FDefaultTransformations;
|
||||||
|
end;
|
||||||
|
|
||||||
function TChartAxis.IsVertical: Boolean; inline;
|
function TChartAxis.IsVertical: Boolean; inline;
|
||||||
begin
|
begin
|
||||||
Result := Alignment in [calLeft, calRight];
|
Result := Alignment in [calLeft, calRight];
|
||||||
@ -644,11 +615,10 @@ begin
|
|||||||
StyleChanged(Self);
|
StyleChanged(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TChartAxis.SetTransformation(
|
procedure TChartAxis.SetTransformations(AValue: TChartAxisTransformations);
|
||||||
AValue: TChartAxisLogLinearTransformation);
|
|
||||||
begin
|
begin
|
||||||
if FTransformation = AValue then exit;
|
if FTransformations = AValue then exit;
|
||||||
FTransformation.Assign(AValue);
|
FTransformations := AValue;
|
||||||
StyleChanged(Self);
|
StyleChanged(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -712,94 +682,13 @@ begin
|
|||||||
a.FAlignment := AXIS_INDEX[AIndex];
|
a.FAlignment := AXIS_INDEX[AIndex];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TChartAxisTransformation }
|
|
||||||
|
|
||||||
function TChartAxisTransformation.AxisToGraph(AX: Double): Double;
|
|
||||||
begin
|
|
||||||
Result := AX;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TChartAxisTransformation.Changed;
|
|
||||||
begin
|
|
||||||
if Assigned(FOnChanged) then
|
|
||||||
FOnChanged(Self);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TChartAxisTransformation.GraphToAxis(AX: Double): Double;
|
|
||||||
begin
|
|
||||||
Result := AX;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TChartAxisTransformation.SetOnChanged(const AValue: TNotifyEvent);
|
|
||||||
begin
|
|
||||||
if TMethod(FOnChanged) = TMethod(AValue) then exit;
|
|
||||||
FOnChanged := AValue;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TChartAxisLogLinearTransformation }
|
|
||||||
|
|
||||||
procedure TChartAxisLogLinearTransformation.Assign(Source: TPersistent);
|
|
||||||
begin
|
|
||||||
if Source is TChartAxisLogLinearTransformation then
|
|
||||||
with Source as TChartAxisLogLinearTransformation do begin
|
|
||||||
Self.Logarithmic := Logarithmic;
|
|
||||||
Self.Offset := Offset;
|
|
||||||
Self.Scale := Scale;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TChartAxisLogLinearTransformation.AxisToGraph(AX: Double): Double;
|
|
||||||
begin
|
|
||||||
if not Logarithmic then
|
|
||||||
Result := AX
|
|
||||||
else if AX > 0 then
|
|
||||||
Result := Ln(AX)
|
|
||||||
else
|
|
||||||
Result := NegInfinity;
|
|
||||||
Result := Result * Scale + Offset;
|
|
||||||
end;
|
|
||||||
|
|
||||||
constructor TChartAxisLogLinearTransformation.Create;
|
|
||||||
begin
|
|
||||||
inherited Create;
|
|
||||||
FScale := 1.0;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TChartAxisLogLinearTransformation.GraphToAxis(AX: Double): Double;
|
|
||||||
begin
|
|
||||||
Result := (AX - Offset) / Scale;
|
|
||||||
if Logarithmic then
|
|
||||||
Result := Exp(AX);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TChartAxisLogLinearTransformation.SetLogarithmic(AValue: Boolean);
|
|
||||||
begin
|
|
||||||
if FLogarithmic = AValue then exit;
|
|
||||||
FLogarithmic := AValue;
|
|
||||||
Changed;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TChartAxisLogLinearTransformation.SetOffset(AValue: Double);
|
|
||||||
begin
|
|
||||||
if FOffset = AValue then exit;
|
|
||||||
FOffset := AValue;
|
|
||||||
Changed;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TChartAxisLogLinearTransformation.SetScale(AValue: Double);
|
|
||||||
begin
|
|
||||||
if FScale = AValue then exit;
|
|
||||||
FScale := AValue;
|
|
||||||
if FScale = 0 then FScale := 1.0;
|
|
||||||
Changed;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure SkipObsoleteAxisProperties;
|
procedure SkipObsoleteAxisProperties;
|
||||||
const
|
const
|
||||||
TRANSFORM_NOTE = 'Obsolete, use Transformation instead';
|
TRANSFORM_NOTE = 'Obsolete, use Transformations instead';
|
||||||
begin
|
begin
|
||||||
RegisterPropertyToSkip(TChartAxis, 'Offset', TRANSFORM_NOTE, '');
|
RegisterPropertyToSkip(TChartAxis, 'Offset', TRANSFORM_NOTE, '');
|
||||||
RegisterPropertyToSkip(TChartAxis, 'Scale', TRANSFORM_NOTE, '');
|
RegisterPropertyToSkip(TChartAxis, 'Scale', TRANSFORM_NOTE, '');
|
||||||
|
RegisterPropertyToSkip(TChartAxis, 'Transformation', TRANSFORM_NOTE, '');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
|
@ -147,18 +147,19 @@ type
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Math, TAChartAxis;
|
Math, TAChartAxis, TATransformations;
|
||||||
|
|
||||||
var
|
var
|
||||||
VIdentityTransformation: TChartAxisTransformation;
|
VIdentityTransform: TChartAxisTransformations;
|
||||||
|
|
||||||
function TransformationByAxis(
|
function TransformationByAxis(
|
||||||
AChart: TChart; AAxisIndex: Integer): TChartAxisTransformation;
|
AChart: TChart; AAxisIndex: Integer): TChartAxisTransformations;
|
||||||
begin
|
begin
|
||||||
|
Result := nil;
|
||||||
if InRange(AAxisIndex, 0, AChart.AxisList.Count - 1) then
|
if InRange(AAxisIndex, 0, AChart.AxisList.Count - 1) then
|
||||||
Result := AChart.AxisList[AAxisIndex].Transformation
|
Result := AChart.AxisList[AAxisIndex].Transformations;
|
||||||
else
|
if Result = nil then
|
||||||
Result := VIdentityTransformation;
|
Result := VIdentityTransform;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -582,8 +583,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
VIdentityTransformation := TChartAxisTransformation.Create;
|
VIdentityTransform := TChartAxisTransformations.Create(nil);
|
||||||
finalization
|
finalization
|
||||||
VIdentityTransformation.Free;
|
VIdentityTransform.Free;
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -79,6 +79,9 @@ type
|
|||||||
public
|
public
|
||||||
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
|
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
|
||||||
procedure SetChildOrder(Child: TComponent; Order: Integer); override;
|
procedure SetChildOrder(Child: TComponent; Order: Integer); override;
|
||||||
|
public
|
||||||
|
function AxisToGraph(AX: Double): Double;
|
||||||
|
function GraphToAxis(AX: Double): Double;
|
||||||
published
|
published
|
||||||
property List: TAxisTransformList read FList;
|
property List: TAxisTransformList read FList;
|
||||||
end;
|
end;
|
||||||
@ -351,6 +354,15 @@ end;
|
|||||||
|
|
||||||
{ TChartAxisTransformations }
|
{ TChartAxisTransformations }
|
||||||
|
|
||||||
|
function TChartAxisTransformations.AxisToGraph(AX: Double): Double;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
Result := AX;
|
||||||
|
for i := 0 to List.Count - 1 do
|
||||||
|
Result := TAxisTransform(List[i]).AxisToGraph(Result);
|
||||||
|
end;
|
||||||
|
|
||||||
constructor TChartAxisTransformations.Create(AOwner: TComponent);
|
constructor TChartAxisTransformations.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
@ -375,6 +387,15 @@ begin
|
|||||||
Proc(TAxisTransform(List[i]));
|
Proc(TAxisTransform(List[i]));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TChartAxisTransformations.GraphToAxis(AX: Double): Double;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
Result := AX;
|
||||||
|
for i := 0 to List.Count - 1 do
|
||||||
|
Result := TAxisTransform(List[i]).GraphToAxis(Result);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TChartAxisTransformations.SetChildOrder(
|
procedure TChartAxisTransformations.SetChildOrder(
|
||||||
Child: TComponent; Order: Integer);
|
Child: TComponent; Order: Integer);
|
||||||
var
|
var
|
||||||
|
Loading…
Reference in New Issue
Block a user