TAChart: Refactor series pointer drawing.

Respect Brush and Pen color of SeriesPointer.
  Allow "empty" circles and rectangles as a pointers.

git-svn-id: trunk@19162 -
This commit is contained in:
ask 2009-03-31 03:38:28 +00:00
parent ce9780a7a4
commit 9cb4b8e525
2 changed files with 48 additions and 41 deletions

View File

@ -231,6 +231,7 @@ begin
FLine.ShowLines := true;
FLine.ShowPoints := true;
FLine.Pointer.Style := psRectangle;
FLine.Pointer.Brush.Color := clRed;
FLine.Title := 'line';
FLine.SeriesColor := clRed;
Chart1.AddSeries(FLine);

View File

@ -654,52 +654,58 @@ begin
end;
procedure TSeriesPointer.Draw(ACanvas: TCanvas; ACenter: TPoint; AColor: TColor);
var
r: TRect;
function PointByIndex(AIndex: Char): TPoint;
// 7--8--9
// 4 5 6
// 1--2--3
const
V: array ['1'..'9'] of -1..1 = (1, 1, 1, 0, 0, 0, -1, -1, -1);
H: array ['1'..'9'] of -1..1 = (-1, 0, 1, -1, 0, 1, -1, 0, 1);
begin
Result := ACenter;
Result.X += H[AIndex] * HorizSize;
Result.Y += V[AIndex] * VertSize;
end;
procedure DrawByString(const AStr: String);
var
pts: array of TPoint;
i: Integer;
j: Integer = 0;
begin
SetLength(pts, Length(AStr));
for i := 1 to Length(AStr) do begin
if AStr[i] = ' ' then begin
if Brush.Style = bsClear then begin
ACanvas.Polyline(pts, 0, j);
// Polyline does not draw the end point.
ACanvas.Pixels[pts[j - 1].X, pts[j - 1].Y] := Pen.Color;
end
else
ACanvas.Polygon(pts, true, 0, j);
j := 0;
end
else begin
pts[j] := PointByIndex(AStr[i]);
Inc(j);
end;
end;
end;
const
DRAW_STRINGS: array [TSeriesPointerStyle] of String =
('', '17931', '28 46', '19 73', '28 46 19 73', '', '41236', '47896');
begin
ACanvas.Brush.Assign(FBrush);
ACanvas.Pen.Assign(FPen);
r := Bounds(ACenter.X, ACenter.Y, 1, 1);
InflateRect(r, FHorizSize, FVertSize);
if FStyle in [psRectangle, psCircle] then
ACanvas.Brush.Color := AColor
if FStyle = psCircle then
ACanvas.Ellipse(
ACenter.X - HorizSize, ACenter.Y - VertSize,
ACenter.X + HorizSize, ACenter.Y + VertSize)
else
ACanvas.Pen.Color := AColor;
// Line does not draw the end point, so coordinates have to be incremented.
case FStyle of
psRectangle:
ACanvas.Rectangle(r);
psCross: begin
ACanvas.Line(r.Left, ACenter.Y, r.Right + 1, ACenter.Y);
ACanvas.Line(ACenter.X, r.Top, ACenter.X, r.Bottom + 1);
end;
psDiagCross: begin
ACanvas.Line(r.Left, r.Top, r.Right + 1, r.Bottom + 1);
ACanvas.Line(r.Left, r.Bottom, r.Right + 1, r.Top - 1);
end;
psStar: begin
ACanvas.Line(r.Left, ACenter.Y, r.Right + 1, ACenter.Y);
ACanvas.Line(ACenter.X, r.Top, ACenter.X, r.Bottom + 1);
ACanvas.Line(r.Left, r.Top, r.Right + 1, r.Bottom + 1);
ACanvas.Line(r.Left, r.Bottom, r.Right + 1, r.Top - 1);
end;
psCircle:
ACanvas.Ellipse(r);
psLowBracket: begin
ACanvas.MoveTo(r.Left, ACenter.Y);
ACanvas.LineTo(r.Left, r.Bottom);
ACanvas.LineTo(r.Right, r.Bottom);
ACanvas.LineTo(r.Right, ACenter.Y - 1);
end;
psHighBracket: begin
ACanvas.MoveTo(r.Left, ACenter.Y);
ACanvas.LineTo(r.Left, r.Top);
ACanvas.LineTo(r.Right, r.Top);
ACanvas.LineTo(r.Right, ACenter.Y + 1);
end;
end;
DrawByString(DRAW_STRINGS[FStyle] + ' ');
end;
procedure TSeriesPointer.SetBrush(AValue: TBrush);