简体   繁体   English

Arbor.js查询

[英]Arbor.js queries

I have been working with arbor.js and need help with the couple of problems. 我一直在使用arbor.js,需要解决几个问题。 I was able to create a graph based on a database, a basic graph. 我能够基于数据库(基本图)创建图。 Now, what I need to do, click on the node and get the node data and get it displayed on the side. 现在,我需要做的是,单击节点并获取节点数据,并将其显示在侧面。 Also have a directed edge. 也要有针对性的优势。 So, the problems are 所以,问题是

  1. My mousedown function is not working. 我的mousedown功能不起作用。 Either it totally won't work or if it works, when I click a node it automatically goes to drag, ie it gets attatched to the mouse and I can't release it. 它要么完全不起作用,要么它完全起作用,当我单击一个节点时,它会自动拖动,即它被附着在鼠标上,而我无法释放它。 What am trying to do is when I click the node I need to display the node details on the side. 当我单击节点时,我需要在侧面显示节点详细信息。 The noded details are on another page which can be retrieved as json. 节点详细信息在另一页上,可以将其检索为json。 My mouse handling code is as follows 我的鼠标处理代码如下

     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 = { clicked:function(e){ var pos = $(canvas).offset(); _mouseP = arbor.Point(e.pageX-pos.left, e.pageY-pos.top) dragged = particleSystem.nearest(_mouseP); var d = document.getElementById("infoDiv"); if (dragged && dragged.node !== null){ // while we're dragging, don't let physics move the node dragged.node.fixed = true } ///document.getElementById('detailBox').innerHTML=selected.node.name; $(canvas).bind('mousemove', handler.dragged) $(window).bind('mouseup', handler.dropped) $(canvas).bind('mousedown', handler.clicked) return false }, dragged:function(e){ var pos = $(canvas).offset(); var s = arbor.Point(e.pageX-pos.left, e.pageY-pos.top) if (dragged && dragged.node !== null){ var p = particleSystem.fromScreen(s) dragged.node.p = p } return false }, dropped:function(e){ if (dragged===null || dragged.node===undefined) return if (dragged.node !== null) dragged.node.fixed = false dragged.node.tempMass = 1000 dragged = null $(canvas).unbind('mousemove', handler.dragged) $(window).unbind('mouseup', handler.dropped) _mouseP = null return false } clicked:function(e){ var pos = $(this).offset(); var p = {x:e.pageX-pos.left, y:e.pageY-pos.top} selected = nearest = dragged = particleSystem.nearest(p); var nodeAddress = "http://localhost:7474/db/data/node/" + selected.node.name; if (selected.node !== null){ // dragged.node.tempMass = 10000 dragged.node.fixed = false; //$(canvas).unbind('mousemove', handler.dragged) } //document.getElementById('detailBox').innerHTML=selected.node.name; getData(nodeAddress); //alert(nodeData.self); return false; } } //My click function //$(canvas).mousedown(function(e){ //}); 

    }, },

    } }

The above code does not work at all, I am new to jQuery as well, hence I can't figure out the error, what the last function clicked, is trying to do is that on the clicking of a node, fetch its details from another page and display it. 上面的代码根本不起作用,我也是jQuery的新手,因此我无法弄清楚错误,最后单击的函数试图执行的操作是在单击节点时从中获取其详细信息另一页并显示它。 The function here is utter fail. 这里的功能完全失败。 Before I tried like this, 在我这样尝试之前

   //My click function
    $(canvas).mousedown(function(e){
        var pos = $(this).offset();
        var p = {x:e.pageX-pos.left, y:e.pageY-pos.top}
        selected = nearest = dragged = particleSystem.nearest(p);
        var nodeAddress = "http://localhost:7474/db/data/node/" + selected.node.name;

        if (selected.node !== null){
        // dragged.node.tempMass = 10000
            dragged.node.fixed = false;
            //$(canvas).unbind('mousemove', handler.dragged)        
        }
        //document.getElementById('detailBox').innerHTML=selected.node.name;
        getData(nodeAddress);
        //alert(nodeData.self);
        return false;
    });



    // start listening
    $(canvas).mousedown(handler.clicked);

This comes outside the handler variable, with this the javascript worked fine, and it displayed the node number on the side. 这在处理程序变量之外,JavaScript可以正常工作,并且在侧面显示了节点号。 But I was not able to query and get the json. 但是我无法查询和获取json。 The graph got stuck to the pointed too. 该图也卡住了。

Is this the way to try it? 这是尝试的方法吗? How can I get it done otherwise. 我如何才能完成它。 Sorry for the big question, and the unintentional wrong format, it is my first post here. 抱歉,我遇到的第一个问题是格式错误,这是我的第一篇文章。

Thanks. 谢谢。

The following code for my handler works for me. 以下适用于我的处理程序的代码对我有用。 YMMV. 因人而异。

Instead of having a clicked function, I have a down which maps to a dropped and dragged . 我没有clicked功能,而是有一个down ,它映射到dropped and dragged
I also included a move variable which is used in the dropped function to indicate whether the node was actually clicked or just dragged. 我还包括一个move变量,该函数在dropped函数中用于指示该节点是实际单击还是被拖动。

Hopefully this helps! 希望这会有所帮助!

initMouseHandling:function(){
// no-nonsense drag and drop (thanks springy.js)
selected = null;
nearest = null;
var dragged = null;
var move = false;

// set up a handler object that will initially listen for mousedowns then
// for moves and mouseups while dragging
var handler = {
  moved:function(e){
    var pos = $(canvas).offset();
    _mouseP = arbor.Point(e.pageX-pos.left, e.pageY-pos.top);
    nearest = particleSystem.nearest(_mouseP);

    if(!nearest.node){
        return false;
    }

    selected = (nearest.distance < nearest.node.data.radius) ? nearest : null

    // code for node that mouse is hovered on ('selected')

  },
  down:function(e){
    var pos = $(canvas).offset();
    _mouseP = arbor.Point(e.pageX-pos.left, e.pageY-pos.top)
    nearest = dragged = particleSystem.nearest(_mouseP);
    move = false;

    if (dragged && dragged.node !== null){
        dragged.node.fixed = true
    }

    $(canvas).bind('mousemove', handler.dragged)
    $(window).bind('mouseup', handler.dropped)

    return false
  },
  dragged:function(e){
    var old_nearest = nearest && nearest.node._id
    var pos = $(canvas).offset();
    var s = arbor.Point(e.pageX-pos.left, e.pageY-pos.top)
    move = true;

    if (!nearest) return
    if (dragged !== null && dragged.node !== null){
      var p = particleSystem.fromScreen(s)
      dragged.node.p = p
    }

    return false
  },

  dropped:function(e){
    var edit = $("#edit").prop('checked')
    if (dragged===null || dragged.node===undefined) return
    if (dragged.node !== null) {
        if(move===false) {

            // code for clicked node (dragged.node)

        }
        dragged.node.fixed = false
    }
    dragged.node.tempMass = 1000
    dragged = null
    selected = null
    $(canvas).unbind('mousemove', handler.dragged)
    $(window).unbind('mouseup', handler.dropped)
    _mouseP = null
    return false
  }
}

$(canvas).mousedown(handler.down);
$(canvas).mousemove(handler.moved);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM