comparison scripts/plot/legend.m @ 10549:95c3e38098bf

Untabify .m scripts
author Rik <code@nomad.inbox5.com>
date Fri, 23 Apr 2010 11:28:50 -0700
parents f9fb8c1a8e45
children 3afcd24ced61
comparison
equal deleted inserted replaced
10548:479536c5bb10 10549:95c3e38098bf
83 83
84 if (nargs > 0) 84 if (nargs > 0)
85 pos = varargin{nargs}; 85 pos = varargin{nargs};
86 if (isnumeric (pos) && isscalar (pos) && round (pos) == pos) 86 if (isnumeric (pos) && isscalar (pos) && round (pos) == pos)
87 if (pos >= -1 && pos <= 4) 87 if (pos >= -1 && pos <= 4)
88 set (ca, "keypos", pos); 88 set (ca, "keypos", pos);
89 nargs--; 89 nargs--;
90 else 90 else
91 error ("legend: invalid position specified"); 91 error ("legend: invalid position specified");
92 endif 92 endif
93 endif 93 endif
94 endif 94 endif
95 95
96 if (nargs > 1) 96 if (nargs > 1)
109 109
110 if (nargs == 1) 110 if (nargs == 1)
111 arg = varargin{1}; 111 arg = varargin{1};
112 if (ischar (arg)) 112 if (ischar (arg))
113 if (rows (arg) == 1) 113 if (rows (arg) == 1)
114 str = tolower (deblank (arg)); 114 str = tolower (deblank (arg));
115 switch (str) 115 switch (str)
116 case {"off", "hide"} 116 case {"off", "hide"}
117 set (ca, "key", "off"); 117 set (ca, "key", "off");
118 nargs--; 118 nargs--;
119 case "show" 119 case "show"
120 set (ca, "key", "on"); 120 set (ca, "key", "on");
121 nargs--; 121 nargs--;
122 case "toggle" 122 case "toggle"
123 val = get (ca, "key"); 123 val = get (ca, "key");
124 if (strcmpi (val, "on")) 124 if (strcmpi (val, "on"))
125 set (ca, "key", "off"); 125 set (ca, "key", "off");
126 else 126 else
127 set (ca, "key", "on"); 127 set (ca, "key", "on");
128 endif 128 endif
129 nargs--; 129 nargs--;
130 case "boxon" 130 case "boxon"
131 set (ca, "key", "on", "keybox", "on"); 131 set (ca, "key", "on", "keybox", "on");
132 nargs--; 132 nargs--;
133 case "boxoff" 133 case "boxoff"
134 set (ca, "keybox", "off"); 134 set (ca, "keybox", "off");
135 nargs--; 135 nargs--;
136 case "left" 136 case "left"
137 set (ca, "keyreverse", "off") 137 set (ca, "keyreverse", "off")
138 nargs--; 138 nargs--;
139 case "right" 139 case "right"
140 set (ca, "keyreverse", "on") 140 set (ca, "keyreverse", "on")
141 nargs--; 141 nargs--;
142 otherwise 142 otherwise
143 endswitch 143 endswitch
144 else 144 else
145 varargin = cellstr (arg); 145 varargin = cellstr (arg);
146 nargs = numel (varargin); 146 nargs = numel (varargin);
147 endif 147 endif
148 elseif (iscellstr (arg)) 148 elseif (iscellstr (arg))
149 varargin = arg; 149 varargin = arg;
150 nargs = numel (varargin); 150 nargs = numel (varargin);
151 else 151 else
156 if (nargs > 0) 156 if (nargs > 0)
157 have_data = false; 157 have_data = false;
158 for k = 1:nkids 158 for k = 1:nkids
159 typ = get (kids(k), "type"); 159 typ = get (kids(k), "type");
160 if (strcmp (typ, "line") || strcmp (typ, "surface") 160 if (strcmp (typ, "line") || strcmp (typ, "surface")
161 || strcmp (typ, "patch") || strcmp (typ, "hggroup")) 161 || strcmp (typ, "patch") || strcmp (typ, "hggroup"))
162 have_data = true; 162 have_data = true;
163 break; 163 break;
164 endif 164 endif
165 endfor 165 endfor
166 if (! have_data) 166 if (! have_data)
167 warning ("legend: plot data is empty; setting key labels has no effect"); 167 warning ("legend: plot data is empty; setting key labels has no effect");
168 endif 168 endif
173 for i = 1:nargs 173 for i = 1:nargs
174 arg = varargin{i}; 174 arg = varargin{i};
175 if (ischar (arg)) 175 if (ischar (arg))
176 typ = get (kids(k), "type"); 176 typ = get (kids(k), "type");
177 while (k > 1 177 while (k > 1
178 && ! (strcmp (typ, "line") || strcmp (typ, "surface") 178 && ! (strcmp (typ, "line") || strcmp (typ, "surface")
179 || strcmp (typ, "patch") || strcmp (typ, "hggroup"))) 179 || strcmp (typ, "patch") || strcmp (typ, "hggroup")))
180 typ = get (kids(--k), "type"); 180 typ = get (kids(--k), "type");
181 endwhile 181 endwhile
182 if (k > 0) 182 if (k > 0)
183 if (strcmp (get (kids(k), "type"), "hggroup")) 183 if (strcmp (get (kids(k), "type"), "hggroup"))
184 hgkids = get (kids(k), "children"); 184 hgkids = get (kids(k), "children");
185 for j = 1 : length (hgkids) 185 for j = 1 : length (hgkids)
186 hgobj = get (hgkids (j)); 186 hgobj = get (hgkids (j));
187 if (isfield (hgobj, "keylabel")) 187 if (isfield (hgobj, "keylabel"))
188 set (hgkids(j), "keylabel", arg); 188 set (hgkids(j), "keylabel", arg);
189 break; 189 break;
190 endif 190 endif
191 endfor 191 endfor
192 else 192 else
193 set (kids(k), "keylabel", arg); 193 set (kids(k), "keylabel", arg);
194 endif 194 endif
195 turn_on_legend = true; 195 turn_on_legend = true;
196 if (--k == 0) 196 if (--k == 0)
197 break; 197 break;
198 endif 198 endif
199 elseif (! warned) 199 elseif (! warned)
200 warned = true; 200 warned = true;
201 warning ("legend: ignoring extra labels"); 201 warning ("legend: ignoring extra labels");
202 endif 202 endif
203 else 203 else
204 error ("legend: expecting argument to be a character string"); 204 error ("legend: expecting argument to be a character string");
205 endif 205 endif
206 endfor 206 endfor