zoom with mousewheel

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Werner
Newbie
Newbie
Posts: 46
Joined: Mon Aug 06, 2007 12:00 am

zoom with mousewheel

Post by Werner » Sat Oct 29, 2011 1:36 pm

Hi,
I use teechart v8.07 and want to implement a zoom while mousewheel.

This example don't work as I expected:

Code: Select all

procedure TChroDataResultFrame.ChroDataChartMouseWheel(Sender: TObject;
  Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint;
  var Handled: Boolean); 
 with ChroDataChart do begin
          if (WheelDelta > 0) then ChroDataChart.ZoomRect(110)
                          else ChroDataChart.ZoomPercent(90);
          Handled:=True;
     end;
I want the following behaviour :

Point on the chart with the mouse
with the wheel button the series are zoomend in or out, while the center is now at the mouseposition.
This scould be similar as the normal zoomrect with left mousebutton

Zoom in and out must result in the same zoom factor. That means if I zoom in and out the same window should be displayed

How can I do that ?

with best regards
Werner

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: zoom with mousewheel

Post by Yeray » Mon Oct 31, 2011 12:44 pm

Hello Werner,

Have you tried using TeeMouseWheel as discussed here?
http://www.teechart.net/support/viewtop ... 66&p=23983
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Werner
Newbie
Newbie
Posts: 46
Joined: Mon Aug 06, 2007 12:00 am

Re: zoom with mousewheel

Post by Werner » Mon Oct 31, 2011 2:41 pm

Dear Yeray,

I have tried the sample, but as I described the ZoomPercent does not fit the problem.
I suppose it has to be realized with ZoomRect, but don't no how.

with best regards
Werner

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

Re: zoom with mousewheel

Post by Narcís » Mon Oct 31, 2011 4:12 pm

Hello Werner,

In that case you could call ZoomRect with a rectangle centered at your mouse X, Y position and with your desired dimensions. Notice the original drawing area is Chart1.ChartRect so you could increase or decrease the rectangle you send to ZoomRect depending on the movement of your mouse wheel.

Hope this helps!
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

Werner
Newbie
Newbie
Posts: 46
Joined: Mon Aug 06, 2007 12:00 am

Re: zoom with mousewheel

Post by Werner » Mon Oct 31, 2011 4:35 pm

Thank you for the info,
do you have a sample project or a code snippet for it ?

with best regards

Werner

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: zoom with mousewheel

Post by Yeray » Wed Nov 02, 2011 10:27 am

Hello Werner,

I found some problems in using the MousePos given in the MouseWheel event, but I can use the mouse positions from the OnMouseMove event:

Code: Select all

uses Series;

var MouseX, MouseY: Integer;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=false;
  Chart1.Legend.Visible:=false;
  Chart1.Panning.MouseWheel:=pmwNone;
  Chart1.AddSeries(TPointSeries).FillSampleValues();
end;

procedure TForm1.Chart1MouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
const radius=50;
begin
  if WheelDelta > 0 then
    Chart1.ZoomRect(Rect(MouseX-radius, MouseY-radius, MouseX+radius, MouseY+radius));
end;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  MouseX:=X;
  MouseY:=Y;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Werner
Newbie
Newbie
Posts: 46
Joined: Mon Aug 06, 2007 12:00 am

Re: zoom with mousewheel

Post by Werner » Wed Nov 02, 2011 12:19 pm

Dear Yeray,
thank you for the code, this is for zoom in.
I have tried this for zoom out, but the behaviour was always zoom in.
Whats wrong ?

BTW : ChroDataChart.ZoomRect(Rect(IMouseX-radius, IMouseY-radius, IMouseX+radius, IMouseY+radius));
results in a compiler error.

Code: Select all

 if WheelDelta > 0 then begin
      Rect.Bottom:= IMouseX-radius;
             Rect.Left:=IMouseY-radius;
             Rect.Right:=IMouseX+radius;
             Rect.Top:=IMouseY+radius;
     ChroDataChart.ZoomRect(Rect); 
  end else begin
     Rect.Bottom:= IMouseX+radius;
             Rect.Left:=IMouseY+radius;
             Rect.Right:=IMouseX-radius;
             Rect.Top:=IMouseY-radius;
             ChroDataChart.ZoomRect(Rect);
  end;

with best regards
Werner

Yeray
Site Admin
Site Admin
Posts: 9613
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: zoom with mousewheel

Post by Yeray » Thu Nov 03, 2011 3:00 pm

Hello Werner,

With the actual v2011, there is a Zoom.History, that would help you to unZoom through the zoom states you've passed. This works fine for me here:

Code: Select all

uses Series;

var MouseX, MouseY: Integer;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=false;
  Chart1.Legend.Visible:=false;
  Chart1.Panning.MouseWheel:=pmwNone;
  Chart1.AddSeries(TPointSeries).FillSampleValues();
  Chart1.Zoom.History:=true;
end;

procedure TForm1.Chart1MouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
const radius=50;
begin
  if WheelDelta > 0 then
    Chart1.ZoomRect(Rect(MouseX-radius, MouseY-radius, MouseX+radius, MouseY+radius))
  else
    Chart1.UndoZoom;
end;

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  MouseX:=X;
  MouseY:=Y;
end;
However, in v8, without the Zoom.History, the UndoZoom call will bring you to the initial step, without any zoom at all, even if you have zoomed several times before the first unzooming.
If you want a Zoom History in v8, you'll have to implement your own history. You could have a two dimension array for each axis. When you zoom in, you add the min and max of each axis before zooming (before the ZoomRect call) so you will be able to restore them in the zoom out procedure.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply