Mercurial > octave
changeset 24502:b480fe1089bb
colorbar.m: Correctly handle changes to colormap of figure or axes.
* colorbar.m: Copy over "colormap" from axes when creating new colorbar.
Change cb_colormap call to match new function prototype.
* colorbar.m (cb_colormap): Change prototype to also include handle to
axes. When colormap changes, copy it to colorbar axes. Call cb_clim()
with axes handle to update limits.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 03 Jan 2018 17:43:07 -0800 |
parents | 2f10c3265607 |
children | 9c178e5252e4 |
files | scripts/plot/draw/colorbar.m |
diffstat | 1 files changed, 10 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/draw/colorbar.m Thu Jan 04 00:42:32 2018 +0100 +++ b/scripts/plot/draw/colorbar.m Wed Jan 03 17:43:07 2018 -0800 @@ -249,7 +249,8 @@ props.__axes_handle__ = hax; position = props.position; - clen = rows (get (hax, "colormap")); + cmap = get (hax, "colormap"); + clen = rows (cmap); cext = get (hax, "clim"); cdiff = (cext(2) - cext(1)) / clen / 2; cmin = cext(1) + cdiff; @@ -269,6 +270,7 @@ if (new_colorbar) hcb = axes ("parent", hpar, "tag", "colorbar", "activepositionproperty", "position", "position", cbpos, + "colormap", cmap, "box", "on", "xdir", "normal", "ydir", "normal"); addproperty ("axislocation", hcb, "radio", "{out}|in"); @@ -353,10 +355,9 @@ if (strcmp (get (hpar, "type"), "figure")) addlistener (hpar, "colormap", {@cb_colormap, ... - hcb, hi, clen}); + hax, hcb, hi, clen}); endif - ## FIXME: listener on axes colormap does not work yet. - addlistener (hax, "colormap", {@cb_colormap, hcb, hi, clen}); + addlistener (hax, "colormap", {@cb_colormap, hax, hcb, hi, clen}); addlistener (hax, "clim", {@cb_clim, hcb, hi}); addlistener (hax, "dataaspectratio", {@cb_colorbar_axis, hcb, props}); addlistener (hax, "dataaspectratiomode", {@cb_colorbar_axis, ... @@ -461,11 +462,13 @@ endfunction ## Update colorbar when changes to axes or figure colormap have occurred. -function cb_colormap (h, d, hcb, hi, init_sz) +function cb_colormap (h, d, hax, hcb, hi, init_sz) persistent sz = init_sz; if (ishghandle (h)) - clen = rows (get (h, "colormap")); + cmap = get (h, "colormap"); + set (hcb, "colormap", cmap); + clen = rows (cmap); if (clen != sz) if (strcmp (get (hcb, "__vertical__"), "on")) set (hi, "cdata", [1:clen]'); @@ -474,7 +477,7 @@ endif sz = clen; ## Also update limits on colorbar axes or there will be white gaps - cb_clim (hcb, d, hcb, hi); + cb_clim (hax, d, hcb, hi); endif endif