Mercurial > octave
changeset 27793:507d2e0fcb43
legend.m: Improve hggroup icons (bug #57388)
* legend.m (create_icon): Invert children for __contour__ plots so that they
are displayed in consistent order. For __errplot__ plots store the format in
the icon's appdata.
(update_icon_position): For __errplot__ draw horizontal, vertical or both
segments depending on the format. For __contour__ make the inner patch 40% as
high as the outer one rather than 60%. For __stem__ draw the marker at the
right of the line.
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Tue, 10 Dec 2019 11:38:55 +0100 |
parents | d68ae60f1557 |
children | 45ad2127582b |
files | scripts/plot/appearance/legend.m |
diffstat | 1 files changed, 32 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/appearance/legend.m Mon Dec 09 19:18:41 2019 +0100 +++ b/scripts/plot/appearance/legend.m Tue Dec 10 11:38:55 2019 +0100 @@ -475,7 +475,7 @@ pos = get (h, "position"); set (h, "units", units); old_pos = getappdata (hl, "__peer_axes_position__"); - + if (! all (pos == old_pos)) update_layout_cb (hl); setappdata (hl, "__peer_axes_position__", pos); @@ -919,7 +919,7 @@ typ = creator; switch (creator) case "__contour__" - hplt = [kids(1), kids(end)]; + hplt = [kids(end), kids(1)]; case {"__errplot__", "__quiver__", "__stem__"} hplt = kids(2:-1:1); otherwise @@ -945,6 +945,7 @@ "linestyle", "linewidth", ... "marker", "markeredgecolor", ... "markerfacecolor", "markersize"}; + switch (typ) case {"line", "__errplot__", "__quiver__", "__stem__"} @@ -971,6 +972,12 @@ addlistener (hmarker, "markersize", @update_marker_cb); add_safe_listener (hl, hplt(1), "beingdeleted", @() delete ([hicon hmarker])) + if (! strcmp (typ, "__errplot__")) + setappdata (hicon, "__creator__", typ); + else + setappdata (hicon, "__creator__", typ, ... + "__format__", get (base_hplt, "format")); + endif case {"patch", "surface", "__scatter__"} @@ -979,6 +986,7 @@ hicon = __go_patch__ (hl, [pprops; vals]{:}); setappdata (hplt, "__icon_link__", linkprop ([hplt, hicon], pprops)); + setappdata (hicon, "__creator__", typ); case "__contour__" @@ -1006,13 +1014,14 @@ add_safe_listener (hl, hplt(1), "beingdeleted", @() delete ([hicon htmp])) + setappdata (hicon, "__creator__", typ); + endswitch htxt = __go_text__ (hl, "string", str, txtpval{:}); addproperty ("peer_object", htxt, "double", base_hplt); addproperty ("peer_object", hicon, "double", base_hplt); - setappdata (hicon, "__creator__", typ); endfunction @@ -1207,7 +1216,7 @@ function update_icon_position (hicon, xdata, ydata) creator = getappdata (hicon, "__creator__"); switch (creator) - case {"line", "__stem__"} + case "line" set (hicon, "markerxdata", mean (xdata), "markerydata", mean (ydata), ... "xdata", xdata, "ydata", [mean(ydata), mean(ydata)]); case {"patch", "surface"} @@ -1227,10 +1236,9 @@ ydata = [y0, y0, y1, y1]; set (hicon, ... "innerxdata", (xdata-xm) * 0.6 + xm, ... - "innerydata", (ydata-ym) * 0.6 + ym, ... + "innerydata", (ydata-ym) * 0.4 + ym, ... "xdata", xdata, "ydata", ydata); case "__errplot__" - ## Draw a double arrow x0 = xdata(1); x1 = xdata(2); xm = mean (xdata); @@ -1238,12 +1246,22 @@ y1 = ydata(2); ym = mean (ydata); - xdata = [x0, x0, x0, x1, x1, x1, x1, ... - xm, xm, xm-2, xm+2, xm, xm, xm-2, xm+2]; - ydata = [ym+2, ym-2, ym, ym, ym+2, ym-2, ym, ... - ym, y0, y0, y0, y0, y1, y1, y1]; + fmt = getappdata (hicon, "__format__"); + if (strcmp (fmt, "yerr")) + xdata = [xm, xm, xm-2, xm+2, xm, xm, xm-2, xm+2]; + ydata = [ym, y0, y0, y0, y0, y1, y1, y1]; + elseif (strcmp (fmt, "xerr")) + xdata = [x0+2, x0+2, x0+2, x1-2, x1-2, x1-2, x1-2]; + ydata = [ym+2, ym-2, ym, ym, ym+2, ym-2, ym]; + else # "both" + xdata = [x0+2, x0+2, x0+2, x1-2, x1-2, x1-2, x1-2, ... + xm, xm, xm-2, xm+2, xm, xm, xm-2, xm+2]; + ydata = [ym+2, ym-2, ym, ym, ym+2, ym-2, ym, ... + ym, y0, y0, y0, y0, y1, y1, y1]; + endif set (hicon, "markerxdata", xm, "markerydata", ym, ... "xdata", xdata, "ydata", ydata); + case "__quiver__" ## Draw an arrow x0 = xdata(1); @@ -1255,6 +1273,10 @@ "xdata", xdata, "ydata", ydata); case "__scatter__" set (hicon, "xdata", mean(xdata), "ydata", mean(ydata)); + case "__stem__" + xdata(2) -= (get (get (hicon, "peer_object"), "markersize") / 2); + set (hicon, "markerxdata", xdata(2), "markerydata", mean (ydata), ... + "xdata", xdata, "ydata", [mean(ydata), mean(ydata)]); endswitch endfunction