TAChart: Replace some hard-coded colors by user-changeable properties.

patch by: Alexander Klenin
part 2 of issue #13196

git-svn-id: trunk@18730 -
This commit is contained in:
vincents 2009-02-17 13:12:59 +00:00
parent c42b11a253
commit 4f120b8014
2 changed files with 26 additions and 4 deletions

View File

@ -236,7 +236,8 @@ begin
FPie := TPieSeries.Create(Chart1);
Chart1.AddSerie(FPie);
FPie.Title := 'pie';
FPie.SeriesColor := clRed;
FPie.LabelBackgroundColor := $80FFFF;
FPie.LabelToPieLinkColor := clCream;
FPie.MarksStyle := smsLabelPercent;
end;

View File

@ -190,6 +190,9 @@ type
TPieSeries = class(TChartSeries)
private
ColorIndex: Integer;
FMiscColors: array [1..3] of TColor;
function GetMiscColor(AIndex: integer): TColor;
procedure SetMiscColor(AIndex: integer; const AValue: TColor);
protected
procedure DrawLegend(ACanvas: TCanvas; const ARect: TRect); override;
function GetLegendCount: Integer; override;
@ -207,6 +210,12 @@ type
published
property Title;
property Active;
property LabelTextColor: TColor index 1
read GetMiscColor write SetMiscColor default clBlack;
property LabelBackgroundColor: TColor index 2
read GetMiscColor write SetMiscColor default clYellow;
property LabelToPieLinkColor: TColor index 3
read GetMiscColor write SetMiscColor default clWhite;
end;
{ TAreaSeries }
@ -1382,17 +1391,17 @@ begin
b := LineEndPoint(center, prevAngle + angleStep / 2, radius + MARKS_DIST);
// line from mark to pie
ACanvas.Pen.Color := clWhite;
ACanvas.Pen.Color := LabelToPieLinkColor;
ACanvas.MoveTo(a.x, a.y);
ACanvas.LineTo(b.x, b.y);
ACanvas.Pen.Color := clBlack;
if b.x < center.x then
b.x -= labelWidths[i];
if b.y < center.y then
b.y -= labelHeights[i];
ACanvas.Brush.Color := clYellow;
ACanvas.Pen.Color := LabelTextColor;
ACanvas.Brush.Color := LabelBackgroundColor;
ACanvas.Rectangle(
b.x - MarkXMargin, b.y - MarkYMargin,
b.x + labelWidths[i] + MarkXMargin, b.y + labelHeights[i] + MarkYMargin);
@ -1439,11 +1448,23 @@ begin
Result := Max(ACanvas.TextWidth(Format('%1.2g %s', [y, Text])), Result);
end;
function TPieSeries.GetMiscColor(AIndex: integer): TColor;
begin
Result := FMiscColors[AIndex];
end;
function TPieSeries.GetSeriesColor: TColor;
begin
Result := clBlack; // SeriesColor is meaningless for PieSeries
end;
procedure TPieSeries.SetMiscColor(AIndex: integer; const AValue: TColor);
begin
if FMiscColors[AIndex] = AValue then exit;
FMiscColors[AIndex] := AValue;
UpdateParentChart;
end;
procedure TPieSeries.SetSeriesColor(const AValue: TColor);
begin