]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/private/__pltopt__.m
update packages
[CreaPhase.git] / octave_packages / m / plot / private / __pltopt__.m
1 ## Copyright (C) 1994-2012 John W. Eaton
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 3 of the License, or (at
8 ## your option) 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, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} __pltopt__ (@var{caller}, @var{opt})
21 ## Undocumented internal function.
22 ## @end deftypefn
23
24 ## @deftypefn {Function File} {} __pltopt__ (@var{caller}, @var{opt})
25 ##
26 ## Decode plot option strings.
27 ##
28 ## @var{opt} can currently be some combination of the following:
29 ##
30 ## @table @code
31 ## @item "-"
32 ## For solid linestyle (default).
33 ##
34 ## @item "--"
35 ## For dashed line style.
36 ##
37 ## @item "-."
38 ## For linespoints plot style.
39 ##
40 ## @item ":"
41 ## For dots plot style.
42 ##
43 ## @item "r"
44 ## Red line color.
45 ##
46 ## @item "g"
47 ## Green line color.
48 ##
49 ## @item "b"
50 ## Blue line color.
51 ##
52 ## @item "c"
53 ## Cyan line color.
54 ##
55 ## @item "m"
56 ## Magenta line color.
57 ##
58 ## @item "y"
59 ## Yellow line color.
60 ##
61 ## @item "k"
62 ## Black line color.
63 ##
64 ## @item "w"
65 ## White line color.
66 ##
67 ## @item ";title;"
68 ## Here @code{"title"} is the label for the key.
69 ##
70 ## @item "+"
71 ## @itemx "o"
72 ## @itemx "*"
73 ## @itemx "."
74 ## @itemx "x"
75 ## @itemx "s"
76 ## @itemx "d"
77 ## @itemx "^"
78 ## @itemx "v"
79 ## @itemx ">"
80 ## @itemx "<"
81 ## @itemx "p"
82 ## @itemx "h"
83 ## Used in combination with the points or linespoints styles, set the point
84 ## style.
85 ## @end table
86 ##
87 ## The legend may be fixed to include the name of the variable
88 ## plotted in some future version of Octave.
89
90 ## Author: jwe
91
92 function [options, valid] = __pltopt__ (caller, opt, err_on_invalid)
93
94   valid = true;
95   options =  __default_plot_options__ ();
96
97   if ((nargin == 2 || nargin == 3) && (nargout == 1 || nargout == 2))
98     if (nargin == 2)
99       err_on_invalid = true;
100     endif
101     if (ischar (opt))
102       nel = rows (opt);
103     elseif (iscellstr (opt))
104       nel = numel (opt);
105     else
106       error ("__pltopt__: expecting argument to be character string or cell array of character strings");
107     endif
108     if (ischar (opt))
109       opt = cellstr (opt);
110     endif
111     for i = nel:-1:1
112       [options(i), valid] = __pltopt1__ (caller, opt{i}, err_on_invalid);
113       if (! err_on_invalid && ! valid)
114         return;
115       endif
116     endfor
117   else
118     print_usage ();
119   endif
120
121 endfunction
122
123 ## Really decode plot option strings.
124
125 ## Author: Rick Niles <niles@axp745.gsfc.nasa.gov>
126 ## Adapted-By: jwe
127 ## Maintainer: jwe
128
129 function [options, valid] = __pltopt1__ (caller, opt, err_on_invalid)
130
131   options = __default_plot_options__ ();
132   valid = true;
133
134   more_opts = 1;
135
136   if (nargin != 2 && nargin != 3)
137     print_usage ();
138   endif
139
140   if (! ischar (opt))
141     return;
142   endif
143
144   have_linestyle = false;
145   have_marker = false;
146
147   ## If called by __errplot__, extract the linestyle before proceeding.
148   if (strcmp (caller,"__errplot__"))
149     if (strncmp (opt, "#~>", 3))
150       n = 3;
151     elseif (strncmp (opt, "#~", 2) || strncmp (opt, "~>", 2))
152       n = 2;
153     elseif (strncmp (opt, "~", 1) || strncmp (opt, ">", 1)
154             || strncmp (opt, "#", 1))
155       n = 1;
156     else
157       n = 0;
158     endif
159     options.errorstyle = opt(1:n);
160     opt(1:n) = [];
161   else
162     options.errorstyle = "~";
163   endif
164
165   while (! isempty (opt))
166     if (strncmp (opt, "--", 2) || strncmp (opt, "-.", 2))
167       options.linestyle = opt(1:2);
168       have_linestyle = true;
169       n = 2;
170     else
171       topt = opt(1);
172       n = 1;
173       if (topt == "-" || topt == ":")
174         have_linestyle = true;
175         options.linestyle = topt;
176       elseif (topt == "+" || topt == "o" || topt == "*"
177               || topt == "." || topt == "x" || topt == "s"
178               || topt == "d" || topt == "^" || topt == "v"
179               || topt == ">" || topt == "<" || topt == "p"
180               || topt == "h" || topt == "@")
181         have_marker = true;
182         ## Backward compatibility.  Leave undocumented.
183         if (topt == "@")
184           topt = "+";
185         endif
186         options.marker = topt;
187 ### Numeric color specs for backward compatibility.  Leave undocumented.
188       elseif (topt == "k" || topt == "0")
189         options.color = [0, 0, 0];
190       elseif (topt == "r" || topt == "1")
191         options.color = [1, 0, 0];
192       elseif (topt == "g" || topt == "2")
193         options.color = [0, 1, 0];
194       elseif (topt == "b" || topt == "3")
195         options.color = [0, 0, 1];
196       elseif (topt == "y")
197         options.color = [1, 1, 0];
198       elseif (topt == "m" || topt == "4")
199         options.color = [1, 0, 1];
200       elseif (topt == "c" || topt == "5")
201         options.color = [0, 1, 1];
202       elseif (topt == "w" || topt == "6")
203         options.color = [1, 1, 1];
204       elseif (isspace (topt))
205         ## Do nothing.
206       elseif (topt == ";")
207         t = index (opt(2:end), ";");
208         if (t)
209           options.key = undo_string_escapes (opt(2:t));
210           n = t+1;
211         else
212           if (err_on_invalid)
213             error ("%s: unfinished key label", caller);
214           else
215             valid = false;
216             options = __default_plot_options__ ();
217             return;
218           endif
219         endif
220       else
221         if (err_on_invalid)
222           error ("%s: unrecognized format character: `%s'", caller, topt);
223         else
224           valid = false;
225           options = __default_plot_options__ ();
226           return;
227         endif
228       endif
229     endif
230     opt(1:n) = [];
231   endwhile
232
233   if (! have_linestyle && have_marker)
234     options.linestyle = "none";
235   endif
236
237   if (have_linestyle && ! have_marker)
238     options.marker = "none";
239   endif
240
241 endfunction