6257
|
1 ## Copyright (C) 2007 John W. Eaton |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
6257
|
9 ## |
|
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. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
6257
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{label}) |
|
21 ## @deftypefnx {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{z}, @var{label}) |
6895
|
22 ## @deftypefnx {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{label}, @var{p1}, @var{v1}, @dots{}) |
|
23 ## @deftypefnx {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{z}, @var{label}, @var{p1}, @var{v1}, @dots{}) |
6257
|
24 ## Create a text object with text @var{label} at position @var{x}, |
6895
|
25 ## @var{y}, @var{z} on the current axes. Property-value pairs following |
|
26 ## @var{label} may be used to specify the appearance of the text. |
6257
|
27 ## @end deftypefn |
|
28 |
|
29 ## Author: jwe |
|
30 |
|
31 function h = text (varargin) |
|
32 |
6405
|
33 nargs = nargin; |
|
34 offset = 0; |
|
35 |
|
36 if (nargs > 2 && isnumeric (varargin{1}) && isnumeric (varargin{2})) |
|
37 x = varargin{1}; |
|
38 y = varargin{2}; |
|
39 offset = 3; |
6257
|
40 |
|
41 if (nargin > 3 && isnumeric (varargin{3})) |
|
42 z = varargin{3}; |
|
43 offset = 4; |
|
44 else |
|
45 z = zeros (size (x)); |
|
46 offset = 3; |
|
47 endif |
|
48 |
|
49 label = varargin{offset}; |
|
50 if (ischar (label) || iscellstr (label)) |
|
51 varargin(1:offset) = []; |
|
52 if (ischar (label)) |
10549
|
53 label = cellstr (label); |
6257
|
54 endif |
|
55 n = numel (label); |
|
56 nx = numel (x); |
|
57 ny = numel (y); |
|
58 nz = numel (z); |
|
59 else |
|
60 error ("text: expecting label to be a character string or cell array of character strings"); |
|
61 endif |
6405
|
62 else |
|
63 x = y = z = 0; |
|
64 nx = ny = nz = 1; |
|
65 label = {""}; |
|
66 n = 1; |
|
67 endif |
6257
|
68 |
6405
|
69 if (rem (numel (varargin), 2) == 0) |
|
70 |
|
71 if (nx == ny && nx == nz) |
|
72 pos = [x(:), y(:), z(:)]; |
|
73 ca = gca (); |
|
74 tmp = zeros (n, 1); |
|
75 if (n == 1) |
10549
|
76 label = label{1}; |
|
77 for i = 1:nx |
|
78 tmp(i) = __go_text__ (ca, "string", label, |
|
79 "position", pos(i,:), |
|
80 varargin{:}); |
|
81 endfor |
|
82 __request_drawnow__ (); |
6405
|
83 elseif (n == nx) |
10549
|
84 for i = 1:nx |
|
85 tmp(i) = __go_text__ (ca, "string", label{i}, |
|
86 "position", pos(i,:), |
|
87 varargin{:}); |
|
88 endfor |
|
89 __request_drawnow__ (); |
6405
|
90 else |
10549
|
91 error ("text: dimension mismatch for coordinates and label"); |
6405
|
92 endif |
|
93 else |
|
94 error ("text: dimension mismatch for coordinates"); |
|
95 endif |
6257
|
96 |
|
97 if (nargout > 0) |
|
98 h = tmp; |
|
99 endif |
|
100 |
|
101 else |
|
102 print_usage (); |
|
103 endif |
|
104 |
|
105 endfunction |