comparison scripts/plot/text.m @ 17497:96cf8ee3440e

text.m: Match variable names to documentation. * scripts/plot/text.m: Improve docstring. Rename variable 'label' to 'string' to match docstring.
author Rik <rik@octave.org>
date Wed, 25 Sep 2013 17:21:31 -0700
parents eaab03308c0b
children 4166048ba6cf
comparison
equal deleted inserted replaced
17496:5789ad69c85a 17497:96cf8ee3440e
19 ## -*- texinfo -*- 19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} text (@var{x}, @var{y}, @var{string}) 20 ## @deftypefn {Function File} {} text (@var{x}, @var{y}, @var{string})
21 ## @deftypefnx {Function File} {} text (@var{x}, @var{y}, @var{z}, @var{string}) 21 ## @deftypefnx {Function File} {} text (@var{x}, @var{y}, @var{z}, @var{string})
22 ## @deftypefnx {Function File} {} text (@dots{}, @var{prop}, @var{val}, @dots{}) 22 ## @deftypefnx {Function File} {} text (@dots{}, @var{prop}, @var{val}, @dots{})
23 ## @deftypefnx {Function File} {@var{h} =} text (@dots{}) 23 ## @deftypefnx {Function File} {@var{h} =} text (@dots{})
24 ## Create a text object with text @var{string} at position @var{x}, 24 ## Create a text object with text @var{string} at position @var{x}, @var{y},
25 ## @var{y}, @var{z} on the current axes. 25 ## (@var{z}) on the current axes.
26 ## 26 ##
27 ## Optional property/value pairs following may be used to specify the 27 ## Multiple locations can be specified if @var{x}, @var{y}, (@var{z}) are
28 ## appearance of the text. 28 ## vectors. Multiple strings can be specified with a character matrix or
29 ## 29 ## a cell array of strings.
30 ## The optional return value @var{h} is a graphics handle to the created text 30 ##
31 ## object. 31 ## Optional property/value pairs may be used to control the appearance of the
32 ## text.
33 ##
34 ## The optional return value @var{h} is a vector of graphics handles to the
35 ## created text objects.
32 ## @seealso{gtext, title, xlabel, ylabel, zlabel} 36 ## @seealso{gtext, title, xlabel, ylabel, zlabel}
33 ## @end deftypefn 37 ## @end deftypefn
34 38
35 ## Author: jwe 39 ## Author: jwe
36 40
52 else 56 else
53 z = zeros (size (x)); 57 z = zeros (size (x));
54 offset = 3; 58 offset = 3;
55 endif 59 endif
56 60
57 label = varargin{offset}; 61 string = varargin{offset};
58 varargin(1:offset) = []; 62 varargin(1:offset) = [];
59 63
60 nx = numel (x); 64 nx = numel (x);
61 ny = numel (y); 65 ny = numel (y);
62 nz = numel (z); 66 nz = numel (z);
63 if (ischar (label)) 67 if (ischar (string))
64 68
65 do_keyword_repl = true; 69 do_keyword_repl = true;
66 nt = rows (label); 70 nt = rows (string);
67 if (nx == 1 && nt == 1) 71 if (nx == 1 && nt == 1)
68 ## Single text object with one line 72 ## Single text object with one line
69 label = {label}; 73 string = {string};
70 elseif (nx == 1 && nt > 1) 74 elseif (nx == 1 && nt > 1)
71 ## Single text object with multiple lines 75 ## Single text object with multiple lines
72 ## FIXME: "default" or "factory" as first row 76 ## FIXME: "default" or "factory" as first row
73 ## should be escaped to "\default" or "\factory" 77 ## should be escaped to "\default" or "\factory"
74 ## Other rows do not require escaping. 78 ## Other rows do not require escaping.
75 do_keyword_repl = false; 79 do_keyword_repl = false;
76 label = {label}; 80 string = {string};
77 elseif (nx > 1 && nt == nx) 81 elseif (nx > 1 && nt == nx)
78 ## Mutiple text objects with different strings 82 ## Mutiple text objects with different strings
79 label = cellstr (label); 83 string = cellstr (string);
80 else 84 else
81 ## Mutiple text objects with same string 85 ## Mutiple text objects with same string
82 label = repmat ({label}, [nx, 1]); 86 string = repmat ({string}, [nx, 1]);
83 nt = nx; 87 nt = nx;
84 endif 88 endif
85 89
86 ## Escape special keywords 90 ## Escape special keywords
87 if (do_keyword_repl) 91 if (do_keyword_repl)
88 label = regexprep (label, '^(default|factory)$', '\\$1'); 92 string = regexprep (string, '^(default|factory)$', '\\$1');
89 endif 93 endif
90 94
91 elseif (iscell (label)) 95 elseif (iscell (string))
92 96
93 nt = numel (label); 97 nt = numel (string);
94 if (nx == 1) 98 if (nx == 1)
95 ## Single text object with one or more lines 99 ## Single text object with one or more lines
96 label = {label}; 100 string = {string};
97 nt = 1; 101 nt = 1;
98 elseif (nx > 1 && nt == nx) 102 elseif (nx > 1 && nt == nx)
99 ## Mutiple text objects with different strings 103 ## Mutiple text objects with different strings
100 else 104 else
101 ## Mutiple text objects with same string 105 ## Mutiple text objects with same string
102 label = repmat ({label}, [nx, 1]); 106 string = repmat ({string}, [nx, 1]);
103 nt = nx; 107 nt = nx;
104 endif 108 endif
105 109
106 else 110 else
107 111
108 error ("text: LABEL must be a character string or cell array of character strings"); 112 error ("text: STRING must be a character string or cell array of character strings");
109 113
110 endif 114 endif
111 else # Only PROP/VALUE pairs 115 else # Only PROP/VALUE pairs
112 x = y = z = 0; 116 x = y = z = 0;
113 nx = ny = nz = 1; 117 nx = ny = nz = 1;
114 label = {""}; 118 string = {""};
115 nt = 1; 119 nt = 1;
116 endif 120 endif
117 121
118 ## Any remaining inputs must occur as PROPERTY/VALUE pairs 122 ## Any remaining inputs must occur as PROPERTY/VALUE pairs
119 if (rem (numel (varargin), 2) != 0) 123 if (rem (numel (varargin), 2) != 0)
129 133
130 if (nx == ny && nx == nz && (nt == nx || nt == 1 || nx == 1)) 134 if (nx == ny && nx == nz && (nt == nx || nt == 1 || nx == 1))
131 pos = [x(:), y(:), z(:)]; 135 pos = [x(:), y(:), z(:)];
132 htmp = zeros (nt, 1); 136 htmp = zeros (nt, 1);
133 if (nx == 1) 137 if (nx == 1)
134 htmp = __go_text__ (hax, "string", label{1}, 138 htmp = __go_text__ (hax, "string", string{1},
135 varargin{:}, 139 varargin{:},
136 "position", pos); 140 "position", pos);
137 elseif (nx == nt) 141 elseif (nx == nt)
138 for n = 1:nt 142 for n = 1:nt
139 htmp(n) = __go_text__ (hax, "string", label{n}, 143 htmp(n) = __go_text__ (hax, "string", string{n},
140 varargin{:}, 144 varargin{:},
141 "position", pos(n,:)); 145 "position", pos(n,:));
142 endfor 146 endfor
143 __request_drawnow__ (); 147 __request_drawnow__ ();
144 else 148 else
145 error ("text: dimension mismatch for coordinates and LABEL"); 149 error ("text: dimension mismatch for coordinates and STRING");
146 endif 150 endif
147 elseif (nt == nx || nt == 1 || nx == 1) 151 elseif (nt == nx || nt == 1 || nx == 1)
148 error ("text: dimension mismatch for coordinates"); 152 error ("text: dimension mismatch for coordinates");
149 else 153 else
150 error ("text: dimension mismatch between coordinates and strings"); 154 error ("text: dimension mismatch between coordinates and strings");