6540
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
|
19 |
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} __bar__ (@dots{}) |
6633
|
22 ## Support function for @code{bar} and @code{hbar}. |
6540
|
23 ## @seealso{bar, hbar} |
|
24 ## @end deftypefn |
|
25 |
|
26 ## Author: jwe |
|
27 |
|
28 function varargout = __bar__ (vertical, func, varargin) |
6886
|
29 |
6540
|
30 width = 0.8; |
|
31 group = true; |
|
32 |
|
33 if (nargin < 3) |
6886
|
34 print_usage (); |
6540
|
35 endif |
|
36 |
6886
|
37 if (nargin > 3 && isnumeric (varargin{2})) |
6540
|
38 x = varargin{1}; |
6886
|
39 if (isvector (x)) |
6540
|
40 x = x(:); |
|
41 endif |
|
42 y = varargin{2}; |
6886
|
43 if (isvector (y)) |
6540
|
44 y = y(:); |
|
45 endif |
6886
|
46 if (size (x, 1) != size (y, 1)) |
6540
|
47 y = varargin{1}; |
6886
|
48 if (isvector (y)) |
6540
|
49 y = y(:); |
|
50 endif |
|
51 x = [1:size(y,1)]'; |
|
52 idx = 2; |
|
53 else |
6886
|
54 if (! isvector (x)) |
6540
|
55 error ("%s: x must be a vector", func); |
|
56 endif |
|
57 idx = 3; |
|
58 endif |
|
59 else |
|
60 y = varargin{1}; |
6886
|
61 if (isvector (y)) |
6540
|
62 y = y(:); |
|
63 endif |
|
64 x = [1:size(y,1)]'; |
|
65 idx = 2; |
|
66 endif |
|
67 |
|
68 newargs = {}; |
6886
|
69 have_line_spec = false; |
6540
|
70 while (idx <= nargin -2) |
6886
|
71 if (isstr (varargin{idx}) && strcmp (varargin{idx}, "grouped")) |
6540
|
72 group = true; |
|
73 idx++; |
6886
|
74 elseif (isstr (varargin{idx}) && strcmp (varargin{idx}, "stacked")) |
6540
|
75 group = false; |
|
76 idx++; |
|
77 else |
6886
|
78 if ((isstr (varargin{idx}) || iscell (varargin{idx})) |
|
79 && ! have_line_spec) |
6885
|
80 [linespec, valid] = __pltopt__ (func, varargin{idx}, false); |
6540
|
81 if (valid) |
6886
|
82 have_line_spec = true; |
6885
|
83 newargs = [{linespec.color}, newargs]; |
|
84 idx++; |
6540
|
85 continue; |
|
86 endif |
|
87 endif |
|
88 if (isscalar(varargin{idx})) |
|
89 width = varargin{idx++}; |
|
90 elseif (idx == nargin - 2) |
|
91 newargs = [newargs,varargin(idx++)]; |
|
92 else |
|
93 newargs = [newargs,varargin(idx:idx+1)]; |
|
94 idx += 2; |
|
95 endif |
|
96 endif |
|
97 endwhile |
|
98 |
|
99 xlen = size (x, 1); |
|
100 ylen = size (y, 1); |
|
101 |
|
102 if (xlen != ylen) |
|
103 error ("%s: length of x and y must be equal", func) |
|
104 endif |
|
105 if (any (x(2:end) < x(1:end-1))) |
|
106 error ("%s: x vector values must be in ascending order", func); |
|
107 endif |
|
108 |
|
109 ycols = size (y, 2); |
|
110 if (group) |
|
111 width = width / ycols; |
|
112 endif |
|
113 |
|
114 cutoff = (x(1:end-1) + x(2:end)) / 2; |
|
115 delta_p = [(cutoff - x(1:end-1)); (x(end) - cutoff(end))] * width; |
|
116 delta_m = [(cutoff(1) - x(1)); (x(2:end) - cutoff)] * width; |
|
117 x1 = (x - delta_m)(:)'; |
|
118 x2 = (x + delta_p)(:)'; |
6886
|
119 xb = repmat ([x1; x1; x2; x2](:), 1, ycols); |
6540
|
120 |
|
121 if (group) |
|
122 width = width / ycols; |
|
123 offset = ((delta_p + delta_m) * [-(ycols - 1) / 2 : (ycols - 1) / 2]); |
6885
|
124 xb(1:4:4*ylen,:) += offset; |
|
125 xb(2:4:4*ylen,:) += offset; |
|
126 xb(3:4:4*ylen,:) += offset; |
|
127 xb(4:4:4*ylen,:) += offset; |
6540
|
128 y0 = zeros (size (y)); |
|
129 y1 = y; |
|
130 else |
|
131 y1 = cumsum(y,2); |
|
132 y0 = [zeros(ylen,1), y1(:,1:end-1)]; |
|
133 endif |
|
134 |
6885
|
135 yb = zeros (4*ylen, ycols); |
|
136 yb(1:4:4*ylen,:) = y0; |
|
137 yb(2:4:4*ylen,:) = y1; |
|
138 yb(3:4:4*ylen,:) = y1; |
|
139 yb(4:4:4*ylen,:) = y0; |
|
140 |
|
141 xb = reshape (xb, 4, numel (xb) / 4); |
|
142 yb = reshape (yb, 4, numel (yb) / 4); |
|
143 |
6886
|
144 if (! have_line_spec) |
6885
|
145 colors = [1, 0, 0; 0, 1, 0; 0, 0, 1; 1, 1, 0; 1, 0, 1; 0, 1, 1]; |
|
146 newargs = [{shiftdim(colors (mod (floor ([0 : (ycols * ylen - 1)] / ylen), |
|
147 6) + 1, :), -1)}, newargs]; |
|
148 endif |
6540
|
149 |
|
150 if (vertical) |
|
151 if (nargout < 1) |
6885
|
152 patch (xb, yb, newargs {:}); |
6540
|
153 elseif (nargout < 2) |
6885
|
154 varargout{1} = patch (xb, yb, newargs {:}); |
6540
|
155 else |
|
156 varargout{1} = xb; |
|
157 varargout{2} = yb; |
|
158 endif |
|
159 else |
|
160 if (nargout < 1) |
6885
|
161 patch (yb, xb, newargs{:}); |
6540
|
162 elseif (nargout < 2) |
6885
|
163 varargout{1} = patch (yb, xb, newargs{:}); |
6540
|
164 else |
|
165 varargout{1} = yb; |
|
166 varargout{2} = xb; |
|
167 endif |
6886
|
168 endif |
6540
|
169 |
|
170 endfunction |