comparison scripts/plot/appearance/legend.m @ 18422:be3702a2eb8a

legend.m: use linewidth from plot object in drawing legend (bug #41283) * legend.m: When creating line object in legend, copy linewidth from plot object. Restrict legend linewidth to a maximum of 5 to prevent overflowing visual area. Add listener for linewidth on plot objects which updates legend.
author Joachim Wiesemann <gnu@jwiesemann.com>
date Tue, 14 Jan 2014 15:32:10 +0100
parents 1d109119ac71
children 1597281144e4
comparison
equal deleted inserted replaced
18421:7c0db9c4e454 18422:be3702a2eb8a
827 switch (get (hplots(k), "type")) 827 switch (get (hplots(k), "type"))
828 828
829 case "line" 829 case "line"
830 color = get (hplots(k), "color"); 830 color = get (hplots(k), "color");
831 style = get (hplots(k), "linestyle"); 831 style = get (hplots(k), "linestyle");
832 lwidth = min (get (hplots(k), "linewidth"), 5);
832 if (! strcmp (style, "none")) 833 if (! strcmp (style, "none"))
833 l1 = line ("xdata", ([xoffset, xoffset + linelength] + xk * xstep) / lpos(3), 834 l1 = line ("xdata", ([xoffset, xoffset + linelength] + xk * xstep) / lpos(3),
834 "ydata", [1, 1] .* (lpos(4) - yoffset - yk * ystep) / lpos(4), 835 "ydata", [1, 1] .* (lpos(4) - yoffset - yk * ystep) / lpos(4),
835 "color", color, "linestyle", style, 836 "color", color, "linestyle", style, "linewidth", lwidth,
836 "marker", "none", 837 "marker", "none",
837 "userdata", hplots(k)); 838 "userdata", hplots(k));
838 hobjects(end+1) = l1; 839 hobjects(end+1) = l1;
839 endif 840 endif
840 marker = get (hplots(k), "marker"); 841 marker = get (hplots(k), "marker");
841 if (! strcmp (marker, "none")) 842 if (! strcmp (marker, "none"))
842 l1 = line ("xdata", (xoffset + 0.5 * linelength + xk * xstep) / lpos(3), 843 l1 = line ("xdata", (xoffset + 0.5 * linelength + xk * xstep) / lpos(3),
843 "ydata", (lpos(4) - yoffset - yk * ystep) / lpos(4), 844 "ydata", (lpos(4) - yoffset - yk * ystep) / lpos(4),
844 "color", color, "linestyle", "none", 845 "color", color, "linestyle", "none", "linewidth", lwidth,
845 "marker", marker, 846 "marker", marker,
846 "markeredgecolor",get (hplots(k), "markeredgecolor"), 847 "markeredgecolor",get (hplots(k), "markeredgecolor"),
847 "markerfacecolor",get (hplots(k), "markerfacecolor"), 848 "markerfacecolor",get (hplots(k), "markerfacecolor"),
848 "markersize", get (hplots(k), "markersize"), 849 "markersize", get (hplots(k), "markersize"),
849 "userdata", hplots(k)); 850 "userdata", hplots(k));
852 853
853 if (addprops) 854 if (addprops)
854 addlistener (hplots(k), "color", 855 addlistener (hplots(k), "color",
855 {@updateline, hlegend, linelength, false}); 856 {@updateline, hlegend, linelength, false});
856 addlistener (hplots(k), "linestyle", 857 addlistener (hplots(k), "linestyle",
858 {@updateline, hlegend, linelength, false});
859 addlistener (hplots(k), "linewidth",
857 {@updateline, hlegend, linelength, false}); 860 {@updateline, hlegend, linelength, false});
858 addlistener (hplots(k), "marker", 861 addlistener (hplots(k), "marker",
859 {@updateline, hlegend, linelength, false}); 862 {@updateline, hlegend, linelength, false});
860 addlistener (hplots(k), "markeredgecolor", 863 addlistener (hplots(k), "markeredgecolor",
861 {@updateline, hlegend, linelength, false}); 864 {@updateline, hlegend, linelength, false});
1147 delete (t1); 1150 delete (t1);
1148 for i = 1 : numel (hplots) 1151 for i = 1 : numel (hplots)
1149 if (ishandle (hplots(i)) && strcmp (get (hplots(i), "type"), "line")) 1152 if (ishandle (hplots(i)) && strcmp (get (hplots(i), "type"), "line"))
1150 dellistener (hplots(i), "color"); 1153 dellistener (hplots(i), "color");
1151 dellistener (hplots(i), "linestyle"); 1154 dellistener (hplots(i), "linestyle");
1155 dellistener (hplots(i), "linewidth");
1152 dellistener (hplots(i), "marker"); 1156 dellistener (hplots(i), "marker");
1153 dellistener (hplots(i), "markeredgecolor"); 1157 dellistener (hplots(i), "markeredgecolor");
1154 dellistener (hplots(i), "markerfacecolor"); 1158 dellistener (hplots(i), "markerfacecolor");
1155 dellistener (hplots(i), "markersize"); 1159 dellistener (hplots(i), "markersize");
1156 dellistener (hplots(i), "displayname"); 1160 dellistener (hplots(i), "displayname");
1196 delete (lm); 1200 delete (lm);
1197 endif 1201 endif
1198 1202
1199 if (! strcmp (linestyle, "none")) 1203 if (! strcmp (linestyle, "none"))
1200 line ("xdata", xpos1, "ydata", ypos1, "color", get (h, "color"), 1204 line ("xdata", xpos1, "ydata", ypos1, "color", get (h, "color"),
1201 "linestyle", get (h, "linestyle"), "marker", "none", 1205 "linestyle", get (h, "linestyle"),
1206 "linewidth", min (get (h, "linewidth"), 5),
1207 "marker", "none",
1202 "userdata", h, "parent", hlegend); 1208 "userdata", h, "parent", hlegend);
1203 endif 1209 endif
1204 if (! strcmp (marker, "none")) 1210 if (! strcmp (marker, "none"))
1205 line ("xdata", xpos2, "ydata", ypos2, "color", get (h, "color"), 1211 line ("xdata", xpos2, "ydata", ypos2, "color", get (h, "color"),
1206 "marker", marker, "markeredgecolor", get (h, "markeredgecolor"), 1212 "marker", marker, "markeredgecolor", get (h, "markeredgecolor"),
1207 "markerfacecolor", get (h, "markerfacecolor"), 1213 "markerfacecolor", get (h, "markerfacecolor"),
1208 "markersize", get (h, "markersize"), "linestyle", "none", 1214 "markersize", get (h, "markersize"),
1215 "linestyle", "none",
1216 "linewidth", min (get (h, "linewidth"), 5),
1209 "userdata", h, "parent", hlegend); 1217 "userdata", h, "parent", hlegend);
1210 endif 1218 endif
1211 endif 1219 endif
1212 endfunction 1220 endfunction
1213 1221