6807
|
1 ## Copyright (C) 2007 John W. Eaton, Shai Ayal, Kai Habel |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
|
19 |
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} __patch__ (@var{p}, @var{x}, @var{y}, @var{c}) |
|
22 ## Create patch object from @var{x} and @var{y} with color @var{c} and parent @var{p}. |
|
23 ## Return handle to patch object. |
|
24 ## @end deftypefn |
|
25 |
|
26 ## Author: Kai Habel |
|
27 |
|
28 function h = __patch__ (p, varargin) |
|
29 |
|
30 if (nargin < 1) |
|
31 print_usage (); |
|
32 endif |
|
33 |
|
34 nvargs = numel (varargin); |
|
35 |
|
36 if (nvargs > 1 && isnumeric (varargin{1}) && isnumeric (varargin{2})) |
|
37 num_data_args = 2; |
|
38 else |
|
39 num_data_args = 0; |
|
40 endif |
|
41 |
|
42 if (rem (nvargs - num_data_args - 1, 2) == 0 && nvargs > 2) |
|
43 else |
|
44 print_usage ("patch"); |
|
45 endif |
|
46 |
|
47 x = varargin{1}; |
|
48 y = varargin{2}; |
|
49 c = varargin{3}; |
|
50 |
|
51 h = __go_patch__ (p); |
|
52 ax = get (h, "parent"); |
|
53 if (num_data_args > 1) |
|
54 set (h, "xdata", x, "ydata", y); |
|
55 endif |
|
56 |
|
57 if (isstr (c)) |
|
58 ## Have color string. |
|
59 set (h, "FaceColor", c); |
|
60 elseif (length (c) == 1) |
|
61 if (isnan (c)) |
|
62 set (h, "FaceColor", [1, 1, 1]); |
|
63 set (h, "CData", c); |
|
64 elseif (isnumeric (c)) |
|
65 ## Have color index. |
|
66 set (h, "FaceColor", "flat"); |
|
67 set (h, "CData", c); |
|
68 |
|
69 clim = get(ax, "CLim"); |
|
70 if (c < clim(1)) |
|
71 set (ax, "CLim", [c, clim(2)]) |
|
72 endif |
|
73 if (c > clim(2)) |
|
74 set (ax, "CLim", [clim(1), c]) |
|
75 end |
|
76 |
|
77 else |
|
78 ## Unknown color value. |
|
79 error ("color value not valid"); |
|
80 end |
|
81 elseif (length (c) == 3) |
|
82 ## Have rgb/rgba value. |
|
83 set (h, "FaceColor", c); |
|
84 else |
|
85 ## Color vector. |
|
86 if (length (c) != length (x) || length (c) != length (y)) |
|
87 error ("size of x, y, and c must be equal") |
|
88 else |
|
89 set (h, "FaceColor", "interp"); |
|
90 set(h, "CData", c); |
|
91 if (abs(max(c) - min(c)) < eps) |
|
92 set (ax, "CLim", [c(1)-1, c(1)+1]) |
|
93 else |
|
94 set (ax, "CLim", [min(c), max(c)]); |
|
95 end |
|
96 end |
|
97 end |
|
98 |
|
99 if (nvargs > num_data_args + 1) |
|
100 set (h, varargin{num_data_args+2:end}); |
|
101 endif |
|
102 |
|
103 endfunction |