Mercurial > hg > octave-nkf
comparison scripts/plot/shading.m @ 17101:c2b2c7ddf93c
shading.m: Don't apply shading to contour hggroups.
* scripts/plot/shading.m: Search through graphic handle
hierarchy and apply shading to patch and surface objects
which are *NOT* in contour hggroups.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 28 Jul 2013 17:15:37 -0700 |
parents | bade805dc0af |
children | eaab03308c0b |
comparison
equal
deleted
inserted
replaced
17100:ae7872816611 | 17101:c2b2c7ddf93c |
---|---|
16 ## along with Octave; see the file COPYING. If not, see | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | 17 ## <http://www.gnu.org/licenses/>. |
18 | 18 |
19 ## -*- texinfo -*- | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} shading (@var{type}) | 20 ## @deftypefn {Function File} {} shading (@var{type}) |
21 ## @deftypefnx {Function File} {} shading (@var{ax}, @var{type}) | 21 ## @deftypefnx {Function File} {} shading (@var{hax}, @var{type}) |
22 ## Set the shading of surface or patch graphic objects. Valid arguments | 22 ## Set the shading of surface or patch graphic objects. |
23 ## for @var{type} are | 23 ## |
24 ## Valid arguments for @var{type} are | |
24 ## | 25 ## |
25 ## @table @asis | 26 ## @table @asis |
26 ## @item "flat" | 27 ## @item "flat" |
27 ## Single colored patches with invisible edges. | 28 ## Single colored patches with invisible edges. |
28 ## | 29 ## |
32 ## @item "interp" | 33 ## @item "interp" |
33 ## Color between patch vertices are interpolated and the patch edges are | 34 ## Color between patch vertices are interpolated and the patch edges are |
34 ## invisible. | 35 ## invisible. |
35 ## @end table | 36 ## @end table |
36 ## | 37 ## |
37 ## If @var{hax} is given the shading is applied to axis @var{hax} instead | 38 ## If the first argument @var{hax} is an axes handle, then plot into this axis, |
38 ## of the current axis. | 39 ## rather than the current axes returned by @code{gca}. |
40 ## If the first argument @var{hax} is an axes handle, then operate on | |
41 ## this axis rather than the current axes returned by @code{gca}. | |
39 ## @end deftypefn | 42 ## @end deftypefn |
40 | 43 |
41 ## Author: Kai Habel <kai.habel@gmx.de> | 44 ## Author: Kai Habel <kai.habel@gmx.de> |
42 | 45 |
43 function shading (varargin) | 46 function shading (varargin) |
52 | 55 |
53 if (isempty (hax)) | 56 if (isempty (hax)) |
54 hax = gca (); | 57 hax = gca (); |
55 endif | 58 endif |
56 | 59 |
57 hp = findobj (hax, "type", "patch"); | 60 ## Find all patch and surface objects that are descendants of hax |
58 hs = findobj (hax, "type", "surface"); | 61 ## and which are not part of a contour plot hggroup. |
59 hall = [hp(:); hs(:)]; | 62 hlist = []; |
63 kids = get (hax, "children"); | |
64 while (! isempty (kids)) | |
65 types = get (kids, "type"); | |
66 hlist = [hlist; kids(strcmp(types, "patch"))]; | |
67 hlist = [hlist; kids(strcmp(types, "surface"))]; | |
68 parents = kids(strcmp(types, "axes")); | |
69 hglist = kids(strcmp (types, "hggroup")); | |
70 for i = 1 : numel (hglist) | |
71 props = get (hglist(i)); | |
72 if (! isfield (props, "levelstep")) | |
73 parents(end+1) = hglist(i); | |
74 endif | |
75 endfor | |
76 kids = get (parents, "children"); | |
77 endwhile | |
78 | |
79 ## FIXME: This is the old, simple code. | |
80 ## Unfortunately, it also shades contour plots which is not desirable. | |
81 ##hp = findobj (hax, "type", "patch"); | |
82 ##hs = findobj (hax, "type", "surface"); | |
83 ##hlist = [hp(:); hs(:)]; | |
60 | 84 |
61 switch (lower (mode)) | 85 switch (lower (mode)) |
62 case "flat" | 86 case "flat" |
63 set (hall, "facecolor", "flat"); | 87 set (hlist, "facecolor", "flat"); |
64 set (hall, "edgecolor", "none"); | 88 set (hlist, "edgecolor", "none"); |
65 case "interp" | 89 case "interp" |
66 set (hall, "facecolor", "interp"); | 90 set (hlist, "facecolor", "interp"); |
67 set (hall, "edgecolor", "none"); | 91 set (hlist, "edgecolor", "none"); |
68 case "faceted" | 92 case "faceted" |
69 set (hall, "facecolor", "flat"); | 93 set (hlist, "facecolor", "flat"); |
70 set (hall, "edgecolor", [0 0 0]); | 94 set (hlist, "edgecolor", [0 0 0]); |
71 otherwise | 95 otherwise |
72 error ('shading: Invalid MODE "%s"', mode); | 96 error ('shading: Invalid MODE "%s"', mode); |
73 endswitch | 97 endswitch |
74 | 98 |
75 endfunction | 99 endfunction |