TAChart: Extract TGenericChartMarks.IsLabelHiddenDueToOverlap function

git-svn-id: trunk@25030 -
This commit is contained in:
ask 2010-04-28 12:43:41 +00:00
parent c2e7239df1
commit 2255790333
2 changed files with 16 additions and 8 deletions

View File

@ -571,7 +571,6 @@ procedure TBasicPointSeries.DrawLabels(ACanvas: TCanvas);
var var
labelRect: TRect; labelRect: TRect;
center: TPoint; center: TPoint;
dummy: TRect = (Left: 0; Top: 0; Right: 0; Bottom: 0);
sz: TSize; sz: TSize;
begin begin
if AText = '' then exit; if AText = '' then exit;
@ -582,13 +581,7 @@ procedure TBasicPointSeries.DrawLabels(ACanvas: TCanvas);
center.Y += OFFSETS[ADir].Y * (Marks.Distance + sz.cy div 2); center.Y += OFFSETS[ADir].Y * (Marks.Distance + sz.cy div 2);
with center do with center do
labelRect := BoundsSize(X - sz.cx div 2, Y - sz.cy div 2, sz); labelRect := BoundsSize(X - sz.cx div 2, Y - sz.cy div 2, sz);
if if Marks.IsLabelHiddenDueToOverlap(FPrevLabelRect, labelRect) then exit;
(Marks.OverlapPolicy = opHideNeighbour) and
not IsRectEmpty(FPrevLabelRect) and
IntersectRect(dummy, labelRect, FPrevLabelRect)
then
exit;
FPrevLabelRect := labelRect;
// Link between the label and the bar. // Link between the label and the bar.
ACanvas.Pen.Assign(Marks.LinkPen); ACanvas.Pen.Assign(Marks.LinkPen);

View File

@ -142,6 +142,8 @@ type
procedure DrawLabel( procedure DrawLabel(
ACanvas: TCanvas; const ALabelRect: TRect; const AText: String); ACanvas: TCanvas; const ALabelRect: TRect; const AText: String);
function IsMarkLabelsVisible: Boolean; function IsMarkLabelsVisible: Boolean;
function IsLabelHiddenDueToOverlap(
var APrevLabelRect: TRect; const ALabelRect: TRect): Boolean;
function MeasureLabel(ACanvas: TCanvas; const AText: String): TSize; function MeasureLabel(ACanvas: TCanvas; const AText: String): TSize;
public public
@ -464,6 +466,19 @@ begin
ACanvas.Clipping := true; ACanvas.Clipping := true;
end; end;
function TGenericChartMarks.IsLabelHiddenDueToOverlap(
var APrevLabelRect: TRect; const ALabelRect: TRect): Boolean;
var
dummy: TRect = (Left: 0; Top: 0; Right: 0; Bottom: 0);
begin
Result :=
(OverlapPolicy = opHideNeighbour) and
not IsRectEmpty(APrevLabelRect) and
IntersectRect(dummy, ALabelRect, APrevLabelRect);
if not Result then
APrevLabelRect := ALabelRect;
end;
function TGenericChartMarks.IsMarginRequired: Boolean; function TGenericChartMarks.IsMarginRequired: Boolean;
begin begin
Result := Result :=