Arbor Js - Node Onclick?

后端 未结 4 503
谎友^
谎友^ 2021-02-03 11:52

I\'m using arbor.js to create a graph.

How do I create an onclick event for a node, or make a node link somewhere upon being clicked?

The Arborjs.or

4条回答
  •  故里飘歌
    2021-02-03 12:16

    In the script renderer.js is the handler for the mouse events, so you can add your code to create your functions.

    I modified the renderer.js to add the click and double-click functions.

    var handler = {
        clicked:function(e){
            var pos = $(canvas).offset();
            _mouseP = arbor.Point(e.pageX-pos.left, e.pageY-pos.top)
            selected = nearest = dragged = particleSystem.nearest(_mouseP);
            if (dragged.node !== null) dragged.node.fixed = true
            $(canvas).bind('mousemove', handler.dragged)
            $(window).bind('mouseup', handler.dropped)
            $(canvas).bind('mouseup', handler.mypersonalfunction)
        },
        mypersonalfunction:function(e){
            if (dragged===null || dragged.node===undefined) return
            if (dragged.node !== null){
                dragged.node.fixed = false                  
                var id=dragged.node.name;
                alert('Node selected: ' + id);
            }            
            return false
        },
    

    You can check the clic and double-click functions in this page.

    I add nodes and edges when a node has been clicked and I add edges to other nodes when the node has been double-clicked (the blue,yellow and green ones)

提交回复
热议问题