Mercurial > hg > octave-nkf
annotate scripts/plot/private/__pie__.m @ 14868:5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
* lin2mu.m, loadaudio.m, wavread.m, accumarray.m, bicubic.m, celldisp.m,
colon.m, cplxpair.m, dblquad.m, divergence.m, genvarname.m, gradient.m,
int2str.m, interp1.m, interp1q.m, interp2.m, interpn.m, loadobj.m, nthargout.m,
__isequal__.m, __splinen__.m, quadgk.m, quadl.m, quadv.m, rat.m, rot90.m,
rotdim.m, saveobj.m, subsindex.m, triplequad.m, delaunay3.m, griddata.m,
inpolygon.m, tsearchn.m, voronoi.m, get_first_help_sentence.m, which.m,
gray2ind.m, pink.m, dlmwrite.m, strread.m, textread.m, textscan.m, housh.m,
ishermitian.m, issymmetric.m, krylov.m, logm.m, null.m, rref.m,
compare_versions.m, copyfile.m, dump_prefs.m, edit.m, fileparts.m,
getappdata.m, isappdata.m, movefile.m, orderfields.m, parseparams.m,
__xzip__.m, rmappdata.m, setappdata.m, swapbytes.m, unpack.m, ver.m, fminbnd.m,
fminunc.m, fsolve.m, glpk.m, lsqnonneg.m, qp.m, sqp.m, configure_make.m,
copy_files.m, describe.m, get_description.m, get_forge_pkg.m, install.m,
installed_packages.m, is_architecture_dependent.m, load_package_dirs.m,
print_package_description.m, rebuild.m, repackage.m, save_order.m, shell.m,
allchild.m, ancestor.m, area.m, axes.m, axis.m, clabel.m, close.m, colorbar.m,
comet.m, comet3.m, contour.m, cylinder.m, ezmesh.m, ezsurf.m, findobj.m,
fplot.m, hist.m, isocolors.m, isonormals.m, isosurface.m, isprop.m, legend.m,
mesh.m, meshz.m, pareto.m, pcolor.m, peaks.m, plot3.m, plotmatrix.m, plotyy.m,
polar.m, print.m, __add_datasource__.m, __add_default_menu__.m,
__axes_limits__.m, __bar__.m, __clabel__.m, __contour__.m, __errcomm__.m,
__errplot__.m, __ezplot__.m, __file_filter__.m, __fltk_print__.m,
__ghostscript__.m, __gnuplot_print__.m, __go_draw_axes__.m,
__go_draw_figure__.m, __interp_cube__.m, __marching_cube__.m, __patch__.m,
__pie__.m, __plt__.m, __print_parse_opts__.m, __quiver__.m, __scatter__.m,
__stem__.m, __tight_eps_bbox__.m, __uigetdir_fltk__.m, __uigetfile_fltk__.m,
__uiputfile_fltk__.m, quiver.m, quiver3.m, rectangle.m, refreshdata.m,
ribbon.m, scatter.m, semilogy.m, shading.m, slice.m, subplot.m, surface.m,
surfl.m, surfnorm.m, text.m, uigetfile.m, uiputfile.m, whitebg.m, deconv.m,
mkpp.m, pchip.m, polyaffine.m, polyder.m, polygcd.m, polyout.m, polyval.m,
ppint.m, ppjumps.m, ppval.m, residue.m, roots.m, spline.m, splinefit.m,
addpref.m, getpref.m, setpref.m, ismember.m, setxor.m, arch_fit.m, arch_rnd.m,
arch_test.m, autoreg_matrix.m, diffpara.m, fftconv.m, filter2.m, hanning.m,
hurst.m, periodogram.m, triangle_sw.m, sinc.m, spectral_xdf.m, spencer.m,
stft.m, synthesis.m, unwrap.m, yulewalker.m, bicgstab.m, gmres.m, pcg.m, pcr.m,
__sprand_impl__.m, speye.m, spfun.m, sprandn.m, spstats.m, svds.m,
treelayout.m, treeplot.m, bessel.m, factor.m, legendre.m, perms.m, primes.m,
magic.m, toeplitz.m, corr.m, cov.m, mean.m, median.m, mode.m, qqplot.m,
quantile.m, ranks.m, zscore.m, logistic_regression_likelihood.m,
bartlett_test.m, chisquare_test_homogeneity.m, chisquare_test_independence.m,
kolmogorov_smirnov_test.m, run_test.m, u_test.m, wilcoxon_test.m, z_test.m,
z_test_2.m, bin2dec.m, dec2base.m, mat2str.m, strcat.m, strchr.m, strjust.m,
strtok.m, substr.m, untabify.m, assert.m, demo.m, example.m, fail.m, speed.m,
test.m, now.m: Use Octave coding conventions for cuddling parentheses in
scripts directory.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Tue, 17 Jul 2012 07:08:39 -0700 |
parents | 72c96de7a403 |
children | efac5593b1de |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11589
diff
changeset
|
1 ## Copyright (C) 2007-2012 David Bateman |
11330 | 2 ## Copyright (C) 2010 Kai Habel |
3 ## | |
4 ## This file is part of Octave. | |
5 ## | |
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. | |
10 ## | |
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. | |
15 ## | |
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/>. | |
19 | |
20 ## -*- texinfo -*- | |
21 ## @deftypefn {Function File} {@var{hlist} =} __pie__ (caller, @dots{}) | |
22 ## Undocumented internal function. | |
23 ## @end deftypefn | |
24 | |
25 function hlist = __pie__ (caller, varargin) | |
26 | |
27 h = varargin{1}; | |
28 x = abs (varargin{2}); | |
29 iarg = 3; | |
30 | |
31 if (! isvector (x)) | |
11338
892ef3688ccf
__pie__.m: improve error messages
John W. Eaton <jwe@octave.org>
parents:
11332
diff
changeset
|
32 error ("%s: expecting vector argument", caller); |
11330 | 33 endif |
34 | |
35 len = length (x); | |
36 | |
37 have_explode = false; | |
38 have_labels = false; | |
39 | |
40 while (iarg <= nargin - 1) | |
41 arg = varargin{iarg++}; | |
42 if (iscell (arg)) | |
43 labels = arg; | |
44 have_labels = true; | |
45 if (numel (x) != numel (labels)) | |
11338
892ef3688ccf
__pie__.m: improve error messages
John W. Eaton <jwe@octave.org>
parents:
11332
diff
changeset
|
46 error ("%s: mismatch in number of labels and data", caller); |
11330 | 47 endif |
11338
892ef3688ccf
__pie__.m: improve error messages
John W. Eaton <jwe@octave.org>
parents:
11332
diff
changeset
|
48 elseif (isnumeric (arg) || islogical (arg)) |
11330 | 49 explode = arg; |
50 have_explode = true; | |
51 if (! size_equal (x, explode)) | |
11338
892ef3688ccf
__pie__.m: improve error messages
John W. Eaton <jwe@octave.org>
parents:
11332
diff
changeset
|
52 error ("%s: mismatch in number of elements in explode and data", |
892ef3688ccf
__pie__.m: improve error messages
John W. Eaton <jwe@octave.org>
parents:
11332
diff
changeset
|
53 caller); |
11330 | 54 endif |
11338
892ef3688ccf
__pie__.m: improve error messages
John W. Eaton <jwe@octave.org>
parents:
11332
diff
changeset
|
55 else |
892ef3688ccf
__pie__.m: improve error messages
John W. Eaton <jwe@octave.org>
parents:
11332
diff
changeset
|
56 error ("%s: %s is invalid as an optional argument", caller, class (arg)); |
11330 | 57 endif |
58 endwhile | |
59 | |
60 if (! have_explode) | |
61 explode = zeros (size (x)); | |
62 endif | |
63 | |
11341
3c7ba1e3dc21
Add missing option slice for pie and pie3
Kai Habel <kai.habel@gmx.de>
parents:
11338
diff
changeset
|
64 normalize = true; |
3c7ba1e3dc21
Add missing option slice for pie and pie3
Kai Habel <kai.habel@gmx.de>
parents:
11338
diff
changeset
|
65 if (sum (x(:)) < 1) |
3c7ba1e3dc21
Add missing option slice for pie and pie3
Kai Habel <kai.habel@gmx.de>
parents:
11338
diff
changeset
|
66 normalize = false; |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
67 endif |
11341
3c7ba1e3dc21
Add missing option slice for pie and pie3
Kai Habel <kai.habel@gmx.de>
parents:
11338
diff
changeset
|
68 |
11330 | 69 if (! have_labels) |
11341
3c7ba1e3dc21
Add missing option slice for pie and pie3
Kai Habel <kai.habel@gmx.de>
parents:
11338
diff
changeset
|
70 if (normalize) |
3c7ba1e3dc21
Add missing option slice for pie and pie3
Kai Habel <kai.habel@gmx.de>
parents:
11338
diff
changeset
|
71 xp = round (100 * x ./ sum (x)); |
3c7ba1e3dc21
Add missing option slice for pie and pie3
Kai Habel <kai.habel@gmx.de>
parents:
11338
diff
changeset
|
72 else |
3c7ba1e3dc21
Add missing option slice for pie and pie3
Kai Habel <kai.habel@gmx.de>
parents:
11338
diff
changeset
|
73 xp = round (100 * x); |
3c7ba1e3dc21
Add missing option slice for pie and pie3
Kai Habel <kai.habel@gmx.de>
parents:
11338
diff
changeset
|
74 endif |
11330 | 75 for i = 1:len |
76 labels{i} = sprintf ("%d%%", xp(i)); | |
77 endfor | |
78 endif | |
79 | |
80 hlist = []; | |
81 refinement = 90; | |
82 phi = 0:refinement:360; | |
11341
3c7ba1e3dc21
Add missing option slice for pie and pie3
Kai Habel <kai.habel@gmx.de>
parents:
11338
diff
changeset
|
83 if (normalize) |
3c7ba1e3dc21
Add missing option slice for pie and pie3
Kai Habel <kai.habel@gmx.de>
parents:
11338
diff
changeset
|
84 xphi = cumsum (x / sum (x) * 360); |
3c7ba1e3dc21
Add missing option slice for pie and pie3
Kai Habel <kai.habel@gmx.de>
parents:
11338
diff
changeset
|
85 else |
3c7ba1e3dc21
Add missing option slice for pie and pie3
Kai Habel <kai.habel@gmx.de>
parents:
11338
diff
changeset
|
86 xphi = cumsum (x * 360); |
3c7ba1e3dc21
Add missing option slice for pie and pie3
Kai Habel <kai.habel@gmx.de>
parents:
11338
diff
changeset
|
87 endif |
3c7ba1e3dc21
Add missing option slice for pie and pie3
Kai Habel <kai.habel@gmx.de>
parents:
11338
diff
changeset
|
88 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
89 for i = 1:len |
11330 | 90 if (i == 1) |
91 xn = 0 : 360 / refinement : xphi(i); | |
92 else | |
93 xn = xphi(i-1) : 360 / refinement : xphi(i); | |
94 endif | |
95 | |
96 if (xn(end) != xphi(i)) | |
97 xn = [xn, xphi(i)]; | |
98 endif | |
99 | |
100 xn2 = (xn(1) + xn(end)) / 2; | |
101 if (explode (i)) | |
102 xoff = - 0.1 * sind (xn2); | |
103 yoff = 0.1 * cosd (xn2); | |
104 else | |
105 xoff = 0; | |
106 yoff = 0; | |
107 endif | |
108 xt = - 1.2 * sind (xn2); | |
109 yt = 1.2 * cosd (xn2); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
110 |
11330 | 111 if (len == 1) |
112 set (h, "clim", [1, 2]); | |
113 else | |
114 set (h, "clim", [1, len]); | |
115 endif | |
116 | |
117 if (strncmp (caller, "pie3", 4)) | |
118 ln = length (xn); | |
119 zlvl = 0.35; | |
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)); | |
124 | |
125 hlist = [hlist; | |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
126 patch (xoff + [0, - sind(xn)], yoff + [0, cosd(xn)], zeros (1, ln + 1), i); |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
127 surface (sx, sy, sz, sc); |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
128 patch (xoff + [0, - sind(xn)], yoff + [0, cosd(xn)], zlvl * ones (1, ln + 1), i); |
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
129 text (xt, yt, zlvl, labels{i})]; |
11330 | 130 |
131 elseif (strncmp (caller, "pie", 3)) | |
132 if (xt > 0) | |
133 align = "left"; | |
134 else | |
135 align = "right"; | |
136 endif | |
137 | |
138 hlist = [hlist; patch(xoff + [0, - sind(xn)], yoff + [0, cosd(xn)], i); | |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
139 text (xt, yt, labels{i}, "horizontalalignment", align)]; |
11330 | 140 |
141 else | |
11338
892ef3688ccf
__pie__.m: improve error messages
John W. Eaton <jwe@octave.org>
parents:
11332
diff
changeset
|
142 error ("__pie__: unknown caller `%s'", caller); |
11330 | 143 endif |
144 endfor | |
145 | |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
146 addlistener (gca, "view", {@update_text_pos, hlist}); |
11330 | 147 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
148 if (strncmp (caller, "pie3", 4)) |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
149 axis ([-1.25, 1.25, -1.25, 1.25, -0.05, 0.4], "equal", "off"); |
11330 | 150 view (-37.5, 30); |
151 elseif (strncmp (caller, "pie", 3)) | |
152 axis ([-1.5, 1.5, -1.5, 1.5], "square", "off"); | |
153 endif | |
154 endfunction | |
155 | |
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"); | |
162 | |
163 ## check if we are called from pie3 | |
164 s = findobj (all_handles, "type", "surface"); | |
165 is_pie3 = false; | |
166 if (length (s) > 0) | |
167 is_pie3 = true; | |
168 endif | |
169 | |
170 if (length (tobj) > 0) | |
171 ax = get (tobj(1), "parent"); | |
172 azel = get (ax, "view"); | |
173 pos = get (tobj, "position"); | |
174 if (iscell (pos)) | |
175 pos = cell2mat (pos); | |
176 endif | |
177 phi = atand (pos(:,1) ./ pos(:,2)); | |
178 [theta, r] = cart2pol (pos(:,1), pos(:,2)); | |
179 theta *= 180/pi; | |
180 theta -= azel(1); | |
181 theta = mod (theta, 360); | |
182 ud_mask = (theta > 180); | |
183 lr_mask = (theta > 90) & (theta < 270); | |
184 for i = 1 : length (tobj) | |
185 if (is_pie3) | |
186 if (ud_mask(i)) | |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
187 set (tobj(i), "position", [pos(i,1), pos(i,2), -0.05]); |
11330 | 188 else |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
189 set (tobj(i), "position", [pos(i,1), pos(i,2), 0.40]); |
11330 | 190 endif |
191 endif | |
192 | |
193 if (lr_mask(i)) | |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
194 set (tobj(i), "horizontalalignment", "right"); |
11330 | 195 else |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
196 set (tobj(i), "horizontalalignment", "left"); |
11330 | 197 endif |
198 endfor | |
199 endif | |
200 endfunction |