mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-06 13:38:19 +02:00
TAChart: Use IChartDrawer to draw radial series
git-svn-id: trunk@29534 -
This commit is contained in:
parent
bea6cd43d9
commit
0ff70e0b68
@ -729,6 +729,7 @@ end;
|
|||||||
|
|
||||||
procedure TChart.DrawReticule(ACanvas: TCanvas);
|
procedure TChart.DrawReticule(ACanvas: TCanvas);
|
||||||
begin
|
begin
|
||||||
|
if ReticuleMode = rmNone then exit;
|
||||||
PrepareXorPen(ACanvas);
|
PrepareXorPen(ACanvas);
|
||||||
if ReticuleMode in [rmVertical, rmCross] then
|
if ReticuleMode in [rmVertical, rmCross] then
|
||||||
DrawLineVert(ACanvas, FReticulePos.X);
|
DrawLineVert(ACanvas, FReticulePos.X);
|
||||||
|
@ -23,7 +23,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, Graphics, SysUtils, Types,
|
Classes, Graphics, SysUtils, Types,
|
||||||
TAChartUtils, TACustomSeries, TALegend;
|
TAChartUtils, TACustomSeries, TADrawUtils, TALegend;
|
||||||
|
|
||||||
type
|
type
|
||||||
TLabelParams = record
|
TLabelParams = record
|
||||||
@ -45,12 +45,12 @@ type
|
|||||||
FExploded: Boolean;
|
FExploded: Boolean;
|
||||||
FFixedRadius: TChartDistance;
|
FFixedRadius: TChartDistance;
|
||||||
FRotateLabels: Boolean;
|
FRotateLabels: Boolean;
|
||||||
procedure Measure(ACanvas: TCanvas);
|
procedure Measure(ADrawer: IChartDrawer);
|
||||||
procedure SetExploded(AValue: Boolean);
|
procedure SetExploded(AValue: Boolean);
|
||||||
procedure SetFixedRadius(AValue: TChartDistance);
|
procedure SetFixedRadius(AValue: TChartDistance);
|
||||||
procedure SetRotateLabels(AValue: Boolean);
|
procedure SetRotateLabels(AValue: Boolean);
|
||||||
function SliceColor(AIndex: Integer): TColor;
|
function SliceColor(AIndex: Integer): TColor;
|
||||||
function TryRadius(ACanvas: TCanvas): TRect;
|
function TryRadius(ADrawer: IChartDrawer): TRect;
|
||||||
private
|
private
|
||||||
FCenter: TPoint;
|
FCenter: TPoint;
|
||||||
FRadius: Integer;
|
FRadius: Integer;
|
||||||
@ -61,7 +61,7 @@ type
|
|||||||
public
|
public
|
||||||
function AddPie(AValue: Double; AText: String; AColor: TColor): Integer;
|
function AddPie(AValue: Double; AText: String; AColor: TColor): Integer;
|
||||||
procedure Assign(ASource: TPersistent); override;
|
procedure Assign(ASource: TPersistent); override;
|
||||||
procedure Draw(ACanvas: TCanvas); override;
|
procedure Draw(ADrawer: IChartDrawer); override;
|
||||||
function FindContainingSlice(const APoint: TPoint): Integer;
|
function FindContainingSlice(const APoint: TPoint): Integer;
|
||||||
|
|
||||||
// Offset slices away from center based on X value.
|
// Offset slices away from center based on X value.
|
||||||
@ -99,7 +99,7 @@ type
|
|||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
public
|
public
|
||||||
procedure Draw(ACanvas: TCanvas); override;
|
procedure Draw(ADrawer: IChartDrawer); override;
|
||||||
function Extent: TDoubleRect; override;
|
function Extent: TDoubleRect; override;
|
||||||
published
|
published
|
||||||
property LinePen: TPen read FLinePen write SetLinePen;
|
property LinePen: TPen read FLinePen write SetLinePen;
|
||||||
@ -112,7 +112,7 @@ implementation
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Math,
|
Math,
|
||||||
TACustomSource, TADrawUtils, TAGraph;
|
TACustomSource, TAGraph;
|
||||||
|
|
||||||
{ TCustomPieSeries }
|
{ TCustomPieSeries }
|
||||||
|
|
||||||
@ -141,25 +141,22 @@ begin
|
|||||||
inherited Assign(ASource);
|
inherited Assign(ASource);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomPieSeries.Draw(ACanvas: TCanvas);
|
procedure TCustomPieSeries.Draw(ADrawer: IChartDrawer);
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
prevAngle: Double = 0;
|
prevAngle: Double = 0;
|
||||||
prevLabelPoly: TPointArray = nil;
|
prevLabelPoly: TPointArray = nil;
|
||||||
drawer: IChartDrawer;
|
|
||||||
begin
|
begin
|
||||||
if IsEmpty then exit;
|
if IsEmpty then exit;
|
||||||
|
|
||||||
Marks.SetAdditionalAngle(0);
|
Marks.SetAdditionalAngle(0);
|
||||||
Measure(ACanvas);
|
Measure(ADrawer);
|
||||||
|
|
||||||
ACanvas.Pen.Color := clBlack;
|
ADrawer.SetPenParams(psSolid, clBlack);
|
||||||
ACanvas.Pen.Style := psSolid;
|
|
||||||
ACanvas.Brush.Style := bsSolid;
|
|
||||||
for i := 0 to Count - 1 do begin
|
for i := 0 to Count - 1 do begin
|
||||||
ACanvas.Brush.Color := SliceColor(i);
|
ADrawer.SetBrushParams(bsSolid, SliceColor(i));
|
||||||
with FSlices[i] do begin
|
with FSlices[i] do begin
|
||||||
ACanvas.RadialPie(
|
ADrawer.RadialPie(
|
||||||
FBase.X - FRadius, FBase.Y - FRadius,
|
FBase.X - FRadius, FBase.Y - FRadius,
|
||||||
FBase.X + FRadius, FBase.Y + FRadius,
|
FBase.X + FRadius, FBase.Y + FRadius,
|
||||||
RadToDeg16(prevAngle), RadToDeg16(FAngle));
|
RadToDeg16(prevAngle), RadToDeg16(FAngle));
|
||||||
@ -168,13 +165,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
if not Marks.IsMarkLabelsVisible then exit;
|
if not Marks.IsMarkLabelsVisible then exit;
|
||||||
prevAngle := 0;
|
prevAngle := 0;
|
||||||
drawer := TCanvasDrawer.Create(ACanvas);
|
|
||||||
for i := 0 to Count - 1 do
|
for i := 0 to Count - 1 do
|
||||||
with FSlices[i].FLabel do begin
|
with FSlices[i].FLabel do begin
|
||||||
if FText <> '' then begin
|
if FText <> '' then begin
|
||||||
if RotateLabels then
|
if RotateLabels then
|
||||||
Marks.SetAdditionalAngle(prevAngle + FSlices[i].FAngle / 2);
|
Marks.SetAdditionalAngle(prevAngle + FSlices[i].FAngle / 2);
|
||||||
Marks.DrawLabel(drawer, FAttachment, FCenter, FText, prevLabelPoly);
|
Marks.DrawLabel(ADrawer, FAttachment, FCenter, FText, prevLabelPoly);
|
||||||
end;
|
end;
|
||||||
prevAngle += FSlices[i].FAngle;
|
prevAngle += FSlices[i].FAngle;
|
||||||
end;
|
end;
|
||||||
@ -225,7 +221,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomPieSeries.Measure(ACanvas: TCanvas);
|
procedure TCustomPieSeries.Measure(ADrawer: IChartDrawer);
|
||||||
const
|
const
|
||||||
MIN_RADIUS = 5;
|
MIN_RADIUS = 5;
|
||||||
var
|
var
|
||||||
@ -239,7 +235,7 @@ begin
|
|||||||
b := Max(cx div 2, cy div 2);
|
b := Max(cx div 2, cy div 2);
|
||||||
while a < b - 1 do begin
|
while a < b - 1 do begin
|
||||||
FRadius := (a + b) div 2;
|
FRadius := (a + b) div 2;
|
||||||
if IsRectInRect(TryRadius(ACanvas), ParentChart.ClipRect) then
|
if IsRectInRect(TryRadius(ADrawer), ParentChart.ClipRect) then
|
||||||
a := FRadius
|
a := FRadius
|
||||||
else
|
else
|
||||||
b := FRadius - 1;
|
b := FRadius - 1;
|
||||||
@ -247,7 +243,7 @@ begin
|
|||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
FRadius := FixedRadius;
|
FRadius := FixedRadius;
|
||||||
TryRadius(ACanvas);
|
TryRadius(ADrawer);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -278,7 +274,7 @@ begin
|
|||||||
ColorOrDefault(Source[AIndex]^.Color, Colors[AIndex mod High(Colors) + 1]);
|
ColorOrDefault(Source[AIndex]^.Color, Colors[AIndex mod High(Colors) + 1]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomPieSeries.TryRadius(ACanvas: TCanvas): TRect;
|
function TCustomPieSeries.TryRadius(ADrawer: IChartDrawer): TRect;
|
||||||
|
|
||||||
function EndPoint(AAngle, ARadius: Double): TPoint;
|
function EndPoint(AAngle, ARadius: Double): TPoint;
|
||||||
begin
|
begin
|
||||||
@ -327,7 +323,7 @@ function TCustomPieSeries.TryRadius(ACanvas: TCanvas): TRect;
|
|||||||
if FText = '' then exit;
|
if FText = '' then exit;
|
||||||
if RotateLabels then
|
if RotateLabels then
|
||||||
Marks.SetAdditionalAngle(AAngle);
|
Marks.SetAdditionalAngle(AAngle);
|
||||||
p := Marks.GetLabelPolygon(ACanvas.TextExtent(FText));
|
p := Marks.GetLabelPolygon(ADrawer.TextExtent(FText));
|
||||||
FCenter += EndPoint(AAngle, Marks.Distance + LabelExtraDist(p, AAngle));
|
FCenter += EndPoint(AAngle, Marks.Distance + LabelExtraDist(p, AAngle));
|
||||||
for i := 0 to High(p) do
|
for i := 0 to High(p) do
|
||||||
ExpandRect(Result, p[i] + FCenter);
|
ExpandRect(Result, p[i] + FCenter);
|
||||||
@ -389,7 +385,7 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPolarSeries.Draw(ACanvas: TCanvas);
|
procedure TPolarSeries.Draw(ADrawer: IChartDrawer);
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
pts: TPointArray;
|
pts: TPointArray;
|
||||||
@ -398,9 +394,9 @@ begin
|
|||||||
SetLength(pts, Count);
|
SetLength(pts, Count);
|
||||||
for i := 0 to Count - 1 do
|
for i := 0 to Count - 1 do
|
||||||
pts[i] := FChart.GraphToImage(GraphPoint(i));
|
pts[i] := FChart.GraphToImage(GraphPoint(i));
|
||||||
ACanvas.Pen := LinePen;
|
ADrawer.Pen := LinePen;
|
||||||
ACanvas.Brush.Style := bsClear;
|
ADrawer.SetBrushParams(bsClear, clTAColor);
|
||||||
ACanvas.Polygon(pts);
|
ADrawer.Polygon(pts);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TPolarSeries.Extent: TDoubleRect;
|
function TPolarSeries.Extent: TDoubleRect;
|
||||||
|
Loading…
Reference in New Issue
Block a user