TAChart: Use TDataPointDragTool in dragdrop demo

git-svn-id: trunk@25762 -
This commit is contained in:
ask 2010-05-30 08:15:48 +00:00
parent 5684de6f96
commit ed2db46b0f
3 changed files with 18 additions and 66 deletions

View File

@ -1,7 +1,7 @@
object Form1: TForm1
Left = 318
Left = 739
Height = 300
Top = 151
Top = 341
Width = 400
Caption = 'Form1'
ClientHeight = 300
@ -17,13 +17,9 @@ object Form1: TForm1
item
Alignment = calLeft
Title.Font.Orientation = 900
Transformation.Offset = 0
Transformation.Scale = 1
end
item
Alignment = calBottom
Transformation.Offset = 0
Transformation.Scale = 1
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue
@ -34,16 +30,15 @@ object Form1: TForm1
'while holding Shift key'
)
Title.Visible = True
Toolset = ChartToolset1
Align = alClient
DoubleBuffered = True
ParentColor = False
OnMouseDown = Chart1MouseDown
OnMouseMove = Chart1MouseMove
OnMouseUp = Chart1MouseUp
object Chart1LineSeries1: TLineSeries
Marks.Clipped = False
Marks.Format = '%0:.9g'
Marks.Style = smsValue
OnGetMark = Chart1LineSeries1GetMark
Pointer.Brush.Color = clPurple
Pointer.HorizSize = 6
Pointer.Style = psDiamond
@ -52,4 +47,12 @@ object Form1: TForm1
ShowPoints = True
end
end
object ChartToolset1: TChartToolset
left = 99
top = 129
object ChartToolset1DataPointDragTool1: TDataPointDragTool
Shift = [ssShift, ssLeft]
ActiveCursor = crHandPoint
end
end
end

View File

@ -6,7 +6,7 @@ interface
uses
Classes, ExtCtrls, SysUtils, FileUtil, LResources, Forms, Controls, Graphics,
Dialogs, TAGraph, TASeries;
Dialogs, TAGraph, TASeries, TATools;
type
@ -15,14 +15,10 @@ type
TForm1 = class(TForm)
Chart1: TChart;
Chart1LineSeries1: TLineSeries;
ChartToolset1: TChartToolset;
ChartToolset1DataPointDragTool1: TDataPointDragTool;
procedure Chart1LineSeries1GetMark(out AFormattedMark: String;
AIndex: Integer);
procedure Chart1MouseDown(
Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure Chart1MouseMove(
Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure Chart1MouseUp(
Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
private
FDragIndex: Integer;
@ -39,61 +35,18 @@ implementation
uses
TAChartUtils;
type
TLineSeriesAccess = class(TLineSeries);
{ TForm1 }
procedure TForm1.Chart1LineSeries1GetMark(
out AFormattedMark: String; AIndex: Integer);
begin
if AIndex = FNearestIndex then
AFormattedMark := Chart1LineSeries1.FormattedMark(AIndex)
if AIndex = ChartToolset1DataPointDragTool1.PointIndex then
with Chart1LineSeries1 do
AFormattedMark := Source.FormatItem(Marks.Format, AIndex)
else
AFormattedMark := '';
end;
procedure TForm1.Chart1MouseDown(
Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
Unused(Button);
Unused(X, Y);
if Shift = [ssShift, ssLeft] then
FDragIndex := FNearestIndex;
end;
procedure TForm1.Chart1MouseMove(
Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
newNearest: Integer;
pt, img: TPoint;
val: TDoublePoint;
begin
Unused(Shift);
pt := Point(X, Y);
if
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));
Chart1LineSeries1.SetYValue(FDragIndex, Chart1.YImageToGraph(Y));
end;
procedure TForm1.Chart1MouseUp(
Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
Unused(Button, Shift);
Unused(X, Y);
FDragIndex := -1;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;

View File

@ -16,13 +16,9 @@ object Form1: TForm1
item
Alignment = calLeft
Title.Font.Orientation = 900
Transformation.Offset = 0
Transformation.Scale = 1
end
item
Alignment = calBottom
Transformation.Offset = 0
Transformation.Scale = 1
end>
Foot.Brush.Color = clBtnFace
Foot.Font.Color = clBlue