我正在使用Arbor Javascript来显示节点和边缘的图形。在图中,我想在鼠标悬停在该节点上时显示节点的标签。这是我的代码:
<canvas id="viewport" width="1000" height="800"></canvas>
<script language="javascript" type="text/javascript">
var sys = arbor.ParticleSystem(1000, 400,1);
sys.parameters({gravity:true});
sys.renderer = Renderer("#viewport") ;
var node;
var label_node= "Javascript";
node = sys.addNode('The first node',{'color':'red','shape':'dot','label': label_node});
我们假设创建了节点。将鼠标移到该节点上时,如何显示该节点的名称label_node
。谁能请我提供代码来完成这一部分。非常感谢您的协助。
答案 0 :(得分:1)
我认为类似的东西应该能够将鼠标悬停在节点上:
var that = {
initMouseHandling:function(){
// no-nonsense drag and drop (thanks springy.js)
var dragged = null;
// set up a handler object that will initially listen for mousedowns then
// for moves and mouseups while dragging
var handler = {
dragged:function(e){
var pos = $(canvas).offset();
var s = arbor.Point(e.pageX-pos.left, e.pageY-pos.top)
dragged = particleSystem.nearest(s);
if (dragged && dragged.node !== null){
// while we're dragging, don't let physics move the node
dragged.node.fixed = true
}
//ADD WHERE YOU WANT TO SHOW THE LABEL
return false
}
$(canvas).mouseover(handler.dragged);
}
}
return that
}
希望有所帮助