TAChart: Add TChartMarks.Clipped property. Update demo.

git-svn-id: trunk@21840 -
This commit is contained in:
ask 2009-09-23 17:10:51 +00:00
parent d7d5afb621
commit 54485700c3
4 changed files with 34 additions and 15 deletions

View File

@ -41,6 +41,7 @@ object Form1: TForm1
OnMouseMove = Chart1MouseMove
OnMouseUp = Chart1MouseUp
object Chart1LineSeries1: TLineSeries
Marks.Clipped = False
Marks.Format = '%0:g'
Marks.Style = smsValue
OnGetMark = Chart1LineSeries1GetMark

View File

@ -14,8 +14,9 @@ LazarusResources.Add('TForm1','FORMDATA',[
+'ft key'#0#13'Title.Visible'#9#5'Align'#7#8'alClient'#14'DoubleBuffered'#9#11
+'ParentColor'#8#11'OnMouseDown'#7#15'Chart1MouseDown'#11'OnMouseMove'#7#15'C'
+'hart1MouseMove'#9'OnMouseUp'#7#13'Chart1MouseUp'#0#11'TLineSeries'#17'Chart'
+'1LineSeries1'#12'Marks.Format'#6#4'%0:g'#11'Marks.Style'#7#8'smsValue'#9'On'
+'GetMark'#7#24'Chart1LineSeries1GetMark'#19'Pointer.Brush.Color'#7#8'clPurpl'
+'e'#17'Pointer.HorizSize'#2#6#13'Pointer.Style'#7#9'psDiamond'#16'Pointer.Ve'
+'rtSize'#2#6#11'SeriesColor'#7#7'clBlack'#10'ShowPoints'#9#0#0#0#0
+'1LineSeries1'#13'Marks.Clipped'#8#12'Marks.Format'#6#4'%0:g'#11'Marks.Style'
+#7#8'smsValue'#9'OnGetMark'#7#24'Chart1LineSeries1GetMark'#19'Pointer.Brush.'
+'Color'#7#8'clPurple'#17'Pointer.HorizSize'#2#6#13'Pointer.Style'#7#9'psDiam'
+'ond'#16'Pointer.VertSize'#2#6#11'SeriesColor'#7#7'clBlack'#10'ShowPoints'#9
+#0#0#0#0
]);

View File

@ -70,17 +70,14 @@ begin
Unused(Shift);
pt := Point(X, Y);
if
TLineSeriesAccess(Chart1LineSeries1).
GetNearestPoint(@PointDist, pt, newNearest, img, val)
then begin
if PointDist(pt, img) <= Sqr(Chart1LineSeries1.Pointer.HorizSize) then begin
if newNearest <> FNearestIndex then begin
FNearestIndex := newNearest;
Chart1.Invalidate;
end;
end
else
FNearestIndex := -1;
not TLineSeriesAccess(Chart1LineSeries1).
GetNearestPoint(@PointDist, pt, newNearest, img, val) or
(PointDist(pt, img) > Sqr(Chart1LineSeries1.Pointer.HorizSize))
then
newNearest := -1;
if newNearest <> FNearestIndex then begin
FNearestIndex := newNearest;
Chart1.Invalidate;
end;
if FDragIndex < 0 then exit;
Chart1LineSeries1.SetXValue(FDragIndex, Chart1.XImageToGraph(X));

View File

@ -270,6 +270,7 @@ type
TChartMarks = class(TChartElement)
private
FClipped: Boolean;
FDistance: Integer;
FFormat: String;
FFrame: TChartPen;
@ -278,6 +279,7 @@ type
FLinkPen: TChartLinkPen;
FStyle: TSeriesMarksStyle;
procedure SetClipped(const AValue: Boolean);
procedure SetDistance(const AValue: Integer);
procedure SetFormat(const AValue: String);
procedure SetFrame(const AValue: TChartPen);
@ -294,6 +296,8 @@ type
ACanvas: TCanvas; const ALabelRect: TRect; const AText: String);
function IsMarkLabelsVisible: Boolean;
published
// If false, labels may overlap axises and legend.
property Clipped: Boolean read FClipped write SetClipped default true;
// Distance between series point and label.
property Distance: Integer
read FDistance write SetDistance default DEF_MARKS_DISTANCE;
@ -988,6 +992,7 @@ end;
constructor TChartMarks.Create(AOwner: TCustomChart);
begin
inherited Create(AOwner);
FClipped := true;
FDistance := DEF_MARKS_DISTANCE;
InitHelper(TFPCanvasHelper(FFrame), TChartPen);
InitHelper(TFPCanvasHelper(FLabelBrush), TChartLabelBrush);
@ -1010,13 +1015,21 @@ end;
procedure TChartMarks.DrawLabel(
ACanvas: TCanvas; const ALabelRect: TRect; const AText: String);
var
wasClipping: Boolean = false;
begin
if not Clipped and ACanvas.Clipping then begin
ACanvas.Clipping := false;
wasClipping := true;
end;
ACanvas.Brush.Assign(LabelBrush);
ACanvas.Pen.Assign(Frame);
ACanvas.Rectangle(ALabelRect);
ACanvas.Font.Assign(LabelFont);
ACanvas.TextOut(
ALabelRect.Left + MARKS_MARGIN_X, ALabelRect.Top + MARKS_MARGIN_Y, AText);
if wasClipping then
ACanvas.Clipping := true;
end;
function TChartMarks.IsMarkLabelsVisible: Boolean;
@ -1024,6 +1037,13 @@ begin
Result := Visible and (Style <> smsNone) and (Format <> '');
end;
procedure TChartMarks.SetClipped(const AValue: Boolean);
begin
if FClipped = AValue then exit;
FClipped := AValue;
StyleChanged(Self);
end;
procedure TChartMarks.SetDistance(const AValue: Integer);
begin
if FDistance = AValue then exit;