Mercurial > hg > octave-lyh
annotate scripts/plot/private/__pltopt__.m @ 11188:4cb1522e4d0f
Use function handle as input to cellfun,
rather than quoted function name or anonymous function wrapper.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Wed, 03 Nov 2010 17:20:56 -0700 |
parents | 1479b93ee655 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2002, 2004, 2005, |
8920 | 2 ## 2006, 2007, 2009 John W. Eaton |
2313 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
933 | 19 |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
20 ## -*- texinfo -*- |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
21 ## @deftypefn {Function File} {} __pltopt__ (@var{caller}, @var{opt}) |
6895 | 22 ## Undocumented internal function. |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
23 ## @end deftypefn |
6895 | 24 |
3500 | 25 ## @deftypefn {Function File} {} __pltopt__ (@var{caller}, @var{opt}) |
6895 | 26 ## |
2311 | 27 ## Decode plot option strings. |
28 ## | |
3449 | 29 ## @var{opt} can currently be some combination of the following: |
2311 | 30 ## |
3449 | 31 ## @table @code |
32 ## @item "-" | |
6267 | 33 ## For solid linestyle (default). |
3717 | 34 ## |
6267 | 35 ## @item "--" |
36 ## For dashed line style. | |
3717 | 37 ## |
6267 | 38 ## @item "-." |
3717 | 39 ## For linespoints plot style. |
40 ## | |
6267 | 41 ## @item ":" |
42 ## For dots plot style. | |
3717 | 43 ## |
6267 | 44 ## @item "r" |
45 ## Red line color. | |
3717 | 46 ## |
6267 | 47 ## @item "g" |
48 ## Green line color. | |
3717 | 49 ## |
6267 | 50 ## @item "b" |
51 ## Blue line color. | |
3717 | 52 ## |
6267 | 53 ## @item "c" |
54 ## Cyan line color. | |
3717 | 55 ## |
6267 | 56 ## @item "m" |
57 ## Magenta line color. | |
4006 | 58 ## |
6267 | 59 ## @item "y" |
60 ## Yellow line color. | |
3717 | 61 ## |
6267 | 62 ## @item "k" |
63 ## Black line color. | |
3717 | 64 ## |
6267 | 65 ## @item "w" |
66 ## White line color. | |
3717 | 67 ## |
3449 | 68 ## @item ";title;" |
69 ## Here @code{"title"} is the label for the key. | |
3717 | 70 ## |
6267 | 71 ## @item "+" |
72 ## @itemx "o" | |
73 ## @itemx "*" | |
74 ## @itemx "." | |
75 ## @itemx "x" | |
76 ## @itemx "s" | |
77 ## @itemx "d" | |
78 ## @itemx "^" | |
79 ## @itemx "v" | |
80 ## @itemx ">" | |
81 ## @itemx "<" | |
82 ## @itemx "p" | |
83 ## @itemx "h" | |
3717 | 84 ## Used in combination with the points or linespoints styles, set the point |
85 ## style. | |
3449 | 86 ## @end table |
2311 | 87 ## |
3449 | 88 ## The legend may be fixed to include the name of the variable |
89 ## plotted in some future version of Octave. | |
933 | 90 |
3162 | 91 ## Author: jwe |
2314 | 92 |
6459 | 93 function [options, valid] = __pltopt__ (caller, opt, err_on_invalid) |
94 | |
95 valid = true; | |
96 options = __default_plot_options__ (); | |
933 | 97 |
6459 | 98 if ((nargin == 2 || nargin == 3) && (nargout == 1 || nargout == 2)) |
99 if (nargin == 2) | |
100 err_on_invalid = true; | |
101 endif | |
6146 | 102 if (ischar (opt)) |
103 nel = rows (opt); | |
104 elseif (iscellstr (opt)) | |
105 nel = numel (opt); | |
106 else | |
107 error ("__pltopt__: expecting argument to be character string or cell array of character strings"); | |
108 endif | |
109 if (ischar (opt)) | |
110 opt = cellstr (opt); | |
111 endif | |
6264 | 112 for i = nel:-1:1 |
6459 | 113 [options(i), valid] = __pltopt1__ (caller, opt{i}, err_on_invalid); |
114 if (! err_on_invalid && ! valid) | |
10549 | 115 return; |
6459 | 116 endif |
6146 | 117 endfor |
118 else | |
6046 | 119 print_usage (); |
933 | 120 endif |
121 | |
122 endfunction | |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
123 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
124 ## Really decode plot option strings. |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
125 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
126 ## Author: Rick Niles <niles@axp745.gsfc.nasa.gov> |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
127 ## Adapted-By: jwe |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
128 ## Maintainer: jwe |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
129 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
130 function [options, valid] = __pltopt1__ (caller, opt, err_on_invalid) |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
131 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
132 options = __default_plot_options__ (); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
133 valid = true; |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
134 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
135 more_opts = 1; |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
136 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
137 if (nargin != 2 && nargin != 3) |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
138 print_usage (); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
139 endif |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
140 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
141 if (! ischar (opt)) |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
142 return; |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
143 endif |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
144 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
145 have_linestyle = false; |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
146 have_marker = false; |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
147 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
148 ## If called by __errplot__, extract the linestyle before proceeding. |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
149 if (strcmp (caller,"__errplot__")) |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
150 if (strncmp (opt, "#~>", 3)) |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
151 n = 3; |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
152 elseif (strncmp (opt, "#~", 2) || strncmp (opt, "~>", 2)) |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
153 n = 2; |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
154 elseif (strncmp (opt, "~", 1) || strncmp (opt, ">", 1) |
10549 | 155 || strncmp (opt, "#", 1)) |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
156 n = 1; |
10575
3eba2cc7cbda
Allow matlab style linestyles in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
157 else |
3eba2cc7cbda
Allow matlab style linestyles in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10549
diff
changeset
|
158 n = 0; |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
159 endif |
10580
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10575
diff
changeset
|
160 options.errorstyle = opt(1:n); |
10135
4516a0c97ced
Handle linestyleorder. Remove @ markers. Treat edgecolor, markeredgecolor and markerfacecolor correctly in scatter.
David Bateman <dbateman@free.fr>
parents:
10121
diff
changeset
|
161 opt(1:n) = []; |
10580
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10575
diff
changeset
|
162 else |
1479b93ee655
Respect linestyleorder in errorbar plots
David Bateman <dbateman@free.fr>
parents:
10575
diff
changeset
|
163 options.errorstyle = "~"; |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
164 endif |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
165 |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
166 while (! isempty (opt)) |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
167 if (strncmp (opt, "--", 2) || strncmp (opt, "-.", 2)) |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
168 options.linestyle = opt(1:2); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
169 have_linestyle = true; |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
170 n = 2; |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
171 else |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
172 topt = opt(1); |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
173 n = 1; |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
174 if (topt == "-" || topt == ":") |
10549 | 175 have_linestyle = true; |
176 options.linestyle = topt; | |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
177 elseif (topt == "+" || topt == "o" || topt == "*" |
10549 | 178 || topt == "." || topt == "x" || topt == "s" |
179 || topt == "d" || topt == "^" || topt == "v" | |
180 || topt == ">" || topt == "<" || topt == "p" | |
181 || topt == "h" || topt == "@") | |
182 have_marker = true; | |
10135
4516a0c97ced
Handle linestyleorder. Remove @ markers. Treat edgecolor, markeredgecolor and markerfacecolor correctly in scatter.
David Bateman <dbateman@free.fr>
parents:
10121
diff
changeset
|
183 ## Backward compatibility. Leave undocumented. |
10549 | 184 if (topt == "@") |
185 topt = "+"; | |
186 endif | |
187 options.marker = topt; | |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
188 ### Numeric color specs for backward compatibility. Leave undocumented. |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
189 elseif (topt == "k" || topt == "0") |
10549 | 190 options.color = [0, 0, 0]; |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
191 elseif (topt == "r" || topt == "1") |
10549 | 192 options.color = [1, 0, 0]; |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
193 elseif (topt == "g" || topt == "2") |
10549 | 194 options.color = [0, 1, 0]; |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
195 elseif (topt == "b" || topt == "3") |
10549 | 196 options.color = [0, 0, 1]; |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
197 elseif (topt == "y") |
10549 | 198 options.color = [1, 1, 0]; |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
199 elseif (topt == "m" || topt == "4") |
10549 | 200 options.color = [1, 0, 1]; |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
201 elseif (topt == "c" || topt == "5") |
10549 | 202 options.color = [0, 1, 1]; |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
203 elseif (topt == "w" || topt == "6") |
10549 | 204 options.color = [1, 1, 1]; |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
205 elseif (isspace (topt)) |
10549 | 206 ## Do nothing. |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
207 elseif (topt == ";") |
10549 | 208 t = index (opt(2:end), ";"); |
209 if (t) | |
210 options.key = undo_string_escapes (opt(2:t)); | |
211 n = t+1; | |
212 else | |
213 if (err_on_invalid) | |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
214 error ("%s: unfinished key label", caller); |
10549 | 215 else |
216 valid = false; | |
217 options = __default_plot_options__ (); | |
218 return; | |
219 endif | |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
220 endif |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
221 else |
10549 | 222 if (err_on_invalid) |
223 error ("%s: unrecognized format character: `%s'", caller, topt); | |
224 else | |
225 valid = false; | |
226 options = __default_plot_options__ (); | |
227 return; | |
228 endif | |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
229 endif |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
230 endif |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
231 opt(1:n) = []; |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
232 endwhile |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
233 |
10135
4516a0c97ced
Handle linestyleorder. Remove @ markers. Treat edgecolor, markeredgecolor and markerfacecolor correctly in scatter.
David Bateman <dbateman@free.fr>
parents:
10121
diff
changeset
|
234 if (! have_linestyle && have_marker) |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
235 options.linestyle = "none"; |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
236 endif |
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
237 |
10135
4516a0c97ced
Handle linestyleorder. Remove @ markers. Treat edgecolor, markeredgecolor and markerfacecolor correctly in scatter.
David Bateman <dbateman@free.fr>
parents:
10121
diff
changeset
|
238 if (have_linestyle && ! have_marker) |
4516a0c97ced
Handle linestyleorder. Remove @ markers. Treat edgecolor, markeredgecolor and markerfacecolor correctly in scatter.
David Bateman <dbateman@free.fr>
parents:
10121
diff
changeset
|
239 options.marker = "none"; |
4516a0c97ced
Handle linestyleorder. Remove @ markers. Treat edgecolor, markeredgecolor and markerfacecolor correctly in scatter.
David Bateman <dbateman@free.fr>
parents:
10121
diff
changeset
|
240 endif |
4516a0c97ced
Handle linestyleorder. Remove @ markers. Treat edgecolor, markeredgecolor and markerfacecolor correctly in scatter.
David Bateman <dbateman@free.fr>
parents:
10121
diff
changeset
|
241 |
9896
1aeb39118764
convert some plot functions to subfunctions or make some them private
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
242 endfunction |