Mercurial > hg > octave-nkf
annotate scripts/plot/private/__clabel__.m @ 14138:72c96de7a403 stable
maint: update copyright notices for 2012
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 02 Jan 2012 14:25:41 -0500 |
parents | b0084095098e |
children | 5d3a684236b0 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11589
diff
changeset
|
1 ## Copyright (C) 2008-2012 David Bateman |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2 ## |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3 ## This file is part of Octave. |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
4 ## |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
5 ## Octave is free software; you can redistribute it and/or modify it |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
8 ## your option) any later version. |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
9 ## |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
10 ## Octave is distributed in the hope that it will be useful, but |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
13 ## General Public License for more details. |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
14 ## |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
16 ## along with Octave; see the file COPYING. If not, see |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
18 |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8507
diff
changeset
|
19 ## -*- texinfo -*- |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8507
diff
changeset
|
20 ## @deftypefn {Function File} {@var{h} =} __clabel__ (@var{c}, @var{v}, @var{hparent}, @var{label_spacing}, @var{z}, @var{varargin}) |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
21 ## Undocumented internal function. |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8507
diff
changeset
|
22 ## @end deftypefn |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
23 |
8507 | 24 function h = __clabel__ (c, v, hparent, label_spacing, z, varargin) |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
25 ## FIXME |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
26 ## Assume that the plot size is 4 by 3 inches. |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
27 lims = axis (); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
28 xspacing = 72 * 4 / abs(lims(1) - lims(2)); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
29 yspacing = 72 * 3 / abs(lims(3) - lims(4)); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
30 |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10549
diff
changeset
|
31 if (isscalar (hparent) && ishandle(hparent) |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10549
diff
changeset
|
32 && strcmp (get (hparent, "type"), "hggroup")) |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
33 x = get (hparent, "xdata"); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
34 xmin = min (x(:)); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
35 xmax = max (x(:)); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
36 y = get (hparent, "ydata"); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
37 ymin = min (y(:)); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
38 ymax = max (y(:)); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
39 else |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
40 i1 = 1; |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
41 while (i1 < length (c)) |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
42 clev = c(1,i1); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
43 clen = c(2,i1); |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
44 p = c(:, i1+1:i1+clen); |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
45 |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
46 xmin = min (c(1,:)); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
47 xmax = max (c(1,:)); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
48 ymin = min (c(2,:)); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
49 ymax = max (c(2,:)); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
50 |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
51 i1 += clen+1; |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
52 endwhile |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
53 endif |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
54 |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
55 ## Decode contourc output format and place labels. |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
56 i1 = 1; |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
57 h = []; |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
58 while (i1 < length (c)) |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
59 clev = c(1,i1); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
60 clen = c(2,i1); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
61 |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
62 if (!isempty (v) && ! any (find (clev == v))) |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
63 i1 += clen+1; |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
64 continue; |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
65 endif |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
66 |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
67 p = c(:, i1+1:i1+clen) .* repmat ([xspacing; yspacing], 1, clen); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
68 d = sqrt (sumsq (diff (p, 1, 2))); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
69 cumd = cumsum (d); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
70 td = sum(d); |
8507 | 71 ntag = ceil (td / label_spacing); |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
72 |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
73 if (all (c(:,i1+1) == c(:,i1+clen))) |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
74 Spacing = td / ntag; |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
75 pos = Spacing / 2 + [0:ntag-1] * Spacing; |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
76 else |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
77 pos = zeros(1, ntag); |
8507 | 78 pos(1) = (td - label_spacing * (ntag - 1)) ./ 2; |
79 pos(2:ntag) = pos(1) + [1:ntag-1] * label_spacing; | |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
80 endif |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
81 |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
82 j1 = 2; |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
83 tlabel = sprintf ("%g", clev); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
84 for i = 1 : ntag |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
85 tagpos = pos(i); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
86 |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
87 while (j1 < clen && cumd(j1) < tagpos) |
10549 | 88 j1++; |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
89 endwhile |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
90 tpos = sum(c(:,i1+j1-1:i1+j1), 2) ./ 2; |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
91 |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10549
diff
changeset
|
92 if (tpos(1) != xmin && tpos(1) != xmax |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10549
diff
changeset
|
93 && tpos(2) != ymin && tpos(2) != ymax) |
10549 | 94 trot = 180 / pi * atan2 (diff (c(2,i1+j1-1:i1+j1)), |
95 diff (c(1,i1+j1-1:i1+j1))); | |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
96 |
10549 | 97 if (ischar (z)) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
98 ht = text (tpos(1), tpos(2), clev, tlabel, "rotation", trot, |
10549 | 99 "parent", hparent, "horizontalalignment", "center", |
100 "userdata", clev, varargin{:}); | |
101 elseif (!isempty (z)) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
102 ht = text (tpos(1), tpos(2), z, tlabel, "rotation", trot, |
10549 | 103 "parent", hparent, "horizontalalignment", "center", |
104 "userdata", clev, varargin{:}); | |
105 else | |
106 ht = text (tpos(1), tpos(2), tlabel, "rotation", trot, | |
107 "parent", hparent, "horizontalalignment", "center", | |
108 "userdata", clev, varargin{:}); | |
109 endif | |
110 h = [h; ht]; | |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
111 endif |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
112 endfor |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
113 i1 += clen+1; |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
114 endwhile |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
115 endfunction |