1af232b54010a9c729db54a7e6f98e71b9f35cb5
[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=5;
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         if (type(PropertyValue)==10)
173
174             index = getColorIndex(PropertyValue);
175
176             ColorVal   = ["red" "green" "blue" "cyan" "magenta" "yellow" "black" "black" "white" "none"]
177
178             markmodeON = find(Curves.mark_mode=="on");
179
180             if index == 10
181                 // 'none' specified
182                 a=gca(); // pick up the background color of the parent axes
183                 if markmodeON <> []
184                     Curves(markmodeON).mark_foreground = a.background;
185                 end
186             elseif index == 11
187                 // 'auto' specified
188                 if markmodeON <> []
189                     Curves(markmodeON).mark_foreground =  Curves.foreground;
190                 end
191             else
192                 if (index==-1)
193                     warning(msprintf(gettext("%s: Wrong value for input argument #%d: A color of the colormap expected.\n"),"setPlotProperty",2));
194                     ResetFigureDDM(current_figure, cur_draw_mode);
195                     return;
196                 else
197                     if markmodeON <> []
198                         Curves(markmodeON).mark_foreground = color(ColorVal(index));
199                     end
200                 end
201             end
202         elseif (type(PropertyValue)==1)
203             if (size(PropertyValue,"*")==3)
204
205                 markmodeON = find(Curves.mark_mode=="on");
206                 if markmodeON <> []
207                     Curves(markmodeON).mark_foreground = addcolor(PropertyValue);
208                 end
209             else
210                 warning(msprintf(gettext("%s: Wrong size for input argument #%d: 3x1 or 1x3 vector expected.\n"),"setPlotProperty",2));
211                 ResetFigureDDM(current_figure, cur_draw_mode);
212                 return;
213             end
214
215         else
216             warning(msprintf(gettext("%s: Wrong type for input argument #%d: Vector or index in the colormap expected.\n"),"setPlotProperty",2));
217             ResetFigureDDM(current_figure, cur_draw_mode);
218             return;
219         end
220
221
222         /////////////////////////
223     case "markbackground"        // <=> MarkerFaceColor
224         /////////////////////////
225         if (type(PropertyValue)==10)
226
227             index = getColorIndex(PropertyValue);
228
229             ColorVal   = ["red" "green" "blue" "cyan" "magenta" "yellow" "black" "black" "white" "none"]
230
231             markmodeON = find(Curves.mark_mode=="on");
232
233             if index == 10
234                 // 'none' specified
235                 a=gca(); // pick up the background color of the parent axes
236                 if markmodeON <> []
237                     Curves(markmodeON).mark_background = a.background;
238                 end
239             elseif index == 11
240                 // 'auto' specified
241                 a=gca();
242                 if markmodeON <> []
243                     Curves(markmodeON).mark_background = a.background;
244                 end
245             else
246                 if (index==-1)
247                     warning(msprintf(gettext("%s: Wrong value for input argument #%d: A color of the colormap expected.\n"),"setPlotProperty",2));
248                     ResetFigureDDM(current_figure, cur_draw_mode);
249                     return;
250                 else
251                     if markmodeON <> []
252                         Curves(markmodeON).mark_background = color(ColorVal(index));
253                     end
254                 end
255             end
256         elseif (type(PropertyValue)==1)
257
258             if (size(PropertyValue,"*")==3)
259
260                 markmodeON = find(Curves.mark_mode=="on");
261                 if markmodeON <> []
262                     Curves(markmodeON).mark_background = addcolor(PropertyValue);
263                 end
264             else
265                 warning(msprintf(gettext("%s: Wrong size for input argument #%d: 3x1 or 1x3 vector expected.\n"),"setPlotProperty",2));
266                 ResetFigureDDM(current_figure, cur_draw_mode);
267                 return;
268             end
269
270         else
271             warning(msprintf(gettext("%s: Wrong type for input argument #%d: Vector or index in the colormap expected.\n"),"setPlotProperty",2));
272             ResetFigureDDM(current_figure, cur_draw_mode);
273             return;
274         end
275
276
277         /////////////////////////
278     case "marksize"        // <=> MarkerSize
279         /////////////////////////
280         if (type(PropertyValue)==1 & size(PropertyValue,"*")==1)
281
282             markmodeON = find(Curves.mark_mode=="on");
283
284             if markmodeON <> []
285                 Curves(markmodeON).mark_size = PropertyValue;
286             end
287         else
288             warning(msprintf(gettext("%s: Wrong type for input argument #%d: An integer expected.\n"),"setPlotProperty",2));
289             ResetFigureDDM(current_figure, cur_draw_mode);
290             return;
291         end
292
293         /////////////////////////
294     case "visible"        // <=> Visible
295         /////////////////////////
296         if (type(PropertyValue)==10 & (PropertyValue=="on" | PropertyValue=="off"))
297             Curves.visible = PropertyValue;
298         else
299             warning(msprintf(gettext("%s: Wrong value for input argument #%d: %s or %s expected.\n"),"setPlotProperty",2,"on","off"));
300             ResetFigureDDM(current_figure, cur_draw_mode);
301             return;
302         end
303
304
305         /////////////////////////
306     case "xdata"
307         /////////////////////////
308
309         // Already done at the beginning of plot execution.
310
311         /////////////////////////
312     case "ydata"
313         /////////////////////////
314
315         // Already done at the beginning of plot execution.
316
317         /////////////////////////
318     case "zdata"        // <=> Zdata is treated after the curve was created
319         /////////////////////////
320
321         if (type(PropertyValue)<>1 | and(size(PropertyValue)<>1))
322             warning(msprintf(gettext("%s: Wrong size or type for input argument #%d: A column or row vector expected.\n"),"setPlotProperty",2));
323             ResetFigureDDM(current_figure, cur_draw_mode);
324             return;
325         else
326             PropertyValue = PropertyValue(:); // force
327
328             for j=1:size(Curves,"*")
329                 if size(Curves(i).data,1) <> size(PropertyValue,"*")
330                     str="plot : incompatible dimensions in input arguments";
331                     warning(str);
332                     ResetFigureDDM(current_figure, cur_draw_mode);
333                     return;
334                 else
335                     for jj=1:size(PropertyValue,"*")
336                         Curves(j).data(jj,3) = PropertyValue(jj);
337                     end
338                     a=gca();
339                     a.view="3d";
340                     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)];
341                     a.view="2d";
342                 end
343             end
344         end
345
346
347
348     end
349
350 endfunction