mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-10 03:16:10 +02:00
TAChart: Draw per-point legend items with the color from the chart source
git-svn-id: trunk@27567 -
This commit is contained in:
parent
3d801aa92c
commit
c95aa6b2f3
@ -201,7 +201,7 @@ object Form1: TForm1
|
||||
object ListChartSource1: TListChartSource
|
||||
DataPoints.Strings = (
|
||||
'0|0|?|'
|
||||
'1|2|?|'
|
||||
'1|2|$00FF00|'
|
||||
'2|5|?|'
|
||||
'3|1|?|'
|
||||
'4|6|?|'
|
||||
|
@ -709,14 +709,17 @@ procedure TBasicPointSeries.GetLegendItemsRect(
|
||||
AItems: TChartLegendItems; ABrush: TBrush);
|
||||
var
|
||||
i: Integer;
|
||||
li: TLegendItemBrushRect;
|
||||
begin
|
||||
case Legend.Multiplicity of
|
||||
lmSingle:
|
||||
AItems.Add(TLegendItemBrushRect.Create(ABrush, Title));
|
||||
lmPoint: begin
|
||||
for i := 0 to Count - 1 do
|
||||
AItems.Add(TLegendItemColorRect.Create(GetColor(i), FormattedMark(i)));
|
||||
end;
|
||||
lmPoint:
|
||||
for i := 0 to Count - 1 do begin
|
||||
li := TLegendItemBrushRect.Create(ABrush, FormattedMark(i));
|
||||
li.Color := GetColor(i);
|
||||
AItems.Add(li);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -33,9 +33,12 @@ type
|
||||
TLegendItem = class
|
||||
private
|
||||
FText: String;
|
||||
FColor: TColor;
|
||||
public
|
||||
constructor Create(const AText: String);
|
||||
constructor Create(const AText: String; AColor: TColor = clTAColor);
|
||||
procedure Draw(ACanvas: TCanvas; const ARect: TRect); virtual;
|
||||
public
|
||||
property Color: TColor read FColor write FColor;
|
||||
end;
|
||||
|
||||
TLegendItemDrawEvent =
|
||||
@ -84,16 +87,6 @@ type
|
||||
procedure Draw(ACanvas: TCanvas; const ARect: TRect); override;
|
||||
end;
|
||||
|
||||
{ TLegendItemColorRect }
|
||||
|
||||
TLegendItemColorRect = class(TLegendItem)
|
||||
private
|
||||
FColor: TColor;
|
||||
public
|
||||
constructor Create(AColor: TColor; const AText: String);
|
||||
procedure Draw(ACanvas: TCanvas; const ARect: TRect); override;
|
||||
end;
|
||||
|
||||
TChartLegendItems = TObjectList;
|
||||
|
||||
TChartLegendBrush = class(TBrush)
|
||||
@ -189,8 +182,9 @@ const
|
||||
|
||||
{ TLegendItem }
|
||||
|
||||
constructor TLegendItem.Create(const AText: String);
|
||||
constructor TLegendItem.Create(const AText: String; AColor: TColor);
|
||||
begin
|
||||
FColor := AColor;
|
||||
FText := AText;
|
||||
end;
|
||||
|
||||
@ -253,7 +247,7 @@ begin
|
||||
// Max width slightly narrower then ARect to leave place for the line.
|
||||
sz.X := Min(FPointer.HorizSize, (ARect.Right - ARect.Left) div 3);
|
||||
sz.Y := Min(FPointer.VertSize, (ARect.Bottom - ARect.Top) div 2);
|
||||
FPointer.DrawSize(ACanvas, c, sz, clTAColor);
|
||||
FPointer.DrawSize(ACanvas, c, sz, Color);
|
||||
end;
|
||||
|
||||
{ TLegendItemBrushRect }
|
||||
@ -267,23 +261,12 @@ end;
|
||||
procedure TLegendItemBrushRect.Draw(ACanvas: TCanvas; const ARect: TRect);
|
||||
begin
|
||||
inherited Draw(ACanvas, ARect);
|
||||
ACanvas.Brush.Assign(FBrush);
|
||||
ACanvas.Rectangle(ARect);
|
||||
end;
|
||||
|
||||
{ TLegendItemColorRect }
|
||||
|
||||
constructor TLegendItemColorRect.Create(AColor: TColor; const AText: String);
|
||||
begin
|
||||
inherited Create(AText);
|
||||
FColor := AColor;
|
||||
end;
|
||||
|
||||
procedure TLegendItemColorRect.Draw(ACanvas: TCanvas; const ARect: TRect);
|
||||
begin
|
||||
inherited Draw(ACanvas, ARect);
|
||||
ACanvas.Brush.Color := FColor;
|
||||
ACanvas.Brush.Style := bsSolid;
|
||||
if FBrush = nil then
|
||||
ACanvas.Brush.Style := bsSolid
|
||||
else
|
||||
ACanvas.Brush.Assign(FBrush);
|
||||
if Color <> clTAColor then
|
||||
ACanvas.Brush.Color := Color;
|
||||
ACanvas.Rectangle(ARect);
|
||||
end;
|
||||
|
||||
|
@ -502,6 +502,7 @@ var
|
||||
lp: TPen;
|
||||
p: TSeriesPointer;
|
||||
i: Integer;
|
||||
li: TLegendItemLinePointer;
|
||||
begin
|
||||
if LineType = ltNone then
|
||||
lp := nil
|
||||
@ -515,8 +516,11 @@ begin
|
||||
lmSingle:
|
||||
AItems.Add(TLegendItemLinePointer.Create(lp, p, Title));
|
||||
lmPoint: begin
|
||||
for i := 0 to Count - 1 do
|
||||
AItems.Add(TLegendItemLinePointer.Create(lp, p, FormattedMark(i)));
|
||||
for i := 0 to Count - 1 do begin
|
||||
li := TLegendItemLinePointer.Create(lp, p, FormattedMark(i));
|
||||
li.Color := GetColor(i);
|
||||
AItems.Add(li);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
@ -957,13 +961,20 @@ end;
|
||||
procedure TPieSeries.GetLegendItems(AItems: TChartLegendItems);
|
||||
var
|
||||
i: Integer;
|
||||
li: TLegendItemBrushRect;
|
||||
begin
|
||||
case Legend.Multiplicity of
|
||||
lmSingle:
|
||||
AItems.Add(TLegendItemColorRect.Create(SliceColor(0), Title));
|
||||
lmSingle: begin
|
||||
li := TLegendItemBrushRect.Create(nil, Title);
|
||||
li.Color := SliceColor(0);
|
||||
AItems.Add(li);
|
||||
end;
|
||||
lmPoint:
|
||||
for i := 0 to Count - 1 do
|
||||
AItems.Add(TLegendItemColorRect.Create(SliceColor(i), FormattedMark(i)));
|
||||
for i := 0 to Count - 1 do begin
|
||||
li := TLegendItemBrushRect.Create(nil, FormattedMark(i));
|
||||
li.Color := SliceColor(i);
|
||||
AItems.Add(li);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user