mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-19 18:53:30 +01:00
TAChart: Add TChartLegendPanel component
git-svn-id: trunk@27781 -
This commit is contained in:
parent
622f3f44df
commit
f67dde1d74
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -2292,6 +2292,7 @@ components/tachart/tafuncseries.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/talegendpanel.pas svneol=native#text/pascal
|
||||
components/tachart/tamultiseries.pas svneol=native#text/pascal
|
||||
components/tachart/taseries.pas svneol=native#text/plain
|
||||
components/tachart/taserieseditor.pas svneol=native#text/plain
|
||||
|
||||
@ -25,7 +25,7 @@
|
||||
for details about the copyright.
|
||||
"/>
|
||||
<Version Major="1"/>
|
||||
<Files Count="17">
|
||||
<Files Count="18">
|
||||
<Item1>
|
||||
<Filename Value="tachartaxis.pas"/>
|
||||
<UnitName Value="TAChartAxis"/>
|
||||
@ -101,6 +101,11 @@
|
||||
<Filename Value="tafuncseries.pas"/>
|
||||
<UnitName Value="TAFuncSeries"/>
|
||||
</Item17>
|
||||
<Item18>
|
||||
<Filename Value="talegendpanel.pas"/>
|
||||
<HasRegisterProc Value="True"/>
|
||||
<UnitName Value="TALegendPanel"/>
|
||||
</Item18>
|
||||
</Files>
|
||||
<LazDoc Paths="$(LazarusDir)\components\tachart\fpdoc\"/>
|
||||
<Type Value="RunAndDesignTime"/>
|
||||
|
||||
@ -10,7 +10,7 @@ uses
|
||||
TAChartAxis, TAChartUtils, TACustomSeries, TADbSource, TAGraph, TASeries,
|
||||
TASeriesEditor, TASources, TASubcomponentsEditor, TATools,
|
||||
TATransformations, TATypes, TADrawUtils, TAMultiSeries, TALegend, TAStyles,
|
||||
TAFuncSeries, LazarusPackageIntf;
|
||||
TAFuncSeries, TALegendPanel, LazarusPackageIntf;
|
||||
|
||||
implementation
|
||||
|
||||
@ -23,6 +23,7 @@ begin
|
||||
RegisterUnit('TATools', @TATools.Register);
|
||||
RegisterUnit('TATransformations', @TATransformations.Register);
|
||||
RegisterUnit('TAStyles', @TAStyles.Register);
|
||||
RegisterUnit('TALegendPanel', @TALegendPanel.Register);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
@ -44,6 +44,20 @@ LazarusResources.Add('tchartaxistransformations','PNG',[
|
||||
+#237'u'#163'U/'#28#12#196#140'r'#249#237'2'#255#18#225#6'm?'#178#231'M;*'#214
|
||||
+#0#0#0#0'IEND'#174'B`'#130
|
||||
]);
|
||||
LazarusResources.Add('tchartlegendpanel','PNG',[
|
||||
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#24#0#0#0#24#8#6#0#0#0#224'w='#248#0
|
||||
+#0#0#4'gAMA'#0#0#177#143#11#252'a'#5#0#0#0#25'tEXtSoftware'#0'Paint.NET v3.5'
|
||||
+'.5I'#138#252#224#0#0#0#213'IDATHK'#221#150#193#13#131'0'#12'E3'#21'g'#206
|
||||
+#140#210#5#178'B'#207'l'#210#13#218#174#209#3#163#184#252#8'#'#227#186#197
|
||||
+#138'S!'#17#233'K'#16#5#191#228';NH'#233'4-'#231#145'Z'#201'4'#5#193'[4'#196
|
||||
+'y'#222#31#244#1'a'#192'4'#189#200'#L'#198#26#215#28#144'o'#29#177#0'<'#30'0'
|
||||
+'{'#247'_'#139'4 ]/&'#144's0'#12'D,'#151'E'#18#128#224','#157#208'0@'#6#182
|
||||
+' '#213#187#8'+'#176#2'r'#31#245'='#21'-'#219't}'#159#251#220#22'}'#243'}'#3
|
||||
+#137#0#180#223'2'#137'+'#164#182#208'8'#201#178'x$'#0#150#0#18#202'A'#241'r'
|
||||
+#169'P<k'#128#204#129'^'#237'n%{V'#16#6#148#157#180#163'j'#139'<'')'#198'T'#3
|
||||
+'p'#150'G'#244'3'#7#173'n4'#243#194#193#13#20#153#185#254#246'4'#255#18#233
|
||||
+#13#248#238#202'A'#8#175'F'#133#0#0#0#0'IEND'#174'B`'#130
|
||||
]);
|
||||
LazarusResources.Add('tchartstyles','PNG',[
|
||||
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#24#0#0#0#24#8#6#0#0#0#224'w='#248#0
|
||||
+#0#0#4'gAMA'#0#0#177#143#11#252'a'#5#0#0#0#25'tEXtSoftware'#0'Paint.NET v3.5'
|
||||
|
||||
@ -213,7 +213,8 @@ type
|
||||
procedure DoOnResize; override;
|
||||
{$ENDIF}
|
||||
procedure PrepareLegend(
|
||||
ACanvas: TCanvas; out ALegendItems: TChartLegendItems; out ARect: TRect);
|
||||
ACanvas: TCanvas; out ALegendItems: TChartLegendItems;
|
||||
var AClipRect: TRect; out ALegendRect: TRect);
|
||||
procedure StyleChanged(Sender: TObject);
|
||||
|
||||
public
|
||||
@ -235,6 +236,7 @@ type
|
||||
procedure ClearSeries;
|
||||
procedure CopyToClipboardBitmap;
|
||||
procedure DeleteSeries(ASeries: TBasicChartSeries);
|
||||
procedure DrawLegendOn(ACanvas: TCanvas; var ARect: TRect);
|
||||
function GetFullExtent: TDoubleRect;
|
||||
procedure PaintOnCanvas(ACanvas: TCanvas; ARect: TRect);
|
||||
procedure SaveToBitmapFile(const AFileName: String); inline;
|
||||
@ -483,11 +485,13 @@ begin
|
||||
FLogicalExtent := GetFullExtent;
|
||||
FCurrentExtent := FLogicalExtent;
|
||||
DrawTitleFoot(ACanvas);
|
||||
PrepareLegend(ACanvas, legendItems, legendRect);
|
||||
if Legend.Visible then
|
||||
PrepareLegend(ACanvas, legendItems, FClipRect, legendRect);
|
||||
try
|
||||
DrawAxis(ACanvas);
|
||||
DisplaySeries(ACanvas);
|
||||
Legend.Draw(ACanvas, legendItems, legendRect);
|
||||
if Legend.Visible then
|
||||
Legend.Draw(ACanvas, legendItems, legendRect);
|
||||
finally
|
||||
legendItems.Free;
|
||||
end;
|
||||
@ -498,18 +502,18 @@ begin
|
||||
end;
|
||||
|
||||
procedure TChart.PrepareLegend(
|
||||
ACanvas: TCanvas; out ALegendItems: TChartLegendItems; out ARect: TRect);
|
||||
ACanvas: TCanvas; out ALegendItems: TChartLegendItems;
|
||||
var AClipRect: TRect; out ALegendRect: TRect);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
if not Legend.Visible then exit;
|
||||
ALegendItems := TChartLegendItems.Create;
|
||||
try
|
||||
for i := 0 to SeriesCount - 1 do
|
||||
with Series[i] do
|
||||
if Active and GetShowInLegend then
|
||||
GetLegendItemsBasic(ALegendItems);
|
||||
ARect := Legend.Prepare(ACanvas, ALegendItems, FClipRect);
|
||||
ALegendRect := Legend.Prepare(ACanvas, ALegendItems, AClipRect);
|
||||
except
|
||||
FreeAndNil(ALegendItems);
|
||||
raise;
|
||||
@ -648,6 +652,19 @@ begin
|
||||
ACanvas.Line(Left, Bottom, Left - Depth, Bottom + Depth);
|
||||
end;
|
||||
|
||||
procedure TChart.DrawLegendOn(ACanvas: TCanvas; var ARect: TRect);
|
||||
var
|
||||
legendItems: TChartLegendItems = nil;
|
||||
legendRect: TRect;
|
||||
begin
|
||||
try
|
||||
PrepareLegend(ACanvas, legendItems, ARect, legendRect);
|
||||
Legend.Draw(ACanvas, legendItems, legendRect);
|
||||
finally
|
||||
legendItems.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TChart.DrawLineHoriz(ACanvas: TCanvas; AY: Integer);
|
||||
begin
|
||||
if (FClipRect.Top < AY) and (AY < FClipRect.Bottom) then
|
||||
|
||||
@ -335,7 +335,6 @@ var
|
||||
pbf: TPenBrushFontRecall;
|
||||
r: TRect;
|
||||
begin
|
||||
if not Visible then exit;
|
||||
pbf := TPenBrushFontRecall.Create(ACanvas, [pbfPen, pbfBrush, pbfFont]);
|
||||
try
|
||||
// Draw the background and the border.
|
||||
@ -364,8 +363,6 @@ var
|
||||
w, x, y, i, textHeight, legendWidth, legendHeight: Integer;
|
||||
f: TPenBrushFontRecall;
|
||||
begin
|
||||
if not Visible then exit;
|
||||
|
||||
f := TPenBrushFontRecall.Create(ACanvas, [pbfFont]);
|
||||
try
|
||||
ACanvas.Font.Assign(Font);
|
||||
|
||||
80
components/tachart/talegendpanel.pas
Normal file
80
components/tachart/talegendpanel.pas
Normal file
@ -0,0 +1,80 @@
|
||||
{
|
||||
*****************************************************************************
|
||||
* *
|
||||
* See the file COPYING.modifiedLGPL.txt, included in this distribution, *
|
||||
* for details about the copyright. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* *
|
||||
*****************************************************************************
|
||||
|
||||
Authors: Alexander Klenin
|
||||
|
||||
}
|
||||
unit TALegendPanel;
|
||||
|
||||
{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, Controls, TAGraph;
|
||||
|
||||
type
|
||||
|
||||
{ TChartLegendPanel }
|
||||
|
||||
TChartLegendPanel = class(TCustomControl)
|
||||
private
|
||||
FChart: TChart;
|
||||
procedure SetChart(const AValue: TChart);
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
procedure Paint; override;
|
||||
published
|
||||
property Chart: TChart read FChart write SetChart;
|
||||
published
|
||||
property Align;
|
||||
end;
|
||||
|
||||
procedure Register;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
TAChartUtils;
|
||||
|
||||
procedure Register;
|
||||
begin
|
||||
RegisterComponents(CHART_COMPONENT_IDE_PAGE, [TChartLegendPanel]);
|
||||
end;
|
||||
|
||||
{ TChartLegendPanel }
|
||||
|
||||
constructor TChartLegendPanel.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
Width := 40;
|
||||
Height := 20;
|
||||
end;
|
||||
|
||||
procedure TChartLegendPanel.Paint;
|
||||
var
|
||||
r: TRect;
|
||||
begin
|
||||
if Chart = nil then exit;
|
||||
r := Canvas.ClipRect;
|
||||
Chart.DrawLegendOn(Canvas, r);
|
||||
end;
|
||||
|
||||
procedure TChartLegendPanel.SetChart(const AValue: TChart);
|
||||
begin
|
||||
if FChart = AValue then exit;
|
||||
FChart := AValue;
|
||||
Invalidate;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user