TAChart: Use IChartDrawer to draw TFuncSeries and TColorMapSeries

git-svn-id: trunk@29637 -
This commit is contained in:
ask 2011-02-21 16:41:13 +00:00
parent 43e58801a0
commit f72f36bdd3
3 changed files with 57 additions and 15 deletions

View File

@ -19,8 +19,8 @@ type
procedure SetPen(APen: TFPCustomPen); procedure SetPen(APen: TFPCustomPen);
strict protected strict protected
function GetFontAngle: Double; override; function GetFontAngle: Double; override;
procedure SimpleTextOut(AX, AY: Integer; const AText: String); override;
function SimpleTextExtent(const AText: String): TPoint; override; function SimpleTextExtent(const AText: String): TPoint; override;
procedure SimpleTextOut(AX, AY: Integer; const AText: String); override;
public public
constructor Create(ACanvas: TAggLCLCanvas); constructor Create(ACanvas: TAggLCLCanvas);
public public
@ -35,6 +35,8 @@ type
function HasCanvas: Boolean; function HasCanvas: Boolean;
procedure Line(AX1, AY1, AX2, AY2: Integer); procedure Line(AX1, AY1, AX2, AY2: Integer);
procedure Line(const AP1, AP2: TPoint); procedure Line(const AP1, AP2: TPoint);
procedure LineTo(AX, AY: Integer); override;
procedure MoveTo(AX, AY: Integer); override;
procedure Polygon( procedure Polygon(
const APoints: array of TPoint; const APoints: array of TPoint;
AStartIndex: Integer = 0; ANumPts: Integer = -1); override; AStartIndex: Integer = 0; ANumPts: Integer = -1); override;
@ -127,6 +129,16 @@ begin
FCanvas.Line(AP1, AP2); FCanvas.Line(AP1, AP2);
end; end;
procedure TAggPasDrawer.LineTo(AX, AY: Integer);
begin
FCanvas.LineTo(AX, AY);
end;
procedure TAggPasDrawer.MoveTo(AX, AY: Integer);
begin
FCanvas.MoveTo(AX, AY);
end;
procedure TAggPasDrawer.Polygon( procedure TAggPasDrawer.Polygon(
const APoints: array of TPoint; AStartIndex, ANumPts: Integer); const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
begin begin

View File

@ -80,6 +80,10 @@ type
function HasCanvas: Boolean; function HasCanvas: Boolean;
procedure Line(AX1, AY1, AX2, AY2: Integer); procedure Line(AX1, AY1, AX2, AY2: Integer);
procedure Line(const AP1, AP2: TPoint); procedure Line(const AP1, AP2: TPoint);
procedure LineTo(AX, AY: Integer);
procedure LineTo(const AP: TPoint);
procedure MoveTo(AX, AY: Integer);
procedure MoveTo(const AP: TPoint);
procedure Polygon( procedure Polygon(
const APoints: array of TPoint; const APoints: array of TPoint;
AStartIndex: Integer = 0; ANumPts: Integer = -1); AStartIndex: Integer = 0; ANumPts: Integer = -1);
@ -119,6 +123,10 @@ type
public public
procedure DrawLineDepth(AX1, AY1, AX2, AY2, ADepth: Integer); procedure DrawLineDepth(AX1, AY1, AX2, AY2, ADepth: Integer);
procedure DrawLineDepth(const AP1, AP2: TPoint; ADepth: Integer); procedure DrawLineDepth(const AP1, AP2: TPoint; ADepth: Integer);
procedure LineTo(AX, AY: Integer); virtual; abstract;
procedure LineTo(const AP: TPoint);
procedure MoveTo(AX, AY: Integer); virtual; abstract;
procedure MoveTo(const AP: TPoint);
procedure Polygon( procedure Polygon(
const APoints: array of TPoint; const APoints: array of TPoint;
AStartIndex: Integer = 0; ANumPts: Integer = -1); virtual; abstract; AStartIndex: Integer = 0; ANumPts: Integer = -1); virtual; abstract;
@ -152,6 +160,8 @@ type
function HasCanvas: Boolean; function HasCanvas: Boolean;
procedure Line(AX1, AY1, AX2, AY2: Integer); procedure Line(AX1, AY1, AX2, AY2: Integer);
procedure Line(const AP1, AP2: TPoint); procedure Line(const AP1, AP2: TPoint);
procedure LineTo(AX, AY: Integer); override;
procedure MoveTo(AX, AY: Integer); override;
procedure Polygon( procedure Polygon(
const APoints: array of TPoint; const APoints: array of TPoint;
AStartIndex: Integer = 0; ANumPts: Integer = -1); override; AStartIndex: Integer = 0; ANumPts: Integer = -1); override;
@ -292,6 +302,16 @@ begin
Polygon([AP1, AP1 + d, AP2 + d, AP2]); Polygon([AP1, AP1 + d, AP2 + d, AP2]);
end; end;
procedure TFPCanvasDrawer.LineTo(const AP: TPoint);
begin
LineTo(AP.X, AP.Y)
end;
procedure TFPCanvasDrawer.MoveTo(const AP: TPoint);
begin
MoveTo(AP.X, AP.Y)
end;
function TFPCanvasDrawer.TextExtent(const AText: String): TPoint; function TFPCanvasDrawer.TextExtent(const AText: String): TPoint;
var var
sl: TStrings; sl: TStrings;
@ -393,6 +413,16 @@ begin
FCanvas.Line(AP1, AP2); FCanvas.Line(AP1, AP2);
end; end;
procedure TCanvasDrawer.LineTo(AX, AY: Integer);
begin
FCanvas.LineTo(AX, AY);
end;
procedure TCanvasDrawer.MoveTo(AX, AY: Integer);
begin
FCanvas.MoveTo(AX, AY);
end;
procedure TCanvasDrawer.Polygon( procedure TCanvasDrawer.Polygon(
const APoints: array of TPoint; AStartIndex, ANumPts: Integer); const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
begin begin

View File

@ -24,7 +24,7 @@ interface
uses uses
Classes, Graphics, Classes, Graphics,
TAChartUtils, TACustomSeries, TACustomSource, TALegend, TATypes; TAChartUtils, TACustomSeries, TACustomSource, TADrawUtils, TALegend, TATypes;
const const
DEF_COLORMAP_STEP = 4; DEF_COLORMAP_STEP = 4;
@ -77,7 +77,7 @@ type
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
procedure Draw(ACanvas: TCanvas); override; procedure Draw(ADrawer: IChartDrawer); override;
function IsEmpty: Boolean; override; function IsEmpty: Boolean; override;
public public
property DomainExclusions: TIntervalList read FDomainExclusions; property DomainExclusions: TIntervalList read FDomainExclusions;
@ -120,7 +120,7 @@ type
public public
function ColorByValue(AValue: Double): TColor; function ColorByValue(AValue: Double): TColor;
procedure Draw(ACanvas: TCanvas); override; procedure Draw(ADrawer: IChartDrawer); override;
function IsEmpty: Boolean; override; function IsEmpty: Boolean; override;
published published
property AxisIndexX; property AxisIndexX;
@ -234,7 +234,7 @@ begin
OnCalculate(AX, Result) OnCalculate(AX, Result)
end; end;
procedure TFuncSeries.Draw(ACanvas: TCanvas); procedure TFuncSeries.Draw(ADrawer: IChartDrawer);
type type
TTransform = function (A: Double): Double of object; TTransform = function (A: Double): Double of object;
TMakeDoublePoint = function (AX, AY: Double): TDoublePoint; TMakeDoublePoint = function (AX, AY: Double): TDoublePoint;
@ -256,7 +256,7 @@ var
begin begin
CalcAt(AXg, AXa, prev, prevInExtent); CalcAt(AXg, AXa, prev, prevInExtent);
if prevInExtent then if prevInExtent then
ACanvas.MoveTo(FChart.GraphToImage(prev)); ADrawer.MoveTo(FChart.GraphToImage(prev));
end; end;
procedure LineTo(AXg, AXa: Double); procedure LineTo(AXg, AXa: Double);
@ -267,10 +267,10 @@ var
CalcAt(AXg, AXa, p, inExtent); CalcAt(AXg, AXa, p, inExtent);
t := p; t := p;
if inExtent and prevInExtent then if inExtent and prevInExtent then
ACanvas.LineTo(FChart.GraphToImage(p)) ADrawer.LineTo(FChart.GraphToImage(p))
else if LineIntersectsRect(prev, t, r) then begin else if LineIntersectsRect(prev, t, r) then begin
ACanvas.MoveTo(FChart.GraphToImage(prev)); ADrawer.MoveTo(FChart.GraphToImage(prev));
ACanvas.LineTo(FChart.GraphToImage(t)); ADrawer.LineTo(FChart.GraphToImage(t));
end; end;
prevInExtent := inExtent; prevInExtent := inExtent;
prev := p; prev := p;
@ -315,7 +315,7 @@ begin
MoveTo(xg, xa); MoveTo(xg, xa);
ACanvas.Pen.Assign(Pen); ADrawer.Pen := Pen;
while xg < xmax do begin while xg < xmax do begin
xg1 := xg + graphStep; xg1 := xg + graphStep;
xa1 := graphToAxisXr(xg1); xa1 := graphToAxisXr(xg1);
@ -421,7 +421,7 @@ begin
inherited Destroy; inherited Destroy;
end; end;
procedure TColorMapSeries.Draw(ACanvas: TCanvas); procedure TColorMapSeries.Draw(ADrawer: IChartDrawer);
var var
ext: TDoubleRect; ext: TDoubleRect;
bounds: TDoubleRect; bounds: TDoubleRect;
@ -444,8 +444,8 @@ begin
NormalizeRect(r); NormalizeRect(r);
offset := ParentChart.GraphToImage(ZeroDoublePoint); offset := ParentChart.GraphToImage(ZeroDoublePoint);
ACanvas.Brush := Brush; ADrawer.Brush := Brush;
ACanvas.Pen.Style := psClear; ADrawer.SetPenParams(psClear, clTAColor);
pt.Y := (r.Top div StepY - 1) * StepY + offset.Y mod StepY; pt.Y := (r.Top div StepY - 1) * StepY + offset.Y mod StepY;
while pt.Y <= r.Bottom do begin while pt.Y <= r.Bottom do begin
next.Y := pt.Y + StepY; next.Y := pt.Y + StepY;
@ -464,8 +464,8 @@ begin
if not (csDesigning in ComponentState) then if not (csDesigning in ComponentState) then
OnCalculate(gp.X, gp.Y, v); OnCalculate(gp.X, gp.Y, v);
if ColorSource <> nil then if ColorSource <> nil then
ACanvas.Brush.Color := ColorByValue(v); ADrawer.BrushColor := ColorByValue(v);
ACanvas.Rectangle( ADrawer.Rectangle(
Max(pt.X, r.Left), Max(pt.Y, r.Top), Max(pt.X, r.Left), Max(pt.Y, r.Top),
Min(next.X, r.Right) + 1, Min(next.Y, r.Bottom) + 1); Min(next.X, r.Right) + 1, Min(next.Y, r.Bottom) + 1);
pt.X := next.X; pt.X := next.X;