annotate scripts/plot/__clabel__.m @ 8289:ac7f334d9652

Add contour group objects and the clabel function
author David Bateman <dbateman@free.fr>
date Thu, 30 Oct 2008 00:13:05 +0100
parents
children cadc73247d65
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8289
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
1 ## Copyright (C) 2008 David Bateman
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
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
19 ## Undocumented internal function.
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
20
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
21 function h = __clabel__ (c, v, hparent, LabelSpacing, z, varargin)
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
22 ## FIXME
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
23 ## 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
24 lims = axis ();
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
25 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
26 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
27
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
28 if (isscalar (hparent) && ishandle(hparent) &&
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
29 strcmp (get (hparent, "type"), "hggroup"))
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
30 x = get (hparent, "xdata");
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
31 xmin = min (x(:));
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
32 xmax = max (x(:));
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
33 y = get (hparent, "ydata");
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
34 ymin = min (y(:));
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
35 ymax = max (y(:));
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
36 else
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
37 i1 = 1;
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
38 while (i1 < length (c))
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
39 clev = c(1,i1);
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
40 clen = c(2,i1);
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
41 p = c(:, i1+1:i1+clen)
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
42
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
43 xmin = min (c(1,:));
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
44 xmax = max (c(1,:));
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
45 ymin = min (c(2,:));
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
46 ymax = max (c(2,:));
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
47
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
48 i1 += clen+1;
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
49 endwhile
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
50 endif
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
51
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
52 ## Decode contourc output format and place labels.
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
53 i1 = 1;
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
54 h = [];
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
55 while (i1 < length (c))
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
56 clev = c(1,i1);
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
57 clen = c(2,i1);
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
58
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
59 if (!isempty (v) && ! any (find (clev == v)))
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
60 i1 += clen+1;
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
61 continue;
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
62 endif
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
63
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
64 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
65 d = sqrt (sumsq (diff (p, 1, 2)));
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
66 cumd = cumsum (d);
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
67 td = sum(d);
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
68 ntag = ceil (td / LabelSpacing);
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
69
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
70 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
71 Spacing = td / ntag;
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
72 pos = Spacing / 2 + [0:ntag-1] * Spacing;
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
73 else
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
74 pos = zeros(1, ntag);
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
75 pos(1) = (td - LabelSpacing * (ntag - 1)) ./ 2;
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
76 pos(2:ntag) = pos(1) + [1:ntag-1] * LabelSpacing;
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
77 endif
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
78
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
79 j1 = 2;
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
80 tlabel = sprintf ("%g", clev);
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
81 for i = 1 : ntag
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
82 tagpos = pos(i);
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
83
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
84 while (j1 < clen && cumd(j1) < tagpos)
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
85 j1++;
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
86 endwhile
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
87 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
88
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
89 if (tpos(1) != xmin && tpos(1) != xmax &&
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
90 tpos(2) != ymin && tpos(2) != ymax)
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
91 trot = 180 / pi * atan2 (diff (c(2,i1+j1-1:i1+j1)),
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
92 diff (c(1,i1+j1-1:i1+j1)));
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
93
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
94 if (ischar (z))
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
95 ht = text (tpos(1), tpos(2), clev, tlabel, "rotation", trot,
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
96 "parent", hparent, "horizontalalignment", "center",
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
97 "userdata", clev, varargin{:});
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
98 elseif (!isempty (z))
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
99 ht = text (tpos(1), tpos(2), z, tlabel, "rotation", trot,
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
100 "parent", hparent, "horizontalalignment", "center",
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
101 "userdata", clev, varargin{:});
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
102 else
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
103 ht = text (tpos(1), tpos(2), tlabel, "rotation", trot,
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
104 "parent", hparent, "horizontalalignment", "center",
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
105 "userdata", clev, varargin{:});
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
106 endif
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
107 h = [h; ht];
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
108 endif
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
109 endfor
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
110 i1 += clen+1;
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
111 endwhile
ac7f334d9652 Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff changeset
112 endfunction