1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2010 - INRIA - Serge Steer <serge.steer@inria.fr>
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
10 function datatipSetDisplay(curve_handle,fun)
11 //Changes the datatips visualisation function for a given curve
13 error(msprintf(_("%s: Wrong number of input argument(s): At least %d expected.\n"),...
14 "datatipSetDisplay",1))
16 if type(curve_handle)<>9|size(curve_handle,'*')<>1|curve_handle.type<>"Polyline" then
17 error(msprintf(_("%s: Wrong type for input argument #%d: A ''%s'' handle expected.\n"),"datatipSetDisplay",1,"Polyline"))
19 ds=datatipGetStruct(curve_handle)
20 if typeof(ds)<>'datatips' then;
21 if ~datatipInitStruct(curve_handle) then return,end
22 ds=datatipGetStruct(curve_handle)
25 // function definition is queried
26 txt=fun2string(ds.formatfunction,'fun')
28 txt=x_dialog('Function Editor',txt)
29 if txt==[] then ok=%f,break,end
30 ierr=execstr(txt,'errcatch')
31 if ierr==0 then ok=%t,break,end
32 messagebox(lasterror(),'','error')
34 if ~ok then return,end
36 if ~datatipCheckFunction(fun) then return,end
38 datatipSetStruct(curve_handle,ds)
39 for k=1:size(ds.tips.children,'*')
40 tip_handle=ds.tips.children(k)
41 point_handle=tip_handle.children(1);
42 string_handle=tip_handle.children(2);
43 tip_index=point_handle.user_data(2)
44 string_handle.text=fun(curve_handle,point_handle.data,tip_index)
45 datatipSetTipStyle(tip_handle,ds.style)
49 function ok=datatipCheckFunction(fun)
51 [out,in,c]=string(fun)
52 if size(in,'*')<>3 then
53 messagebox(_("The selected function must have 3 input parameters (curve,pt,index)"))
56 if size(out,'*')<>1 then
57 messagebox(_("The selected function must have 1 output parameter (str)"))