Please insert following Sourcecode
Posted: Wed Nov 05, 2008 8:56 am
1.) Clip DragPoint to min/max.
TDragPointTool=class(TTeeCustomToolSeries)
private
fXMinimum:double;
fXMaximum:double;
fYMinimum:double;
fYMaximum:double;
fXClip:boolean;
fYClip:boolean;
....
published
property XMinimum:double read fXMinimum write fXMinimum;
property XMaximum:double read fXMaximum write fXMaximum;
property YMinimum:double read fYMinimum write fYMinimum;
property YMaximum:double read fYMaximum write fYMaximum;
property XClip:boolean read fXClip write fXClip;
property YClip:boolean read fYClip write fYClip;
Constructor TDragPointTool.Create(AOwner: TComponent);
begin
inherited;
fXMinimum:=-1000.0;
fXmaximum:=1000.0;
fYMinimum:=-1000.0;
fYmaximum:=1000.0;
fXClip:=true;
fYClip:=true;
procedure TDragPointTool.ChartMouseEvent(AEvent: TChartMouseEvent;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Function CheckAxisLimits(Axis:TChartAxis; Position:Integer):Double;
begin
with Axis do
if Maximum=Minimum then
begin
AutomaticMaximum:=False;
Maximum:=Maximum+0.1*MinAxisIncrement; // 6.02, fix when values are equal
end;
result:=Axis.CalcPosPoint(Position);
end;
var
Tmp:double;
begin
if Assigned(Series) then
Case AEvent of
cmeUp: IDragging:=-1; { stop dragging on mouse up }
cmeMove: if IDragging<>-1 then { if dragging... }
With Series do
begin
BeginUpdate;
{ Change the Series point X and / or Y values... }
if (Self.DragStyle=dsX) or (Self.DragStyle=dsBoth) then
begin
Tmp:=XScreenToValue(x);
if Tmp < fXMinimum then
Tmp := fXMinimum;
if Tmp > fXMaximum then
Tmp := fXMaximum;
if fXClip=true then
begin
if (IDragging = 0) and (IDragging < (count-1)) then // 1.Pkt
begin
if Tmp > XValue[IDragging+1] then
Tmp:= XValue[IDragging+1];
end else
begin
if IDragging = (count-1) then // last Pkt
begin
if (IDragging > 0) and (Tmp < XValue[IDragging-1]) then
Tmp:= XValue[IDragging-1];
end else
begin
if Tmp > XValue[IDragging+1] then
Tmp:= XValue[IDragging+1];
if Tmp < XValue[IDragging-1] then
Tmp:= XValue[IDragging-1];
end;
end;
XValue[IDragging]:=Tmp;
end else
begin
XValue[IDragging]:=CheckAxisLimits(GetHorizAxis,x);
end;
end;
if (Self.DragStyle=dsY) or (Self.DragStyle=dsBoth) then
begin
if fYClip=true then
begin
Tmp:=YScreenToValue(y);
if Tmp < fYMinimum then
Tmp := fYMinimum;
if Tmp > fYMaximum then
Tmp := fYMaximum;
YValue[IDragging]:=Tmp;
end else
begin
YValue[IDragging]:=CheckAxisLimits(GetVertAxis,y);
end;
end;
EndUpdate;
{ Notify the point values change... }
if Assigned(FOnDrag) then FOnDrag(Self,IDragging);
end;
cmeDown: begin { when the mouse button is pressed... }
IDragging:=Series.Clicked(x,y);
{ if clicked a Series point... }
if IDragging<>-1 then ParentChart.CancelMouse:=True;
end;
end;
end;
2.) disable Mousewheel function if no panning
function TCustomChart.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer;
{$IFDEF CLX}const{$ENDIF} MousePos: TPoint): Boolean;
begin
result:=false; // <---- here
if AllowPanning <> pmNone then // <--- and here
result:=inherited DoMouseWheel(Shift,WheelDelta,MousePos);
TDragPointTool=class(TTeeCustomToolSeries)
private
fXMinimum:double;
fXMaximum:double;
fYMinimum:double;
fYMaximum:double;
fXClip:boolean;
fYClip:boolean;
....
published
property XMinimum:double read fXMinimum write fXMinimum;
property XMaximum:double read fXMaximum write fXMaximum;
property YMinimum:double read fYMinimum write fYMinimum;
property YMaximum:double read fYMaximum write fYMaximum;
property XClip:boolean read fXClip write fXClip;
property YClip:boolean read fYClip write fYClip;
Constructor TDragPointTool.Create(AOwner: TComponent);
begin
inherited;
fXMinimum:=-1000.0;
fXmaximum:=1000.0;
fYMinimum:=-1000.0;
fYmaximum:=1000.0;
fXClip:=true;
fYClip:=true;
procedure TDragPointTool.ChartMouseEvent(AEvent: TChartMouseEvent;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Function CheckAxisLimits(Axis:TChartAxis; Position:Integer):Double;
begin
with Axis do
if Maximum=Minimum then
begin
AutomaticMaximum:=False;
Maximum:=Maximum+0.1*MinAxisIncrement; // 6.02, fix when values are equal
end;
result:=Axis.CalcPosPoint(Position);
end;
var
Tmp:double;
begin
if Assigned(Series) then
Case AEvent of
cmeUp: IDragging:=-1; { stop dragging on mouse up }
cmeMove: if IDragging<>-1 then { if dragging... }
With Series do
begin
BeginUpdate;
{ Change the Series point X and / or Y values... }
if (Self.DragStyle=dsX) or (Self.DragStyle=dsBoth) then
begin
Tmp:=XScreenToValue(x);
if Tmp < fXMinimum then
Tmp := fXMinimum;
if Tmp > fXMaximum then
Tmp := fXMaximum;
if fXClip=true then
begin
if (IDragging = 0) and (IDragging < (count-1)) then // 1.Pkt
begin
if Tmp > XValue[IDragging+1] then
Tmp:= XValue[IDragging+1];
end else
begin
if IDragging = (count-1) then // last Pkt
begin
if (IDragging > 0) and (Tmp < XValue[IDragging-1]) then
Tmp:= XValue[IDragging-1];
end else
begin
if Tmp > XValue[IDragging+1] then
Tmp:= XValue[IDragging+1];
if Tmp < XValue[IDragging-1] then
Tmp:= XValue[IDragging-1];
end;
end;
XValue[IDragging]:=Tmp;
end else
begin
XValue[IDragging]:=CheckAxisLimits(GetHorizAxis,x);
end;
end;
if (Self.DragStyle=dsY) or (Self.DragStyle=dsBoth) then
begin
if fYClip=true then
begin
Tmp:=YScreenToValue(y);
if Tmp < fYMinimum then
Tmp := fYMinimum;
if Tmp > fYMaximum then
Tmp := fYMaximum;
YValue[IDragging]:=Tmp;
end else
begin
YValue[IDragging]:=CheckAxisLimits(GetVertAxis,y);
end;
end;
EndUpdate;
{ Notify the point values change... }
if Assigned(FOnDrag) then FOnDrag(Self,IDragging);
end;
cmeDown: begin { when the mouse button is pressed... }
IDragging:=Series.Clicked(x,y);
{ if clicked a Series point... }
if IDragging<>-1 then ParentChart.CancelMouse:=True;
end;
end;
end;
2.) disable Mousewheel function if no panning
function TCustomChart.DoMouseWheel(Shift: TShiftState; WheelDelta: Integer;
{$IFDEF CLX}const{$ENDIF} MousePos: TPoint): Boolean;
begin
result:=false; // <---- here
if AllowPanning <> pmNone then // <--- and here
result:=inherited DoMouseWheel(Shift,WheelDelta,MousePos);