Zomming/Unzooming using Mouse Wheel

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Avijit
Newbie
Newbie
Posts: 72
Joined: Tue Sep 15, 2009 12:00 am

Zomming/Unzooming using Mouse Wheel

Post by Avijit » Mon Nov 30, 2009 9:27 am

Hi TeeChart Team,
I am trying to allow the user to zoom and unzoom using the Mouse Wheel.
I have 10 data series and each are having its own custop y axis of same size. Means no data is overlaped. Each data series is having its own separate y axis.
I found one topic on this kind of zooming in the forum. I did tried that and it worked.
But the problems i found are -

1. When i am unzooming, the data is getting compressed and compressed irrespective of the chart size. Is it possible to set the minimum limit after which unzoom will be stopped. That means, once the data is back to its normal view from the zoomed view, the unzoom should not happen anymore. Also the mouse wheel steps are not actually the history zooming steps. Can i make the mouse wheel unzoom based on History zooming steps?

2. Zooming is irrespective of the mouse position and direction. I mean, even if my mouse is at the corner of the chart, zomming is getting applied to the middle of the chart. My intention of using the mouse wheel in that corner is to zoom into that corner data. But once i zoom, the data itself going to the scrollable area. About direction - I have set the zoom direction to both but still the zooming is happening on in horizontal direction.

Please let me know how can i solve these problems.

Regards,
Avijit

AIS
Newbie
Newbie
Posts: 70
Joined: Wed Jun 25, 2008 12:00 am

Re: Zomming/Unzooming using Mouse Wheel

Post by AIS » Mon Nov 30, 2009 9:41 am

I have had the same problem earlier today and written the following code:

Code: Select all

/// <summary>
        /// method zoom a given axis for one step (10%) in or out and recognize the current mouse position to zoom only the area where the mouse is
        /// </summary>
        /// <param name="axis">axis to zoom</param>
        /// <param name="zoomIn">in or out</param>
        /// <param name="mousePosition">current mouse point</param>
        protected static void ZoomAxis(Steema.TeeChart.Axis axis, Boolean zoomIn, Point mousePosition)
        {
            double zoomDelta = 0;
            double scrollDelta = 0;
            int mousePos = 0;
            if (zoomIn)
            {
                zoomDelta = (axis.Maximum - axis.Minimum) * 0.1;
            }
            else
            {
                zoomDelta = (axis.Maximum - axis.Minimum) * -(100.0/110.0/10.0);
            }

            if (axis.Horizontal)
            {
                mousePos = mousePosition.X;
            }
            else
            {
                mousePos = mousePosition.Y;
            }
            scrollDelta = (axis.CalcPosPoint(mousePos) - axis.Minimum) / ((axis.Maximum - axis.Minimum) / 2.0);
            axis.SetMinMax(axis.Minimum + (zoomDelta * scrollDelta), axis.Maximum - (zoomDelta * (2 - scrollDelta)));
        }
In addition you must set zoomed property to true after a call of this function and also it is recommend to set autorepaint to false before calling the function for each axis and at the end call chart.Refresh(). Within the UndoneZoom event of the chart you must set the automatic property of each axis to true due to the use of SetMinMax().

I hope it helps :)

Avijit
Newbie
Newbie
Posts: 72
Joined: Tue Sep 15, 2009 12:00 am

Re: Zomming/Unzooming using Mouse Wheel

Post by Avijit » Mon Nov 30, 2009 11:31 am

Hi AIS,
Your code is solving the 2nd problem very well.
Thanks for the help.

Regards,
Avijit

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

Re: Zomming/Unzooming using Mouse Wheel

Post by Yeray » Mon Nov 30, 2009 2:08 pm

Hi Avijit,

Please take a look at the following example and see if it is doing what you expected. I'm using MouseScroll event to zoom/unzoom all the custom axis and the bottom axis as well.
I've also added the BeforeDrawValues and AfterDrawValues events like in the demo at All Featres\Welcome !\Axes\Opaque zones

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }

        private void InitializeChart()
        {
            chartController1.Chart = tChart1;

            tChart1.Aspect.View3D = false;
            tChart1.Panel.MarginLeft = 7;

            int nSeries = 4;                        

            for (int i = 0; i < nSeries; i++)
            {
                new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
                tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
                tChart1.Axes.Custom[i].AxisPen.Color = tChart1[i].Color;
                tChart1[i].FillSampleValues(50);
                tChart1[i].CustomVertAxis = tChart1.Axes.Custom[i];
                tChart1[i].BeforeDrawValues += new Steema.TeeChart.PaintChartEventHandler(lines_BeforeDrawValues);
                tChart1[i].AfterDrawValues += new Steema.TeeChart.PaintChartEventHandler(lines_AfterDrawValues);
            }

            tChart1.Draw();
            Rectangle rect = tChart1.Chart.ChartRect;

            for (int i = 0; i < tChart1.Series.Count; i++)
            {
                tChart1.Axes.Custom[i].StartEndPositionUnits = Steema.TeeChart.PositionUnits.Pixels;             
                tChart1.Axes.Custom[i].StartPosition = i * (rect.Height / tChart1.Series.Count);
                tChart1.Axes.Custom[i].EndPosition = (i + 1) * (rect.Height / tChart1.Series.Count);
            }

            tChart1.MouseWheel += new MouseEventHandler(tChart1_MouseWheel);            
        }

        void lines_AfterDrawValues(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            tChart1.Graphics3D.ClearClipRegions();
        }

        void lines_BeforeDrawValues(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            Steema.TeeChart.Styles.Series s = sender as Steema.TeeChart.Styles.Series;

            int left = s.GetHorizAxis.IStartPos;
            int right = s.GetHorizAxis.IEndPos;
            int top = s.GetVertAxis.IStartPos;
            int bottom = s.GetVertAxis.IEndPos;
            tChart1.Graphics3D.ClipRectangle(left, top, right, bottom);
        }        

        void tChart1_MouseWheel(object sender, MouseEventArgs e)
        {
            double AMin, AMax, tmpDelta;

            if (e.Delta > 0)
            {
                for (int i = 0; i < tChart1.Axes.Custom.Count; i++)
                {                    
                    AMin = tChart1.Axes.Custom[i].CalcPosPoint(tChart1.Axes.Custom[i].IEndPos);
                    AMax = tChart1.Axes.Custom[i].CalcPosPoint(tChart1.Axes.Custom[i].IStartPos);
                    tmpDelta = (AMax - AMin) * 0.1;
                    tChart1.Axes.Custom[i].SetMinMax(AMin + tmpDelta, AMax - tmpDelta);
                }
                AMin = tChart1.Axes.Bottom.CalcPosPoint(tChart1.Axes.Bottom.IEndPos);
                AMax = tChart1.Axes.Bottom.CalcPosPoint(tChart1.Axes.Bottom.IStartPos);
                tmpDelta = (AMax - AMin) * 0.1;
                tChart1.Axes.Bottom.SetMinMax(AMin + tmpDelta, AMax - tmpDelta);
            }
            else
            {
                for (int i = 0; i < tChart1.Axes.Custom.Count; i++)
                {
                    AMin = tChart1.Axes.Custom[i].CalcPosPoint(tChart1.Axes.Custom[i].IEndPos);
                    AMax = tChart1.Axes.Custom[i].CalcPosPoint(tChart1.Axes.Custom[i].IStartPos);
                    tmpDelta = (AMax - AMin) * (-0.1);
                    tChart1.Axes.Custom[i].SetMinMax(AMin + tmpDelta, AMax - tmpDelta);
                }
                AMin = tChart1.Axes.Bottom.CalcPosPoint(tChart1.Axes.Bottom.IEndPos);
                AMax = tChart1.Axes.Bottom.CalcPosPoint(tChart1.Axes.Bottom.IStartPos);
                tmpDelta = (AMax - AMin) * (-0.1);
                tChart1.Axes.Bottom.SetMinMax(AMin + tmpDelta, AMax - tmpDelta);
            }
        }
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

AIS
Newbie
Newbie
Posts: 70
Joined: Wed Jun 25, 2008 12:00 am

Re: Zomming/Unzooming using Mouse Wheel

Post by AIS » Mon Nov 30, 2009 3:11 pm

For a correct zoom in and zoom out calculation step wise there is a good explanation from narcis within this thread

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

Re: Zomming/Unzooming using Mouse Wheel

Post by Narcís » Mon Nov 30, 2009 3:15 pm

Hello AIS and Avijit,

Also there's Zoom.History which is a new property in TeeChart for .NET 2009 and is false by default. It's a historical recording of Chart zoom-ins, so that zoom-out is in their reverse sequence. You can find an example at What's New?\Welcome !\New in Zoom and Scroll\Zoom History in the features demo included with v2009.
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