TAChart: add TChartMarks.Distance property.

git-svn-id: trunk@18883 -
This commit is contained in:
ask 2009-03-03 16:42:27 +00:00
parent 6e5def3ad7
commit ddda8edc89
2 changed files with 21 additions and 9 deletions

View File

@ -1181,7 +1181,7 @@ var
h: Integer;
begin
if not Marks.IsMarkLabelsVisible then exit;
h := ACanvas.TextHeight('0') + 10 + 2 * 2 + 4;
h := ACanvas.TextHeight('0') + Marks.Distance + 2 * 2 + 4;
AMargins.Top := Max(AMargins.Top, h);
AMargins.Bottom := Max(AMargins.Bottom, h);
end;
@ -1215,8 +1215,6 @@ var
prevLabelRect: TRect = (Left: 0; Top: 0; Right: 0; Bottom: 0);
procedure DrawLabel;
const
DIST = 10;
var
labelRect: TRect;
dummy: TRect = (Left: 0; Top: 0; Right: 0; Bottom: 0);
@ -1231,8 +1229,10 @@ var
labelSize := ACanvas.TextExtent(labelText);
xc := (r.Left + r.Right) div 2;
labelPos.X := xc - labelSize.cx div 2;
labelPos.Y :=
ifthen(barTopY = 0, r.Bottom + DIST, r.Top - DIST - labelSize.cy);
if barTopY = 0 then
labelPos.Y := r.Bottom + Marks.Distance
else
labelPos.Y := r.Top - Marks.Distance - labelSize.cy;
labelRect := Bounds(labelPos.X, labelPos.Y, labelSize.cx, labelSize.cy);
InflateRect(labelRect, 4, 2);
if
@ -1389,7 +1389,6 @@ var
a, b, center: TPoint;
const
MARGIN = 8;
MARKS_DIST = 32;
MarkYMargin = 2;
MarkXMargin = 4;
begin
@ -1415,7 +1414,7 @@ begin
YImageMin - center.y - MaxIntValue(labelHeights));
end;
if Marks.IsMarkLabelsVisible then
radius -= MARKS_DIST;
radius -= Marks.Distance;
radius := Max(radius - MARGIN, 0);
prevAngle := 0;
@ -1436,7 +1435,7 @@ begin
if not Marks.IsMarkLabelsVisible then continue;
a := LineEndPoint(center, prevAngle - angleStep / 2, radius);
b := LineEndPoint(center, prevAngle - angleStep / 2, radius + MARKS_DIST);
b := LineEndPoint(center, prevAngle - angleStep / 2, radius + Marks.Distance);
// line from mark to pie
ACanvas.Pen.Color := LabelToPieLinkColor;
@ -1454,7 +1453,6 @@ begin
b.x - MarkXMargin, b.y - MarkYMargin,
b.x + labelWidths[i] + MarkXMargin, b.y + labelHeights[i] + MarkYMargin);
ACanvas.TextOut(b.x, b.y, labelTexts[i]);
end;
end;

View File

@ -158,8 +158,11 @@ type
TChartMarks = class(TChartElement)
private
FDistance: Integer;
FFormat: String;
FStyle: TSeriesMarksStyle;
procedure SetDistance(const AValue: Integer);
procedure SetFormat(const AValue: String);
procedure SetStyle(const AValue: TSeriesMarksStyle);
public
@ -168,6 +171,8 @@ type
procedure Assign(Source: TPersistent); override;
function IsMarkLabelsVisible: Boolean;
published
// Distance between series point and label.
property Distance: Integer read FDistance write SetDistance default 20;
property Format: String read FFormat write SetFormat;
property Style: TSeriesMarksStyle
read FStyle write SetStyle default smsNone;
@ -446,6 +451,7 @@ begin
inherited Assign(Source);
if Source is TChartMarks then
with TChartMarks(Source) do begin
Self.FDistance := FDistance;
Self.FFormat := FFormat;
Self.FStyle := FStyle;
end;
@ -454,6 +460,7 @@ end;
constructor TChartMarks.Create(AOwner: TCustomChart);
begin
inherited Create(AOwner);
FDistance := 20;
FStyle := smsNone;
FVisible := true;
end;
@ -463,6 +470,13 @@ begin
Result := Visible and (Style <> smsNone) and (Format <> '');
end;
procedure TChartMarks.SetDistance(const AValue: Integer);
begin
if FDistance = AValue then exit;
FDistance := AValue;
StyleChanged(Self);
end;
procedure TChartMarks.SetFormat(const AValue: String);
begin
if FFormat = AValue then exit;