1 ## Copyright (C) 2008-2012 David Bateman
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {@var{h} =} __clabel__ (@var{c}, @var{v}, @var{hparent}, @var{label_spacing}, @var{z}, @var{varargin})
21 ## Undocumented internal function.
24 function h = __clabel__ (c, v, hparent, label_spacing, z, varargin)
26 ## Assume that the plot size is 4 by 3 inches.
28 xspacing = 72 * 4 / abs(lims(1) - lims(2));
29 yspacing = 72 * 3 / abs(lims(3) - lims(4));
31 if (isscalar (hparent) && ishandle(hparent)
32 && strcmp (get (hparent, "type"), "hggroup"))
33 x = get (hparent, "xdata");
36 y = get (hparent, "ydata");
41 while (i1 < length (c))
44 p = c(:, i1+1:i1+clen);
55 ## Decode contourc output format and place labels.
58 while (i1 < length (c))
62 if (!isempty (v) && ! any (find (clev == v)))
67 p = c(:, i1+1:i1+clen) .* repmat ([xspacing; yspacing], 1, clen);
68 d = sqrt (sumsq (diff (p, 1, 2)));
71 ntag = ceil (td / label_spacing);
73 if (all (c(:,i1+1) == c(:,i1+clen)))
75 pos = Spacing / 2 + [0:ntag-1] * Spacing;
78 pos(1) = (td - label_spacing * (ntag - 1)) ./ 2;
79 pos(2:ntag) = pos(1) + [1:ntag-1] * label_spacing;
83 tlabel = sprintf ("%g", clev);
87 while (j1 < clen && cumd(j1) < tagpos)
90 tpos = sum(c(:,i1+j1-1:i1+j1), 2) ./ 2;
92 if (tpos(1) != xmin && tpos(1) != xmax
93 && tpos(2) != ymin && tpos(2) != ymax)
94 trot = 180 / pi * atan2 (diff (c(2,i1+j1-1:i1+j1)),
95 diff (c(1,i1+j1-1:i1+j1)));
98 ht = text (tpos(1), tpos(2), clev, tlabel, "rotation", trot,
99 "parent", hparent, "horizontalalignment", "center",
100 "userdata", clev, varargin{:});
101 elseif (!isempty (z))
102 ht = text (tpos(1), tpos(2), z, tlabel, "rotation", trot,
103 "parent", hparent, "horizontalalignment", "center",
104 "userdata", clev, varargin{:});
106 ht = text (tpos(1), tpos(2), tlabel, "rotation", trot,
107 "parent", hparent, "horizontalalignment", "center",
108 "userdata", clev, varargin{:});