1 ## Copyright (C) 2007-2012 Michael Goffioul
2 ## Copyright (C) 2007-2009 David Bateman
4 ## This file is part of Octave.
6 ## Octave is free software; you can redistribute it and/or modify it
7 ## under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 3 of the License, or (at
9 ## your option) any later version.
11 ## Octave is distributed in the hope that it will be useful, but
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ## General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with Octave; see the file COPYING. If not, see
18 ## <http://www.gnu.org/licenses/>.
21 ## @deftypefn {Function File} {} area (@var{x}, @var{y})
22 ## @deftypefnx {Function File} {} area (@var{x}, @var{y}, @var{lvl})
23 ## @deftypefnx {Function File} {} area (@dots{}, @var{prop}, @var{val}, @dots{})
24 ## @deftypefnx {Function File} {} area (@var{y}, @dots{})
25 ## @deftypefnx {Function File} {} area (@var{h}, @dots{})
26 ## @deftypefnx {Function File} {@var{h} =} area (@dots{})
27 ## Area plot of cumulative sum of the columns of @var{y}. This shows the
28 ## contributions of a value to a sum, and is functionally similar to
29 ## @code{plot (@var{x}, cumsum (@var{y}, 2))}, except that the area under
30 ## the curve is shaded.
32 ## If the @var{x} argument is omitted it is assumed to be given by
33 ## @code{1 : rows (@var{y})}. A value @var{lvl} can be defined that determines
34 ## where the base level of the shading under the curve should be defined.
36 ## Additional arguments to the @code{area} function are passed to
39 ## The optional return value @var{h} is a graphics handle to the hggroup
40 ## object representing the area patch objects.
41 ## @seealso{plot, patch}
44 function h = area (varargin)
46 [ax, varargin, nargin] = __plt_get_axis_arg__ ("area", varargin{:});
53 ## Check for (X) or (X,Y) arguments and possible base value.
54 if (nargin >= idx && ismatrix (varargin{idx}))
58 if (isscalar (varargin{idx}))
61 elseif (ismatrix (varargin{idx}))
65 if (nargin >= idx && isscalar (varargin{idx}))
74 ## Check for additional args.
76 args = {varargin{idx:end}};
83 x = repmat ([1:size(y, 1)]', 1, size (y, 2));
85 x = repmat (x(:), 1, size (y, 2));
91 tmp = __area__ (ax, x, y, bv, args{:});
92 unwind_protect_cleanup
105 function retval = __area__ (ax, x, y, bv, varargin)
107 y0 = bv * ones (1, rows (y));
108 y0 = zeros (1, rows (y));
110 for i = 1: size (y, 2);
112 retval = [retval; hg];
113 args = __add_datasource__ ("area", hg, {"x", "y"}, varargin{:});
117 addproperty ("xdata", hg, "data", x1);
118 addproperty ("ydata", hg, "data", y1);
120 addlistener (hg, "xdata", @update_data);
121 addlistener (hg, "ydata", @update_data);
124 h = patch (ax, [x1(1), x1, fliplr(x1)], [bv, y1, bv*ones(1, length(y1))],
125 __next_line_color__ (), "parent", hg);
128 h = patch (ax, [x1(1), x1, fliplr(x1)], [y0(1), y1, fliplr(y0)],
129 __next_line_color__ (), "parent", hg);
134 addproperty ("basevalue", hg, "data", bv);
135 addlistener (hg, "basevalue", @move_baseline);
137 addproperty ("edgecolor", hg, "patchedgecolor", get (h, "edgecolor"));
138 addproperty ("linewidth", hg, "patchlinewidth", get (h, "linewidth"));
139 addproperty ("linestyle", hg, "patchlinestyle", get (h, "linestyle"));
140 addproperty ("facecolor", hg, "patchfacecolor", get (h, "facecolor"));
142 addlistener (hg, "edgecolor", @update_props);
143 addlistener (hg, "linewidth", @update_props);
144 addlistener (hg, "linestyle", @update_props);
145 addlistener (hg, "facecolor", @update_props);
147 addproperty ("areagroup", hg, "data");
148 set (retval, "areagroup", retval);
150 if (! isempty (args))
157 function update_props (h, d)
158 kids = get (h, "children");
159 set (kids, "edgecolor", get (h, "edgecolor"),
160 "linewidth", get (h, "linewidth"),
161 "linestyle", get (h, "linestyle"),
162 "facecolor", get (h, "facecolor"));
165 function move_baseline (h, d)
166 persistent recursion = false;
168 ## Don't allow recursion
172 hlist = get (h, "areagroup");
173 b0 = get (h, "basevalue");
177 b1 = get (hh, "basevalue");
179 set (hh, "basevalue", b0);
184 unwind_protect_cleanup
190 function update_data (h, d)
191 hlist = get (h, "areagroup");
192 bv = get (h, "basevalue");
193 for i = 1 : length (hlist)
195 x1 = get (hh, "xdata")(:);
196 y1 = get (hh, "ydata")(:);
198 set (get (hh, "children"), "xdata", [x1(1); x1; flipud(x1)]);
200 set (get (hh, "children"), "ydata", [bv; y1; bv*ones(length(y1), 1)]);
203 set (get (hh, "children"), "ydata", [y0(1); y1; flipud(y0)]);