From bad4e3f9a396902836a6be65bb69e6adc6e11fad Mon Sep 17 00:00:00 2001 From: ask Date: Fri, 6 May 2011 09:42:30 +0000 Subject: [PATCH] TAChart: Add PieSeries.MarkPositions property. Implement labels inside of slices. git-svn-id: trunk@30570 - --- components/tachart/taradialseries.pas | 28 ++++++++++++++++++++++----- components/tachart/taseries.pas | 1 + 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/components/tachart/taradialseries.pas b/components/tachart/taradialseries.pas index bde6ffc03a..8be08f6217 100644 --- a/components/tachart/taradialseries.pas +++ b/components/tachart/taradialseries.pas @@ -38,9 +38,16 @@ type FLabel: TLabelParams; end; + TPieMarkPositions = (pmpAround, pmpInside); + { TCustomPieSeries } TCustomPieSeries = class(TChartSeries) + private + FCenter: TPoint; + FMarkPositions: TPieMarkPositions; + FRadius: Integer; + FSlices: array of TPieSlice; private FExploded: Boolean; FFixedRadius: TChartDistance; @@ -48,13 +55,10 @@ type procedure Measure(ADrawer: IChartDrawer); procedure SetExploded(AValue: Boolean); procedure SetFixedRadius(AValue: TChartDistance); + procedure SetMarkPositions(AValue: TPieMarkPositions); procedure SetRotateLabels(AValue: Boolean); function SliceColor(AIndex: Integer): TColor; function TryRadius(ADrawer: IChartDrawer): TRect; - private - FCenter: TPoint; - FRadius: Integer; - FSlices: array of TPieSlice; protected procedure AfterAdd; override; procedure GetLegendItems(AItems: TChartLegendItems); override; @@ -68,6 +72,8 @@ type property Exploded: Boolean read FExploded write SetExploded default false; property FixedRadius: TChartDistance read FFixedRadius write SetFixedRadius default 0; + property MarkPositions: TPieMarkPositions + read FMarkPositions write SetMarkPositions default pmpAround; property RotateLabels: Boolean read FRotateLabels write SetRotateLabels default false; end; @@ -261,6 +267,13 @@ begin UpdateParentChart; end; +procedure TCustomPieSeries.SetMarkPositions(AValue: TPieMarkPositions); +begin + if FMarkPositions = AValue then exit; + FMarkPositions := AValue; + UpdateParentChart; +end; + procedure TCustomPieSeries.SetRotateLabels(AValue: Boolean); begin if FRotateLabels = AValue then exit; @@ -320,6 +333,7 @@ function TCustomPieSeries.TryRadius(ADrawer: IChartDrawer): TRect; var i: Integer; p: TPointArray; + d: TPoint; begin with ALabel do begin FCenter := FAttachment; @@ -329,7 +343,11 @@ function TCustomPieSeries.TryRadius(ADrawer: IChartDrawer): TRect; if RotateLabels then Marks.SetAdditionalAngle(AAngle); p := Marks.GetLabelPolygon(ADrawer, ADrawer.TextExtent(FText)); - FCenter += EndPoint(AAngle, Marks.Distance + LabelExtraDist(p, AAngle)); + d := EndPoint(AAngle, Marks.Distance + LabelExtraDist(p, AAngle)); + case MarkPositions of + pmpAround: FCenter += d; + pmpInside: FCenter -= d; + end; for i := 0 to High(p) do ExpandRect(Result, p[i] + FCenter); end; diff --git a/components/tachart/taseries.pas b/components/tachart/taseries.pas index ff818d5f2a..23085d997e 100644 --- a/components/tachart/taseries.pas +++ b/components/tachart/taseries.pas @@ -111,6 +111,7 @@ type published property Exploded; property FixedRadius; + property MarkPositions; property RotateLabels; property Source; end;