annotate scripts/plot/util/zoom.m @ 19417:ec037d41da06

zoom: allow x, y, and z axes to be zoomed independently * zoom.m: Accept vector argument for zoom factor.
author John W. Eaton <jwe@octave.org>
date Mon, 06 Oct 2014 06:52:20 -0400
parents 0f9c5a15c8fa
children 8e1883060940
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 -*-
19344
0f9c5a15c8fa doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 19281
diff changeset
20 ## @deftypefn {Command} {} zoom (@var{factor})
19281
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
19417
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
27 ## factor is less than one, zoom out. If the zoom factor is a two- or
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
28 ## three-element vector, then the elements specify the zoom factors for
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
29 ## the x, y, and z axes respectively.
19281
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{"out"}, zoom to the initial zoom setting.
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 ##
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 ## 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
34 ## current axes limits.
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 ##
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 ## @seealso{pan, rotate3d}
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 ## @end deftypefn
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 ## Eventually we need to also support these features:
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 ## @deftypefn {Command} {} zoom
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 ## @deftypefnx {Command} {} zoom on
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 ## @deftypefnx {Command} {} zoom off
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 ## @deftypefnx {Command} {} zoom xon
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 ## @deftypefnx {Command} {} zoom yon
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 ## @deftypefnx {Command} {} zoom (@var{hfig}, @var{option})
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 ## @deftypefnx {Command} {zoom_object_handle =} zoom (@var{hfig})
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 function zoom (varargin)
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 hfig = NaN;
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 nargs = nargin;
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 if (nargs > 2)
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 print_usage ();
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 endif
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57
19417
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
58 if (nargin == 1 && nargout > 0 && isfigure (varargin{1}))
19281
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 error ("zoom_object_handle = zoom (hfig): not implemented");
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 endif
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 if (nargs == 2)
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 hfig = varargin{1};
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 if (isfigure (hfig))
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 varargin(1) = [];
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 nargs--;
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 else
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 error ("zoom: expecting figure handle as first argument");
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 endif
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 endif
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 if (isnan (hfig))
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 hfig = gcf ();
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 endif
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 if (nargs == 0)
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 error ("zoom: toggling zoom mode is not implemented");
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 elseif (nargs == 1)
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 arg = varargin{1};
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 if (isnumeric (arg))
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 factor = arg;
19417
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
82 switch (numel (factor))
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
83 case 3
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
84 xfactor = factor(1);
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
85 yfactor = factor(2);
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
86 zfactor = factor(3);
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
87 case 2
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
88 xfactor = factor(1);
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
89 yfactor = factor(2);
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
90 zfactor = 1;
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
91 case 1
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
92 xfactor = yfactor = zfactor = factor;
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
93 otherwise
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
94 error ("zoom: invalid factor");
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
95 endswitch
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
96 if (xfactor < 0 || yfactor < 0 || zfactor < 0)
19281
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 error ("zoom: factor must be greater than 1");
19417
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
98 elseif (xfactor == 1 && yfactor == 1 && zfactor == 1)
19281
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 return;
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100 endif
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101 cax = get (hfig, "currentaxes");
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102 if (! isempty (cax))
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 limits = axis ();
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104 initial_zoom = getappdata (cax, "initial_zoom");
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 if (isempty (initial_zoom))
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106 setappdata (cax, "__initial_zoom__", limits);
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107 endif
19417
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
108 limits(1:2) /= xfactor;
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
109 limits(3:4) /= yfactor;
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
110 if (numel (limits) > 4)
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
111 limits(5:6) /= zfactor;
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
112 endif
ec037d41da06 zoom: allow x, y, and z axes to be zoomed independently
John W. Eaton <jwe@octave.org>
parents: 19344
diff changeset
113 axis (cax, limits);
19281
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114 endif
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115 elseif (ischar (arg))
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116 switch (arg)
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117 case {"on", "off", "xon", "yon"}
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118 error ("zoom %s: not implemented", arg);
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120 case "out"
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121 cax = get (hfig, "currentaxes");
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122 if (! isempty (cax))
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 initial_zoom = getappdata (cax, "__initial_zoom__");
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124 if (! isempty (initial_zoom))
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125 axis (cax, initial_zoom);
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 endif
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127 endif
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129 case "reset"
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130 cax = get (hfig, "currentaxes");
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131 if (! isempty (cax))
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132 setappdata (cax, "__initial_zoom__", axis ());
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133 endif
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135 otherwise
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136 error ("zoom: unrecognized option '%s'", arg);
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137 endswitch
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138 else
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139 error ("zoom: wrong type argument '%s'", class (arg));
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140 endif
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141 endif
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142
8a6f87637c16 hg new function, zoom
John W. Eaton <jwe@octave.org>
parents:
diff changeset
143 endfunction