TAChart: Exactly reserve margins for the first and the last mark on the axis

git-svn-id: trunk@31713 -
This commit is contained in:
ask 2011-07-16 18:20:23 +00:00
parent 4ed00f8de5
commit 9b3b52f19f
2 changed files with 39 additions and 19 deletions

View File

@ -530,7 +530,7 @@ procedure TChartAxis.Measure(
end;
var
sz: Integer;
sz, rmin, rmax, c, i: Integer;
begin
if not Visible then exit;
if IsVertical then
@ -542,12 +542,21 @@ begin
if sz > 0 then
sz += FHelper.FDrawer.Scale(TickLength) +
FHelper.FDrawer.Scale(Marks.Distance);
FHelper.GetClipRange(rmin, rmax);
with AMeasureData do begin
FSize := Max(sz, FSize);
FTitleSize := Max(TitleSize, FTitleSize);
if FMarkTexts <> nil then begin
FFirstMark := Max(FirstLastSize(0), FFirstMark);
FLastMark := Max(FirstLastSize(High(FMarkTexts)), FLastMark);
for i := 0 to High(FMarkTexts) do begin
c := FHelper.GraphToImage(FMarkValues[i]);
if not InRange(c, rmin, rmax) then continue;
FFirstMark := Max(FirstLastSize(i) - c + rmin, FFirstMark);
break;
end;
for i := High(FMarkTexts) downto 0 do begin
c := FHelper.GraphToImage(FMarkValues[i]);
if not InRange(c, rmin, rmax) then continue;
FLastMark := Max(FirstLastSize(i) - rmax + c, FLastMark);
break;
end;
end;
end;

View File

@ -163,9 +163,8 @@ type
procedure DrawLabel(ALabelCenter: TPoint; const AText: String); inline;
procedure DrawLabelAndTick(
ACoord, AFixedCoord: Integer; const AText: String); virtual; abstract;
function GraphToImage(AGraph: Double): Integer; virtual; abstract;
procedure GridLine(ACoord: Integer); virtual; abstract;
function IsInClipRange(ACoord: Integer): Boolean; virtual; abstract;
function IsInClipRange(ACoord: Integer): Boolean;
procedure LineZ(AP1, AP2: TPoint); inline;
function TryApplyStripes: Boolean; inline;
public
@ -180,11 +179,13 @@ type
FZOffset: TPoint;
procedure BeginDrawing; virtual;
constructor Create; virtual;
function Clone: TAxisDrawHelper;
constructor Create; virtual;
procedure DrawMark(
AFixedCoord: Integer; AMark: Double; const AText: String);
procedure EndDrawing; virtual; abstract;
procedure GetClipRange(out AMin, AMax: Integer); virtual; abstract;
function GraphToImage(AGraph: Double): Integer; virtual; abstract;
end;
TAxisDrawHelperClass = class of TAxisDrawHelper;
@ -197,10 +198,10 @@ type
ACoord, AFixedCoord: Integer; const AText: String); override;
function GraphToImage(AGraph: Double): Integer; override;
procedure GridLine(ACoord: Integer); override;
function IsInClipRange(ACoord: Integer): Boolean; override;
public
procedure BeginDrawing; override;
procedure EndDrawing; override;
procedure GetClipRange(out AMin, AMax: Integer); override;
end;
{ TAxisDrawHelperY }
@ -211,10 +212,10 @@ type
ACoord, AFixedCoord: Integer; const AText: String); override;
function GraphToImage(AGraph: Double): Integer; override;
procedure GridLine(ACoord: Integer); override;
function IsInClipRange(ACoord: Integer): Boolean; override;
public
procedure BeginDrawing; override;
procedure EndDrawing; override;
procedure GetClipRange(out AMin, AMax: Integer); override;
end;
implementation
@ -279,6 +280,14 @@ begin
end;
end;
function TAxisDrawHelper.IsInClipRange(ACoord: Integer): Boolean;
var
rmin, rmax: Integer;
begin
GetClipRange(rmin, rmax);
Result := InRange(ACoord, rmin, rmax);
end;
procedure TAxisDrawHelper.LineZ(AP1, AP2: TPoint);
begin
FDrawer.Line(AP1 + FZOffset, AP2 + FZOffset);
@ -317,6 +326,12 @@ begin
BarZ(FPrevCoord + 1, FClipRect^.Top + 1, FClipRect^.Right, FClipRect^.Bottom);
end;
procedure TAxisDrawHelperX.GetClipRange(out AMin, AMax: Integer);
begin
AMin := FClipRect^.Left;
AMax := FClipRect^.Right;
end;
function TAxisDrawHelperX.GraphToImage(AGraph: Double): Integer;
begin
Result := FTransf.XGraphToImage(AGraph);
@ -329,11 +344,6 @@ begin
LineZ(Point(ACoord, FClipRect^.Top), Point(ACoord, FClipRect^.Bottom));
end;
function TAxisDrawHelperX.IsInClipRange(ACoord: Integer): Boolean;
begin
Result := InRange(ACoord, FClipRect^.Left, FClipRect^.Right);
end;
{ TAxisDrawHelperY }
procedure TAxisDrawHelperY.BeginDrawing;
@ -362,6 +372,12 @@ begin
BarZ(FClipRect^.Left + 1, FClipRect^.Top + 1, FClipRect^.Right, FPrevCoord);
end;
procedure TAxisDrawHelperY.GetClipRange(out AMin, AMax: Integer);
begin
AMin := FClipRect^.Top;
AMax := FClipRect^.Bottom;
end;
function TAxisDrawHelperY.GraphToImage(AGraph: Double): Integer;
begin
Result := FTransf.YGraphToImage(AGraph);
@ -374,11 +390,6 @@ begin
LineZ(Point(FClipRect^.Left, ACoord), Point(FClipRect^.Right, ACoord));
end;
function TAxisDrawHelperY.IsInClipRange(ACoord: Integer): Boolean;
begin
Result := InRange(ACoord, FClipRect^.Top, FClipRect^.Bottom);
end;
{ TChartAxisTitle }
procedure TChartAxisTitle.Assign(Source: TPersistent);