changeset 27723:a0143104b224

legend.m: fix icon height for patch and surface objects (bug #57269) * legend.m (textitem_data): Fix icon height for patch and surface objects.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Tue, 19 Nov 2019 22:53:09 +0100
parents 62a57f086bf9
children 19e80f22aa47
files scripts/plot/appearance/legend.m
diffstat 1 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/appearance/legend.m	Tue Nov 19 18:29:25 2019 +0100
+++ b/scripts/plot/appearance/legend.m	Tue Nov 19 22:53:09 2019 +0100
@@ -965,6 +965,7 @@
   persistent hmargin = 3;
   persistent vmargin = 3;
   persistent item_width = 15;
+  persistent item_height = 7;
 
   ext = get (objlist(:,1), "extent");
   markers = get (objlist(:,2), "marker");
@@ -1022,7 +1023,8 @@
       nrow = ceil (nitem / ncol);
     endif
 
-    rowheights = arrayfun (@(idx) max(ext(idx:nrow:end, 2)), 1:nrow);
+    rowheights = arrayfun (@(idx) max([item_height; ext(idx:nrow:end, 2)]), ...
+                           1:nrow);
     x = hmargin;
     for ii = 1:ncol
       y = vmargin;
@@ -1039,8 +1041,8 @@
 
         y0 = y1 = y + hg/2;
         if (! strcmp (types{iter}, "line"))
-          y0 = y + dx;
-          y1 = y + hg - dx;
+          y0 = y + hg/2 - item_height/2 + dx;
+          y1 = y + hg/2 + item_height/2 - dx;
         endif
 
         ## [x0, x1, y0, y1]
@@ -1083,7 +1085,7 @@
       x = hmargin;
 
       endidx = min (iter+ncol-1, nitem);
-      hg = max (ext(iter:endidx,2));
+      hg = max ([item_height; ext(iter:endidx,2)]);
 
       for jj = 1:ncol
         if (iter > nitem)
@@ -1100,8 +1102,8 @@
         ybase = y + hg / 2;
         y0 = y1 = ybase;
         if (! strcmp (types{iter}, "line"))
-          y0 = y + dx;
-          y1 = y + hg - dx;
+          y0 = y + hg/2 - item_height/2 + dx;
+          y1 = y + hg/2 + item_height/2 - dx;
         endif
 
         ## [x0, x1, y0, y1]