changeset 27714:a984e6722601

legend.m: better vertical alignment for horizontal orientation (bug #57264) * legend.m (textitem_data): For horizontal alignment, precompute the baseline for each row. Fix index typos.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Tue, 19 Nov 2019 11:16:22 +0100
parents e297d20e2d4f
children 95cc1f535ba8
files scripts/plot/appearance/legend.m
diffstat 1 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/appearance/legend.m	Mon Nov 18 23:50:25 2019 +0100
+++ b/scripts/plot/appearance/legend.m	Tue Nov 19 11:16:22 2019 +0100
@@ -1018,7 +1018,7 @@
         endif
 
         y0 = y1 = y + hg/2;
-        if (! strcmp (types{jj}, "line"))
+        if (! strcmp (types{iter}, "line"))
           y0 = y + dx;
           y1 = y + hg - dx;
         endif
@@ -1061,6 +1061,10 @@
     y = vmargin;
     for ii = 1:nrow
       x = hmargin;
+
+      endidx = min (iter+ncol-1, nitem);
+      hg = max (ext(iter:endidx,2));
+
       for jj = 1:ncol
         if (iter > nitem)
           continue;
@@ -1069,13 +1073,13 @@
         wd = colwidth(jj);
 
         dx = 0;
-        if (! strcmp (markers, "none"))
+        if (! strcmp (markers{iter}, "none"))
           dx = markersz{iter}/2;
         endif
 
-        ybase = y + ext(iter,2) / 2;
+        ybase = y + hg / 2;
         y0 = y1 = ybase;
-        if (! strcmp (types{jj}, "line"))
+        if (! strcmp (types{iter}, "line"))
           y0 = y + dx;
           y1 = y + hg - dx;
         endif
@@ -1085,7 +1089,7 @@
         ## [x, y, z]
         txtdata(iter,:) = [x+item_width+hmargin, ybase, 0];
 
-        ymax = max ([ymax, ybase+ext(iter,2)/2+vmargin]);
+        ymax = max ([ymax, ybase+hg/2+vmargin]);
         x += (3*hmargin + item_width + wd);
         iter++;
       endfor