changeset 6977:e78e31f0a236

[project @ 2007-10-08 19:09:32 by jwe]
author jwe
date Mon, 08 Oct 2007 19:09:32 +0000
parents b84117de13da
children b75630794a11
files scripts/ChangeLog scripts/plot/__go_draw_axes__.m scripts/plot/legend.m
diffstat 3 files changed, 71 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Mon Oct 08 18:30:46 2007 +0000
+++ b/scripts/ChangeLog	Mon Oct 08 19:09:32 2007 +0000
@@ -1,3 +1,8 @@
+2007-10-08  Peter A. Gustafson  <petegus@umich.edu>
+
+	* plot/__go_draw_axes__.m, plot/legend.m:
+	Handle compatible position specifiers as strings.
+
 2007-10-08  John Swensen  <jpswensen@comcast.net>
 
 	* general/num2str.m: Eliminate extra whitespace in output.
--- a/scripts/plot/__go_draw_axes__.m	Mon Oct 08 18:30:46 2007 +0000
+++ b/scripts/plot/__go_draw_axes__.m	Mon Oct 08 19:09:32 2007 +0000
@@ -755,9 +755,18 @@
 	box = "nobox";
       endif
       inout = "inside";
-      switch (axis_obj.keypos)
+      keypos = axis_obj.keypos;
+      if (ischar (keypos))
+	keypos = lower (keypos);
+	keyout = findstr (keypos, "outside");
+	if (! isempty (keyout))
+	  inout = "outside";
+	  keypos = keypos (1:keyout-1);
+	endif
+      endif
+      switch (keypos)
 	case -1
-	  pos = "right bottom";
+	  pos = "right top";
 	  inout = "outside";
 	case 1
 	  pos = "right top";
@@ -765,8 +774,29 @@
 	  pos = "left top";
 	case 3
 	  pos = "left bottom";
-	case 4
+	case {4, 0}
 	  pos = "right bottom";
+	case "north"
+	  pos = "center top";
+	case "south"
+	  pos = "center bottom";
+	case "east"
+	  pos = "right center";
+	case "west"
+	  pos = "left center";
+	case "northeast"
+	  pos = "right top";
+	case "northwest"
+	  pos = "left top";
+	case "southeast"
+	  pos = "right bottom";
+	case "southwest"
+	  pos = "left bottom";
+	case "best" 
+	  pos = "";
+	  warning ("legend: 'Best' not yet implemented for location specifier.\n");
+	  ## least conflict with data in plot
+	  ## least unused space outside plot
 	otherwise
 	  pos = "";
       endswitch
--- a/scripts/plot/legend.m	Mon Oct 08 18:30:46 2007 +0000
+++ b/scripts/plot/legend.m	Mon Oct 08 19:09:32 2007 +0000
@@ -20,11 +20,11 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} legend (@var{st1}, @var{st2}, @dots{})
-## @deftypefnx {Function File} {} legend (@var{st1}, @var{st2}, @dots{}, @var{pos})
+## @deftypefnx {Function File} {} legend (@var{st1}, @var{st2}, @dots{}, "location", @var{pos})
 ## @deftypefnx {Function File} {} legend (@var{matstr})
-## @deftypefnx {Function File} {} legend (@var{matstr}, @var{pos})
+## @deftypefnx {Function File} {} legend (@var{matstr}, "location", @var{pos})
 ## @deftypefnx {Function File} {} legend (@var{cell})
-## @deftypefnx {Function File} {} legend (@var{cell}, @var{pos})
+## @deftypefnx {Function File} {} legend (@var{cell}, "location", @var{pos})
 ## @deftypefnx {Function File} {} legend ('@var{func}')
 ##
 ## Display a legend for the current axes using the specified strings
@@ -36,19 +36,26 @@
 ## The optional parameter @var{pos} specifies the location of the legend
 ## as follows:
 ##
-## @multitable @columnfractions 0.1 0.1 0.8
-## @item @tab -1 @tab
-##   To the top right of the plot
-## @item @tab 0 @tab
-##   Don't move the legend box (default)
-## @item @tab 1 @tab
-##   Upper right-hand corner
-## @item @tab 2 @tab
-##   Upper left-hand corner
-## @item @tab 3 @tab
-##   Lower left-hand corner
-## @item @tab 4 @tab
-##   Lower right-hand corner
+## @multitable @columnfractions 0.06 0.14 0.80
+## @item @tab north @tab
+##   center top
+## @item @tab south @tab
+##   center bottom
+## @item @tab east @tab
+##   right center
+## @item @tab west @tab
+##   left center
+## @item @tab northeast @tab
+##   right top (default)
+## @item @tab northwest @tab
+##   left top
+## @item @tab southeast @tab
+##   right bottom
+## @item @tab southwest @tab
+##   left bottom
+## @item 
+## @item @tab outside @tab
+##   can be appended to any location string
 ## @end multitable
 ##
 ## Some specific functions are directely avaliable using @var{func}:
@@ -89,6 +96,14 @@
       endif
     endif
   endif
+  
+  if (nargs > 1)
+    pos = varargin{nargs-1};
+    if (strcmpi (pos, "location")  && ischar (str))
+      set (ca, "keypos", str);
+      nargs -= 2;
+    endif
+  endif
 
   kids = get (ca, "children");
   nkids = numel (kids);
@@ -183,7 +198,7 @@
 %! close all;
 %! plot(1:10, 1:10);
 %! title("a very long label can sometimes cause problems");
-%! legend({"hello world"}, -1)
+%! legend({"hello world"}, "location", "northeastoutside")
 
 %!demo
 %! close all;
@@ -194,5 +209,5 @@
 %! endfor; hold off;
 %! title("Signals with random offset and uniform noise")
 %! xlabel("Sample Nr [k]"); ylabel("Amplitude [V]");
-%! legend(labels, -1)
+%! legend(labels, "location", "southoutside")
 %! legend("boxon")