Please insert following Sourcecode

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Achim
Newbie
Newbie
Posts: 10
Joined: Tue Nov 27, 2007 12:00 am

Please insert following Sourcecode

Post by Achim » 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);

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Nov 05, 2008 9:51 am

Hi Achim,

Sorry but I don't understand which are the exact problems here. Could you please provide more detailed information?

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Achim
Newbie
Newbie
Posts: 10
Joined: Tue Nov 27, 2007 12:00 am

Post by Achim » Wed Nov 05, 2008 11:23 am


Sorry but I don't understand which are the exact problems here. Could you please provide more detailed information?

Thanks in advance.
1.)
If you use the mouse to drag a series point, there is no limit. You can drag and drag and drag, the values can grows up to thousand and millions.
With the code above, it is possible to clip/limit this behavour. You can set a min/max value, and if you want to drag beyond these values, the dragging will stop.

2.)
It is(or was in older versions) possible to use the mouse wheel for panning, even if panning is not allowed. The two lines prevent this behaviour.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Nov 05, 2008 11:31 am

Hi Achim,
1.)
If you use the mouse to drag a series point, there is no limit. You can drag and drag and drag, the values can grows up to thousand and millions.
With the code above, it is possible to clip/limit this behavour. You can set a min/max value, and if you want to drag beyond these values, the dragging will stop.
Thanks for your suggestion. We'll add your suggestion to the wish-list to be considered for inclusion in future releases. However, some users may not be happy with this change as it may break their functionality.
2.)
It is(or was in older versions) possible to use the mouse wheel for panning, even if panning is not allowed. The two lines prevent this behaviour.
You can achieve this much easily. You just need to use this:

Code: Select all

TeeUseMouseWheel := True; 
Chart1.TabStop:=True;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Achim
Newbie
Newbie
Posts: 10
Joined: Tue Nov 27, 2007 12:00 am

Post by Achim » Wed Nov 05, 2008 1:40 pm

However, some users may not be happy with this change as it may break their functionality.
There is an on/off property in the code above. Default-seting should be 'off'.


2.)
It is(or was in older versions) possible to use the mouse wheel for panning, even if panning is not allowed. The two lines prevent this behaviour.
You can achieve this much easily. You just need to use this:

Code: Select all

TeeUseMouseWheel := True; 
Chart1.TabStop:=True;

Thanks, I'll try it.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Nov 05, 2008 2:06 pm

Hi Achim,

Ok, thanks for your feedback!
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply