TAChart: Extract TChart.DrawBackground helper, fix axis drawing on chart without series

git-svn-id: trunk@27795 -
This commit is contained in:
ask 2010-10-21 13:07:56 +00:00
parent 387d267fa5
commit b8d55daabb
2 changed files with 62 additions and 61 deletions

View File

@ -172,10 +172,8 @@ type
procedure Assign(Source: TPersistent); override;
procedure Draw(
ACanvas: TCanvas; const AExtent: TDoubleRect;
const ATransf: ICoordTransformer; const ARect: TRect);
procedure DrawTitle(
ACanvas: TCanvas; const ACenter: TPoint; ASize: Integer;
const ARect: TRect);
const ATransf: ICoordTransformer);
procedure DrawTitle(ACanvas: TCanvas; const ACenter: TPoint; ASize: Integer);
function IsVertical: Boolean; inline;
procedure Measure(
ACanvas: TCanvas; const AExtent: TDoubleRect; AFirstPass: Boolean;
@ -435,7 +433,7 @@ end;
procedure TChartAxis.Draw(
ACanvas: TCanvas; const AExtent: TDoubleRect;
const ATransf: ICoordTransformer; const ARect: TRect);
const ATransf: ICoordTransformer);
var
prevLabelPoly: TPointArray = nil;
@ -500,11 +498,10 @@ var
var
i, coord: Integer;
v: Double;
a: TChartAxisMargins absolute ARect;
begin
if not Visible then exit;
ACanvas.Font := Marks.LabelFont;
coord := a[Alignment];
coord := TChartAxisMargins(FAxisRect)[Alignment];
zoffset := Point(-ZPosition, ZPosition);
for i := 0 to High(FMarkValues) do begin
v := GetTransform.AxisToGraph(FMarkValues[i]);
@ -516,7 +513,7 @@ begin
end;
procedure TChartAxis.DrawTitle(
ACanvas: TCanvas; const ACenter: TPoint; ASize: Integer; const ARect: TRect);
ACanvas: TCanvas; const ACenter: TPoint; ASize: Integer);
var
p: TPoint;
dummy: TPointArray = nil;
@ -526,10 +523,10 @@ begin
p := ACenter;
d := (ASize + Title.Distance) div 2;
case Alignment of
calLeft: p.X := ARect.Left - d;
calTop: p.Y := ARect.Top - d;
calRight: p.X := ARect.Right + d;
calBottom: p.Y := ARect.Bottom + d;
calLeft: p.X := FTitleRect.Left - d;
calTop: p.Y := FTitleRect.Top - d;
calRight: p.X := FTitleRect.Right + d;
calBottom: p.Y := FTitleRect.Bottom + d;
end;
p += Point(-ZPosition, ZPosition);
Title.DrawLabel(ACanvas, p, p, Title.Caption, dummy);
@ -799,9 +796,8 @@ begin
while AIndex < FZOrder.Count do
with TChartAxis(FZOrder[AIndex]) do begin
if ACurrentZ < ZPosition then break;
Draw(ACanvas, AExtent, ATransf, FAxisRect);
DrawTitle(
ACanvas, FCenterPoint, FGroups[FGroupIndex].FTitleSize, FTitleRect);
Draw(ACanvas, AExtent, ATransf);
DrawTitle(ACanvas, FCenterPoint, FGroups[FGroupIndex].FTitleSize);
AIndex += 1;
end;
end;
@ -887,7 +883,7 @@ end;
procedure TChartAxisList.PrepareGroups;
var
i, g, prevGroup, groupCount: Integer;
i, prevGroup, groupCount: Integer;
begin
InitAndSort(FGroupOrder, @AxisGroupCompare);
SetLength(FGroups, Count);

View File

@ -203,7 +203,7 @@ type
protected
procedure Clean(ACanvas: TCanvas; ARect: TRect);
procedure DisplaySeries(ACanvas: TCanvas);
procedure DrawAxis(ACanvas: TCanvas);
procedure DrawBackground(const ACanvas: TCanvas);
procedure DrawTitleFoot(ACanvas: TCanvas);
procedure MouseDown(
Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
@ -213,6 +213,7 @@ type
{$IFDEF LCLGtk2}
procedure DoOnResize; override;
{$ENDIF}
procedure PrepareAxis(ACanvas: TCanvas);
procedure PrepareLegend(
ACanvas: TCanvas; out ALegendItems: TChartLegendItems;
var AClipRect: TRect; out ALegendRect: TRect);
@ -492,7 +493,8 @@ begin
if Legend.Visible then
PrepareLegend(ACanvas, legendItems, FClipRect, legendRect);
try
DrawAxis(ACanvas);
PrepareAxis(ACanvas);
DrawBackground(ACanvas);
DisplaySeries(ACanvas);
if Legend.Visible then
Legend.Draw(ACanvas, legendItems, legendRect);
@ -524,6 +526,24 @@ begin
end;
end;
procedure TChart.DrawBackground(const ACanvas: TCanvas);
begin
with ACanvas do begin
if FFrame.Visible then
Pen.Assign(FFrame)
else
Pen.Style := psClear;
Brush.Color := BackColor;
with FClipRect do
Rectangle(Left, Top, Right + 1, Bottom + 1);
end;
// Z axis
if Depth > 0 then
with FClipRect do
ACanvas.Line(Left, Bottom, Left - Depth, Bottom + Depth);
end;
procedure TChart.HideReticule;
begin
// Hide reticule - - it will be drawn again in the next MouseMove.
@ -617,7 +637,7 @@ begin
end;
end;
procedure TChart.DrawAxis(ACanvas: TCanvas);
procedure TChart.PrepareAxis(ACanvas: TCanvas);
var
axisMargin: TChartAxisMargins = (0, 0, 0, 0);
a: TChartAxisAlignment;
@ -637,23 +657,7 @@ begin
CalculateTransformationCoeffs(GetMargins(ACanvas));
AxisList.Measure(ACanvas, CurrentExtent, false, axisMargin);
// Background
with ACanvas do begin
if FFrame.Visible then
Pen.Assign(FFrame)
else
Pen.Style := psClear;
Brush.Color := BackColor;
with FClipRect do
Rectangle(Left, Top, Right + 1, Bottom + 1);
end;
AxisList.Prepare(FClipRect);
// Z axis
if Depth > 0 then
with FClipRect do
ACanvas.Line(Left, Bottom, Left - Depth, Bottom + Depth);
end;
procedure TChart.DrawLegendOn(ACanvas: TCanvas; var ARect: TRect);
@ -861,38 +865,39 @@ var
i, d, axisIndex: Integer;
seriesInZOrder: TFPList;
begin
if SeriesCount = 0 then exit;
d := Depth;
axisIndex := 0;
seriesInZOrder := TFPList.Create;
try
seriesInZOrder.Assign(FSeries.FList);
seriesInZOrder.Sort(@CompareZPosition);
if SeriesCount > 0 then begin;
seriesInZOrder := TFPList.Create;
try
seriesInZOrder.Assign(FSeries.FList);
seriesInZOrder.Sort(@CompareZPosition);
d := Depth;
for i := 0 to SeriesCount - 1 do
with TBasicChartSeries(seriesInZOrder[i]) do begin
AxisList.Draw(ACanvas, CurrentExtent, Self, ZPosition, axisIndex);
if not Active then continue;
OffsetDrawArea(Min(ZPosition, d), Min(Depth, d));
ACanvas.ClipRect := FClipRect;
ACanvas.Clipping := true;
try
for i := 0 to SeriesCount - 1 do
with TBasicChartSeries(seriesInZOrder[i]) do begin
if not Active then continue;
// Interleave axises with series according to ZPosition.
AxisList.Draw(ACanvas, CurrentExtent, Self, ZPosition, axisIndex);
OffsetDrawArea(Min(ZPosition, d), Min(Depth, d));
ACanvas.ClipRect := FClipRect;
ACanvas.Clipping := true;
try
Draw(ACanvas);
except
Active := false;
raise;
try
Draw(ACanvas);
except
Active := false;
raise;
end;
finally
OffsetDrawArea(-Min(ZPosition, d), -Min(Depth, d));
ACanvas.Clipping := false;
end;
finally
OffsetDrawArea(-Min(ZPosition, d), -Min(Depth, d));
ACanvas.Clipping := false;
end;
end;
AxisList.Draw(ACanvas, CurrentExtent, Self, MaxInt, axisIndex);
finally
seriesInZOrder.Free;
finally
seriesInZOrder.Free;
end;
end;
AxisList.Draw(ACanvas, CurrentExtent, Self, MaxInt, axisIndex);
end;
procedure TChart.DrawReticule(ACanvas: TCanvas);