diff scripts/plot/pie.m @ 11330:4f399d91eb32

add pie3 to plot functions
author Kai Habel <kai.habel@gmx.de>
date Thu, 09 Dec 2010 16:17:03 +0100
parents be55736a0783
children 3c7ba1e3dc21
line wrap: on
line diff
--- a/scripts/plot/pie.m
+++ b/scripts/plot/pie.m
@@ -36,7 +36,7 @@
 ##
 ## The optional return value @var{h} provides a handle to the patch object.
 ##
-## @seealso{bar, stem}
+## @seealso{pie3, bar, stem}
 ## @end deftypefn
 
 ## Very roughly based on pie.m from octave-forge whose author was
@@ -53,7 +53,7 @@
     unwind_protect
       axes (h);
       newplot ();
-      tmp = __pie__ (h, varargin{:});
+      tmp = __pie__ ("pie", h, varargin{:});
     unwind_protect_cleanup
       axes (oldh);
     end_unwind_protect
@@ -65,94 +65,6 @@
 
 endfunction
 
-function hlist = __pie__ (varargin)
-
-  h = varargin{1};
-  x = abs (varargin{2});
-  iarg = 3;
-
-  if (! isvector (x))
-    error ("pie: expecting vector argument");
-  endif
-
-  len = length (x);
-
-  have_explode = false;
-  have_labels = false;
-
-  while (iarg <= nargin)
-    arg = varargin{iarg++};
-    if (iscell (arg))
-      labels = arg;
-      have_labels = true;
-      if (numel (x) != numel (labels))
-        error ("pie: mismatch in number of labels and data");
-      endif
-    elseif (isnumeric (arg))
-      explode = arg;
-      have_explode = true;
-      if (! size_equal (x, explode))
-        error ("pie: mismatch in number of elements in explode and data");
-      endif
-    endif
-  endwhile
-
-  if (! have_explode)
-    explode = zeros (size (x));
-  endif
-
-  if (! have_labels)
-    xp = round (100 * x ./ sum (x)); 
-    for i = 1:len
-      labels{i} = sprintf ("%d%%", xp(i));
-    endfor
-  endif
-
-  hlist = [];
-  refinement = 90;
-  phi = 0:refinement:360;
-  xphi = cumsum (x / sum (x) * 360);
-  for i = 1:len 
-    if (i == 1)
-      xn = 0 : 360 / refinement : xphi(i);
-    else
-      xn = xphi(i-1) : 360 / refinement : xphi(i);
-    endif
-
-    if (xn(end) != xphi(i))
-      xn = [xn, xphi(i)];
-    endif
-
-    xn2 = (xn(1) + xn(end)) / 2;
-    if (explode (i))
-      xoff = - 0.1 * sind (xn2);
-      yoff = 0.1 * cosd (xn2);
-    else
-      xoff = 0;
-      yoff = 0;
-    endif
-    xt = - 1.2 * sind (xn2);
-    yt = 1.2 * cosd (xn2);
-    if (xt > 0)
-      align = "left";
-    else
-      align = "right";
-    endif
-
-    hlist = [hlist; patch(xoff + [0, - sind(xn)], yoff + [0, cosd(xn)], i);
-             text(xt, yt, labels{i}, "horizontalalignment", align)];
-  endfor
-
-  if (len == 1)
-    set (h, "clim", [1, 2]);
-  else
-    set (h, "clim", [1, len]);
-  endif
-
-  axis ([-1.5, 1.5, -1.5, 1.5], "square");
-
-endfunction
-
 %!demo
 %! pie ([3, 2, 1], [0, 0, 1]);
 %! colormap([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);