1 ## Copyright (C) 2007-2012 David Bateman
2 ## Copyright (C) 2010 Kai Habel
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} {@var{hlist} =} __pie__ (caller, @dots{})
22 ## Undocumented internal function.
25 function hlist = __pie__ (caller, varargin)
28 x = abs (varargin{2});
32 error ("%s: expecting vector argument", caller);
40 while (iarg <= nargin - 1)
41 arg = varargin{iarg++};
45 if (numel (x) != numel (labels))
46 error ("%s: mismatch in number of labels and data", caller);
48 elseif (isnumeric (arg) || islogical (arg))
51 if (! size_equal (x, explode))
52 error ("%s: mismatch in number of elements in explode and data",
56 error ("%s: %s is invalid as an optional argument", caller, class (arg));
61 explode = zeros (size (x));
71 xp = round (100 * x ./ sum (x));
76 labels{i} = sprintf ("%d%%", xp(i));
82 phi = 0:refinement:360;
84 xphi = cumsum (x / sum (x) * 360);
86 xphi = cumsum (x * 360);
91 xn = 0 : 360 / refinement : xphi(i);
93 xn = xphi(i-1) : 360 / refinement : xphi(i);
96 if (xn(end) != xphi(i))
100 xn2 = (xn(1) + xn(end)) / 2;
102 xoff = - 0.1 * sind (xn2);
103 yoff = 0.1 * cosd (xn2);
108 xt = - 1.2 * sind (xn2);
109 yt = 1.2 * cosd (xn2);
112 set (h, "clim", [1, 2]);
114 set (h, "clim", [1, len]);
117 if (strncmp (caller, "pie3", 4))
120 sx = repmat (xoff + [0, - sind(xn), 0], [2 1]);
121 sy = repmat (yoff + [0, cosd(xn), 0], [2 1]);
122 sz = [zeros(1, ln + 2); zlvl * ones(1, ln + 2)];
123 sc = i * ones (size (sz));
126 patch(xoff + [0, - sind(xn)], yoff + [0, cosd(xn)], zeros (1, ln + 1), i);
127 surface(sx, sy, sz, sc);
128 patch(xoff + [0, - sind(xn)], yoff + [0, cosd(xn)], zlvl * ones (1, ln + 1), i);
129 text(xt, yt, zlvl, labels{i})];
131 elseif (strncmp (caller, "pie", 3))
138 hlist = [hlist; patch(xoff + [0, - sind(xn)], yoff + [0, cosd(xn)], i);
139 text(xt, yt, labels{i}, "horizontalalignment", align)];
142 error ("__pie__: unknown caller `%s'", caller);
146 addlistener(gca, "view", {@update_text_pos, hlist});
148 if (strncmp (caller, "pie3", 4))
149 axis ([-1.25, 1.25, -1.25, 1.25, -0.05, 0.4], "equal", "off");
151 elseif (strncmp (caller, "pie", 3))
152 axis ([-1.5, 1.5, -1.5, 1.5], "square", "off");
156 function update_text_pos (all_handles)
157 ## Text objects in the foreground should be at the base level.
158 ## Text objects in the background should be at the top level.
159 ## Text objects on the right side should be aligned to the right
160 ## and on the left side to the left.
161 tobj = findobj (all_handles, "type", "text");
163 ## check if we are called from pie3
164 s = findobj (all_handles, "type", "surface");
170 if (length (tobj) > 0)
171 ax = get (tobj(1), "parent");
172 azel = get (ax, "view");
173 pos = get (tobj, "position");
175 pos = cell2mat (pos);
177 phi = atand (pos(:,1) ./ pos(:,2));
178 [theta, r] = cart2pol (pos(:,1), pos(:,2));
181 theta = mod (theta, 360);
182 ud_mask = (theta > 180);
183 lr_mask = (theta > 90) & (theta < 270);
184 for i = 1 : length (tobj)
187 set (tobj(i), "position", [pos(i,1), pos(i,2), -0.05]);
189 set (tobj(i), "position", [pos(i,1), pos(i,2), 0.40]);
194 set (tobj(i), "horizontalalignment", "right");
196 set (tobj(i), "horizontalalignment", "left");