# HG changeset patch # User Kai Habel # Date 1291907823 -3600 # Node ID 4f399d91eb32641e3f8eec1dc78f9088a168b640 # Parent 6b073da9d7fc5c97b919f7cb0850ce3472f06b5b add pie3 to plot functions diff -r 6b073da9d7fc -r 4f399d91eb32 ChangeLog --- a/ChangeLog Thu Dec 09 02:42:29 2010 -0500 +++ b/ChangeLog Thu Dec 09 16:17:03 2010 +0100 @@ -1,3 +1,7 @@ +2010-12-09 Kai Habel + + * NEWS: Add pie3 to new functions list. + 2010-12-09 Marco Atzeri * configure.ac: Don't add -lwsock32 to LIBS on cygwin systems. diff -r 6b073da9d7fc -r 4f399d91eb32 NEWS --- a/NEWS Thu Dec 09 02:42:29 2010 -0500 +++ b/NEWS Thu Dec 09 16:17:03 2010 +0100 @@ -313,14 +313,14 @@ ** The following functions are new in Octave 3.4: - accumdim fileread nfields pqpnonneg textread - bitpack fminbnd nth_element randi uigetdir - bitunpack fskipl onCleanup repelems uigetfile - blkmm ifelse pbaspect reset uiputfile - cbrt ishermitian powerset rsf2csf uimenu - chop isindex ppder saveas whitebg - daspect luupdate ppint sizemax - erfcx merge ppjumps strread + accumdim fileread nfields ppjumps strread + bitpack fminbnd nth_element pqpnonneg textread + bitunpack fskipl onCleanup randi uigetdir + blkmm ifelse pbaspect repelems uigetfile + cbrt ishermitian pie3 reset uiputfile + chop isindex powerset rsf2csf uimenu + daspect luupdate ppder saveas whitebg + erfcx merge ppint saveas ** Using the image function to view images with external programs such diff -r 6b073da9d7fc -r 4f399d91eb32 doc/ChangeLog --- a/doc/ChangeLog Thu Dec 09 02:42:29 2010 -0500 +++ b/doc/ChangeLog Thu Dec 09 16:17:03 2010 +0100 @@ -1,3 +1,7 @@ +2010-12-09 Kai Habel + + * interpreter/plot.txi: Add pie3 function. + 2010-11-26 John W. Eaton * interpreter/install.txi (Compiling Octave with 64-bit diff -r 6b073da9d7fc -r 4f399d91eb32 doc/interpreter/plot.txi --- a/doc/interpreter/plot.txi Thu Dec 09 02:42:29 2010 -0500 +++ b/doc/interpreter/plot.txi Thu Dec 09 16:17:03 2010 +0100 @@ -202,6 +202,8 @@ @DOCSTRING(pie) +@DOCSTRING(pie3) + @DOCSTRING(quiver) @DOCSTRING(quiver3) diff -r 6b073da9d7fc -r 4f399d91eb32 scripts/ChangeLog --- a/scripts/ChangeLog Thu Dec 09 02:42:29 2010 -0500 +++ b/scripts/ChangeLog Thu Dec 09 16:17:03 2010 +0100 @@ -1,3 +1,11 @@ +2010-12-09 Kai Habel + + * (plot/pie3.m, plot/private/__pie__.m): New functions. + * (plot/pie.m): Move __pie__ function to plot/private, in order to be used + by pie and pie3. + * miscellaneous/unimplemented.m: Remove pie3.m from list of + unimplemented functions. + 2010-12-09 John W. Eaton * time/datestr.m: Don't call localtime (mktime (tm)) to fill in diff -r 6b073da9d7fc -r 4f399d91eb32 scripts/miscellaneous/unimplemented.m --- a/scripts/miscellaneous/unimplemented.m Thu Dec 09 02:42:29 2010 -0500 +++ b/scripts/miscellaneous/unimplemented.m Thu Dec 09 16:17:03 2010 +0100 @@ -314,7 +314,6 @@ "pcode", "pdepe", "pdeval", - "pie3", "playshow", "plotbrowser", "plotedit", diff -r 6b073da9d7fc -r 4f399d91eb32 scripts/plot/module.mk --- a/scripts/plot/module.mk Thu Dec 09 02:42:29 2010 -0500 +++ b/scripts/plot/module.mk Thu Dec 09 16:17:03 2010 +0100 @@ -24,6 +24,7 @@ plot/private/__interp_cube__.m \ plot/private/__line__.m \ plot/private/__patch__.m \ + plot/private/__pie__.m \ plot/private/__plt__.m \ plot/private/__pltopt__.m \ plot/private/__quiver__.m \ @@ -123,6 +124,7 @@ plot/pcolor.m \ plot/peaks.m \ plot/pie.m \ + plot/pie3.m \ plot/plot.m \ plot/plot3.m \ plot/plotmatrix.m \ diff -r 6b073da9d7fc -r 4f399d91eb32 scripts/plot/pie.m --- a/scripts/plot/pie.m Thu Dec 09 02:42:29 2010 -0500 +++ b/scripts/plot/pie.m Thu Dec 09 16:17:03 2010 +0100 @@ -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]); diff -r 6b073da9d7fc -r 4f399d91eb32 scripts/plot/pie3.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/pie3.m Thu Dec 09 16:17:03 2010 +0100 @@ -0,0 +1,77 @@ +## Copyright (C) 2007, 2008, 2009 David Bateman +## Copyright (C) 2010 Kai Habel +## +## 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 +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {} pie3 (@var{y}) +## @deftypefnx {Function File} {} pie3 (@var{y}, @var{explode}) +## @deftypefnx {Function File} {} pie3 (@dots{}, @var{labels}) +## @deftypefnx {Function File} {} pie3 (@var{h}, @dots{}); +## @deftypefnx {Function File} {@var{h} =} pie3 (@dots{}); +## Drawa a 3D pie chart. +## +## Called with a single vector argument, produces a 3D pie chart of the +## elements in @var{x}, with the size of the slice determined by percentage +## size of the values of @var{x}. +## +## The variable @var{explode} is a vector of the same length as @var{x} that +## if non zero 'explodes' the slice from the pie chart. +## +## If given @var{labels} is a cell array of strings of the same length as +## @var{x}, giving the labels of each of the slices of the pie chart. +## +## The optional return value @var{h} provides a handle list to patch, surface +## and text objects generating this plot. +## +## @seealso{pie, bar, stem} +## @end deftypefn + +## Very roughly based on pie.m from octave-forge whose author was +## Daniel Heiserer + +function retval = pie3 (varargin) + + [h, varargin] = __plt_get_axis_arg__ ("pie", varargin{:}); + + if (nargin < 1) + print_usage (); + else + oldh = gca (); + unwind_protect + axes (h); + newplot (); + tmp = __pie__ ("pie3", h, varargin{:}); + unwind_protect_cleanup + axes (oldh); + end_unwind_protect + endif + + if (nargout > 0) + retval = tmp; + endif + +endfunction + +%!demo +%! pie3 ([5:-1:1], [0, 0, 1, 0, 0]); +%! colormap([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]); + +%!demo +%! pie3 ([3, 2, 1], [0, 0, 1], {"Cheddar", "Swiss", "Camembert"}); +%! colormap([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]); +%! axis ([-2,2,-2,2]); diff -r 6b073da9d7fc -r 4f399d91eb32 scripts/plot/private/__pie__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/plot/private/__pie__.m Thu Dec 09 16:17:03 2010 +0100 @@ -0,0 +1,183 @@ +## Copyright (C) 2007, 2008, 2009 David Bateman +## Copyright (C) 2010 Kai Habel +## +## 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 +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{hlist} =} __pie__ (caller, @dots{}) +## Undocumented internal function. +## @end deftypefn + +function hlist = __pie__ (caller, 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 - 1) + 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 (len == 1) + set (h, "clim", [1, 2]); + else + set (h, "clim", [1, len]); + endif + + if (strncmp (caller, "pie3", 4)) + ln = length (xn); + zlvl = 0.35; + sx = repmat (xoff + [0, - sind(xn), 0], [2 1]); + sy = repmat (yoff + [0, cosd(xn), 0], [2 1]); + sz = [zeros(1, ln + 2); zlvl * ones(1, ln + 2)]; + sc = i * ones (size (sz)); + + hlist = [hlist; + patch(xoff + [0, - sind(xn)], yoff + [0, cosd(xn)], zeros (1, ln + 1), i); + surface(sx, sy, sz, sc); + patch(xoff + [0, - sind(xn)], yoff + [0, cosd(xn)], zlvl * ones (1, ln + 1), i); + text(xt, yt, zlvl, labels{i})]; + + elseif (strncmp (caller, "pie", 3)) + 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)]; + + else + error ("__pie__: unknown caller"); + endif + endfor + + addlistener(gca, "view", {@update_text_pos, hlist}); + + if (strncmp (caller, "pie3", 4)) + axis ([-1.25, 1.25, -1.25, 1.25, -0.05, 0.4], "equal", "off") + view (-37.5, 30); + elseif (strncmp (caller, "pie", 3)) + axis ([-1.5, 1.5, -1.5, 1.5], "square", "off"); + endif +endfunction + +function update_text_pos (all_handles) + ## Text objects in the foreground should be at the base level. + ## Text objects in the background should be at the top level. + ## Text objects on the right side should be aligned to the right + ## and on the left side to the left. + tobj = findobj (all_handles, "type", "text"); + + ## check if we are called from pie3 + s = findobj (all_handles, "type", "surface"); + is_pie3 = false; + if (length (s) > 0) + is_pie3 = true; + endif + + if (length (tobj) > 0) + ax = get (tobj(1), "parent"); + azel = get (ax, "view"); + pos = get (tobj, "position"); + if (iscell (pos)) + pos = cell2mat (pos); + endif + phi = atand (pos(:,1) ./ pos(:,2)); + [theta, r] = cart2pol (pos(:,1), pos(:,2)); + theta *= 180/pi; + theta -= azel(1); + theta = mod (theta, 360); + ud_mask = (theta > 180); + lr_mask = (theta > 90) & (theta < 270); + for i = 1 : length (tobj) + if (is_pie3) + if (ud_mask(i)) + set (tobj(i), "position", [pos(i,1), pos(i,2), -0.05]) + else + set (tobj(i), "position", [pos(i,1), pos(i,2), 0.40]) + endif + endif + + if (lr_mask(i)) + set (tobj(i), "horizontalalignment", "right") + else + set (tobj(i), "horizontalalignment", "left") + endif + endfor + endif +endfunction diff -r 6b073da9d7fc -r 4f399d91eb32 src/ChangeLog --- a/src/ChangeLog Thu Dec 09 02:42:29 2010 -0500 +++ b/src/ChangeLog Thu Dec 09 16:17:03 2010 +0100 @@ -1,6 +1,6 @@ 2010-12-09 Marco Atzeri - * mappers.cc: In test for gamma, expect Inf for gamma(-1), not NaN. + * mappers.cc: In test for gamma, expect Inf for gamma(-1), not NaN. 2010-12-08 John W. Eaton