octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: area function


From: David Bateman
Subject: Re: area function
Date: Fri, 09 Nov 2007 16:52:00 +0100
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

Michael Goffioul wrote:
> On 11/9/07, David Bateman <address@hidden> wrote:
>   
>> I quickly ported Michael's area function from jhandles to Octave while
>> removing the area-series code, and the result is the attached patch.
>>     
>
> I would have prefered that you separate the front-end and the backend
> as I did in my implementation. The idea in my implementation was that
> the front-end area.m would be shared by any implementation (responsible
> for argument checking, parsing and formatting) and the backend
> (renamed to __go_areaseries__) would do the rest. In this case, you
> could have re-implemented __go_areaseries__ to create simple patches
> instead of areaseries objects.
>
> With your current implementation, I don't have any other choice than
> keeping my front-end version... :-(
>
> Michael.
>
>   
Ok, then what about the attached version?

D.

-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary

*** ./scripts/plot/Makefile.in.orig13   2007-11-09 15:31:09.715404867 +0100
--- ./scripts/plot/Makefile.in  2007-11-09 16:40:40.918542764 +0100
***************
*** 34,39 ****
--- 34,40 ----
  INSTALL_DATA = @INSTALL_DATA@
  
  SOURCES = \
+   __area__.m \
    __axes_limits__.m \
    __axis_label__.m \
    __bar__.m \
***************
*** 61,66 ****
--- 62,68 ----
    __pltopt1__.m \
    __pltopt__.m \
    ancestor.m \
+   area.m \
    axes.m \
    axis.m \
    bar.m \
*** ./scripts/plot/area.m.orig13        2007-11-09 15:31:18.169982771 +0100
--- ./scripts/plot/area.m       2007-11-09 16:49:53.632644538 +0100
***************
*** 0 ****
--- 1,103 ----
+ ## Copyright (C) 2007 Michael Goffioul
+ ##
+ ## This file is part of Octave.
+ ##
+ ## Octave is free software; you can redistribute it and/or modify it
+ ## under the terms of the GNU General Public License as published by
+ ## the Free Software Foundation; either version 3 of the License, or (at
+ ## your option) any later version.
+ ##
+ ## Octave is distributed in the hope that it will be useful, but
+ ## WITHOUT ANY WARRANTY; without even the implied warranty of
+ ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ ## General Public License for more details.
+ ##
+ ## You should have received a copy of the GNU General Public License
+ ## along with Octave; see the file COPYING.  If not, see
+ ## <http://www.gnu.org/licenses/>.
+ 
+ ## -*- texinfo -*-
+ ## @deftypefn {Function File} {} area (@var{x}, @var{y})
+ ## @deftypefnx {Function File} {} area (@var{x}, @var{y}, @var{lvl})
+ ## @deftypefnx {Function File} {} area (@dots{}, @var{prop}, @var{val}, 
@dots{})
+ ## @deftypefnx {Function File} {} area (@var{y}, @dots{})
+ ## @deftypefnx {Function File} {} area (@var{h}, @dots{})
+ ## @deftypefnx {Function File} address@hidden =} area (@dots{})
+ ## Area plot of cummulative sum of the columns of @var{y}. This shows the
+ ## contributions of a value to a sum, and is functionally similar to 
+ ## @code{plot (@var{x}, cumsum (@var{y}, 2))}, except that the area under 
+ ## the curve is shaded.
+ ##
+ ## If the @var{x} argument is ommitted it is assumed to be given by
+ ## @code{1 : rows (@var{y})}. A value @var{lvl} can be defined that determines
+ ## where the base level of the shading under the curve should be defined.
+ ##
+ ## Additional arguments to the @code{area} function are passed to the 
+ ## @code{patch}. The optional return value @var{h} provides a handle to 
+ ## the list of patch objects.
+ ## @seealso{plot, patch}
+ ## @end deftypefn
+ 
+ function [ h ] = area (varargin)
+ 
+   if (nargin > 0)
+     idx = 1;
+     ax = [];
+     x = y = [];
+     bv = 0;
+     args = {};
+     # check for axes parent
+     if (ishandle (varargin{idx}) &&
+       strcmp (get (varargin{idx}, "type"), "axes"))
+       ax = varargin{idx};
+       idx++;
+     endif
+     # check for (X) or (X,Y) arguments and possible base value
+     if (nargin >= idx && ismatrix (varargin{idx}))
+       y = varargin{idx};
+       idx++;
+       if (nargin >= idx)
+         if (isscalar (varargin{idx}))
+           bv = varargin{idx};
+           idx++;
+         elseif (ismatrix (varargin{idx}))
+           x = y;
+           y = varargin{idx};
+           idx++;
+           if (nargin >= idx && isscalar (varargin{idx}))
+             bv = varargin{idx};
+             idx++;
+           endif
+         endif
+       endif
+     else
+       print_usage ();
+     endif
+     # check for additional args
+     if (nargin >= idx)
+       args = {varargin{idx:end}};
+     endif
+     newplot ();
+     if (isvector (y))
+       y = y(:);
+     endif
+     if (isempty (x))
+       x = repmat ([1:size(y, 1)]', 1, size (y, 2));
+     elseif (isvector (x))
+       x = repmat (x(:),  1, size (y, 2));
+     endif
+ 
+     if (isempty (ax))
+       tmp = __area__ (gca (), x, y, bv, args{:});
+     else
+       tmp = __area__ (ax, x, y, bv, args{:});
+     endif
+ 
+     if (nargout > 0)
+       h = tmp;
+     endif
+   else
+     print_usage ();
+   endif
+ 
+ endfunction
*** ./scripts/plot/__area__.m.orig13    2007-11-09 16:41:12.988991124 +0100
--- ./scripts/plot/__area__.m   2007-11-09 16:50:35.591608112 +0100
***************
*** 0 ****
--- 1,33 ----
+ ## Copyright (C) 2007 David Bateman
+ ##
+ ## This file is part of Octave.
+ ##
+ ## Octave is free software; you can redistribute it and/or modify it
+ ## under the terms of the GNU General Public License as published by
+ ## the Free Software Foundation; either version 3 of the License, or (at
+ ## your option) any later version.
+ ##
+ ## Octave is distributed in the hope that it will be useful, but
+ ## WITHOUT ANY WARRANTY; without even the implied warranty of
+ ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ ## General Public License for more details.
+ ##
+ ## You should have received a copy of the GNU General Public License
+ ## along with Octave; see the file COPYING.  If not, see
+ ## <http://www.gnu.org/licenses/>.
+ 
+ ## Undocumented internal function.
+ 
+ function retval = __area__ (ax, x, y, bv, varargin)
+   colors = [1, 0, 0; 0, 1, 0; 0, 0, 1; 1, 1, 0; 1, 0, 1; 0, 1, 1];
+   x = [x(1,:) ; x ; x(end,:)];
+   y = cumsum ([[bv, ones(1, size (y, 2) - 1)] ; y ; ...
+              [bv, ones(1, size (y, 2) - 1)]], 2);
+ 
+   retval = patch (ax, x(:, 1), y (:, 1), colors (1,:), varargin{:});
+   for i = 2 : size(y, 2)
+     retval = [retval; patch(ax, [x(:,i); flipud(x(:,i))], ...
+                           [y(:, i) ; flipud(y(:, i-1))], colors(i,:),
+                           varargin{:})];
+   endfor
+ endfunction
*** ./doc/interpreter/plot.txi.orig13   2007-11-09 15:47:43.269827650 +0100
--- ./doc/interpreter/plot.txi  2007-11-09 15:48:09.991484572 +0100
***************
*** 182,187 ****
--- 182,189 ----
  
  @DOCSTRING(pcolor)
  
+ @DOCSTRING(area)
+ 
  The axis function may be used to change the axis limits of an existing
  plot.
  
2007-11-09  David Bateman  <address@hidden>

        * area.m, __area__.m: New functions
        * Makefile.in (SOURCES): Add them to the list of files.

2007-11-09  David Bateman  <address@hidden>

        * interpreter/plot.txi: Document the new area function.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]