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