* Bug 16366 fixed: plot(..,':') was dash-dotted
[scilab.git] / scilab / modules / graphics / macros / setPlotProperty.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2004-2006 - INRIA - Fabrice Leray
3 // Copyright (C) 2012 - 2016 - Scilab Enterprises
4 // Copyright (C) 2018, 2019 - Samuel GOUGEON
5 //
6 // This file is hereby licensed under the terms of the GNU GPL v2.0,
7 // pursuant to article 5.3.4 of the CeCILL v.2.1.
8 // This file was originally licensed under the terms of the CeCILL v2.1,
9 // and continues to be available under such terms.
10 // For more information, see the COPYING file which you should have received
11 // along with this program.
12
13 function [fail]=setPlotProperty(PropertyName,PropertyValue,Curves,current_figure,cur_draw_mode)
14
15     fail=0;
16
17     //conversion to lower format
18     str = convstr(PropertyName);
19
20
21
22     //Property = ['foreground' 'clipping'];
23
24     [PName] = getPlotPropertyName(str,current_figure,cur_draw_mode)
25
26
27     if (PName==[])
28         ResetFigureDDM(current_figure, cur_draw_mode);
29         return;
30     end
31
32     select PName
33
34         /////////////////////////
35     case "foreground"         // <=> Color
36         /////////////////////////
37         c = iscolor(PropertyValue);
38         if or(isnan(c(:,1)))
39             msg = _("%s: Argument #%d: Wrong color specification.\n")
40             warning(msprintf(msg, "setPlotProperty", 2));
41             ResetFigureDDM(current_figure, cur_draw_mode);
42             return
43         end
44         if size(c,"r")<length(Curves)
45             msg = _("%s: Arguments #%d and #%d: Incompatible sizes.\n")
46             warning(msprintf(msg, "setPlotProperty", 2, 3));
47             ResetFigureDDM(current_figure, cur_draw_mode);
48             return
49         end
50         Curves.line_mode = "on";
51         if size(c,2) > 1    // c is RGB
52             ind = addcolor(c(1:length(Curves),:));
53         else
54             ind = c
55         end
56         for i = 1:length(ind)
57             Curves($-i+1).foreground = ind(i);
58             Curves($-i+1).mark_foreground = ind(i);
59         end
60
61         /////////////////////////
62     case "clipping"           // Clipping
63         /////////////////////////
64         if (type(PropertyValue)==10 & (PropertyValue=="on" | PropertyValue=="off"))
65             Curves.clip_state=PropertyValue;
66         else
67             warning(msprintf(gettext("%s: Wrong value for input argument #%d: %s or %s expected.\n"),"setPlotProperty",2,"on","off"));
68             ResetFigureDDM(current_figure, cur_draw_mode);
69             return;
70         end
71
72
73         /////////////////////////
74     case "linestyle"          // LineStyle
75         /////////////////////////
76         if (type(PropertyValue)==10)
77             if (PropertyValue=="--")
78                 Curves.line_style=2;
79                 Curves.line_mode = "on";
80             elseif (PropertyValue=="-.")
81                 Curves.line_style=4;
82                 Curves.line_mode = "on";
83             elseif (PropertyValue==":")
84                 Curves.line_style=8;
85                 Curves.line_mode = "on";
86             elseif (PropertyValue=="-")
87                 Curves.line_style=1;
88                 Curves.line_mode = "on";
89             elseif (PropertyValue=="none")
90                 Curves.line_mode = "off";
91             end
92         else
93             warning(msprintf(gettext("%s: Wrong type for input argument #%d: string expected.\n"),"setPlotProperty",2));
94             ResetFigureDDM(current_figure, cur_draw_mode);
95             return;
96         end
97
98         /////////////////////////
99     case "thickness"        // <=> LineWidth
100         /////////////////////////
101         if (type(PropertyValue)==1)
102             Curves.thickness=PropertyValue;
103         else
104             warning(msprintf(gettext("%s: Wrong type for input argument #%d: A scalar expected.\n"),"setPlotProperty",2));
105             ResetFigureDDM(current_figure, cur_draw_mode);
106             return;
107         end
108
109         /////////////////////////
110     case "markstyle"        // <=> Marker
111         /////////////////////////
112         if (type(PropertyValue)==10)
113
114             str = convstr(PropertyValue);
115             //Marks
116             Table = [ "+" "o" "*" "." "x" "square" "diamond" "^" "v" ">" "<" "pentagram" "none"];
117             MarksStyleVal=[1 9 10 0 2 11 5 6 7 12 13 14 -99];
118             //    MarksSizeVal =[4 3 7  1 3  3 4 3 3  3  3  3 -99];
119
120             opt1=[];
121
122             k=find(part(Table,1:length(str))==str);
123
124             if (k == [])
125                 warning(msprintf(gettext("%s: Wrong value for input argument #%d: A marker style expected.\n"),"setPlotProperty", 2));
126                 PName=[];
127                 ResetFigureDDM(current_figure, cur_draw_mode);
128                 return;
129             elseif ( size(k,"*") > 1)
130                 warning(msprintf(gettext("%s: Wrong value for input argument #%d: A marker style expected.\n"),"setPlotProperty", 2)); //unreachable case normally
131                 PName=[];
132                 ResetFigureDDM(current_figure, cur_draw_mode);
133                 return;
134             end
135
136             opt = Table(k);
137             for i=1:length(str)
138                 if part(opt,i) <> part(str,i)
139                     break;
140                 end
141             end
142
143             opt1 = [opt1 k];
144
145             str = part(str,i:length(str));
146
147             if (size(opt1,"*") > 1)
148                 warning(msprintf(gettext("%s: Wrong value for input argument #%d: A marker style expected.\n"),"setPlotproperty",2));
149                 ResetFigureDDM(current_figure, cur_draw_mode);
150                 return;
151             end
152
153             if (opt1 > 0)
154                 Curves.mark_style = MarksStyleVal(opt1);
155                 Curves.mark_size  = 6;
156                 //MarksSizeVal(opt1);
157             else
158                 // 'none' is selected
159                 Curves.mark_mode="off"
160             end
161
162         else
163             warning(msprintf(gettext("%s: Wrong type for input argument #%d: string expected.\n"),"setPlotProperty"));
164             ResetFigureDDM(current_figure, cur_draw_mode);
165             return;
166         end
167
168
169         /////////////////////////
170     case "markforeground"        // <=> MarkerEdgeColor
171         /////////////////////////
172
173         markmodeON = find(Curves.mark_mode=="on");
174         tmp = "/^"+PropertyValue+"/"
175         if type(PropertyValue)==10 & size(PropertyValue,"*")==1 & ..
176                                         grep(["none" "auto"], tmp, "r") <> []
177             if grep("none", tmp, "r") <> []
178                 if markmodeON <> []
179                     Curves(markmodeON).mark_foreground = gca().background;
180                 end
181             else // 'auto' specified
182                 if markmodeON <> []
183                     Curves(markmodeON).mark_foreground =  Curves.foreground;
184                 end
185             end
186         else
187             co = iscolor(PropertyValue)
188             if or(isnan(co(:,1)))
189                 msg = gettext("%s: Argument #%d: Wrong color specification.\n")
190                 warning(msprintf(msg, "setPlotProperty", 2))
191                 ResetFigureDDM(current_figure, cur_draw_mode)
192                 return
193             end
194             if markmodeON <> []
195                 if size(co,2)==1
196                     Curves(markmodeON).mark_foreground = co;
197                 else
198                     Curves(markmodeON).mark_foreground = addcolor(co);
199                 end
200             end
201         end
202
203         /////////////////////////
204     case "markbackground"        // <=> MarkerFaceColor
205         /////////////////////////
206
207         markmodeON = find(Curves.mark_mode=="on");
208         tmp = "/^"+PropertyValue+"/"
209         if type(PropertyValue)==10 & size(PropertyValue,"*")==1 & ..
210                                         grep(["none" "auto"], tmp, "r") <> []
211             if markmodeON <> []
212                 Curves(markmodeON).mark_background = gca().background;
213             end
214         else
215             co = iscolor(PropertyValue)
216             if or(isnan(co(:,1)))
217                 msg = gettext("%s: Argument #%d: Wrong color specification.\n")
218                 warning(msprintf(msg, "setPlotProperty", 2))
219                 ResetFigureDDM(current_figure, cur_draw_mode)
220                 return
221             end
222             if markmodeON <> []
223                 if size(co,2)==1
224                     Curves(markmodeON).mark_background = co;
225                 else
226                     Curves(markmodeON).mark_background = addcolor(co);
227                 end
228             end
229         end
230
231         /////////////////////////
232     case "marksize"        // <=> MarkerSize
233         /////////////////////////
234         if (type(PropertyValue)==1 & size(PropertyValue,"*")==1)
235
236             markmodeON = find(Curves.mark_mode=="on");
237
238             if markmodeON <> []
239                 Curves(markmodeON).mark_size = PropertyValue;
240             end
241         else
242             warning(msprintf(gettext("%s: Wrong type for input argument #%d: An integer expected.\n"),"setPlotProperty",2));
243             ResetFigureDDM(current_figure, cur_draw_mode);
244             return;
245         end
246
247         /////////////////////////
248     case "visible"        // <=> Visible
249         /////////////////////////
250         if (type(PropertyValue)==10 & (PropertyValue=="on" | PropertyValue=="off"))
251             Curves.visible = PropertyValue;
252         else
253             warning(msprintf(gettext("%s: Wrong value for input argument #%d: %s or %s expected.\n"),"setPlotProperty",2,"on","off"));
254             ResetFigureDDM(current_figure, cur_draw_mode);
255             return;
256         end
257
258
259         /////////////////////////
260     case "xdata"
261         /////////////////////////
262
263         // Already done at the beginning of plot execution.
264
265         /////////////////////////
266     case "ydata"
267         /////////////////////////
268
269         // Already done at the beginning of plot execution.
270
271         /////////////////////////
272     case "zdata"        // <=> Zdata is treated after the curve was created
273         /////////////////////////
274
275         if (type(PropertyValue)<>1 | and(size(PropertyValue)<>1))
276             warning(msprintf(gettext("%s: Wrong size or type for input argument #%d: A column or row vector expected.\n"),"setPlotProperty",2));
277             ResetFigureDDM(current_figure, cur_draw_mode);
278             return;
279         else
280             PropertyValue = PropertyValue(:); // force
281
282             for j=1:size(Curves,"*")
283                 if size(Curves(i).data,1) <> size(PropertyValue,"*")
284                     str="plot : incompatible dimensions in input arguments";
285                     warning(str);
286                     ResetFigureDDM(current_figure, cur_draw_mode);
287                     return;
288                 else
289                     for jj=1:size(PropertyValue,"*")
290                         Curves(j).data(jj,3) = PropertyValue(jj);
291                     end
292                     a=gca();
293                     a.view="3d";
294                     a.data_bounds=[a.data_bounds(1,1) a.data_bounds(1,2) min(PropertyValue) ;  a.data_bounds(2,1) a.data_bounds(2,2) max(PropertyValue)];
295                     a.view="2d";
296                 end
297             end
298         end
299
300     end
301 endfunction