mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-05 22:38:32 +01:00
TAChart: Add pie series support to the svg drawer
git-svn-id: trunk@38542 -
This commit is contained in:
parent
6ca1bc4e51
commit
fdfaa2f99a
@ -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;
|
||||
|
||||
@ -96,6 +96,8 @@ uses
|
||||
const
|
||||
RECT_FMT =
|
||||
'<rect x="%d" y="%d" width="%d" height="%d" style="%s"/>';
|
||||
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(
|
||||
'<path d="M%s L%s A%s 0 0,0 %s Z" style="%s"/>',
|
||||
[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.
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user