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