mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-03 06:58:53 +01:00
TAChart: Add Margin and SymbolWidth properties to TChartLegend
git-svn-id: trunk@21890 -
This commit is contained in:
parent
50cc9941e0
commit
83a241e7ea
@ -7,6 +7,11 @@ interface
|
|||||||
uses
|
uses
|
||||||
Classes, Contnrs, SysUtils, Graphics, TAChartUtils, TATypes;
|
Classes, Contnrs, SysUtils, Graphics, TAChartUtils, TATypes;
|
||||||
|
|
||||||
|
const
|
||||||
|
DEF_LEGEND_SPACING = 4;
|
||||||
|
DEF_LEGEND_MARGIN = 4;
|
||||||
|
DEF_LEGEND_SYMBOL_WIDTH = 20;
|
||||||
|
|
||||||
type
|
type
|
||||||
{ TLegendItem }
|
{ TLegendItem }
|
||||||
|
|
||||||
@ -57,12 +62,16 @@ type
|
|||||||
FAlignment: TLegendAlignment;
|
FAlignment: TLegendAlignment;
|
||||||
FFont: TFont;
|
FFont: TFont;
|
||||||
FFrame: TChartPen;
|
FFrame: TChartPen;
|
||||||
|
FMargin: TChartDistance;
|
||||||
FSpacing: TChartDistance;
|
FSpacing: TChartDistance;
|
||||||
|
FSymbolWidth: TChartDistance;
|
||||||
|
|
||||||
procedure SetAlignment(AValue: TLegendAlignment);
|
procedure SetAlignment(AValue: TLegendAlignment);
|
||||||
procedure SetFont(AValue: TFont);
|
procedure SetFont(AValue: TFont);
|
||||||
procedure SetFrame(AValue: TChartPen);
|
procedure SetFrame(AValue: TChartPen);
|
||||||
procedure SetSpacing(const AValue: TChartDistance);
|
procedure SetMargin(AValue: TChartDistance);
|
||||||
|
procedure SetSpacing(AValue: TChartDistance);
|
||||||
|
procedure SetSymbolWidth(AValue: TChartDistance);
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TCustomChart);
|
constructor Create(AOwner: TCustomChart);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -76,7 +85,12 @@ type
|
|||||||
read FAlignment write SetAlignment default laRight;
|
read FAlignment write SetAlignment default laRight;
|
||||||
property Font: TFont read FFont write SetFont;
|
property Font: TFont read FFont write SetFont;
|
||||||
property Frame: TChartPen read FFrame write SetFrame;
|
property Frame: TChartPen read FFrame write SetFrame;
|
||||||
property Spacing: TChartDistance read FSpacing write SetSpacing default 5;
|
property Margin: TChartDistance
|
||||||
|
read FMargin write SetMargin default DEF_LEGEND_MARGIN;
|
||||||
|
property Spacing: TChartDistance
|
||||||
|
read FSpacing write SetSpacing default DEF_LEGEND_SPACING;
|
||||||
|
property SymbolWidth: TChartDistance
|
||||||
|
read FSymbolWidth write SetSymbolWidth default DEF_LEGEND_SYMBOL_WIDTH;
|
||||||
property Visible default false;
|
property Visible default false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -86,9 +100,7 @@ uses
|
|||||||
FPCanvas, Math, Types;
|
FPCanvas, Math, Types;
|
||||||
|
|
||||||
const
|
const
|
||||||
ICON_WIDTH = 17;
|
SYMBOL_TEXT_SPACING = 4;
|
||||||
ICON_SPACING = 3;
|
|
||||||
MARGINS = 3;
|
|
||||||
|
|
||||||
{ TLegendItem }
|
{ TLegendItem }
|
||||||
|
|
||||||
@ -99,7 +111,7 @@ end;
|
|||||||
|
|
||||||
procedure TLegendItem.Draw(ACanvas: TCanvas; const ARect: TRect);
|
procedure TLegendItem.Draw(ACanvas: TCanvas; const ARect: TRect);
|
||||||
begin
|
begin
|
||||||
ACanvas.TextOut(ARect.Right + ICON_SPACING, ARect.Top, FText);
|
ACanvas.TextOut(ARect.Right + SYMBOL_TEXT_SPACING, ARect.Top, FText);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TLegendItemLine }
|
{ TLegendItemLine }
|
||||||
@ -166,7 +178,9 @@ constructor TChartLegend.Create(AOwner: TCustomChart);
|
|||||||
begin
|
begin
|
||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
FAlignment := laRight;
|
FAlignment := laRight;
|
||||||
FSpacing := 5;
|
FMargin := DEF_LEGEND_MARGIN;
|
||||||
|
FSpacing := DEF_LEGEND_SPACING;
|
||||||
|
FSymbolWidth := DEF_LEGEND_SYMBOL_WIDTH;
|
||||||
Visible := false;
|
Visible := false;
|
||||||
|
|
||||||
InitHelper(TFPCanvasHelper(FFont), TFont);
|
InitHelper(TFPCanvasHelper(FFont), TFont);
|
||||||
@ -199,11 +213,11 @@ begin
|
|||||||
for i := 0 to AItems.Count - 1 do
|
for i := 0 to AItems.Count - 1 do
|
||||||
with AItems[i] as TLegendItem do
|
with AItems[i] as TLegendItem do
|
||||||
w := Max(ACanvas.TextWidth(FText), w);
|
w := Max(ACanvas.TextWidth(FText), w);
|
||||||
w += 2 * Spacing + ICON_WIDTH + ICON_SPACING;
|
w += 2 * Spacing + SYMBOL_TEXT_SPACING + SymbolWidth;
|
||||||
th := ACanvas.TextHeight('Iy');
|
th := ACanvas.TextHeight('Iy');
|
||||||
|
|
||||||
AClipRect.Right -= w + 2 * MARGINS;
|
AClipRect.Right -= w + 2 * Margin;
|
||||||
x1 := AClipRect.Right + MARGINS;
|
x1 := AClipRect.Right + Margin;
|
||||||
y1 := AClipRect.Top;
|
y1 := AClipRect.Top;
|
||||||
|
|
||||||
// Border
|
// Border
|
||||||
@ -212,7 +226,7 @@ begin
|
|||||||
ACanvas.Rectangle(Bounds(
|
ACanvas.Rectangle(Bounds(
|
||||||
x1, y1, w, Spacing + AItems.Count * (th + Spacing)));
|
x1, y1, w, Spacing + AItems.Count * (th + Spacing)));
|
||||||
|
|
||||||
r := Bounds(x1 + Spacing, y1 + Spacing, ICON_WIDTH, th);
|
r := Bounds(x1 + Spacing, y1 + Spacing, SymbolWidth, th);
|
||||||
for i := 0 to AItems.Count - 1 do begin
|
for i := 0 to AItems.Count - 1 do begin
|
||||||
ACanvas.Brush.Color := clWhite;
|
ACanvas.Brush.Color := clWhite;
|
||||||
ACanvas.Pen.Assign(Frame);
|
ACanvas.Pen.Assign(Frame);
|
||||||
@ -243,12 +257,26 @@ begin
|
|||||||
StyleChanged(Self);
|
StyleChanged(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TChartLegend.SetSpacing(const AValue: TChartDistance);
|
procedure TChartLegend.SetMargin(AValue: TChartDistance);
|
||||||
|
begin
|
||||||
|
if FMargin = AValue then exit;
|
||||||
|
FMargin := AValue;
|
||||||
|
StyleChanged(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TChartLegend.SetSpacing(AValue: TChartDistance);
|
||||||
begin
|
begin
|
||||||
if FSpacing = AValue then exit;
|
if FSpacing = AValue then exit;
|
||||||
FSpacing := AValue;
|
FSpacing := AValue;
|
||||||
StyleChanged(Self);
|
StyleChanged(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TChartLegend.SetSymbolWidth(AValue: TChartDistance);
|
||||||
|
begin
|
||||||
|
if FSymbolWidth = AValue then exit;
|
||||||
|
FSymbolWidth := AValue;
|
||||||
|
StyleChanged(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user