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