1

我正在使用 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一旦我将鼠标移到该节点上,如何显示该节点的名称。谁能给我提供这部分的代码。非常感谢您的帮助。

4

1 回答 1

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
  }

希望有帮助

于 2014-10-15T09:36:21.597 回答