mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-22 12:39:23 +02:00
TAChart: Add TPieSeries.Exploded property
git-svn-id: trunk@21907 -
This commit is contained in:
parent
76ac5c262e
commit
4abec83a51
@ -84,6 +84,8 @@ type
|
|||||||
|
|
||||||
TPieSeries = class(TChartSeries)
|
TPieSeries = class(TChartSeries)
|
||||||
private
|
private
|
||||||
|
FExploded: Boolean;
|
||||||
|
procedure SetExploded(const AValue: Boolean);
|
||||||
function SliceColor(AIndex: Integer): TColor;
|
function SliceColor(AIndex: Integer): TColor;
|
||||||
protected
|
protected
|
||||||
procedure AfterAdd; override;
|
procedure AfterAdd; override;
|
||||||
@ -94,6 +96,8 @@ type
|
|||||||
function AddPie(Value: Double; Text: String; Color: TColor): Longint;
|
function AddPie(Value: Double; Text: String; Color: TColor): Longint;
|
||||||
procedure Draw(ACanvas: TCanvas); override;
|
procedure Draw(ACanvas: TCanvas); override;
|
||||||
published
|
published
|
||||||
|
// Offset slices away from center based on X value.
|
||||||
|
property Exploded: Boolean read FExploded write SetExploded default false;
|
||||||
property Source;
|
property Source;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -768,17 +772,15 @@ end;
|
|||||||
|
|
||||||
procedure TPieSeries.Draw(ACanvas: TCanvas);
|
procedure TPieSeries.Draw(ACanvas: TCanvas);
|
||||||
var
|
var
|
||||||
i, radius: Integer;
|
|
||||||
prevAngle, angleStep: Double;
|
|
||||||
labelWidths, labelHeights: TIntegerDynArray;
|
labelWidths, labelHeights: TIntegerDynArray;
|
||||||
labelTexts: TStringDynArray;
|
labelTexts: TStringDynArray;
|
||||||
a, b, center: TPoint;
|
|
||||||
r: TRect;
|
procedure Measure(out ACenter: TPoint; out ARadius: Integer);
|
||||||
const
|
const
|
||||||
MARGIN = 8;
|
MARGIN = 8;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
if IsEmpty then exit;
|
|
||||||
|
|
||||||
SetLength(labelWidths, Count);
|
SetLength(labelWidths, Count);
|
||||||
SetLength(labelHeights, Count);
|
SetLength(labelHeights, Count);
|
||||||
SetLength(labelTexts, Count);
|
SetLength(labelTexts, Count);
|
||||||
@ -791,37 +793,55 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
with ParentChart do begin
|
with ParentChart do begin
|
||||||
center := CenterPoint(ClipRect);
|
ACenter := CenterPoint(ClipRect);
|
||||||
// Reserve space for labels.
|
// Reserve space for labels.
|
||||||
radius := Min(
|
ARadius := Min(
|
||||||
ClipRect.Right - center.x - MaxIntValue(labelWidths),
|
ClipRect.Right - ACenter.x - MaxIntValue(labelWidths),
|
||||||
ClipRect.Bottom - center.y - MaxIntValue(labelHeights));
|
ClipRect.Bottom - ACenter.y - MaxIntValue(labelHeights));
|
||||||
end;
|
end;
|
||||||
if Marks.IsMarkLabelsVisible then
|
if Marks.IsMarkLabelsVisible then
|
||||||
radius -= Marks.Distance;
|
ARadius -= Marks.Distance;
|
||||||
radius := Max(radius - MARGIN, 0);
|
ARadius := Max(ARadius - MARGIN, 0);
|
||||||
|
if Exploded then
|
||||||
|
ARadius := Trunc(ARadius / (Max(Source.Extent.b.X, 0) + 1));
|
||||||
|
end;
|
||||||
|
|
||||||
prevAngle := 0;
|
var
|
||||||
|
i, radius: Integer;
|
||||||
|
prevAngle: Double = 0;
|
||||||
|
angleStep, sliceCenterAngle: Double;
|
||||||
|
a, b, c, center: TPoint;
|
||||||
|
r: TRect;
|
||||||
|
const
|
||||||
|
RAD_TO_DEG16 = 360 * 16;
|
||||||
|
begin
|
||||||
|
if IsEmpty then exit;
|
||||||
|
|
||||||
|
Measure(center, radius);
|
||||||
for i := 0 to Count - 1 do begin
|
for i := 0 to Count - 1 do begin
|
||||||
// if y < 0 then y := -y;
|
|
||||||
// if y = 0 then y := 0.1; // just to simulate tchart when y=0
|
|
||||||
|
|
||||||
angleStep := Source[i]^.Y / Source.ValuesTotal * 360 * 16;
|
|
||||||
ACanvas.Pen.Color := clBlack;
|
ACanvas.Pen.Color := clBlack;
|
||||||
ACanvas.Pen.Style := psSolid;
|
ACanvas.Pen.Style := psSolid;
|
||||||
ACanvas.Brush.Style := bsSolid;
|
ACanvas.Brush.Style := bsSolid;
|
||||||
ACanvas.Brush.Color := SliceColor(i);
|
ACanvas.Brush.Color := SliceColor(i);
|
||||||
|
|
||||||
|
with Source[i]^ do begin
|
||||||
|
angleStep := Y / Source.ValuesTotal * RAD_TO_DEG16;
|
||||||
|
sliceCenterAngle := prevAngle + angleStep / 2;
|
||||||
|
if Exploded and (X > 0) then
|
||||||
|
c := LineEndPoint(center, sliceCenterAngle, radius * X)
|
||||||
|
else
|
||||||
|
c := center;
|
||||||
|
end;
|
||||||
ACanvas.RadialPie(
|
ACanvas.RadialPie(
|
||||||
center.x - radius, center.y - radius,
|
c.x - radius, c.y - radius, c.x + radius, c.y + radius,
|
||||||
center.x + radius, center.y + radius, round(prevAngle), round(angleStep));
|
round(prevAngle), round(angleStep));
|
||||||
|
|
||||||
prevAngle += angleStep;
|
prevAngle += angleStep;
|
||||||
|
|
||||||
if not Marks.IsMarkLabelsVisible then continue;
|
if not Marks.IsMarkLabelsVisible then continue;
|
||||||
|
|
||||||
a := LineEndPoint(center, prevAngle - angleStep / 2, radius);
|
a := LineEndPoint(c, sliceCenterAngle, radius);
|
||||||
b := LineEndPoint(center, prevAngle - angleStep / 2, radius + Marks.Distance);
|
b := LineEndPoint(c, sliceCenterAngle, radius + Marks.Distance);
|
||||||
|
|
||||||
// line from mark to pie
|
// line from mark to pie
|
||||||
ACanvas.Pen.Assign(Marks.LinkPen);
|
ACanvas.Pen.Assign(Marks.LinkPen);
|
||||||
@ -851,6 +871,13 @@ begin
|
|||||||
Result := clBlack; // SeriesColor is meaningless for PieSeries
|
Result := clBlack; // SeriesColor is meaningless for PieSeries
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TPieSeries.SetExploded(const AValue: Boolean);
|
||||||
|
begin
|
||||||
|
if FExploded = AValue then exit;
|
||||||
|
FExploded := AValue;
|
||||||
|
UpdateParentChart;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TPieSeries.SetSeriesColor(const AValue: TColor);
|
procedure TPieSeries.SetSeriesColor(const AValue: TColor);
|
||||||
begin
|
begin
|
||||||
// SeriesColor is meaningless for PieSeries
|
// SeriesColor is meaningless for PieSeries
|
||||||
|
Loading…
Reference in New Issue
Block a user