From 3464f50fbd94370895643d926ca3ad81fae73b2b Mon Sep 17 00:00:00 2001 From: ask Date: Fri, 7 Sep 2012 16:15:02 +0000 Subject: [PATCH] TAChart: Add Marks.Shape property git-svn-id: trunk@38561 - --- components/tachart/tageometry.pas | 7 ++++++ components/tachart/tatypes.pas | 38 ++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/components/tachart/tageometry.pas b/components/tachart/tageometry.pas index e6aa0f500e..38e226c39b 100644 --- a/components/tachart/tageometry.pas +++ b/components/tachart/tageometry.pas @@ -29,6 +29,7 @@ type FC: TDoublePoint; FR: TDoublePoint; constructor InitBoundingBox(AX1, AY1, AX2, AY2: Integer); + constructor InitRadius(ARX, ARY: Double); public function GetPoint(AParametricAngle: Double): TDoublePoint; function TesselateRadialPie( @@ -547,6 +548,12 @@ begin FR.Y := Abs(AY1 - AY2) / 2; end; +constructor TEllipse.InitRadius(ARX, ARY: Double); +begin + FC := ZeroDoublePoint; + FR := DoublePoint(ARX, ARY); +end; + // Represent the ellipse sector with a polygon on an integer grid. // Polygon vertices are no more then AStep pixels apart. function TEllipse.TesselateRadialPie( diff --git a/components/tachart/tatypes.pas b/components/tachart/tatypes.pas index f48a86faed..554d727b87 100644 --- a/components/tachart/tatypes.pas +++ b/components/tachart/tatypes.pas @@ -114,7 +114,8 @@ type procedure DrawLabel( ADrawer: IChartDrawer; const ADataPoint, ALabelCenter: TPoint; const AText: String; var APrevLabelPoly: TPointArray); - function GetLabelPolygon(ADrawer: IChartDrawer; ASize: TPoint): TPointArray; + function GetLabelPolygon( + ADrawer: IChartDrawer; ASize: TPoint): TPointArray; virtual; function MeasureLabel(ADrawer: IChartDrawer; const AText: String): TSize; public // If false, labels may overlap axises and legend. @@ -171,6 +172,7 @@ type TChartArrow = class; TChartMarkAttachment = (maDefault, maEdge, maCenter); + TChartMarkLabelShape = (cmsRectangle, cmsEllipse); { TGenericChartMarks } @@ -185,6 +187,7 @@ type FArrow: TChartArrow; FAttachment: TChartMarkAttachment; FFrame: _TFramePen; + FShape: TChartMarkLabelShape; FYIndex: Integer; function GetDistanceToCenter: Boolean; procedure SetArrow(AValue: TChartArrow); @@ -196,6 +199,7 @@ type procedure SetLabelBrush(AValue: _TLabelBrush); procedure SetLabelFont(AValue: TFont); procedure SetLinkPen(AValue: _TLinkPen); + procedure SetShape(AValue: TChartMarkLabelShape); procedure SetStyle(AValue: TSeriesMarksStyle); procedure SetYIndex(AValue: Integer); strict protected @@ -220,6 +224,8 @@ type public procedure Assign(ASource: TPersistent); override; function CenterOffset(ADrawer: IChartDrawer; const AText: String): TSize; + function GetLabelPolygon( + ADrawer: IChartDrawer; ASize: TPoint): TPointArray; override; function IsMarkLabelsVisible: Boolean; procedure SetAdditionalAngle(AAngle: Double); public @@ -241,6 +247,8 @@ type property Clipped; property Distance: TChartDistance read FDistance write SetDistance; property LabelFont: TFont read FLabelFont write SetLabelFont; + property Shape: TChartMarkLabelShape + read FShape write SetShape default cmsRectangle; property Visible default true; end; @@ -824,6 +832,27 @@ begin Result := LabelFont; end; +function TGenericChartMarks.GetLabelPolygon(ADrawer: IChartDrawer; + ASize: TPoint): TPointArray; +var + e: TEllipse; + a: Double; + i: Integer; +begin + AddMargins(ADrawer, ASize); + case Shape of + cmsRectangle: Result := RotateRect(ASize, GetLabelAngle); + cmsEllipse: begin + e.InitRadius(ASize.X / 2, ASize.Y / 2); + Result := e.TesselateRadialPie(0, 2 * Pi, 3); + SetLength(Result, Length(Result) - 1); + a := GetLabelAngle; + for i := 0 to High(Result) do + Result[i] := RotatePoint(Result[i], a); + end; + end; +end; + function TGenericChartMarks.GetLinkPen: TChartPen; begin Result := LinkPen; @@ -907,6 +936,13 @@ begin StyleChanged(Self); end; +procedure TGenericChartMarks.SetShape(AValue: TChartMarkLabelShape); +begin + if FShape = AValue then exit; + FShape := AValue; + StyleChanged(Self); +end; + procedure TGenericChartMarks.SetStyle(AValue: TSeriesMarksStyle); begin if FStyle = AValue then exit;