* Bug #12150 fixed - datatipCreate failed with one single point.
[scilab.git] / scilab / modules / graphics / macros / datatips / datatipSetTipPosition.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2011 - INRIA - Serge Steer <serge.steer@inria.fr>
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 datatipSetTipPosition(ud,tip_handle,pt,k)
11 //datatip utility function
12   point_handle=tip_handle.children(1)
13   string_handle=tip_handle.children(2)
14
15   tip_refs=point_handle.user_data
16   [curve_handle,point_index]=tip_refs(:)
17   formatfunction=ud.formatfunction
18
19   if ud.style==0 | size(curve_handle.data,1) == 1 then
20     point_handle.data=pt
21   else
22     if k<size(curve_handle.data,1)
23       dxy=curve_handle.data(k+1,:)-pt;
24     else
25       dxy=pt-curve_handle.data(k-1,:);
26     end
27     dxy=dxy/norm(dxy)/10000;
28     point_handle.data=[pt;pt+dxy]
29   end
30   tip_refs(2)=k;
31   point_handle.user_data=tip_refs
32   string_handle.text=formatfunction(curve_handle,pt,k)
33   setStringPosition(tip_handle,pt)
34
35 endfunction