From fdfaa2f99a2c276f6d9aeb954b888112ab9ac552 Mon Sep 17 00:00:00 2001 From: ask Date: Thu, 6 Sep 2012 15:22:10 +0000 Subject: [PATCH] TAChart: Add pie series support to the svg drawer git-svn-id: trunk@38542 - --- components/tachart/tachartutils.pas | 6 +++++ components/tachart/tadrawersvg.pas | 38 +++++++++++++++++++++-------- components/tachart/tageometry.pas | 10 ++++++++ 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/components/tachart/tachartutils.pas b/components/tachart/tachartutils.pas index 52decbfc38..032189dde0 100644 --- a/components/tachart/tachartutils.pas +++ b/components/tachart/tachartutils.pas @@ -259,6 +259,7 @@ const function BoundsSize(ALeft, ATop: Integer; ASize: TSize): TRect; inline; +function Deg16ToRad(ADeg16: Integer): Double; inline; function DoubleInterval(AStart, AEnd: Double): TDoubleInterval; inline; procedure Exchange(var A, B: Integer); overload; inline; @@ -317,6 +318,11 @@ begin Result := Bounds(ALeft, ATop, ASize.cx, ASize.cy); end; +function Deg16ToRad(ADeg16: Integer): Double; +begin + Result := DegToRad(ADeg16 / 16); +end; + function DoubleInterval(AStart, AEnd: Double): TDoubleInterval; begin Result.FStart := AStart; diff --git a/components/tachart/tadrawersvg.pas b/components/tachart/tadrawersvg.pas index 0d4bfef5f0..4ee6497dad 100644 --- a/components/tachart/tadrawersvg.pas +++ b/components/tachart/tadrawersvg.pas @@ -96,6 +96,8 @@ uses const RECT_FMT = ''; +var + fmtSettings: TFormatSettings; function ColorToHex(AColor: TFPColor): String; begin @@ -108,6 +110,16 @@ begin Result := Format('#%.2x%.2x%.2x', [red shr 8, green shr 8, blue shr 8]); end; +function DP2S(AValue: TDoublePoint): String; +begin + Result := Format('%g,%g', [AValue.X, AValue.Y], fmtSettings); +end; + +function F2S(AValue: Double): String; +begin + Result := FloatToStr(AValue, fmtSettings); +end; + { TSVGDrawer } procedure TSVGDrawer.AddToFontOrientation(ADelta: Integer); @@ -226,16 +238,11 @@ begin end; function TSVGDrawer.OpacityStr: String; -var - fs: TFormatSettings; begin if FTransparency = 0 then Result := '' - else begin - fs := DefaultFormatSettings; - fs.DecimalSeparator := '.'; - Result := FloatToStr((255 - FTransparency) / 256, fs); - end; + else + Result := F2S((255 - FTransparency) / 256); end; function TSVGDrawer.PointsToStr( @@ -276,10 +283,16 @@ end; procedure TSVGDrawer.RadialPie( AX1, AY1, AX2, AY2: Integer; AStartAngle16Deg, AAngleLength16Deg: Integer); +var + e: TEllipse; + p1, p2: TDoublePoint; begin - Unused(AX1, AY1); - Unused(AX2, AY2); - Unused(AStartAngle16Deg, AAngleLength16Deg); + e.InitBoundingBox(AX1, AY1, AX2, AY2); + p1 := e.GetPoint(Deg16ToRad(AStartAngle16Deg)); + p2 := e.GetPoint(Deg16ToRad(AStartAngle16Deg + AAngleLength16Deg)); + WriteFmt( + '', + [DP2S(e.FC), DP2S(p1), DP2S(e.FR), DP2S(p2), StyleFill + StyleStroke]); end; procedure TSVGDrawer.Rectangle(AX1, AY1, AX2, AY2: Integer); @@ -399,5 +412,10 @@ begin FStream.WriteBuffer(le[1], Length(le)); end; +initialization + + fmtSettings := DefaultFormatSettings; + fmtSettings.DecimalSeparator := '.'; + end. diff --git a/components/tachart/tageometry.pas b/components/tachart/tageometry.pas index 2584cbe4ae..9225beb416 100644 --- a/components/tachart/tageometry.pas +++ b/components/tachart/tageometry.pas @@ -29,6 +29,8 @@ type FC: TDoublePoint; FR: TDoublePoint; constructor InitBoundingBox(AX1, AY1, AX2, AY2: Integer); + public + function GetPoint(AParametricAngle: Double): TDoublePoint; end; function CopyPoints( @@ -520,6 +522,14 @@ end; { TEllipse } +function TEllipse.GetPoint(AParametricAngle: Double): TDoublePoint; +var + s, c: Extended; +begin + SinCos(AParametricAngle, s, c); + Result := DoublePoint(c, -s) * FR + FC; +end; + constructor TEllipse.InitBoundingBox(AX1, AY1, AX2, AY2: Integer); begin FC.X := (AX1 + AX2) / 2;