Mercurial > octave
annotate scripts/plot/appearance/__clabel__.m @ 33670:9dd2a8e7e0d5 default tip @
uifigure.m: Make sure variable exists before it is used (bug #65459).
* scripts/gui/uifigure.m: The variable "props" might have been used before it
existed. Make sure it exists for all code paths.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Mon, 24 Jun 2024 10:29:15 +0200 |
parents | 2e484f9f1f18 |
children |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31706
diff
changeset
|
3 ## Copyright (C) 2008-2024 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
7 ## |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
8 ## This file is part of Octave. |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
9 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24478
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24478
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22353
diff
changeset
|
13 ## (at your option) any later version. |
8289
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 ## 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
|
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22353
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22353
diff
changeset
|
18 ## GNU General Public License for more details. |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
19 ## |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
20 ## 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
|
21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24478
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
25 |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8507
diff
changeset
|
26 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
27 ## @deftypefn {} {@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
|
28 ## Undocumented internal function. |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8507
diff
changeset
|
29 ## @end deftypefn |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
30 |
8507 | 31 function h = __clabel__ (c, v, hparent, label_spacing, z, varargin) |
17176
abf384f5d243
maint: Remove unneeded input validation from internal fcns in private/ directories.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
32 |
17470
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
33 hax = ancestor (hparent, "axes"); |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
34 units = get (hax, "units"); |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
35 set (hax, "units", "points"); |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
36 axpos = get (hax, "position"); |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
37 set (hax, "units", units); |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
38 lims = axis (); |
17470
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
39 xspacing = axpos(3) / (lims(2) - lims (1)); |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
40 yspacing = axpos(4) / (lims(4) - lims (3)); |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
41 |
24478
59041be1994b
Use new function isgraphics to simplify m-files.
Rik <rik@octave.org>
parents:
24423
diff
changeset
|
42 if (isscalar (hparent) && isgraphics (hparent, "hggroup")) |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
43 x = get (hparent, "xdata"); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
44 xmin = min (x(:)); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
45 xmax = max (x(:)); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
46 y = get (hparent, "ydata"); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
47 ymin = min (y(:)); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
48 ymax = max (y(:)); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
49 else |
17470
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
50 xmin = xmax = ymin = ymax = NaN; |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
51 i = 1; |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
52 while (i < length (c)) |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
53 clen = c(2,i); |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
54 data = c(:, i+(1:clen)); |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
55 |
17470
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
56 xmin = min ([xmin, data(1,:)]); |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
57 xmax = max ([xmax, data(1,:)]); |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
58 ymin = min ([ymin, data(2,:)]); |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
59 ymax = max ([ymax, data(2,:)]); |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
60 |
17470
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
61 i += clen+1; |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
62 endwhile |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
63 endif |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
64 |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
65 ## Decode contourc output format and place labels. |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
66 h = []; |
17470
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
67 i = 1; |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
68 while (i < length (c)) |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
69 clev = c(1,i); |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
70 clen = c(2,i); |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
71 |
17470
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
72 if (! isempty (v) && ! any (v == clev)) |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
73 i += clen+1; |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
74 continue; |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
75 endif |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
76 |
17470
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
77 p = bsxfun (@times, c(:, i+(1:clen)), [xspacing; yspacing]); |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
78 d = sqrt (sumsq (diff (p, 1, 2))); |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
79 cumd = cumsum (d); |
17470
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
80 td = cumd(end); |
8507 | 81 ntag = ceil (td / label_spacing); |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
82 |
17470
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
83 if (all (c(:,i+1) == c(:,i+clen))) |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
84 ## Closed contour |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
85 ## FIXME: This spreads the tags uniformly around the contour which |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
86 ## looks nice, but it does not respect the label_spacing attribute. |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
87 ## Should we follow user input, which can result in two labels being |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
88 ## quite close to each other? |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
89 spacing = td / ntag; |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
90 pos = spacing/2 + spacing*[0:ntag-1]; |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
91 else |
17470
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
92 ## Open contour |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
93 pos = zeros (1, ntag); |
17470
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
94 pos(1) = (td - label_spacing*(ntag - 1)) / 2; |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
95 pos(2:ntag) = pos(1) + label_spacing*[1:ntag-1]; |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
96 endif |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
97 |
17470
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
98 tlabel = sprintf ("%.5g", clev); |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
99 |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
100 for tagpos = pos |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
101 |
17470
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
102 j = find (cumd > tagpos, 1); |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
103 if (isempty (j)) |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
104 j = clen; |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
105 endif |
31314
909770674508
__clabel__.m: Do not print erroneous labels (bug #63213)
Tommi Höynälänmaa <tommi.hoynalanmaa@iki.fi>
parents:
30564
diff
changeset
|
106 tpos = sum (c(:,i+j:i+j+1), 2) / 2; |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
107 |
17176
abf384f5d243
maint: Remove unneeded input validation from internal fcns in private/ directories.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
108 if ( tpos(1) != xmin && tpos(1) != xmax |
abf384f5d243
maint: Remove unneeded input validation from internal fcns in private/ directories.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
109 && tpos(2) != ymin && tpos(2) != ymax) |
31314
909770674508
__clabel__.m: Do not print erroneous labels (bug #63213)
Tommi Höynälänmaa <tommi.hoynalanmaa@iki.fi>
parents:
30564
diff
changeset
|
110 trot = 180 / pi * atan2 (diff (c(2,i+j:i+j+1)) * yspacing, |
909770674508
__clabel__.m: Do not print erroneous labels (bug #63213)
Tommi Höynälänmaa <tommi.hoynalanmaa@iki.fi>
parents:
30564
diff
changeset
|
111 diff (c(1,i+j:i+j+1)) * xspacing); |
17470
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
112 if (abs (trot) > 90) |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
113 trot += 180; |
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
114 endif |
29400
4362d6e42bc0
clabel.m: clip labels in parent axes boundaries (bug #60131).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
29358
diff
changeset
|
115 |
10549 | 116 if (ischar (z)) |
29400
4362d6e42bc0
clabel.m: clip labels in parent axes boundaries (bug #60131).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
29358
diff
changeset
|
117 tpos = [tpos.' clev]; |
17470
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
118 elseif (! isempty (z)) |
29400
4362d6e42bc0
clabel.m: clip labels in parent axes boundaries (bug #60131).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
29358
diff
changeset
|
119 tpos = [tpos.' z]; |
10549 | 120 else |
29400
4362d6e42bc0
clabel.m: clip labels in parent axes boundaries (bug #60131).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
29358
diff
changeset
|
121 tpos = [tpos.' 0]; |
10549 | 122 endif |
29434
91f32bf0d497
maint: strip trailing spaces from code base.
Rik <rik@octave.org>
parents:
29400
diff
changeset
|
123 |
29400
4362d6e42bc0
clabel.m: clip labels in parent axes boundaries (bug #60131).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
29358
diff
changeset
|
124 ht = __go_text__ (hparent, "position", tpos, "string", tlabel, ... |
4362d6e42bc0
clabel.m: clip labels in parent axes boundaries (bug #60131).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
29358
diff
changeset
|
125 "rotation", trot, "clipping", "on", ... |
4362d6e42bc0
clabel.m: clip labels in parent axes boundaries (bug #60131).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
29358
diff
changeset
|
126 "horizontalalignment", "center", ... |
4362d6e42bc0
clabel.m: clip labels in parent axes boundaries (bug #60131).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
29358
diff
changeset
|
127 "userdata", clev, varargin{:}); |
10549 | 128 h = [h; ht]; |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
129 endif |
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
130 endfor |
17470
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
131 i += clen+1; |
8289
ac7f334d9652
Add contour group objects and the clabel function
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
132 endwhile |
17470
576cf0589c6d
Overhaul contour labeling functions.
Rik <rik@octave.org>
parents:
17338
diff
changeset
|
133 |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
134 endfunction |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
17176
diff
changeset
|
135 |
19175
cd554c5b65ee
Mark __clabel__ and __getlegenddata__ as internal functions not requiring BIST.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
136 |
cd554c5b65ee
Mark __clabel__ and __getlegenddata__ as internal functions not requiring BIST.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
137 ## No test needed for internal helper function. |
cd554c5b65ee
Mark __clabel__ and __getlegenddata__ as internal functions not requiring BIST.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
138 %!assert (1) |