comparison scripts/plot/util/zoom.m @ 19281:8a6f87637c16

hg new function, zoom * zoom.m: New function. * plot/util/module.mk: Add it to the list. * pan.m, rotate3d.m: Update @seealso lists. * plot.txi: Document it. * NEWS: Mention it.
author John W. Eaton <jwe@octave.org>
date Sat, 13 Sep 2014 16:45:31 -0400
parents
children 0f9c5a15c8fa
comparison
equal deleted inserted replaced
19280:99aec089e8c3 19281:8a6f87637c16
1 ## Copyright (C) 2014 John W. Eaton
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Command} {} zoom (@var{factor})
21 ## @deftypefnx {Command} {} zoom out
22 ## @deftypefnx {Command} {} zoom reset
23 ## Zoom the current axes object.
24 ##
25 ## Given a numeric argument greater than zero, zoom by the given factor.
26 ## If the zoom factor is greater than one, zoom in on the plot. If the
27 ## factor is less than one, zoom out.
28 ##
29 ## Given the option @qcode{"out"}, zoom to the initial zoom setting.
30 ##
31 ## Given the option @qcode{"reset"}, set the initial zoom setting to the
32 ## current axes limits.
33 ##
34 ## @seealso{pan, rotate3d}
35 ## @end deftypefn
36
37 ## Eventually we need to also support these features:
38 ## @deftypefn {Command} {} zoom
39 ## @deftypefnx {Command} {} zoom on
40 ## @deftypefnx {Command} {} zoom off
41 ## @deftypefnx {Command} {} zoom xon
42 ## @deftypefnx {Command} {} zoom yon
43 ## @deftypefnx {Command} {} zoom (@var{hfig}, @var{option})
44 ## @deftypefnx {Command} {zoom_object_handle =} zoom (@var{hfig})
45
46 function zoom (varargin)
47
48 hfig = NaN;
49
50 nargs = nargin;
51
52 if (nargs > 2)
53 print_usage ();
54 endif
55
56 if (nargin == 1 && isfigure (varargin{1}))
57 error ("zoom_object_handle = zoom (hfig): not implemented");
58 endif
59
60 if (nargs == 2)
61 hfig = varargin{1};
62 if (isfigure (hfig))
63 varargin(1) = [];
64 nargs--;
65 else
66 error ("zoom: expecting figure handle as first argument");
67 endif
68 endif
69
70 if (isnan (hfig))
71 hfig = gcf ();
72 endif
73
74 if (nargs == 0)
75 error ("zoom: toggling zoom mode is not implemented");
76 elseif (nargs == 1)
77 arg = varargin{1};
78 if (isnumeric (arg))
79 factor = arg;
80 if (factor < 0)
81 error ("zoom: factor must be greater than 1");
82 elseif (factor == 1)
83 return;
84 endif
85 cax = get (hfig, "currentaxes");
86 if (! isempty (cax))
87 limits = axis ();
88 initial_zoom = getappdata (cax, "initial_zoom");
89 if (isempty (initial_zoom))
90 setappdata (cax, "__initial_zoom__", limits);
91 endif
92 axis (cax, limits / factor);
93 endif
94 elseif (ischar (arg))
95 switch (arg)
96 case {"on", "off", "xon", "yon"}
97 error ("zoom %s: not implemented", arg);
98
99 case "out"
100 cax = get (hfig, "currentaxes");
101 if (! isempty (cax))
102 initial_zoom = getappdata (cax, "__initial_zoom__");
103 if (! isempty (initial_zoom))
104 axis (cax, initial_zoom);
105 endif
106 endif
107
108 case "reset"
109 cax = get (hfig, "currentaxes");
110 if (! isempty (cax))
111 setappdata (cax, "__initial_zoom__", axis ());
112 endif
113
114 otherwise
115 error ("zoom: unrecognized option '%s'", arg);
116 endswitch
117 else
118 error ("zoom: wrong type argument '%s'", class (arg));
119 endif
120 endif
121
122 endfunction