zoom_wheel(hfig,opt​ions)

Version 1.0.0.0 (7.93 KB) by Hugo
Zoom in and out using the wheel in a rather practical manner
115 Downloads
Updated 31 Mar 2015

View License

% ZOOM IN AND OUT USING THE MOUSE WHEEL
This codes implements the zoom in figures using the wheel.
This is done by modifying the WindowScrollWheelFcn callback function.

% SYNTAX:

*) zoom_wheel: will add the zoom functionality in the current figure.
*) zoom_wheel(hfig): will add the zoom functionality in the figure
identified with the figure handle hfig.
*) zoom_wheel(options): will add the zoom functionality in the current
figure with customization given by options.
*) zoom_wheel(hfig, options): will add the zoom functionality in the figure
identified with the figure handle hfig with customization given by options.

% INPUT ARGUMENTS

*) hfig: Figure handle. If none is provided, current figure will be
employed.
*) options: Structure with the following fields for customizing the behaviour of the zoom functionality
*) Magnify: General magnitication factor. Unity or greater (by default 1.1).
*) XMagnify: Magnification factor of X axis (unity by default).
*) YMagnify: Magnification factor of Y axis (unity by default).
*) ChangeMagnify: Relative increase of the magnification factor. Unity or greater (by default 1.1).
*) IncreaseChange: Relative increase in the ChangeMagnify factor. Unity or greater (by default 1.1).
*) MinValue: Sets the minimum value that Magnify, ChangeMagnify and
IncreaseChange can take.
*) Pause: Number of seconds that information about the value of
Magnify and ChangeMagnify will be displayed everytime their value if
changed.

% BEHAVIOUR:

The magnification along the X axis is given by the formula

options.Magnify * options.XMagnify

and analogously for the Y axis. Whether zooming in (incrementing the
distance between data points) or zooming out (decrementing the distance
between data points) depends on the direction of rotation of the mouse wheel.

When *shift* is pressed, the rotation of the mouse wheel changes the
value of options.Magnify according to the following:

options.Magnify <- options.Magnify * options.ChangeMagnify

and if *Ctrl* is pressed, the rotation of the mouse wheel changes the
value of options.ChangeMagnify according to the following:

options.ChangeMagnify <- options.ChangeMagnify * options.IncreaseChange

When pressing *Alt* while moving the wheel, the zoom returns to the
original state, but not the values of options.

Notice that, in order to add this functionality, zoom_wheel modifies
the WindowScrollWheelFcn callback function in your figure, loosing
nay previous functionality this callback function may have provided
for the particular figure zoom_wheel is applied on.

% EXAMPLES:

h=figure(1);
plot(rand(100,1),rand(100,1));

options.Magnify = 1.05;
options.ChangeMagnify = 1.2;
zoom_wheel(h,options);

% Please, report any bugs to Hugo.Eyherabide@cs.helsinki.fi

% Copyright (c) 2015, Hugo Gabriel Eyherabide, University of Helsinki, Finland.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Cite As

Hugo (2024). zoom_wheel(hfig,options) (https://www.mathworks.com/matlabcentral/fileexchange/50350-zoom_wheel-hfig-options), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2015a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Data Exploration in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0