changeset 19259: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 5d3111977623
children cdfc8bc9ab62
files scripts/plot/util/zoom.m
diffstat 1 files changed, 26 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/util/zoom.m	Sun Oct 05 11:23:25 2014 -0500
+++ b/scripts/plot/util/zoom.m	Mon Oct 06 06:52:20 2014 -0400
@@ -24,7 +24,9 @@
 ##
 ## Given a numeric argument greater than zero, zoom by the given factor.
 ## If the zoom factor is greater than one, zoom in on the plot.  If the
-## factor is less than one, zoom out.
+## factor is less than one, zoom out.  If the zoom factor is a two- or
+## three-element vector, then the elements specify the zoom factors for
+## the x, y, and z axes respectively.
 ##
 ## Given the option @qcode{"out"}, zoom to the initial zoom setting.
 ##
@@ -53,7 +55,7 @@
     print_usage ();
   endif
 
-  if (nargin == 1 && isfigure (varargin{1}))
+  if (nargin == 1 && nargout > 0 && isfigure (varargin{1}))
     error ("zoom_object_handle = zoom (hfig): not implemented");
   endif
 
@@ -77,9 +79,23 @@
     arg = varargin{1};
     if (isnumeric (arg))
       factor = arg;
-      if (factor < 0)
+      switch (numel (factor))
+        case 3
+          xfactor = factor(1);
+          yfactor = factor(2);
+          zfactor = factor(3);
+        case 2
+          xfactor = factor(1);
+          yfactor = factor(2);
+          zfactor = 1;
+        case 1
+          xfactor = yfactor = zfactor = factor;
+        otherwise
+          error ("zoom: invalid factor");
+      endswitch
+      if (xfactor < 0 || yfactor < 0 || zfactor < 0)
         error ("zoom: factor must be greater than 1");
-      elseif (factor == 1)
+      elseif (xfactor == 1 && yfactor == 1 && zfactor == 1)
         return;
       endif
       cax = get (hfig, "currentaxes");
@@ -89,7 +105,12 @@
         if (isempty (initial_zoom))
           setappdata (cax, "__initial_zoom__", limits);
         endif
-        axis (cax, limits / factor);
+        limits(1:2) /= xfactor;
+        limits(3:4) /= yfactor;
+        if (numel (limits) > 4)
+          limits(5:6) /= zfactor;
+        endif
+        axis (cax, limits);
       endif
     elseif (ischar (arg))
       switch (arg)