diff --git a/.gitattributes b/.gitattributes index 6d92475932..4a0028a987 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/components/tachart/tachartlazaruspkg.lpk b/components/tachart/tachartlazaruspkg.lpk index 3e95edca85..fbcb8f24f0 100644 --- a/components/tachart/tachartlazaruspkg.lpk +++ b/components/tachart/tachartlazaruspkg.lpk @@ -20,7 +20,7 @@ for details about the copyright. "/> - + @@ -57,6 +57,10 @@ + + + + diff --git a/components/tachart/tachartlazaruspkg.pas b/components/tachart/tachartlazaruspkg.pas index 66d96d7e6d..a446b3caa6 100644 --- a/components/tachart/tachartlazaruspkg.pas +++ b/components/tachart/tachartlazaruspkg.pas @@ -8,7 +8,7 @@ interface uses TASeries, TAGraph, TAChartUtils, TASeriesEditor, TATypes, TASources, - TADbSource, TACustomSeries, LazarusPackageIntf; + TADbSource, TACustomSeries, TALegend, LazarusPackageIntf; implementation diff --git a/components/tachart/tagraph.pas b/components/tachart/tagraph.pas index 72650f8651..7c44e6878b 100644 --- a/components/tachart/tagraph.pas +++ b/components/tachart/tagraph.pas @@ -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; diff --git a/components/tachart/talegend.pas b/components/tachart/talegend.pas new file mode 100644 index 0000000000..e6cb46521b --- /dev/null +++ b/components/tachart/talegend.pas @@ -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. + diff --git a/components/tachart/tatypes.pas b/components/tachart/tatypes.pas index d1b9e72e02..41f62d7da8 100644 --- a/components/tachart/tatypes.pas +++ b/components/tachart/tatypes.pas @@ -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);