# HG changeset patch # User Ben Abbott # Date 1322872962 18000 # Node ID f35b593688a5eeb47e80afa1aaf2d2cdab56a088 # Parent a33ec41d0340951c631c2818a91d195f50e7fa9b Changing the legend's interpreter property should be inherited by the legend's labels (Fix bug #34342). * scripts/plot/__go_draw_axes__.m: Add no_tex() to escape "_" & "^". * scripts/plot/legend.m: Fix the text labels updater. Warn if extra entries are present. Add demos and fix others. diff --git a/scripts/plot/legend.m b/scripts/plot/legend.m --- a/scripts/plot/legend.m +++ b/scripts/plot/legend.m @@ -378,13 +378,15 @@ break; endif elseif (! warned) - warned = true; - warning ("legend: ignoring extra labels"); + break; endif else error ("legend: expecting argument to be a character string"); endif endfor + if (i < nargs && ! warned) + warning ("legend: ignoring extra labels"); + endif else k = nkids; while (k > 0) @@ -816,22 +818,14 @@ endfunction function updatelegendtext (h, d) + hax = get (h, "userdata").handle; kids = get (h, "children"); - k = numel (kids); - in = get (h, "interpreter"); - tc = get (h, "textcolor"); - while (k > 0) - typ = get (kids(k), "type"); - while (k > 0 && ! strcmp (typ, "text")) - typ = get (kids(--k), "type"); - endwhile - if (k > 0) - set (kids (k), "interpreter", in, "color", tc); - if (--k == 0) - break; - endif - endif - endwhile + text_kids = findobj (kids, "-property", "interpreter", "type", "text"); + interpreter = get (h, "interpreter"); + textcolor = get (h, "textcolor"); + set (kids, "interpreter", interpreter, "color", textcolor); + hobj = cell2mat (get (kids, "userdata")); + set (hobj, "interpreter", interpreter); endfunction function hideshowlegend (h, d, ca, pos1, pos2) @@ -1134,21 +1128,34 @@ %!demo %! clf -%! x = 0:4; +%! x = 1:5; %! subplot (2, 2, 1) %! plot (x, rand (numel (x))); -%! legend (cellstr (num2str ((1:10)')), "location", "northwestoutside") +%! legend (cellstr (num2str (x')), "location", "northwestoutside") %! legend boxon %! subplot (2, 2, 2) %! plot (x, rand (numel (x))); -%! legend (cellstr (num2str ((1:10)')), "location", "northeastoutside") +%! legend (cellstr (num2str (x')), "location", "northeastoutside") %! legend boxon %! subplot (2, 2, 3); %! plot (x, rand (numel (x))); -%! legend (cellstr (num2str ((1:10)')), "location", "southwestoutside") +%! legend (cellstr (num2str (x')), "location", "southwestoutside") %! legend boxon %! subplot (2, 2, 4) %! plot (x, rand (numel (x))); -%! legend (cellstr (num2str ((1:10)')), "location", "southeastoutside") +%! legend (cellstr (num2str (x')), "location", "southeastoutside") %! legend boxon +%!demo +%! clf +%! plot (rand (2)) +%! title ("Warn of extra labels") +%! legend ("Hello", "World", "interpreter", "foobar") + +%!demo +%! clf +%! plot (rand (2)) +%! title ("Turn off TeX interpreter") +%! h = legend ("Hello_World", "foo^bar"); +%! set (h, "interpreter", "none") + diff --git a/scripts/plot/private/__go_draw_axes__.m b/scripts/plot/private/__go_draw_axes__.m --- a/scripts/plot/private/__go_draw_axes__.m +++ b/scripts/plot/private/__go_draw_axes__.m @@ -441,6 +441,7 @@ while (! isempty (kids)) obj = get (kids(end)); + if (isfield (obj, "units")) units = obj.units; unwind_protect @@ -2302,10 +2303,38 @@ warning ("latex markup not supported for text objects"); warned_latex = true; endif + elseif (enhanced) + str = no_super_sub_scripts (str); endif endif endfunction +function str = no_super_sub_scripts (str) + if (iscellstr (str)) + labels = str; + else + labels = cellstr (str); + endif + for marker = "_^" + for m = 1 : numel(labels) + n1 = strfind (labels{m}, sprintf ("\\%s", marker)); + n2 = strfind (labels{m}, marker); + if (! isempty (n1)) + n1 = n1 + 1; + n2 = setdiff (n2, n1); + end + for n = n2 + labels{m} = [labels{m}(1:n2-1), "\\", labels{m}(n2:end)]; + endfor + endfor + endfor + if (iscellstr (str)) + str = labels; + else + str = char (labels); + endif +endfunction + function str = __tex2enhanced__ (str, fnt, it, bld) persistent sym = __setup_sym_table__ (); persistent flds = fieldnames (sym);