TAChart: Use broadacster/listener to update chart after changes in axis transformation

git-svn-id: trunk@24473 -
This commit is contained in:
ask 2010-04-06 15:35:21 +00:00
parent 10de772730
commit ce83bb5a91
2 changed files with 16 additions and 13 deletions

View File

@ -104,6 +104,7 @@ type
TChartAxis = class(TCollectionItem)
private
FListener: TListener;
FMarkTexts: TStringDynArray;
FMarkValues: TDoubleDynArray;
FSize: Integer;
@ -323,6 +324,7 @@ end;
constructor TChartAxis.Create(ACollection: TCollection);
begin
inherited Create(ACollection);
FListener := TListener.Create(@FTransformations, @StyleChanged);
FGrid := TChartAxisPen.Create;
FGrid.OnChange := @StyleChanged;
FGrid.Style := psDot;
@ -330,7 +332,6 @@ begin
FTickColor := clBlack;
FTickLength := DEF_TICK_LENGTH;
FTitle := TChartAxisTitle.Create(ACollection.Owner as TCustomChart);
//FTransformation.OnChanged := @StyleChanged;
FVisible := true;
end;
@ -338,6 +339,7 @@ destructor TChartAxis.Destroy;
begin
FTitle.Free;
FMarks.Free;
FListener.Free;
FGrid.Free;
inherited;
end;
@ -644,7 +646,11 @@ end;
procedure TChartAxis.SetTransformations(AValue: TChartAxisTransformations);
begin
if FTransformations = AValue then exit;
if FListener.IsListening then
Transformations.Broadcaster.Unsubscribe(FListener);
FTransformations := AValue;
if FTransformations <> nil then
Transformations.Broadcaster.Subscribe(FListener);
StyleChanged(Self);
end;

View File

@ -35,9 +35,7 @@ type
TAxisTransform = class(TIndexedComponent)
private
FEnabled: Boolean;
FOnChanged: TNotifyEvent;
FTransformations: TChartAxisTransformations;
procedure SetOnChanged(const AValue: TNotifyEvent);
procedure SetTransformations(AValue: TChartAxisTransformations);
protected
procedure ReadState(Reader: TReader); override;
@ -57,8 +55,8 @@ type
function AxisToGraph(AX: Double): Double; virtual;
function GraphToAxis(AX: Double): Double; virtual;
property OnChanged: TNotifyEvent read FOnChanged write SetOnChanged;
property Transformations: TChartAxisTransformations read FTransformations write SetTransformations;
property Transformations: TChartAxisTransformations
read FTransformations write SetTransformations;
published
property Enabled: Boolean read FEnabled write FEnabled default true;
end;
@ -72,6 +70,7 @@ type
TChartAxisTransformations = class (TComponent)
private
FBroadcaster: TBroadcaster;
FList: TAxisTransformList;
public
constructor Create(AOwner: TComponent); override;
@ -82,6 +81,8 @@ type
public
function AxisToGraph(AX: Double): Double;
function GraphToAxis(AX: Double): Double;
property Broadcaster: TBroadcaster read FBroadcaster;
published
property List: TAxisTransformList read FList;
end;
@ -278,8 +279,8 @@ end;
procedure TAxisTransform.Changed;
begin
if Assigned(FOnChanged) then
FOnChanged(Self);
if Transformations <> nil then
Transformations.Broadcaster.Broadcast;
end;
constructor TAxisTransform.Create(AOwner: TComponent);
@ -330,12 +331,6 @@ begin
Move(Index, EnsureRange(AValue, 0, Count - 1));
end;
procedure TAxisTransform.SetOnChanged(const AValue: TNotifyEvent);
begin
if TMethod(FOnChanged) = TMethod(AValue) then exit;
FOnChanged := AValue;
end;
procedure TAxisTransform.SetParentComponent(AParent: TComponent);
begin
if not (csLoading in ComponentState) then
@ -366,6 +361,7 @@ end;
constructor TChartAxisTransformations.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FBroadcaster := TBroadcaster.Create;
FList := TAxisTransformList.Create;
end;
@ -374,6 +370,7 @@ begin
while List.Count > 0 do
TAxisTransform(List[List.Count - 1]).Free;
FList.Free;
FBroadcaster.Free;
inherited;
end;