comparison scripts/plot/private/__bar__.m @ 10549:95c3e38098bf

Untabify .m scripts
author Rik <code@nomad.inbox5.com>
date Fri, 23 Apr 2010 11:28:50 -0700
parents 1aeb39118764
children 1840a0ecf1fb
comparison
equal deleted inserted replaced
10548:479536c5bb10 10549:95c3e38098bf
46 y = y(:); 46 y = y(:);
47 endif 47 endif
48 if (size (x, 1) != size (y, 1)) 48 if (size (x, 1) != size (y, 1))
49 y = varargin{1}; 49 y = varargin{1};
50 if (isvector (y)) 50 if (isvector (y))
51 y = y(:); 51 y = y(:);
52 endif 52 endif
53 x = [1:size(y,1)]'; 53 x = [1:size(y,1)]';
54 idx = 2; 54 idx = 2;
55 else 55 else
56 if (! isvector (x)) 56 if (! isvector (x))
57 error ("%s: x must be a vector", func); 57 error ("%s: x must be a vector", func);
58 endif 58 endif
59 idx = 3; 59 idx = 3;
60 endif 60 endif
61 else 61 else
62 y = varargin{1}; 62 y = varargin{1};
76 elseif (ischar (varargin{idx}) && strcmpi (varargin{idx}, "stacked")) 76 elseif (ischar (varargin{idx}) && strcmpi (varargin{idx}, "stacked"))
77 group = false; 77 group = false;
78 idx++; 78 idx++;
79 else 79 else
80 if ((ischar (varargin{idx}) || iscell (varargin{idx})) 80 if ((ischar (varargin{idx}) || iscell (varargin{idx}))
81 && ! have_line_spec) 81 && ! have_line_spec)
82 [linespec, valid] = __pltopt__ (func, varargin{idx}, false); 82 [linespec, valid] = __pltopt__ (func, varargin{idx}, false);
83 if (valid) 83 if (valid)
84 have_line_spec = true; 84 have_line_spec = true;
85 newargs = [{linespec.color}, newargs]; 85 newargs = [{linespec.color}, newargs];
86 idx++; 86 idx++;
87 continue; 87 continue;
88 endif 88 endif
89 endif 89 endif
90 if (isscalar(varargin{idx})) 90 if (isscalar(varargin{idx}))
91 width = varargin{idx++}; 91 width = varargin{idx++};
92 elseif (idx == nargin - 2) 92 elseif (idx == nargin - 2)
93 newargs = [newargs,varargin(idx++)]; 93 newargs = [newargs,varargin(idx++)];
94 elseif (ischar (varargin{idx}) 94 elseif (ischar (varargin{idx})
95 && strcmpi (varargin{idx}, "basevalue") 95 && strcmpi (varargin{idx}, "basevalue")
96 && isscalar (varargin{idx+1})) 96 && isscalar (varargin{idx+1}))
97 bv = varargin{idx+1}; 97 bv = varargin{idx+1};
98 idx += 2; 98 idx += 2;
99 else 99 else
100 newargs = [newargs,varargin(idx:idx+1)]; 100 newargs = [newargs,varargin(idx:idx+1)];
101 idx += 2; 101 idx += 2;
102 endif 102 endif
103 endif 103 endif
104 endwhile 104 endwhile
105 105
106 xlen = size (x, 1); 106 xlen = size (x, 1);
151 unwind_protect 151 unwind_protect
152 axes (h); 152 axes (h);
153 newplot (); 153 newplot ();
154 154
155 tmp = bars (h, vertical, x, y, xb, yb, width, group, 155 tmp = bars (h, vertical, x, y, xb, yb, width, group,
156 have_line_spec, bv, newargs{:}); 156 have_line_spec, bv, newargs{:});
157 if (nargout == 1) 157 if (nargout == 1)
158 varargout{1} = tmp; 158 varargout{1} = tmp;
159 endif 159 endif
160 unwind_protect_cleanup 160 unwind_protect_cleanup
161 axes (oldh); 161 axes (oldh);
162 end_unwind_protect 162 end_unwind_protect
163 else 163 else
183 tmp = [tmp; hg]; 183 tmp = [tmp; hg];
184 args = __add_datasource__ ("bar", hg, {"x", "y"}, varargin{:}); 184 args = __add_datasource__ ("bar", hg, {"x", "y"}, varargin{:});
185 185
186 if (vertical) 186 if (vertical)
187 if (! have_color_spec) 187 if (! have_color_spec)
188 if (ycols == 1) 188 if (ycols == 1)
189 lev = clim(1); 189 lev = clim(1);
190 else 190 else
191 lev = (i - 1) * (clim(2) - clim(1)) / (ycols - 1) - clim(1); 191 lev = (i - 1) * (clim(2) - clim(1)) / (ycols - 1) - clim(1);
192 endif 192 endif
193 h = patch(xb(:,:,i), yb(:,:,i), "FaceColor", "flat", 193 h = patch(xb(:,:,i), yb(:,:,i), "FaceColor", "flat",
194 "cdata", lev, "parent", hg); 194 "cdata", lev, "parent", hg);
195 else 195 else
196 h = patch(xb(:,:,i), yb(:,:,i), "parent", hg); 196 h = patch(xb(:,:,i), yb(:,:,i), "parent", hg);
197 endif 197 endif
198 else 198 else
199 if (! have_color_spec) 199 if (! have_color_spec)
200 if (ycols == 1) 200 if (ycols == 1)
201 lev = clim(1) 201 lev = clim(1)
202 else 202 else
203 lev = (i - 1) * (clim(2) - clim(1)) / (ycols - 1) - clim(1); 203 lev = (i - 1) * (clim(2) - clim(1)) / (ycols - 1) - clim(1);
204 endif 204 endif
205 h = patch(yb(:,:,i), xb(:,:,i), "FaceColor", "flat", 205 h = patch(yb(:,:,i), xb(:,:,i), "FaceColor", "flat",
206 "cdata", lev, "parent", hg); 206 "cdata", lev, "parent", hg);
207 else 207 else
208 h = patch(yb(:,:,i), xb(:,:,i), "parent", hg); 208 h = patch(yb(:,:,i), xb(:,:,i), "parent", hg);
209 endif 209 endif
210 endif 210 endif
211 211
212 if (i == 1) 212 if (i == 1)
213 x_axis_range = get (ax, "xlim"); 213 x_axis_range = get (ax, "xlim");
282 282
283 for i = 1 : length (kids) 283 for i = 1 : length (kids)
284 obj = get (kids (i)); 284 obj = get (kids (i));
285 if (strcmp (obj.type, "hggroup") && isfield (obj, "baseline")) 285 if (strcmp (obj.type, "hggroup") && isfield (obj, "baseline"))
286 if (any (get (obj.baseline, "xdata") != xlim)) 286 if (any (get (obj.baseline, "xdata") != xlim))
287 set (obj.baseline, "xdata", xlim); 287 set (obj.baseline, "xdata", xlim);
288 endif 288 endif
289 endif 289 endif
290 endfor 290 endfor
291 endfunction 291 endfunction
292 292
296 296
297 kids = get (get (h, "parent"), "children"); 297 kids = get (get (h, "parent"), "children");
298 for i = 1 : length (kids) 298 for i = 1 : length (kids)
299 obj = get (kids (i)); 299 obj = get (kids (i));
300 if (strcmp (obj.type, "hggroup") && isfield (obj, "baseline") 300 if (strcmp (obj.type, "hggroup") && isfield (obj, "baseline")
301 && obj.baseline == h) 301 && obj.baseline == h)
302 ## Only alter if changed to avoid recursion of the listener functions 302 ## Only alter if changed to avoid recursion of the listener functions
303 if (! strcmpi (get (kids(i), "showbaseline"), visible)) 303 if (! strcmpi (get (kids(i), "showbaseline"), visible))
304 set (kids (i), "showbaseline", visible); 304 set (kids (i), "showbaseline", visible);
305 endif 305 endif
306 if (! strcmpi (get (kids(i), "basevalue"), visible)) 306 if (! strcmpi (get (kids(i), "basevalue"), visible))
307 set (kids (i), "basevalue", ydata); 307 set (kids (i), "basevalue", ydata);
308 endif 308 endif
309 endif 309 endif
310 endfor 310 endfor
311 endfunction 311 endfunction
312 312
318 unwind_protect 318 unwind_protect
319 recursion = true; 319 recursion = true;
320 hlist = get (h, "bargroup"); 320 hlist = get (h, "bargroup");
321 showbaseline = get (h, "showbaseline"); 321 showbaseline = get (h, "showbaseline");
322 for hh = hlist(:)' 322 for hh = hlist(:)'
323 if (hh != h) 323 if (hh != h)
324 set (hh, "showbaseline", showbaseline); 324 set (hh, "showbaseline", showbaseline);
325 endif 325 endif
326 endfor 326 endfor
327 set (get (h, "baseline"), "visible", showbaseline); 327 set (get (h, "baseline"), "visible", showbaseline);
328 unwind_protect_cleanup 328 unwind_protect_cleanup
329 recursion = false; 329 recursion = false;
330 end_unwind_protect 330 end_unwind_protect
360 unwind_protect 360 unwind_protect
361 recursion = true; 361 recursion = true;
362 hlist = get (h, "bargroup"); 362 hlist = get (h, "bargroup");
363 x = get (h, "xdata"); 363 x = get (h, "xdata");
364 if (!isvector (x)) 364 if (!isvector (x))
365 x = x(:); 365 x = x(:);
366 endif 366 endif
367 y = []; 367 y = [];
368 for hh = hlist(:)' 368 for hh = hlist(:)'
369 ytmp = get (hh, "ydata"); 369 ytmp = get (hh, "ydata");
370 y = [y ytmp(:)]; 370 y = [y ytmp(:)];
371 endfor 371 endfor
372 372
373 [xb, yb] = bar (x, y, get (h, "barwidth"), get (h, "barlayout"), 373 [xb, yb] = bar (x, y, get (h, "barwidth"), get (h, "barlayout"),
374 "basevalue", get (h, "basevalue")); 374 "basevalue", get (h, "basevalue"));
375 ny = columns (y); 375 ny = columns (y);
376 vert = strcmpi (get (h, "horizontal"), "off"); 376 vert = strcmpi (get (h, "horizontal"), "off");
377 377
378 for i = 1:ny 378 for i = 1:ny
379 hp = get (hlist(i), "children"); 379 hp = get (hlist(i), "children");
380 if (vert) 380 if (vert)
381 set (hp, "xdata", xb(:,:,i), "ydata", yb(:,:,i)); 381 set (hp, "xdata", xb(:,:,i), "ydata", yb(:,:,i));
382 else 382 else
383 set (hp, "xdata", yb(:,:,i), "ydata", xb(:,:,i)); 383 set (hp, "xdata", yb(:,:,i), "ydata", xb(:,:,i));
384 endif 384 endif
385 endfor 385 endfor
386 unwind_protect_cleanup 386 unwind_protect_cleanup
387 recursion = false; 387 recursion = false;
388 end_unwind_protect 388 end_unwind_protect
389 endif 389 endif
401 barlayout = get (h, "barlayout"); 401 barlayout = get (h, "barlayout");
402 horizontal = get (h, "horizontal"); 402 horizontal = get (h, "horizontal");
403 403
404 ## To prevent recursion, only change if modified 404 ## To prevent recursion, only change if modified
405 for hh = hlist(:)' 405 for hh = hlist(:)'
406 if (hh != h) 406 if (hh != h)
407 if (get (hh, "barwidth") != barwidth) 407 if (get (hh, "barwidth") != barwidth)
408 set (hh, "barwidth", barwidth); 408 set (hh, "barwidth", barwidth);
409 endif 409 endif
410 if (! strcmpi (get (hh, "barlayout"), barlayout)) 410 if (! strcmpi (get (hh, "barlayout"), barlayout))
411 set (hh, "barlayout", barlayout); 411 set (hh, "barlayout", barlayout);
412 endif 412 endif
413 if (! strcmpi (get (hh, "horizontal"), horizontal)) 413 if (! strcmpi (get (hh, "horizontal"), horizontal))
414 set (hh, "horizontal", horizontal); 414 set (hh, "horizontal", horizontal);
415 endif 415 endif
416 endif 416 endif
417 endfor 417 endfor
418 update_data (h, d); 418 update_data (h, d);
419 unwind_protect_cleanup 419 unwind_protect_cleanup
420 recursion = false; 420 recursion = false;
421 end_unwind_protect 421 end_unwind_protect