mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-11 11:19:14 +02:00
TAChart: Update drag-and-drop demo to display point marks on mouse-over
git-svn-id: trunk@21806 -
This commit is contained in:
parent
e1f5717199
commit
e6c2ca7274
@ -45,8 +45,8 @@
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="main.pas"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="Main"/>
|
||||
</Unit1>
|
||||
|
@ -7,17 +7,26 @@ object Form1: TForm1
|
||||
ClientHeight = 300
|
||||
ClientWidth = 400
|
||||
OnCreate = FormCreate
|
||||
LCLVersion = '0.9.27'
|
||||
LCLVersion = '0.9.29'
|
||||
object Chart1: TChart
|
||||
Left = 0
|
||||
Height = 300
|
||||
Top = 0
|
||||
Width = 400
|
||||
BottomAxis.Grid.Style = psDot
|
||||
AxisList = <
|
||||
item
|
||||
Alignment = calLeft
|
||||
Offset = 0
|
||||
Scale = 1
|
||||
Title.Font.Orientation = 900
|
||||
end
|
||||
item
|
||||
Alignment = calBottom
|
||||
Offset = 0
|
||||
Scale = 1
|
||||
end>
|
||||
Foot.Brush.Color = clBtnFace
|
||||
Foot.Font.Color = clBlue
|
||||
LeftAxis.Grid.Style = psDot
|
||||
LeftAxis.Title.Angle = 90
|
||||
Title.Brush.Color = clBtnFace
|
||||
Title.Font.Color = clBlue
|
||||
Title.Text.Strings = (
|
||||
@ -32,6 +41,9 @@ object Form1: TForm1
|
||||
OnMouseMove = Chart1MouseMove
|
||||
OnMouseUp = Chart1MouseUp
|
||||
object Chart1LineSeries1: TLineSeries
|
||||
Marks.Format = '%0:g'
|
||||
Marks.Style = smsValue
|
||||
OnGetMark = Chart1LineSeries1GetMark
|
||||
Pointer.Brush.Color = clPurple
|
||||
Pointer.HorizSize = 6
|
||||
Pointer.Style = psDiamond
|
||||
|
@ -3,16 +3,19 @@
|
||||
LazarusResources.Add('TForm1','FORMDATA',[
|
||||
'TPF0'#6'TForm1'#5'Form1'#4'Left'#3'>'#1#6'Height'#3','#1#3'Top'#3#151#0#5'Wi'
|
||||
+'dth'#3#144#1#7'Caption'#6#5'Form1'#12'ClientHeight'#3','#1#11'ClientWidth'#3
|
||||
+#144#1#8'OnCreate'#7#10'FormCreate'#10'LCLVersion'#6#6'0.9.27'#0#6'TChart'#6
|
||||
+'Chart1'#4'Left'#2#0#6'Height'#3','#1#3'Top'#2#0#5'Width'#3#144#1#21'BottomA'
|
||||
+'xis.Grid.Style'#7#5'psDot'#16'Foot.Brush.Color'#7#9'clBtnFace'#15'Foot.Font'
|
||||
+'.Color'#7#6'clBlue'#19'LeftAxis.Grid.Style'#7#5'psDot'#20'LeftAxis.Title.An'
|
||||
+'gle'#2'Z'#17'Title.Brush.Color'#7#9'clBtnFace'#16'Title.Font.Color'#7#6'clB'
|
||||
+'lue'#18'Title.Text.Strings'#1#6#24'You can drag data points'#6#23'while hol'
|
||||
+'ding Shift key'#0#13'Title.Visible'#9#5'Align'#7#8'alClient'#14'DoubleBuffe'
|
||||
+'red'#9#11'ParentColor'#8#11'OnMouseDown'#7#15'Chart1MouseDown'#11'OnMouseMo'
|
||||
+'ve'#7#15'Chart1MouseMove'#9'OnMouseUp'#7#13'Chart1MouseUp'#0#11'TLineSeries'
|
||||
+#17'Chart1LineSeries1'#19'Pointer.Brush.Color'#7#8'clPurple'#17'Pointer.Hori'
|
||||
+'zSize'#2#6#13'Pointer.Style'#7#9'psDiamond'#16'Pointer.VertSize'#2#6#11'Ser'
|
||||
+'iesColor'#7#7'clBlack'#10'ShowPoints'#9#0#0#0#0
|
||||
+#144#1#8'OnCreate'#7#10'FormCreate'#10'LCLVersion'#6#6'0.9.29'#0#6'TChart'#6
|
||||
+'Chart1'#4'Left'#2#0#6'Height'#3','#1#3'Top'#2#0#5'Width'#3#144#1#8'AxisList'
|
||||
+#14#1#9'Alignment'#7#7'calLeft'#6'Offset'#5#0#0#0#0#0#0#0#0#0#0#5'Scale'#5#0
|
||||
+#0#0#0#0#0#0#128#255'?'#22'Title.Font.Orientation'#3#132#3#0#1#9'Alignment'#7
|
||||
+#9'calBottom'#6'Offset'#5#0#0#0#0#0#0#0#0#0#0#5'Scale'#5#0#0#0#0#0#0#0#128
|
||||
+#255'?'#0#0#16'Foot.Brush.Color'#7#9'clBtnFace'#15'Foot.Font.Color'#7#6'clBl'
|
||||
+'ue'#17'Title.Brush.Color'#7#9'clBtnFace'#16'Title.Font.Color'#7#6'clBlue'#18
|
||||
+'Title.Text.Strings'#1#6#24'You can drag data points'#6#23'while holding Shi'
|
||||
+'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
|
||||
]);
|
||||
|
@ -15,6 +15,8 @@ type
|
||||
TForm1 = class(TForm)
|
||||
Chart1: TChart;
|
||||
Chart1LineSeries1: TLineSeries;
|
||||
procedure Chart1LineSeries1GetMark(out AFormattedMark: String;
|
||||
AIndex: Integer);
|
||||
procedure Chart1MouseDown(
|
||||
Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
||||
procedure Chart1MouseMove(
|
||||
@ -24,6 +26,7 @@ type
|
||||
procedure FormCreate(Sender: TObject);
|
||||
private
|
||||
FDragIndex: Integer;
|
||||
FNearestIndex: Integer;
|
||||
end;
|
||||
|
||||
var
|
||||
@ -39,29 +42,46 @@ type
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
procedure TForm1.Chart1LineSeries1GetMark(
|
||||
out AFormattedMark: String; AIndex: Integer);
|
||||
begin
|
||||
if AIndex = FNearestIndex then
|
||||
AFormattedMark := Chart1LineSeries1.DefaultFormattedMark(AIndex)
|
||||
else
|
||||
AFormattedMark := '';
|
||||
end;
|
||||
|
||||
procedure TForm1.Chart1MouseDown(
|
||||
Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
||||
var
|
||||
pt, img: TPoint;
|
||||
val: TDoublePoint;
|
||||
begin
|
||||
Unused(Button);
|
||||
pt := Point(X, Y);
|
||||
if
|
||||
(Shift = [ssShift, ssLeft]) and
|
||||
TLineSeriesAccess(Chart1LineSeries1).GetNearestPoint(
|
||||
@PointDist, pt, FDragIndex, img, val) and
|
||||
(PointDist(pt, img) <= Sqr(Chart1LineSeries1.Pointer.HorizSize))
|
||||
then
|
||||
else
|
||||
FDragIndex := -1;
|
||||
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);
|
||||
Unused(X, Y);
|
||||
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;
|
||||
end;
|
||||
if FDragIndex < 0 then exit;
|
||||
Chart1LineSeries1.SetXValue(FDragIndex, Chart1.XImageToGraph(X));
|
||||
Chart1LineSeries1.SetYValue(FDragIndex, Chart1.YImageToGraph(Y));
|
||||
@ -83,6 +103,7 @@ begin
|
||||
for i := 1 to 10 do
|
||||
Chart1LineSeries1.AddXY(i, Random(20) - 10);
|
||||
FDragIndex := -1;
|
||||
FNearestIndex := -1;
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
Loading…
Reference in New Issue
Block a user