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