mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-05 13:39:39 +01:00
TAChart: Auto-update TChartLegendPanel
git-svn-id: trunk@27783 -
This commit is contained in:
parent
e3573e3e88
commit
53f0743f12
@ -410,7 +410,8 @@ end;
|
||||
|
||||
procedure TCustomChartSeries.UpdateParentChart;
|
||||
begin
|
||||
if ParentChart <> nil then ParentChart.Invalidate;
|
||||
if ParentChart <> nil then
|
||||
ParentChart.StyleChanged(Self);
|
||||
end;
|
||||
|
||||
{ TChartSeries }
|
||||
|
||||
@ -159,6 +159,7 @@ type
|
||||
|
||||
private
|
||||
FActiveToolIndex: Integer;
|
||||
FBroadcaster: TBroadcaster;
|
||||
FBuiltinToolset: TBasicChartToolset;
|
||||
FClipRect: TRect;
|
||||
FCurrentExtent: TDoubleRect;
|
||||
@ -215,8 +216,6 @@ type
|
||||
procedure PrepareLegend(
|
||||
ACanvas: TCanvas; out ALegendItems: TChartLegendItems;
|
||||
var AClipRect: TRect; out ALegendRect: TRect);
|
||||
procedure StyleChanged(Sender: TObject);
|
||||
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
@ -242,6 +241,7 @@ type
|
||||
procedure SaveToBitmapFile(const AFileName: String); inline;
|
||||
procedure SaveToFile(AClass: TRasterImageClass; const AFileName: String);
|
||||
function SaveToImage(AClass: TRasterImageClass): TRasterImage;
|
||||
procedure StyleChanged(Sender: TObject); override;
|
||||
procedure ZoomFull; override;
|
||||
public // Coordinate conversion
|
||||
function GraphToImage(const AGraphPoint: TDoublePoint): TPoint;
|
||||
@ -253,6 +253,7 @@ type
|
||||
|
||||
public
|
||||
property ActiveToolIndex: Integer read FActiveToolIndex;
|
||||
property Broadcaster: TBroadcaster read FBroadcaster;
|
||||
property ChartHeight: Integer read GetChartHeight;
|
||||
property ChartWidth: Integer read GetChartWidth;
|
||||
property ClipRect: TRect read FClipRect;
|
||||
@ -371,6 +372,7 @@ const
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
|
||||
FBroadcaster := TBroadcaster.Create;
|
||||
FAllowZoom := true;
|
||||
FAxisVisible := true;
|
||||
|
||||
@ -428,6 +430,7 @@ begin
|
||||
FreeAndNil(FExtent);
|
||||
FreeAndNil(FMargins);
|
||||
FreeAndNil(FBuiltinToolset);
|
||||
FreeAndNil(FBroadcaster);
|
||||
|
||||
DrawData.DeleteByChart(Self);
|
||||
inherited;
|
||||
@ -456,6 +459,7 @@ end;
|
||||
procedure TChart.StyleChanged(Sender: TObject);
|
||||
begin
|
||||
Invalidate;
|
||||
Broadcaster.Broadcast(Sender);
|
||||
end;
|
||||
|
||||
procedure TChart.Paint;
|
||||
|
||||
@ -20,7 +20,7 @@ unit TALegendPanel;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, Controls, TAGraph;
|
||||
Classes, Controls, TAChartUtils, TAGraph;
|
||||
|
||||
type
|
||||
|
||||
@ -29,9 +29,12 @@ type
|
||||
TChartLegendPanel = class(TCustomControl)
|
||||
private
|
||||
FChart: TChart;
|
||||
procedure SetChart(const AValue: TChart);
|
||||
FListener: TListener;
|
||||
procedure ChartChanged(Sender: TObject);
|
||||
procedure SetChart(AValue: TChart);
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
procedure Paint; override;
|
||||
published
|
||||
property Chart: TChart read FChart write SetChart;
|
||||
@ -44,7 +47,7 @@ procedure Register;
|
||||
implementation
|
||||
|
||||
uses
|
||||
TAChartUtils;
|
||||
SysUtils;
|
||||
|
||||
procedure Register;
|
||||
begin
|
||||
@ -53,26 +56,43 @@ end;
|
||||
|
||||
{ TChartLegendPanel }
|
||||
|
||||
procedure TChartLegendPanel.ChartChanged(Sender: TObject);
|
||||
begin
|
||||
// TODO: Do not auto-update on chart zooming/scrolling.
|
||||
Invalidate;
|
||||
end;
|
||||
|
||||
constructor TChartLegendPanel.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FListener := TListener.Create(@FChart, @ChartChanged);
|
||||
Width := 40;
|
||||
Height := 20;
|
||||
end;
|
||||
|
||||
destructor TChartLegendPanel.Destroy;
|
||||
begin
|
||||
FreeAndNil(FListener);
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TChartLegendPanel.Paint;
|
||||
var
|
||||
r: TRect;
|
||||
begin
|
||||
if Chart = nil then exit;
|
||||
r := Canvas.ClipRect;
|
||||
r := Rect(0, 0, Width, Height);
|
||||
Chart.DrawLegendOn(Canvas, r);
|
||||
end;
|
||||
|
||||
procedure TChartLegendPanel.SetChart(const AValue: TChart);
|
||||
procedure TChartLegendPanel.SetChart(AValue: TChart);
|
||||
begin
|
||||
if FChart = AValue then exit;
|
||||
if FListener.IsListening then
|
||||
FChart.Broadcaster.Unsubscribe(FListener);
|
||||
FChart := AValue;
|
||||
if FChart <> nil then
|
||||
FChart.Broadcaster.Subscribe(FListener);
|
||||
Invalidate;
|
||||
end;
|
||||
|
||||
|
||||
@ -42,6 +42,7 @@ type
|
||||
TCustomChart = class(TCustomControl)
|
||||
public
|
||||
procedure ZoomFull; virtual; abstract;
|
||||
procedure StyleChanged(Sender: TObject); virtual; abstract;
|
||||
end;
|
||||
|
||||
{ TChartPen }
|
||||
@ -352,7 +353,7 @@ end;
|
||||
procedure TChartElement.StyleChanged(Sender: TObject);
|
||||
begin
|
||||
if FOwner <> nil then
|
||||
FOwner.Invalidate;
|
||||
FOwner.StyleChanged(Sender);
|
||||
end;
|
||||
|
||||
{ TChartTitle }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user