cayley/static/third_party/sigmajs/plugins/sigma.plugins.dragNodes.min.js
2014-06-20 18:34:31 -04:00

1 line
No EOL
1.4 KiB
JavaScript

(function(){"use strict";if("undefined"==typeof sigma)throw"sigma is not declared";sigma.utils.pkg("sigma.plugins"),sigma.plugins.dragNodes=function(a,b){if(sigma.renderers.webgl&&b instanceof sigma.renderers.webgl)throw new Error("The sigma.plugins.dragNodes is not compatible with the WebGL renderer");var c=document.body,d=b.container,e=d.lastChild,f=b.camera,g=null,h="",i=!1;h=b instanceof sigma.renderers.webgl?b.options.prefix.substr(5):b.options.prefix;var j=function(a){i||(g=a.data.node,e.addEventListener("mousedown",l),i=!0)},k=function(){i&&(e.removeEventListener("mousedown",l),i=!1)},l=function(){var d=a.graph.nodes().length;d>1&&(e.removeEventListener("mousedown",l),c.addEventListener("mousemove",n),c.addEventListener("mouseup",m),b.unbind("outNode",k),b.settings({mouseEnabled:!1,enableHovering:!1}),a.refresh())},m=function(){e.addEventListener("mousedown",l),c.removeEventListener("mousemove",n),c.removeEventListener("mouseup",m),k(),b.bind("outNode",k),b.settings({mouseEnabled:!0,enableHovering:!0}),a.refresh()},n=function(b){for(var c=b.pageX-d.offsetLeft,e=b.pageY-d.offsetTop,i=Math.cos(f.angle),j=Math.sin(f.angle),k=a.graph.nodes(),l=[],m=0;2>m;m++){var n=k[m],o={x:n.x*i+n.y*j,y:n.y*i-n.x*j,renX:n[h+"x"],renY:n[h+"y"]};l.push(o)}c=(c-l[0].renX)/(l[1].renX-l[0].renX)*(l[1].x-l[0].x)+l[0].x,e=(e-l[0].renY)/(l[1].renY-l[0].renY)*(l[1].y-l[0].y)+l[0].y,g.x=c*i-e*j,g.y=e*i+c*j,a.refresh()};b.bind("overNode",j),b.bind("outNode",k)}}).call(window);