سؤال

I tried to drag a node individually by getting the mouse position, by it seems to be catched by the whole graph grab behavior. The properties of the selected nodes are properly modified but the other nodes are moving together, even if I set n.x and n.y.

Here's my attempt : http://jsfiddle.net/blt909/yhk3b/

jQuery(document).ready(function(){
   var sigRoot = document.getElementById('sig');
   var sigInst = sigma.init(sigRoot).position(0, 0, 1);
   var mousePos = {};
   $(document).mousemove(function(e){
       var $div = $("#sig");
       mousePos = {
           x: e.pageX,
           y: e.pageY
       };
   });   

    function onNodeDown(evt) {
        var sigmajs = evt.target;
        var nodeId = evt.content[0];
        sigmajs.iterNodes(function(n){
            n.size = 5;
            n.color = "#0000FF";
            n.displayX = mousePos.x;
            n.displayY = mousePos.y;
            console.log(n);
       },[nodeId]);    

       sigmajs.draw(2,2,2, false);

       sigmajs.refresh();
    };

    sigInst.graphProperties({
        minNodeSize: 2,
        maxNodeSize: 5
    });

    sigInst.addNode('000',{
        label: '000',
        color: '#000000',
          x: Math.random() * 100,
          y: Math.random() * 100
    }).addNode('111',{
        label: '111',
        color: '#111111',
          x: Math.random() * 100,
          y: Math.random() * 100
    }).addNode('222',{
        label: '222',
        color: '#222222',
          x: Math.random() * 100,
          y: Math.random() * 100
    }).addEdge('111222','111','222')
      .addEdge('111000','111','000');

      sigInst.bind('downnodes',onNodeDown);

      sigInst.draw();
  })

Did anybody tried the same trick on sigma.js?

Thanks for your help

هل كانت مفيدة؟

المحلول

The new sigma.js has a dragNodes plugin sigma.plugins.dragNodes.js but it only works in canvas, just include the plugin file and pass the sigma object:

<script src="./plugins/sigma.plugins.dragNodes/sigma.plugins.dragNodes.js"></script>
let dragListener = sigma.plugins.dragNodes(sigInst, sigInst.renderers[0])
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top