comparison scripts/plot/private/__getlegenddata__.m @ 17539:485aeffc0c22

__getlegenddata__.m: Recode for better performance. * scripts/plot/private/__getlegenddata__.m: Use try/catch block instead of getting all fields into a struct.
author Rik <rik@octave.org>
date Wed, 02 Oct 2013 21:35:59 -0700
parents 1c89599167a6
children
comparison
equal deleted inserted replaced
17538:b29c8a067c11 17539:485aeffc0c22
20 ## @deftypefn {Function File} {[@var{hplots}, @var{strings}]} = __getlegenddata__ (@var{h}) 20 ## @deftypefn {Function File} {[@var{hplots}, @var{strings}]} = __getlegenddata__ (@var{h})
21 ## Undocumented internal function. 21 ## Undocumented internal function.
22 ## @end deftypefn 22 ## @end deftypefn
23 23
24 function [hplots, text_strings] = __getlegenddata__ (hlegend) 24 function [hplots, text_strings] = __getlegenddata__ (hlegend)
25
25 hplots = []; 26 hplots = [];
26 text_strings = {}; 27 text_strings = {};
27 ca = getfield (get (hlegend, "userdata"), "handle"); 28 ca = getfield (get (hlegend, "userdata"), "handle");
28 kids = []; 29 if (numel (ca) == 1)
29 for i = 1:numel (ca) 30 kids = get (ca, "children");
30 kids = [kids; get(ca(i), "children")]; 31 else
31 endfor 32 kids = [get(kids, "children"){:}];
33 endif
32 34
33 for i = numel (kids):-1:1 35 for i = numel (kids):-1:1
34 typ = get (kids(i), "type"); 36 typ = get (kids(i), "type");
35 if (strcmp (typ, "line") || strcmp (typ, "surface") 37 if (any (strcmp (typ, {"line", "patch", "surface", "hggroup"})))
36 || strcmp (typ, "patch") || strcmp (typ, "hggroup"))
37
38 if (strcmp (typ, "hggroup")) 38 if (strcmp (typ, "hggroup"))
39 hgkids = get (kids(i), "children"); 39 hgkids = get (kids(i), "children");
40 for j = 1 : length (hgkids) 40 for j = 1 : length (hgkids)
41 hgobj = get (hgkids (j)); 41 try
42 if (isfield (hgobj, "displayname") && ! isempty (hgobj.displayname)) 42 dname = get (hgkids(j), "DisplayName");
43 hplots = [hplots, hgkids(j)]; 43 if (! isempty (dname))
44 text_strings = {text_strings{:}, hgobj.displayname}; 44 hplots(end+1) = hgkids(j);
45 break; 45 text_strings(end+1) = dname;
46 endif 46 break; # break from j-loop over hgkids
47 endif
48 end_try_catch
47 endfor 49 endfor
48 else 50 else
49 if (! isempty (get (kids (i), "displayname"))) 51 dname = get (kids(i), "DisplayName");
50 hplots = [hplots, kids(i)]; 52 if (! isempty (dname))
51 text_strings = {text_strings{:}, get(kids (i), "displayname")}; 53 hplots(end+1) = kids(i);
54 text_strings(end+1) = dname;
52 endif 55 endif
53 endif 56 endif
54
55 endif 57 endif
56 endfor 58 endfor
57 59
58 endfunction 60 endfunction
59 61