changeset 17534:ec105d91547e

legend.m: Inherit font properties from current axes. Default interpreter to 'tex'. * scripts/plot/legend.m: Legend object now inherits font properties from axis. Text labels, in turn, inherit from legend object. The default interpreter is now 'tex' which matches the default for text objects.
author Rik <rik@octave.org>
date Tue, 01 Oct 2013 17:06:28 -0700
parents bb7756dff055
children 5eae41c8c07f
files scripts/plot/legend.m
diffstat 1 files changed, 23 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/legend.m	Tue Oct 01 16:28:25 2013 -0700
+++ b/scripts/plot/legend.m	Tue Oct 01 17:06:28 2013 -0700
@@ -544,7 +544,7 @@
       ## Get axis size and fontsize in points.
       ## Rely on listener to handle coversion.
       units = get (ca(1), "units");
-      fontunits = get (ca(1), "fontunits");
+      #fontunits = get (ca(1), "fontunits");
       unwind_protect
         set (ca(1), "units", "points");
         set (ca(1), "fontunits", "points");
@@ -558,14 +558,14 @@
         endif
         ca_pos = unmodified_axes_position;
         ca_outpos = unmodified_axes_outerposition;
-        ca_fontsize = get (ca(1), "fontsize");
+      #  ca_fontsize = get (ca(1), "fontsize");
         tightinset = get (ca(1), "tightinset");
         for i = 2 : numel (ca)
           tightinset = max (tightinset, get (ca(i), "tightinset"));
         endfor
       unwind_protect_cleanup
         set (ca(1), "units", units);
-        set (ca(1), "fontunits", fontunits);
+      #  set (ca(1), "fontunits", fontunits);
       end_unwind_protect
 
       ## Padding between legend entries horizontally and vertically
@@ -575,7 +575,6 @@
       linelength = 15;
 
       ## Create the axis first
-      ## FIXME: hlegend should inherit properties from "ca"
       curaxes = get (fig, "currentaxes");
       unwind_protect
         ud = ancestor (hplots, "axes");
@@ -590,7 +589,12 @@
                           "xlim", [0, 1], "ylim", [0, 1],
                           "visible", ifelse (strcmp (box, "on"), "on", "off"),
                           "activepositionproperty", "position",
-                          "fontsize", ca_fontsize);
+                          "interpreter", "tex");
+          ## Inherit properties from current axis
+          ## "fontunits" shoud be first because it affects interpretation of "fontsize"
+          proplist = {"fontunits", "fontangle", "fontname", "fontsize", "fontweight"};
+          ca_props = get (ca(1), proplist); 
+          set (hlegend, proplist, ca_props);
         else
           addprops = false;
           axes (hlegend);
@@ -611,7 +615,12 @@
           addproperty ("string", hlegend, "any", text_strings);
           addproperty ("textposition", hlegend, "radio", "{left}|right");
         endif
+        ## Inherit visual properties from legend object
+        fontunits = get (hlegend, "fontunits");
+        fontangle = get (hlegend, "fontangle");
+        fontname = get (hlegend, "fontname");
         fontsize = get (hlegend, "fontsize");
+        fontweight = get (hlegend, "fontweight");
         interpreter = get (hlegend, "interpreter");
         textcolor = get (hlegend, "textcolor");
         ## Add text label to the axis first, checking their extents
@@ -622,11 +631,15 @@
         for k = 1 : nentries
           halign = ifelse (strcmp (textpos, "right"), "left", "right");
           texthandle = [texthandle, text(0, 0, text_strings{k},
-                                         "userdata", hplots(k),
-                                         "color", textcolor,
-                                         "horizontalalignment", halign,
-                                         "interpreter", interpreter,
-                                         "fontsize", fontsize)];
+                                               "userdata", hplots(k),
+                                               "color", textcolor,
+                                               "horizontalalignment", halign,
+                                               "interpreter", interpreter,
+                                               "fontunits", fontunits,
+                                               "fontangle", fontangle,
+                                               "fontname", fontname,
+                                               "fontsize", fontsize,
+                                               "fontweight", fontweight)];,
           units = get (texthandle(end), "units");
           unwind_protect
             set (texthandle(end), "units", "points");
@@ -1023,7 +1036,6 @@
 endfunction
 
 function updatelegendtext (h, ~)
-#  keyboard;
   htext = findobj (get (h, "children"), "type", "text");
 
   tprops = {"interpreter", "fontunits", "fontangle", "fontname", "fontsize",...