Mercurial > hg > octave-nkf
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 |
rev | line source |
---|---|
19281 | 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 -*- | |
19344
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19281
diff
changeset
|
20 ## @deftypefn {Command} {} zoom (@var{factor}) |
19281 | 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 | |
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 | 30 ## |
31 ## Given the option @qcode{"out"}, zoom to the initial zoom setting. | |
32 ## | |
33 ## Given the option @qcode{"reset"}, set the initial zoom setting to the | |
34 ## current axes limits. | |
35 ## | |
36 ## @seealso{pan, rotate3d} | |
37 ## @end deftypefn | |
38 | |
39 ## Eventually we need to also support these features: | |
40 ## @deftypefn {Command} {} zoom | |
41 ## @deftypefnx {Command} {} zoom on | |
42 ## @deftypefnx {Command} {} zoom off | |
43 ## @deftypefnx {Command} {} zoom xon | |
44 ## @deftypefnx {Command} {} zoom yon | |
45 ## @deftypefnx {Command} {} zoom (@var{hfig}, @var{option}) | |
46 ## @deftypefnx {Command} {zoom_object_handle =} zoom (@var{hfig}) | |
47 | |
48 function zoom (varargin) | |
49 | |
50 hfig = NaN; | |
51 | |
52 nargs = nargin; | |
53 | |
54 if (nargs > 2) | |
55 print_usage (); | |
56 endif | |
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 | 59 error ("zoom_object_handle = zoom (hfig): not implemented"); |
60 endif | |
61 | |
62 if (nargs == 2) | |
63 hfig = varargin{1}; | |
64 if (isfigure (hfig)) | |
65 varargin(1) = []; | |
66 nargs--; | |
67 else | |
68 error ("zoom: expecting figure handle as first argument"); | |
69 endif | |
70 endif | |
71 | |
72 if (isnan (hfig)) | |
73 hfig = gcf (); | |
74 endif | |
75 | |
76 if (nargs == 0) | |
77 error ("zoom: toggling zoom mode is not implemented"); | |
78 elseif (nargs == 1) | |
79 arg = varargin{1}; | |
80 if (isnumeric (arg)) | |
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 | 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 | 99 return; |
100 endif | |
101 cax = get (hfig, "currentaxes"); | |
102 if (! isempty (cax)) | |
103 limits = axis (); | |
104 initial_zoom = getappdata (cax, "initial_zoom"); | |
105 if (isempty (initial_zoom)) | |
106 setappdata (cax, "__initial_zoom__", limits); | |
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 | 114 endif |
115 elseif (ischar (arg)) | |
116 switch (arg) | |
117 case {"on", "off", "xon", "yon"} | |
118 error ("zoom %s: not implemented", arg); | |
119 | |
120 case "out" | |
121 cax = get (hfig, "currentaxes"); | |
122 if (! isempty (cax)) | |
123 initial_zoom = getappdata (cax, "__initial_zoom__"); | |
124 if (! isempty (initial_zoom)) | |
125 axis (cax, initial_zoom); | |
126 endif | |
127 endif | |
128 | |
129 case "reset" | |
130 cax = get (hfig, "currentaxes"); | |
131 if (! isempty (cax)) | |
132 setappdata (cax, "__initial_zoom__", axis ()); | |
133 endif | |
134 | |
135 otherwise | |
136 error ("zoom: unrecognized option '%s'", arg); | |
137 endswitch | |
138 else | |
139 error ("zoom: wrong type argument '%s'", class (arg)); | |
140 endif | |
141 endif | |
142 | |
143 endfunction |