Mercurial > octave
changeset 26832:ca40628fff39
legend.m: Update legend when target axes colormap changes (bug #54757).
* legend.m: When creating legend axes object, inherit colormap from target axes
if it is not the default colormap from the figure. Add listener on target axes
colormap property that calls cb_legend_colormap_update().
* legend.m (cb_legend_colormap_update): New function that copies colormap from
target axes to legend axes object.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 03 Mar 2019 17:15:22 -0800 |
parents | e255897f353d |
children | 10c9f39d0d17 |
files | scripts/plot/appearance/legend.m |
diffstat | 1 files changed, 11 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/appearance/legend.m Sun Mar 03 23:05:23 2019 +0100 +++ b/scripts/plot/appearance/legend.m Sun Mar 03 17:15:22 2019 -0800 @@ -610,6 +610,11 @@ fontsz *= 0.90; # Reduce legend fontsize to 90% of axes fontsize set (hlegend, {"fontunits", "fontsize"}, {fontunits, fontsz}); set (hlegend, "fontunits", "points"); # legend always works in pts. + ## Also inherit colormap from axes if it is different than figure + cax_cmap = get (cax, "colormap"); + if (! isequal (cax_cmap, get (hpar, "colormap"))) + set (hlegend, "colormap", cax_cmap); + endif old_hplots = []; else ## Re-use existing legend. @@ -1067,6 +1072,7 @@ endif if (addprops) + addlistener (cax, "colormap", {@cb_legend_colormap_update, hlegend}); addlistener (hlegend, "edgecolor", @cb_legend_text_update); addlistener (hlegend, "fontangle", @cb_legend_text_update); addlistener (hlegend, "fontname", @cb_legend_text_update); @@ -1122,6 +1128,11 @@ endfunction +## Colormap of the base axes has changed. +function cb_legend_colormap_update (cax, ~, hlegend) + set (hlegend, "colormap", get (cax, "colormap")); +endfunction + ## A non-text property of legend has changed requiring an update. function cb_legend_update (hleg, ~) persistent recursive = false;