Mercurial > octave
changeset 29146:3000414c60eb
Return patch objects for bar,barh rather than hggroups when 'hist' is given (bug #59589).
* bar.m, barh.m: Reverse order of first two arguments to match new __bar__
prototype.
* __bar__.m: Reverse first two arguments of function and have the calling
function's name be the first argument and whether it is vertical/horizontal
as the second. When returning patch objects, set CLIMMODE property to "auto".
When returning bar objects, set XLIMMODE property to "manual".
* __bar__.m (bars): Add new parameter "ishist" to function prototype.
Add new if clause which checks "ishist" and constructs patch objects for the
bars and then returns immediately.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 04 Dec 2020 15:47:48 -0800 |
parents | 1024bc946c95 |
children | d9ac99164c18 |
files | scripts/plot/draw/bar.m scripts/plot/draw/barh.m scripts/plot/draw/private/__bar__.m |
diffstat | 3 files changed, 40 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/draw/bar.m Sun Nov 29 18:02:37 2020 +0100 +++ b/scripts/plot/draw/bar.m Fri Dec 04 15:47:48 2020 -0800 @@ -114,7 +114,7 @@ function varargout = bar (varargin) varargout = cell (nargout, 1); - [varargout{:}] = __bar__ (true, "bar", varargin{:}); + [varargout{:}] = __bar__ ("bar", true, varargin{:}); endfunction %!demo
--- a/scripts/plot/draw/barh.m Sun Nov 29 18:02:37 2020 +0100 +++ b/scripts/plot/draw/barh.m Fri Dec 04 15:47:48 2020 -0800 @@ -78,7 +78,7 @@ function varargout = barh (varargin) varargout = cell (nargout, 1); - [varargout{:}] = __bar__ (false, "barh", varargin{:}); + [varargout{:}] = __bar__ ("barh", false, varargin{:}); endfunction
--- a/scripts/plot/draw/private/__bar__.m Sun Nov 29 18:02:37 2020 +0100 +++ b/scripts/plot/draw/private/__bar__.m Fri Dec 04 15:47:48 2020 -0800 @@ -28,7 +28,7 @@ ## Undocumented internal function. ## @end deftypefn -function varargout = __bar__ (vertical, func, varargin) +function varargout = __bar__ (func, vertical, varargin) [hax, varargin, nargin] = __plt_get_axis_arg__ (func, varargin{:}); @@ -224,8 +224,8 @@ unwind_protect hax = newplot (hax); - htmp = bars (hax, vertical, x, y, xb, yb, gwidth, group, - have_line_spec | ishist, bv, newargs{:}); + htmp = bars (hax, ishist, vertical, x, y, xb, yb, gwidth, group, + have_line_spec, bv, newargs{:}); if (! ishold ()) if (numel (x(:,1)) <= 15 && all (x(:,1) == fix (x(:,1)))) @@ -237,13 +237,17 @@ set (hax, "ytick", x(:,1)); endif endif - ## Hack prevents color and xlim setting changes when basevalue changes. - if (vertical) - set (hax, "clim", [0 1], "xlimmode", "manual"); + if (ishist) + set (hax, "climmode", "auto"); else - set (hax, "clim", [0 1], "ylimmode", "manual"); + ## Hack prevents xlim setting changes when basevalue changes. + if (vertical) + set (hax, "xlimmode", "manual"); + else + set (hax, "ylimmode", "manual"); + endif endif - set (hax, "box", "on", "layer", "top", "climmode", "auto"); + set (hax, "box", "on", "layer", "top"); endif unwind_protect_cleanup if (! isempty (oldfig)) @@ -265,12 +269,35 @@ endfunction -function hglist = bars (hax, vertical, x, y, xb, yb, width, group, have_color_spec, base_value, varargin) +function hglist = bars (hax, ishist, vertical, x, y, xb, yb, width, group, have_color_spec, base_value, varargin) + hglist = []; nbars = columns (y); - clim = get (hax, "clim"); - hglist = []; + + if (ishist) + ## Special case for Matlab compatibility. For 'hist', 'histc' arguments, + ## return Patch objects rather than hggroup Bar object. + for i = 1:nbars + if (vertical) + h = patch (hax, xb(:,:,i), yb(:,:,i), + "cdata", i*ones (columns (xb),1), "FaceColor", "flat"); + else + h = patch (hax, yb(:,:,i), xb(:,:,i), + "cdata", i*ones (columns (yb),1), "FaceColor", "flat"); + endif + + if (! isempty (varargin)) + set (h, varargin{:}); + endif + + hglist = [hglist; h]; + endfor + + return; # return immediately, rest of function is for creating Bar object. + endif + + ## Code to create hggroup Bar object for i = 1:nbars hg = hggroup (); hglist = [hglist; hg];