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 |
6895
|
20 ## Undocumented internal function. |
6540
|
21 |
|
22 ## Author: jwe |
|
23 |
|
24 function varargout = __bar__ (vertical, func, varargin) |
6886
|
25 |
6540
|
26 width = 0.8; |
|
27 group = true; |
|
28 |
|
29 if (nargin < 3) |
6886
|
30 print_usage (); |
6540
|
31 endif |
|
32 |
6886
|
33 if (nargin > 3 && isnumeric (varargin{2})) |
6540
|
34 x = varargin{1}; |
6886
|
35 if (isvector (x)) |
6540
|
36 x = x(:); |
|
37 endif |
|
38 y = varargin{2}; |
6886
|
39 if (isvector (y)) |
6540
|
40 y = y(:); |
|
41 endif |
6886
|
42 if (size (x, 1) != size (y, 1)) |
6540
|
43 y = varargin{1}; |
6886
|
44 if (isvector (y)) |
6540
|
45 y = y(:); |
|
46 endif |
|
47 x = [1:size(y,1)]'; |
|
48 idx = 2; |
|
49 else |
6886
|
50 if (! isvector (x)) |
6540
|
51 error ("%s: x must be a vector", func); |
|
52 endif |
|
53 idx = 3; |
|
54 endif |
|
55 else |
|
56 y = varargin{1}; |
6886
|
57 if (isvector (y)) |
6540
|
58 y = y(:); |
|
59 endif |
|
60 x = [1:size(y,1)]'; |
|
61 idx = 2; |
|
62 endif |
|
63 |
|
64 newargs = {}; |
6886
|
65 have_line_spec = false; |
6540
|
66 while (idx <= nargin -2) |
6886
|
67 if (isstr (varargin{idx}) && strcmp (varargin{idx}, "grouped")) |
6540
|
68 group = true; |
|
69 idx++; |
6886
|
70 elseif (isstr (varargin{idx}) && strcmp (varargin{idx}, "stacked")) |
6540
|
71 group = false; |
|
72 idx++; |
|
73 else |
6886
|
74 if ((isstr (varargin{idx}) || iscell (varargin{idx})) |
|
75 && ! have_line_spec) |
6885
|
76 [linespec, valid] = __pltopt__ (func, varargin{idx}, false); |
6540
|
77 if (valid) |
6886
|
78 have_line_spec = true; |
6885
|
79 newargs = [{linespec.color}, newargs]; |
|
80 idx++; |
6540
|
81 continue; |
|
82 endif |
|
83 endif |
|
84 if (isscalar(varargin{idx})) |
|
85 width = varargin{idx++}; |
|
86 elseif (idx == nargin - 2) |
|
87 newargs = [newargs,varargin(idx++)]; |
|
88 else |
|
89 newargs = [newargs,varargin(idx:idx+1)]; |
|
90 idx += 2; |
|
91 endif |
|
92 endif |
|
93 endwhile |
|
94 |
|
95 xlen = size (x, 1); |
|
96 ylen = size (y, 1); |
|
97 |
|
98 if (xlen != ylen) |
|
99 error ("%s: length of x and y must be equal", func) |
|
100 endif |
|
101 if (any (x(2:end) < x(1:end-1))) |
|
102 error ("%s: x vector values must be in ascending order", func); |
|
103 endif |
|
104 |
|
105 ycols = size (y, 2); |
|
106 if (group) |
|
107 width = width / ycols; |
|
108 endif |
|
109 |
|
110 cutoff = (x(1:end-1) + x(2:end)) / 2; |
|
111 delta_p = [(cutoff - x(1:end-1)); (x(end) - cutoff(end))] * width; |
|
112 delta_m = [(cutoff(1) - x(1)); (x(2:end) - cutoff)] * width; |
|
113 x1 = (x - delta_m)(:)'; |
|
114 x2 = (x + delta_p)(:)'; |
6886
|
115 xb = repmat ([x1; x1; x2; x2](:), 1, ycols); |
6540
|
116 |
|
117 if (group) |
|
118 width = width / ycols; |
|
119 offset = ((delta_p + delta_m) * [-(ycols - 1) / 2 : (ycols - 1) / 2]); |
6885
|
120 xb(1:4:4*ylen,:) += offset; |
|
121 xb(2:4:4*ylen,:) += offset; |
|
122 xb(3:4:4*ylen,:) += offset; |
|
123 xb(4:4:4*ylen,:) += offset; |
6540
|
124 y0 = zeros (size (y)); |
|
125 y1 = y; |
|
126 else |
|
127 y1 = cumsum(y,2); |
|
128 y0 = [zeros(ylen,1), y1(:,1:end-1)]; |
|
129 endif |
|
130 |
6885
|
131 yb = zeros (4*ylen, ycols); |
|
132 yb(1:4:4*ylen,:) = y0; |
|
133 yb(2:4:4*ylen,:) = y1; |
|
134 yb(3:4:4*ylen,:) = y1; |
|
135 yb(4:4:4*ylen,:) = y0; |
|
136 |
|
137 xb = reshape (xb, 4, numel (xb) / 4); |
|
138 yb = reshape (yb, 4, numel (yb) / 4); |
|
139 |
6886
|
140 if (! have_line_spec) |
6885
|
141 colors = [1, 0, 0; 0, 1, 0; 0, 0, 1; 1, 1, 0; 1, 0, 1; 0, 1, 1]; |
|
142 newargs = [{shiftdim(colors (mod (floor ([0 : (ycols * ylen - 1)] / ylen), |
|
143 6) + 1, :), -1)}, newargs]; |
|
144 endif |
6540
|
145 |
|
146 if (vertical) |
|
147 if (nargout < 1) |
6885
|
148 patch (xb, yb, newargs {:}); |
6540
|
149 elseif (nargout < 2) |
6885
|
150 varargout{1} = patch (xb, yb, newargs {:}); |
6540
|
151 else |
|
152 varargout{1} = xb; |
|
153 varargout{2} = yb; |
|
154 endif |
|
155 else |
|
156 if (nargout < 1) |
6885
|
157 patch (yb, xb, newargs{:}); |
6540
|
158 elseif (nargout < 2) |
6885
|
159 varargout{1} = patch (yb, xb, newargs{:}); |
6540
|
160 else |
|
161 varargout{1} = yb; |
|
162 varargout{2} = xb; |
|
163 endif |
6886
|
164 endif |
6540
|
165 |
|
166 endfunction |