TAChart: Extract TChartLegend into a separate unit

git-svn-id: trunk@21865 -
This commit is contained in:
ask 2009-09-25 15:19:47 +00:00
parent 7355a841d9
commit 574f3fa348
6 changed files with 102 additions and 80 deletions

1
.gitattributes vendored
View File

@ -1755,6 +1755,7 @@ components/tachart/tacustomseries.pas svneol=native#text/plain
components/tachart/tadbsource.pas svneol=native#text/pascal components/tachart/tadbsource.pas svneol=native#text/pascal
components/tachart/tagraph.lrs svneol=native#text/pascal components/tachart/tagraph.lrs svneol=native#text/pascal
components/tachart/tagraph.pas svneol=native#text/plain components/tachart/tagraph.pas svneol=native#text/plain
components/tachart/talegend.pas svneol=native#text/plain
components/tachart/taseries.pas svneol=native#text/plain components/tachart/taseries.pas svneol=native#text/plain
components/tachart/taserieseditor.lfm svneol=native#text/plain components/tachart/taserieseditor.lfm svneol=native#text/plain
components/tachart/taserieseditor.lrs svneol=native#text/pascal components/tachart/taserieseditor.lrs svneol=native#text/pascal

View File

@ -20,7 +20,7 @@
for details about the copyright. for details about the copyright.
"/> "/>
<Version Major="1"/> <Version Major="1"/>
<Files Count="8"> <Files Count="9">
<Item1> <Item1>
<Filename Value="taseries.pas"/> <Filename Value="taseries.pas"/>
<UnitName Value="TASeries"/> <UnitName Value="TASeries"/>
@ -57,6 +57,10 @@
<Filename Value="tacustomseries.pas"/> <Filename Value="tacustomseries.pas"/>
<UnitName Value="TACustomSeries"/> <UnitName Value="TACustomSeries"/>
</Item8> </Item8>
<Item9>
<Filename Value="TALegend.pas"/>
<UnitName Value="TALegend"/>
</Item9>
</Files> </Files>
<Type Value="RunAndDesignTime"/> <Type Value="RunAndDesignTime"/>
<RequiredPkgs Count="3"> <RequiredPkgs Count="3">

View File

@ -8,7 +8,7 @@ interface
uses uses
TASeries, TAGraph, TAChartUtils, TASeriesEditor, TATypes, TASources, TASeries, TAGraph, TAChartUtils, TASeriesEditor, TATypes, TASources,
TADbSource, TACustomSeries, LazarusPackageIntf; TADbSource, TACustomSeries, TALegend, LazarusPackageIntf;
implementation implementation

View File

@ -30,7 +30,7 @@ interface
uses uses
LCLIntF, LCLType, LResources, LCLIntF, LCLType, LResources,
SysUtils, Classes, Controls, Graphics, Dialogs, SysUtils, Classes, Controls, Graphics, Dialogs,
TAChartUtils, TATypes; TAChartUtils, TATypes, TALegend;
const const
LEGEND_SPACING = 5; LEGEND_SPACING = 5;
@ -610,7 +610,7 @@ end;
procedure TChart.DrawLegend(ACanvas: TCanvas); procedure TChart.DrawLegend(ACanvas: TCanvas);
var var
w, h, x1, y1, x2, y2, i, TH: Integer; w, h, x1, y1, x2, y2, i, th: Integer;
pbf: TPenBrushFontRecall; pbf: TPenBrushFontRecall;
r: TRect; r: TRect;
begin begin
@ -623,7 +623,7 @@ begin
ACanvas.Font.Assign(FLegend.Font); ACanvas.Font.Assign(FLegend.Font);
w := GetLegendWidth(ACanvas); w := GetLegendWidth(ACanvas);
TH := ACanvas.TextHeight('I'); th := ACanvas.TextHeight('I');
h := 0; h := 0;
for i := 0 to SeriesCount - 1 do for i := 0 to SeriesCount - 1 do
with Series[i] do with Series[i] do
@ -633,21 +633,21 @@ begin
x1 := FClipRect.Right + 5; x1 := FClipRect.Right + 5;
y1 := FClipRect.Top; y1 := FClipRect.Top;
x2 := x1 + w; x2 := x1 + w;
y2 := y1 + LEGEND_SPACING + h * (TH + LEGEND_SPACING); y2 := y1 + LEGEND_SPACING + h * (th + LEGEND_SPACING);
// Border // Border
ACanvas.Brush.Assign(FGraphBrush); ACanvas.Brush.Assign(FGraphBrush);
ACanvas.Pen.Assign(FLegend.Frame); ACanvas.Pen.Assign(FLegend.Frame);
ACanvas.Rectangle(x1, y1, x2, y2); ACanvas.Rectangle(x1, y1, x2, y2);
r := Bounds(x1 + LEGEND_SPACING, y1 + LEGEND_SPACING, 17, TH); r := Bounds(x1 + LEGEND_SPACING, y1 + LEGEND_SPACING, 17, th);
for i := 0 to SeriesCount - 1 do for i := 0 to SeriesCount - 1 do
with Series[i] do with Series[i] do
if Active and ShowInLegend then begin if Active and ShowInLegend then begin
ACanvas.Pen.Color := FLegend.Frame.Color; ACanvas.Pen.Color := FLegend.Frame.Color;
ACanvas.Brush.Assign(FGraphBrush); ACanvas.Brush.Assign(FGraphBrush);
DrawLegend(ACanvas, r); DrawLegend(ACanvas, r);
OffsetRect(r, 0, GetLegendCount * (TH + LEGEND_SPACING)); OffsetRect(r, 0, GetLegendCount * (th + LEGEND_SPACING));
end; end;
finally finally
pbf.Free; pbf.Free;

View File

@ -0,0 +1,89 @@
unit TALegend;
{$H+}
interface
uses
Classes, SysUtils, Graphics, TAChartUtils, TATypes;
type
{ TChartLegend }
TChartLegend = class(TChartElement)
private
FAlignment: TLegendAlignment;
FFont: TFont;
FFrame: TChartPen;
procedure SetAlignment(AValue: TLegendAlignment);
procedure SetFont(AValue: TFont);
procedure SetFrame(AValue: TChartPen);
public
constructor Create(AOwner: TCustomChart);
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
published
property Alignment: TLegendAlignment
read FAlignment write SetAlignment default laRight;
property Font: TFont read FFont write SetFont;
property Frame: TChartPen read FFrame write SetFrame;
property Visible default false;
end;
implementation
uses
FPCanvas;
{ TChartLegend }
procedure TChartLegend.Assign(Source: TPersistent);
begin
if Source is TChartLegend then
with TChartLegend(Source) do
Self.FAlignment := FAlignment;
inherited Assign(Source);
end;
constructor TChartLegend.Create(AOwner: TCustomChart);
begin
inherited Create(AOwner);
FAlignment := laRight;
Visible := false;
InitHelper(TFPCanvasHelper(FFont), TFont);
InitHelper(TFPCanvasHelper(FFrame), TChartPen);
end;
destructor TChartLegend.Destroy;
begin
FFont.Free;
FFrame.Free;
inherited;
end;
procedure TChartLegend.SetAlignment(AValue: TLegendAlignment);
begin
if FAlignment = AValue then exit;
FAlignment := AValue;
StyleChanged(Self);
end;
procedure TChartLegend.SetFont(AValue: TFont);
begin
FFont.Assign(AValue);
StyleChanged(Self);
end;
procedure TChartLegend.SetFrame(AValue: TChartPen);
begin
FFrame.Assign(AValue);
StyleChanged(Self);
end;
end.

View File

@ -80,28 +80,6 @@ type
property Visible: Boolean read FVisible write SetVisible; property Visible: Boolean read FVisible write SetVisible;
end; end;
TChartLegend = class(TChartElement)
private
FAlignment: TLegendAlignment;
FFont: TFont;
FFrame: TChartPen;
procedure SetAlignment(AValue: TLegendAlignment);
procedure SetFont(AValue: TFont);
procedure SetFrame(AValue: TChartPen);
public
constructor Create(AOwner: TCustomChart);
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
published
property Alignment: TLegendAlignment
read FAlignment write SetAlignment default laRight;
property Font: TFont read FFont write SetFont;
property Frame: TChartPen read FFrame write SetFrame;
property Visible default false;
end;
TChartTitle = class(TChartElement) TChartTitle = class(TChartElement)
private private
FAlignment: TAlignment; FAlignment: TAlignment;
@ -476,56 +454,6 @@ begin
FOwner.Invalidate; FOwner.Invalidate;
end; end;
{ TChartLegend }
procedure TChartLegend.Assign(Source: TPersistent);
begin
if Source is TChartLegend then
with TChartLegend(Source) do begin
Self.FAlignment := FAlignment;
Self.FVisible := FVisible;
end;
inherited Assign(Source);
end;
constructor TChartLegend.Create(AOwner: TCustomChart);
begin
inherited Create(AOwner);
FAlignment := laRight;
FVisible := false;
InitHelper(TFPCanvasHelper(FFont), TFont);
InitHelper(TFPCanvasHelper(FFrame), TChartPen);
end;
destructor TChartLegend.Destroy;
begin
FFont.Free;
FFrame.Free;
inherited;
end;
procedure TChartLegend.SetAlignment(AValue: TLegendAlignment);
begin
if FAlignment = AValue then exit;
FAlignment := AValue;
StyleChanged(Self);
end;
procedure TChartLegend.SetFont(AValue: TFont);
begin
FFont.Assign(AValue);
StyleChanged(Self);
end;
procedure TChartLegend.SetFrame(AValue: TChartPen);
begin
FFrame.Assign(AValue);
StyleChanged(Self);
end;
{ TChartTitle } { TChartTitle }
procedure TChartTitle.Assign(Source: TPersistent); procedure TChartTitle.Assign(Source: TPersistent);