changeset 13800:5acb5c25e4ae

allow axes handle to be passed to title function * __axis_label__.m: Accept axes handle argument. Don't call gca. * xlabel.m, ylabel.m, zlabel.m: Pass axes handle to __axis_label__ instead of calling axes to temporaritly set currentaxes. Eliminate unneeded unwind_protect block. * title.m: Accept axes handle. Pass axes handle to __axis_label__.
author John W. Eaton <jwe@octave.org>
date Thu, 03 Nov 2011 04:41:40 -0400
parents 760e4e88dba3
children 195ff3561152
files scripts/plot/private/__axis_label__.m scripts/plot/title.m scripts/plot/xlabel.m scripts/plot/ylabel.m scripts/plot/zlabel.m
diffstat 5 files changed, 26 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/private/__axis_label__.m	Thu Nov 03 04:33:25 2011 -0400
+++ b/scripts/plot/private/__axis_label__.m	Thu Nov 03 04:41:40 2011 -0400
@@ -17,23 +17,21 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} __axis_label__ (@var{caller}, @var{txt}, @dots{})
+## @deftypefn {Function File} {} __axis_label__ (@var{caller}, @var{h}, @var{txt}, @dots{})
 ## Undocumented internal function.
 ## @end deftypefn
 
 ## Author: jwe
 
-function retval = __axis_label__ (caller, txt, varargin)
+function retval = __axis_label__ (ah, caller, txt, varargin)
 
-  ca = gca ();
-
-  h = get (gca (), caller);
+  h = get (ah, caller);
 
-  set (h, "fontangle", get (ca, "fontangle"),
-       "fontname", get (ca, "fontname"),
-       "fontsize", get (ca, "fontsize"),
-       "fontunits", get (ca, "fontunits"),
-       "fontweight", get (ca, "fontweight"),
+  set (h, "fontangle", get (ah, "fontangle"),
+       "fontname", get (ah, "fontname"),
+       "fontsize", get (ah, "fontsize"),
+       "fontunits", get (ah, "fontunits"),
+       "fontweight", get (ah, "fontweight"),
        "string", txt,
        varargin{:});
 
--- a/scripts/plot/title.m	Thu Nov 03 04:33:25 2011 -0400
+++ b/scripts/plot/title.m	Thu Nov 03 04:41:40 2011 -0400
@@ -19,23 +19,27 @@
 ## -*- texinfo -*-
 ## @deftypefn  {Function File} {} title (@var{string})
 ## @deftypefnx {Function File} {} title (@var{string}, @var{p1}, @var{v1}, @dots{})
+## @deftypefnx {Function File} {} title (@var{h}, @dots{})
+## @deftypefnx {Function File} {@var{h} =} title (@dots{})
 ## Create a title object and return a handle to it.
 ## @end deftypefn
 
 ## Author: jwe
 
-function h = title (string, varargin)
+function h = title (varargin)
+
+  [h, varargin, nargin] = __plt_get_axis_arg__ ("title", varargin{:});
 
-  if (rem (nargin, 2) == 1)
-    if (nargout > 0)
-      h = __axis_label__ ("title", string, varargin{:});
-    else
-      __axis_label__ ("title", string, varargin{:});
-    endif
-  else
+  if (rem (nargin, 2) != 1)
     print_usage ();
   endif
 
+  tmp = __axis_label__ (h, "title", varargin{:});
+
+  if (nargout > 0)
+    retval = tmp;
+  endif
+
 endfunction
 
 %!demo
--- a/scripts/plot/xlabel.m	Thu Nov 03 04:33:25 2011 -0400
+++ b/scripts/plot/xlabel.m	Thu Nov 03 04:41:40 2011 -0400
@@ -39,14 +39,8 @@
     print_usage ();
   endif
 
-  oldh = gca ();
-  unwind_protect
-    axes (h);
-    tmp = __axis_label__ ("xlabel", varargin{:},
-                          "color", get (h, "xcolor"));
-  unwind_protect_cleanup
-    axes (oldh);
-  end_unwind_protect
+  tmp = __axis_label__ (h, "xlabel", varargin{:},
+                        "color", get (h, "xcolor"));
 
   if (nargout > 0)
     retval = tmp;
--- a/scripts/plot/ylabel.m	Thu Nov 03 04:33:25 2011 -0400
+++ b/scripts/plot/ylabel.m	Thu Nov 03 04:41:40 2011 -0400
@@ -33,14 +33,8 @@
     print_usage ();
   endif
 
-  oldh = gca ();
-  unwind_protect
-    axes (h);
-    tmp = __axis_label__ ("ylabel", varargin{:},
-                          "color", get (h, "ycolor"));
-  unwind_protect_cleanup
-    axes (oldh);
-  end_unwind_protect
+  tmp = __axis_label__ (h, "ylabel", varargin{:},
+                        "color", get (h, "ycolor"));
 
   if (nargout > 0)
     retval = tmp;
--- a/scripts/plot/zlabel.m	Thu Nov 03 04:33:25 2011 -0400
+++ b/scripts/plot/zlabel.m	Thu Nov 03 04:41:40 2011 -0400
@@ -33,14 +33,8 @@
     print_usage ();
   endif
 
-  oldh = gca ();
-  unwind_protect
-    axes (h);
-    tmp = __axis_label__ ("zlabel", varargin{:},
-                          "color", get (h, "zcolor"));
-  unwind_protect_cleanup
-    axes (oldh);
-  end_unwind_protect
+  tmp = __axis_label__ (h, "zlabel", varargin{:},
+                        "color", get (h, "zcolor"));
 
   if (nargout > 0)
     retval = tmp;