Messages standardization
[scilab.git] / scilab / modules / compatibility_functions / macros / mtlb_plot.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2002-2004 - INRIA - Vincent COUVERT 
3 // 
4 // This file must be used under the terms of the CeCILL.
5 // This source file is licensed as described in the file COPYING, which
6 // you should have received as part of this distribution.  The terms
7 // are also available at    
8 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
9
10 function h=mtlb_plot(varargin)
11 // Emulation function for Matlab plot()
12
13 // Default for Matlab graphics
14 mtlbColorOrder=[..
15         0    0    1   ;..
16         0    0.5  0   ;..
17         1    0    0   ;..
18         0    0.75 0.75;..
19         0.75 0    0.75;..
20         0.75 0.75 0   ;..
21         0.25 0.25 0.25].*255;
22
23 // red green blue cyan magenta yellow black white
24 mtlbcolors=["r"  ,"g"    ,"b"   ,"c"   ,"m"      ,"y"     ,"k"    ,"w"    ]
25 scicolors= ["red","green","blue","cyan","magenta","yellow","black","white"]
26
27 mtlbmarkers=["+","o","*",".","x","s","d","^","v",">","<","p","h"]
28 scimarkers= [ 1 , 9 , 3 , 0 , 2 , -1, 5 , 6 , 7 , -1, -1, -1, -1]
29
30 mtlblinestyles=["-","--",":","-."]
31 scilinestyles= [ 0 , 2  , -1, 5  ]
32
33 // plot(axes_handle,...)
34 if type(varargin(1))==9 then
35   set("current_axes",varargin(1))
36   varargin(1)=null()
37 end
38
39
40 mtlbColor=mtlbColorOrder(1,:)
41 colorIndex=1
42
43 // plot(Y)
44 if lstsize(varargin)==1 then
45   mtlb_plotY(varargin(1))
46 elseif lstsize(varargin)==2 then
47   
48   // plot(Y,Linespec)
49   if type(varargin(2))==10 then
50     mtlb_plotY(varargin(1))
51     curh=gce()
52     curh=curh.children(1)
53     mstyl=linespec2sci(varargin(2),curh)
54     if ~isempty(mstyl) then
55       mtlb_plotY(varargin(1))
56       a=gca()
57       markplot=a.children(1)
58       markplot.children(1).mark_mode="on"
59       markplot.children(1).mark_style=mstyl
60     end
61     if colorIndex<>7 then 
62       colorIndex=colorIndex+1;
63     else
64       colorIndex=1;
65     end
66     mtlbColor=mtlbColorOrder(colorIndex,:);
67   // plot(X,Y)
68   else
69     mtlb_plotXY(varargin(1),varargin(2))
70     if colorIndex<>7 then 
71       colorIndex=colorIndex+1;
72     else
73       colorIndex=1;
74     end
75     mtlbColor=mtlbColorOrder(colorIndex,:);
76   end
77 // plot(X,Y,Linespec)  
78 elseif lstsize(varargin)==3 & type(varargin(3))==10 then
79   mtlb_plotXY(varargin(1),varargin(2))
80   curh=gce()
81   curh=curh.children(1)
82   mstyl=linespec2sci(varargin(3),curh)
83   if ~isempty(mstyl) then
84     mtlb_plotXY(varargin(1),varargin(2))
85     a=gca()
86     markplot=a.children(1)
87     markplot.children(1).mark_mode="on"
88     markplot.children(1).mark_style=mstyl
89   end
90   if colorIndex<>7 then 
91     colorIndex=colorIndex+1;
92   else
93     colorIndex=1;
94   end
95   mtlbColor=mtlbColorOrder(colorIndex,:);
96 else
97   k=1
98   while k<=lstsize(varargin)
99     if k<lstsize(varargin) & type(varargin(k))<>10 then
100       mtlb_plotXY(varargin(k),varargin(k+1))
101       set(gca(),"auto_clear","off")
102       X=varargin(k)
103       Y=varargin(k+1)
104       lineplot=gce()
105       markplot=lineplot
106       k=k+2
107       if colorIndex<>7 then 
108         colorIndex=colorIndex+1;
109       else
110         colorIndex=1;
111       end
112       mtlbColor=mtlbColorOrder(colorIndex,:);
113     elseif k<=lstsize(varargin) & type(varargin(k))==10 then
114       opt=varargin(k)
115       opt=convstr(opt,"l")
116       if ~isempty(strindex("linestyle",opt)) then
117         curh=lineplot.children(1)
118         linespec2sci(varargin(k+1),curh)
119         k=k+2
120       elseif ~isempty(strindex("linewidth",opt)) then
121         lineplot.children(1).thickness=varargin(k+1)
122         k=k+2
123       elseif ~isempty(strindex("marker",opt)) then
124         curh=markplot.children(1)
125         linespec2sci(varargin(k+1),curh)
126         k=k+2
127       elseif ~isempty(strindex("markeredgecolor",opt)) then
128         warning(msprintf(gettext("%s: ''%s'' option ignored.\n"),"mtlb_plot","MarkerEdgeColor"));
129         k=k+2
130       elseif ~isempty(strindex("markerfacecolor",opt)) then
131         curh=markplot.children(1)
132         linespec2sci(varargin(k+1),curh)
133         k=k+2
134       elseif ~isempty(strindex("markersize",opt)) then
135         scimarksize=[8 10 12 14 18 24]
136         markplot.children(1).mark_size=scimarksize(max(find(scimarksize<varargin(k+1))))
137         k=k+2
138       else
139         curh=lineplot.children(1)
140         mstyl=linespec2sci(varargin(k),curh)
141         if ~isempty(mstyl) then
142           mtlb_plotXY(X,Y)
143           a=gca()
144           markplot=a.children(1)
145           markplot.children(1).mark_mode="on"
146           markplot.children(1).mark_style=mstyl
147         end
148         k=k+1
149       end
150     end
151   end
152 end
153 a=gca()
154 a.auto_clear="on"
155 // Log axis ?
156 global mtlb_log_mod
157 if ~isempty(mtlb_log_mod)
158   a.log_flags = mtlb_log_mod;
159 end
160 h=a.children
161 endfunction
162
163 function mtlb_plotY(Y)
164   if norm(Y,1)==0 then
165     plot2d(Y)
166   else
167     plot2d(real(Y),imag(Y))
168   end
169   e=gce()
170   e.children(1).foreground=color(mtlbColor(1),mtlbColor(2),mtlbColor(3))
171   e.children(1).line_style=0
172 endfunction
173
174 function mtlb_plotXY(X,Y)
175   plot2d(X,Y)
176   e=gce()
177   e.children(1).foreground=color(mtlbColor(1),mtlbColor(2),mtlbColor(3))
178   e.children(1).line_style=0
179 endfunction
180
181 function mark=linespec2sci(linespec,cur_handle)
182 mtlbColor=mtlbColor;
183 linep=%F
184 // line style
185 ind=[]
186 for k=1:size(mtlblinestyles,"*")
187   found=strindex(linespec,mtlblinestyles(k))
188   if ~isempty(found) then
189     ind=k
190     linep=%T
191   end
192 end
193 styl=scilinestyles(ind)
194 if styl>=0 then
195   cur_handle.line_style=styl
196 elseif ~isempty(ind) then
197   warning(msprintf(gettext("%s: Unknown line style found in ''%s'' -> set to 6.\n"),"mtlb_plot",linespec));
198   cur_handle.line_style=6
199 end
200
201 // color
202 ind=[]
203 for k=1:size(mtlbcolors,"*")
204   found=strindex(linespec,mtlbcolors(k))
205   if ~isempty(found) then
206     ind=k
207     break
208   end
209 end
210 clr=scicolors(ind)
211 if ~isempty(clr) then
212   cur_handle.foreground=color(clr)
213   mtlbColor=name2rgb(clr)
214 elseif ~isempty(ind) then
215   warning(msprintf(gettext("%s: Unknown color found in ''%s'' -> set to black.\n"),"mtlb_plot",linespec));
216   cur_handle.foreground=color("black")
217   mtlbColor=name2rgb("black")
218 end
219
220 // marker
221 ind=[]
222 for k=1:size(mtlbmarkers,"*")
223   found=strindex(linespec,mtlbmarkers(k))
224   if ~isempty(found) then
225     ind=k
226     break
227   end
228 end
229 mark=scimarkers(ind)
230 if ~linep & mark>=0 & ~isempty(mark) then
231   cur_handle.mark_mode="on"
232   cur_handle.mark_style=mark
233   cur_handle.mark_size=1
234 elseif ~linep & mark>=0 & ~isempty(mark) then
235   cur_handle.mark_mode="on"
236   cur_handle.mark_style=4
237   cur_handle.mark_size=1
238 elseif ~isempty(ind) then
239   mark=4
240 end
241 mtlbColor=resume(mtlbColor)
242 endfunction
243