I want to create tooltips for each line in a treeplot-similar plot in MATLAB. I used code examples to create the following script that shows whether the mouse is over a line object:
function test_mouseover2
f=figure(1);
axis([0 1 0 1]);
L=line([0.2500 0.5000], [0.6 0.8], 'Color','red');
set(f,'WindowButtonMotionFcn',{@mousemove,L,process});
end
function mousemove(src,ev,L,process)
obj = hittest(src);
if obj == L
disp('Yes');
else
disp('No');
end
end
In my further project I need multiple lines in the plot. The simple example in the following shows that two lines are plotted. However, the result in the command window is always "No":
function test_mouseover2
f=figure(1);
axis([0 1 0 1]);
L=line([0.2500 0.5000; 0.125 0.25], [0.6 0.8; 0.2 0.6], 'Color','red');
set(f,'WindowButtonMotionFcn',{@mousemove,L,process});
end
function mousemove(src,ev,L,process)
obj = hittest(src);
if obj == L
disp('Yes');
else
disp('No');
end
end
Is there another approach to check whether the mouse is over a line object or not?