From 07f7a1931edb0ba6d1dc4db5d7e91ea0c670d464 Mon Sep 17 00:00:00 2001 From: wp_xyz Date: Thu, 14 Sep 2023 16:02:15 +0200 Subject: [PATCH] TAChart: Improved legend symbol for TPolarSeries. --- components/tachart/talegend.pas | 34 +++++++++++++++++++++++++++ components/tachart/taradialseries.pas | 8 ++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/components/tachart/talegend.pas b/components/tachart/talegend.pas index 2f362d46e6..2f0b639519 100644 --- a/components/tachart/talegend.pas +++ b/components/tachart/talegend.pas @@ -101,6 +101,17 @@ type procedure Draw(ADrawer: IChartDrawer; const ARect: TRect); override; end; + { TLegendItemLinePointerBrush } + + TLegendItemLinePointerBrush = class(TLegendItemLinePointer) + strict protected + FUseBrush: Boolean; + public + constructor Create(APen: TPen; ABrush: TBrush; APointer: TSeriesPointer; + const AText: String); + procedure Draw(ADrawer: IChartDrawer; const ARect: TRect); override; + end; + { TLegendItemBrushRect } TLegendItemBrushRect = class(TLegendItem) @@ -516,6 +527,29 @@ begin FPointer.DrawSize(ADrawer, c, sz, Color, 0.0, FPresetBrush); end; + +{ TLegendItemLinePointerBrush } + +constructor TLegendItemLinePointerBrush.Create(APen: TPen; ABrush: TBrush; + APointer: TSeriesPointer; const AText: String); +begin + CreateWithBrush(APen, ABrush, APointer, AText); +end; + +procedure TLegendItemLinePointerBrush.Draw( + ADrawer: IChartDrawer; const ARect: TRect); +begin + ADrawer.SetBrush(FBrush); + if Assigned(FPointer) then + begin + ADrawer.FillRect(ARect.Left, (ARect.Top + ARect.Bottom) div 2, ARect.Right, ARect.Bottom); + FPresetBrush := false; + ADrawer.SetBrush(FPointer.Brush); + end; + inherited; +end; + + { TLegendItemBrushRect } constructor TLegendItemBrushRect.Create( diff --git a/components/tachart/taradialseries.pas b/components/tachart/taradialseries.pas index 0f3421a076..b63c2eaa4f 100644 --- a/components/tachart/taradialseries.pas +++ b/components/tachart/taradialseries.pas @@ -1357,7 +1357,13 @@ begin case Legend.Multiplicity of lmSingle: - AItems.Add(TLegendItemLinePointer.Create(LinePen, p, LegendTextSingle)); + if Filled then begin + if ShowPoints then + AItems.Add(TLegendItemLinePointerBrush.Create(LinePen, Brush, p, LegendTextSingle)) + else + AItems.Add(TLegendItemBrushPenRect.Create(Brush, LinePen, LegendTextSingle)); + end else + AItems.Add(TLegendItemLinePointer.Create(LinePen, p, LegendTextSingle)); lmPoint: for i := 0 to Count - 1 do begin li := TLegendItemLinePointer.Create(LinePen, p, LegendTextPoint(i));