changeset 26239:64061eace057

legend.m: Implement "bestoutside" location. * legend.m: Use strcmp rather than switch statement to validate orientation. For "bestoutside" choose "northeastoutside" if orientation is vertical and "southoutside" if orientation is horizontal.
author Rik <rik@octave.org>
date Fri, 14 Dec 2018 15:38:24 -0800
parents 71d618146e4c
children a957e0da8613
files scripts/plot/appearance/legend.m
diffstat 1 files changed, 17 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/appearance/legend.m	Fri Dec 14 13:39:15 2018 -0800
+++ b/scripts/plot/appearance/legend.m	Fri Dec 14 15:38:24 2018 -0800
@@ -237,12 +237,9 @@
   endwhile
 
   ## Validate the orientation
-  switch (orientation)
-    case {"vertical", "horizontal", "default"}
-      ## These are all accepted orientations.
-    otherwise
-      error ("legend: unrecognized legend orientation");
-  endswitch
+  if (! any (strcmp (orientation, {"vertical", "horizontal", "default"})))
+    error ("legend: unrecognized legend orientation");
+  endif
 
   ## Validate the location type
   outside = false;
@@ -257,11 +254,23 @@
   switch (location)
     case {"north", "south", "east", "west", "northeast", "northwest", ...
           "southeast", "southwest", "default"}
+      ## These are all valid locations, do nothing.
+
     case "best"
-      warning ("legend: 'best' not yet implemented for location specifier\n");
-      location = "northeast";
+      if (outside)
+        if (strcmp (orientation, "horizontal"))
+          location = "south";
+        else
+          location = "northeast";
+        endif
+      else
+        warning ("legend: 'best' not yet implemented for location specifier, using 'northeast' instead\n");
+        location = "northeast";
+      endif
+
     case "none"
       ## FIXME: Should there be any more error checking on this?
+
     otherwise
       error ("legend: unrecognized legend location");
   endswitch