mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-07-31 16:36:02 +02:00
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:
parent
ce9780a7a4
commit
9cb4b8e525
@ -231,6 +231,7 @@ begin
|
|||||||
FLine.ShowLines := true;
|
FLine.ShowLines := true;
|
||||||
FLine.ShowPoints := true;
|
FLine.ShowPoints := true;
|
||||||
FLine.Pointer.Style := psRectangle;
|
FLine.Pointer.Style := psRectangle;
|
||||||
|
FLine.Pointer.Brush.Color := clRed;
|
||||||
FLine.Title := 'line';
|
FLine.Title := 'line';
|
||||||
FLine.SeriesColor := clRed;
|
FLine.SeriesColor := clRed;
|
||||||
Chart1.AddSeries(FLine);
|
Chart1.AddSeries(FLine);
|
||||||
|
@ -654,52 +654,58 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSeriesPointer.Draw(ACanvas: TCanvas; ACenter: TPoint; AColor: TColor);
|
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
|
begin
|
||||||
ACanvas.Brush.Assign(FBrush);
|
ACanvas.Brush.Assign(FBrush);
|
||||||
ACanvas.Pen.Assign(FPen);
|
ACanvas.Pen.Assign(FPen);
|
||||||
r := Bounds(ACenter.X, ACenter.Y, 1, 1);
|
|
||||||
InflateRect(r, FHorizSize, FVertSize);
|
|
||||||
|
|
||||||
if FStyle in [psRectangle, psCircle] then
|
if FStyle = psCircle then
|
||||||
ACanvas.Brush.Color := AColor
|
ACanvas.Ellipse(
|
||||||
|
ACenter.X - HorizSize, ACenter.Y - VertSize,
|
||||||
|
ACenter.X + HorizSize, ACenter.Y + VertSize)
|
||||||
else
|
else
|
||||||
ACanvas.Pen.Color := AColor;
|
DrawByString(DRAW_STRINGS[FStyle] + ' ');
|
||||||
|
|
||||||
// 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;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSeriesPointer.SetBrush(AValue: TBrush);
|
procedure TSeriesPointer.SetBrush(AValue: TBrush);
|
||||||
|
Loading…
Reference in New Issue
Block a user