comparison scripts/plot/text.m @ 6257:44c91c5dfe1d

[project @ 2007-01-30 19:16:52 by jwe]
author jwe
date Tue, 30 Jan 2007 19:16:55 +0000
parents
children b298a4c12fc3
comparison
equal deleted inserted replaced
6256:83949ae13b2c 6257:44c91c5dfe1d
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
7 ## the Free Software Foundation; either version 2, or (at your option)
8 ## any later version.
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
16 ## along with Octave; see the file COPYING. If not, write to the Free
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 ## 02110-1301, USA.
19
20 ## -*- texinfo -*-
21 ## @deftypefn {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{label})
22 ## @deftypefnx {Function File} {@var{h} =} text (@var{x}, @var{y}, @var{z}, @var{label})
23 ## Create a text object with text @var{label} at position @var{x},
24 ## @var{y}, @var{z} on the current axes. The label may be followed by
25 ## property-value pairs.
26 ## @end deftypefn
27
28 ## Author: jwe
29
30 function h = text (varargin)
31
32 if (nargin > 2)
33 x = y = z = 0;
34 if (isnumeric (varargin{1}) && isnumeric (varargin{2}))
35 x = varargin{1};
36 y = varargin{2};
37 else
38 error ("text: expecting first two arguments to be numeric");
39 endif
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))
53 label = cellstr (label);
54 endif
55 n = numel (label);
56 nx = numel (x);
57 ny = numel (y);
58 nz = numel (z);
59 if (nx == ny && nx == nz)
60 pos = [x(:), y(:), z(:)];
61 ca = gca ();
62 tmp = zeros (n, 1);
63 if (n == 1)
64 label = label{1};
65 for i = 1:nx
66 tmp(i) = __uiobject_text_ctor__ (ca, "string", label,
67 "position", pos(i,:),
68 varargin{:});
69 endfor
70 elseif (n == nx)
71 for i = 1:nx
72 tmp(i) = __uiobject_text_ctor__ (ca, "string", label{i},
73 "position", pos(i,:),
74 varargin{:});
75 endfor
76 else
77 error ("text: dimension mismatch for coordinates and label");
78 endif
79 else
80 error ("text: dimension mismatch for coordinates");
81 endif
82 else
83 error ("text: expecting label to be a character string or cell array of character strings");
84 endif
85
86 for i = 1:numel (tmp)
87 __uiobject_adopt__ (ca, tmp(i));
88 endfor
89
90 if (nargout > 0)
91 h = tmp;
92 endif
93
94 else
95 print_usage ();
96 endif
97
98 endfunction