mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-06 00:37:18 +01:00
TAChart: Extract TChartLegend into a separate unit
git-svn-id: trunk@21865 -
This commit is contained in:
parent
7355a841d9
commit
574f3fa348
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -1755,6 +1755,7 @@ components/tachart/tacustomseries.pas svneol=native#text/plain
|
||||
components/tachart/tadbsource.pas svneol=native#text/pascal
|
||||
components/tachart/tagraph.lrs svneol=native#text/pascal
|
||||
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/taserieseditor.lfm svneol=native#text/plain
|
||||
components/tachart/taserieseditor.lrs svneol=native#text/pascal
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
for details about the copyright.
|
||||
"/>
|
||||
<Version Major="1"/>
|
||||
<Files Count="8">
|
||||
<Files Count="9">
|
||||
<Item1>
|
||||
<Filename Value="taseries.pas"/>
|
||||
<UnitName Value="TASeries"/>
|
||||
@ -57,6 +57,10 @@
|
||||
<Filename Value="tacustomseries.pas"/>
|
||||
<UnitName Value="TACustomSeries"/>
|
||||
</Item8>
|
||||
<Item9>
|
||||
<Filename Value="TALegend.pas"/>
|
||||
<UnitName Value="TALegend"/>
|
||||
</Item9>
|
||||
</Files>
|
||||
<Type Value="RunAndDesignTime"/>
|
||||
<RequiredPkgs Count="3">
|
||||
|
||||
@ -8,7 +8,7 @@ interface
|
||||
|
||||
uses
|
||||
TASeries, TAGraph, TAChartUtils, TASeriesEditor, TATypes, TASources,
|
||||
TADbSource, TACustomSeries, LazarusPackageIntf;
|
||||
TADbSource, TACustomSeries, TALegend, LazarusPackageIntf;
|
||||
|
||||
implementation
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ interface
|
||||
uses
|
||||
LCLIntF, LCLType, LResources,
|
||||
SysUtils, Classes, Controls, Graphics, Dialogs,
|
||||
TAChartUtils, TATypes;
|
||||
TAChartUtils, TATypes, TALegend;
|
||||
|
||||
const
|
||||
LEGEND_SPACING = 5;
|
||||
@ -610,7 +610,7 @@ end;
|
||||
|
||||
procedure TChart.DrawLegend(ACanvas: TCanvas);
|
||||
var
|
||||
w, h, x1, y1, x2, y2, i, TH: Integer;
|
||||
w, h, x1, y1, x2, y2, i, th: Integer;
|
||||
pbf: TPenBrushFontRecall;
|
||||
r: TRect;
|
||||
begin
|
||||
@ -623,7 +623,7 @@ begin
|
||||
ACanvas.Font.Assign(FLegend.Font);
|
||||
|
||||
w := GetLegendWidth(ACanvas);
|
||||
TH := ACanvas.TextHeight('I');
|
||||
th := ACanvas.TextHeight('I');
|
||||
h := 0;
|
||||
for i := 0 to SeriesCount - 1 do
|
||||
with Series[i] do
|
||||
@ -633,21 +633,21 @@ begin
|
||||
x1 := FClipRect.Right + 5;
|
||||
y1 := FClipRect.Top;
|
||||
x2 := x1 + w;
|
||||
y2 := y1 + LEGEND_SPACING + h * (TH + LEGEND_SPACING);
|
||||
y2 := y1 + LEGEND_SPACING + h * (th + LEGEND_SPACING);
|
||||
|
||||
// Border
|
||||
ACanvas.Brush.Assign(FGraphBrush);
|
||||
ACanvas.Pen.Assign(FLegend.Frame);
|
||||
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
|
||||
with Series[i] do
|
||||
if Active and ShowInLegend then begin
|
||||
ACanvas.Pen.Color := FLegend.Frame.Color;
|
||||
ACanvas.Brush.Assign(FGraphBrush);
|
||||
DrawLegend(ACanvas, r);
|
||||
OffsetRect(r, 0, GetLegendCount * (TH + LEGEND_SPACING));
|
||||
OffsetRect(r, 0, GetLegendCount * (th + LEGEND_SPACING));
|
||||
end;
|
||||
finally
|
||||
pbf.Free;
|
||||
|
||||
89
components/tachart/talegend.pas
Normal file
89
components/tachart/talegend.pas
Normal 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.
|
||||
|
||||
@ -80,28 +80,6 @@ type
|
||||
property Visible: Boolean read FVisible write SetVisible;
|
||||
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)
|
||||
private
|
||||
FAlignment: TAlignment;
|
||||
@ -476,56 +454,6 @@ begin
|
||||
FOwner.Invalidate;
|
||||
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 }
|
||||
|
||||
procedure TChartTitle.Assign(Source: TPersistent);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user