TAChart: Add pointers to TDataPointDistanceTool

git-svn-id: trunk@38329 -
This commit is contained in:
ask 2012-08-22 09:48:58 +00:00
parent 2a08196858
commit aa894b143a
2 changed files with 47 additions and 8 deletions
components/tachart

View File

@ -505,6 +505,11 @@ type
TDataPointDistanceToolMeasureEvent =
procedure (ASender: TDataPointDistanceTool) of object;
TDataPointDistanceToolPointer = class(TSeriesPointer)
published
property Style default psVertBar;
end;
TDataPointDistanceTool = class(TDataPointDrawTool)
published
type
@ -515,8 +520,12 @@ type
FMeasureMode: TChartDistanceMode;
FOnMeasure: TDataPointDistanceToolMeasureEvent;
FOptions: TOptions;
FPointerEnd: TDataPointDistanceToolPointer;
FPointerStart: TDataPointDistanceToolPointer;
function GetPointEnd: TDataPointTool.TPointRef; inline;
procedure SetOptions(AValue: TOptions);
procedure SetPointerEnd(AValue: TDataPointDistanceToolPointer);
procedure SetPointerStart(AValue: TDataPointDistanceToolPointer);
strict protected
procedure DoDraw; override;
@ -542,6 +551,10 @@ type
property MeasureMode: TChartDistanceMode
read FMeasureMode write FMeasureMode default cdmXY;
property Options: TOptions read FOptions write SetOptions default [];
property PointerEnd: TDataPointDistanceToolPointer
read FPointerEnd write SetPointerEnd;
property PointerStart: TDataPointDistanceToolPointer
read FPointerStart write SetPointerStart;
published
property OnMeasure: TDataPointDistanceToolMeasureEvent
read FOnMeasure write FOnMeasure;
@ -1737,12 +1750,16 @@ begin
SetLength(FAnchors, 2);
FAnchors[0] := TDataPointTool.TPointRef.Create;
FAnchors[1] := TDataPointTool.TPointRef.Create;
FPointerEnd := TDataPointDistanceToolPointer.Create(nil);
FPointerStart := TDataPointDistanceToolPointer.Create(nil);
end;
destructor TDataPointDistanceTool.Destroy;
begin
FAnchors[0].Free;
FAnchors[1].Free;
FreeAndNil(FPointerEnd);
FreeAndNil(FPointerStart);
inherited;
end;
@ -1783,6 +1800,7 @@ end;
procedure TDataPointDistanceTool.DoDraw;
var
p1, p2: TPoint;
a: Double;
begin
p1 := FChart.GraphToImage(PointStart.GraphPos);
p2 := FChart.GraphToImage(PointEnd.GraphPos);
@ -1792,6 +1810,13 @@ begin
end;
if p1 = p2 then exit;
FChart.Drawer.Line(p1, p2);
a := ArcTan2(p2.Y - p1.Y, p2.X - p1.X);
with PointerStart do
if Visible then
DrawSize(FChart.Drawer, p1, Point(HorizSize, VertSize), clTAColor, a);
with PointerEnd do
if Visible then
DrawSize(FChart.Drawer, p2, Point(HorizSize, VertSize), clTAColor, a);
end;
function TDataPointDistanceTool.FindRef(
@ -1893,6 +1918,20 @@ begin
FOptions := AValue;
end;
procedure TDataPointDistanceTool.SetPointerEnd(
AValue: TDataPointDistanceToolPointer);
begin
if FPointerEnd = AValue then exit;
FPointerEnd.Assign(AValue);
end;
procedure TDataPointDistanceTool.SetPointerStart(
AValue: TDataPointDistanceToolPointer);
begin
if FPointerStart = AValue then exit;
FPointerStart.Assign(AValue);
end;
initialization
ToolsClassRegistry := TStringList.Create;

View File

@ -295,7 +295,8 @@ type
procedure Draw(ADrawer: IChartDrawer; ACenter: TPoint; AColor: TColor);
procedure DrawSize(
ADrawer: IChartDrawer; ACenter, ASize: TPoint; AColor: TColor);
ADrawer: IChartDrawer; ACenter, ASize: TPoint; AColor: TColor;
AAngle: Double = 0.0);
published
property Brush: TBrush read FBrush write SetBrush;
property HorizSize: Integer read FHorizSize write SetHorizSize default DEF_POINTER_SIZE;
@ -926,7 +927,7 @@ begin
InitHelper(FPen, TChartPen);
FHorizSize := DEF_POINTER_SIZE;
FStyle := psRectangle;
SetPropDefaults(Self, ['Style']);
FVertSize := DEF_POINTER_SIZE;
FVisible := true;
end;
@ -944,10 +945,10 @@ begin
DrawSize(ADrawer, ACenter, Point(HorizSize, VertSize), AColor);
end;
procedure TSeriesPointer.DrawSize(
ADrawer: IChartDrawer; ACenter, ASize: TPoint; AColor: TColor);
procedure TSeriesPointer.DrawSize(ADrawer: IChartDrawer;
ACenter, ASize: TPoint; AColor: TColor; AAngle: Double);
function PointByIndex(AIndex: Char): TPoint;
function PointByIndex(AIndex: Char): TPoint; inline;
// 7--8--9
// 4 5 6
// 1--2--3
@ -955,9 +956,8 @@ procedure TSeriesPointer.DrawSize(
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] * ASize.X;
Result.Y += V[AIndex] * ASize.Y;
Result := ACenter + RotatePoint(
Point(H[AIndex] * ASize.X, V[AIndex] * ASize.Y), AAngle);
end;
procedure DrawByString(const AStr: String);