simi
[iramuteq] / webexport / js / sigma.min.js
1 /* sigmajs.org - an open-source light-weight JavaScript graph drawing library - Version: 0.1 - Author:  Alexis Jacomy - License: MIT */
2 var sigma={tools:{},classes:{},instances:{}};
3 (function(){Array.prototype.some||(Array.prototype.some=function(l,r){var h=this.length;if("function"!=typeof l)throw new TypeError;for(var m=0;m<h;m++)if(m in this&&l.call(r,this[m],m,this))return!0;return!1});Array.prototype.forEach||(Array.prototype.forEach=function(l,r){var h=this.length;if("function"!=typeof l)throw new TypeError;for(var m=0;m<h;m++)m in this&&l.call(r,this[m],m,this)});Array.prototype.map||(Array.prototype.map=function(l,r){var h=this.length;if("function"!=typeof l)throw new TypeError;
4 for(var m=Array(h),p=0;p<h;p++)p in this&&(m[p]=l.call(r,this[p],p,this));return m});Array.prototype.filter||(Array.prototype.filter=function(l,r){var h=this.length;if("function"!=typeof l)throw new TypeError;for(var m=[],p=0;p<h;p++)if(p in this){var x=this[p];l.call(r,x,p,this)&&m.push(x)}return m});Object.keys||(Object.keys=function(){var l=Object.prototype.hasOwnProperty,r=!{toString:null}.propertyIsEnumerable("toString"),h="toString toLocaleString valueOf hasOwnProperty isPrototypeOf propertyIsEnumerable constructor".split(" "),
5 m=h.length;return function(p){if("object"!==typeof p&&"function"!==typeof p||null===p)throw new TypeError("Object.keys called on non-object");var x=[],v;for(v in p)l.call(p,v)&&x.push(v);if(r)for(v=0;v<m;v++)l.call(p,h[v])&&x.push(h[v]);return x}}())})();
6 sigma.classes.EventDispatcher=function(){var l={},r=this;this.one=function(h,m){if(!m||!h)return r;("string"==typeof h?h.split(" "):h).forEach(function(h){l[h]||(l[h]=[]);l[h].push({h:m,one:!0})});return r};this.bind=function(h,m){if(!m||!h)return r;("string"==typeof h?h.split(" "):h).forEach(function(h){l[h]||(l[h]=[]);l[h].push({h:m,one:!1})});return r};this.unbind=function(h,m){h||(l={});var p="string"==typeof h?h.split(" "):h;m?p.forEach(function(h){l[h]&&(l[h]=l[h].filter(function(h){return h.h!=
7 m}));l[h]&&0==l[h].length&&delete l[h]}):p.forEach(function(h){delete l[h]});return r};this.dispatch=function(h,m){l[h]&&(l[h].forEach(function(l){l.h({type:h,content:m,target:r})}),l[h]=l[h].filter(function(h){return!h.one}));return r}};sigma.classes.Cascade=function(){this.p={};this.config=function(l,r){if("string"==typeof l&&void 0==r)return this.p[l];var h="object"==typeof l&&void 0==r?l:{};"string"==typeof l&&(h[l]=r);for(var m in h)void 0!=this.p[m]&&(this.p[m]=h[m]);return this}};
8 (function(){function l(){function b(a){return{x:a.x,y:a.y,size:a.size,degree:a.degree,inDegree:a.inDegree,outDegree:a.outDegree,displayX:a.displayX,displayY:a.displayY,displaySize:a.displaySize,label:a.label,id:a.id,color:a.color,fixed:a.fixed,active:a.active,hidden:a.hidden,forceLabel:a.forceLabel,attr:a.attr}}function k(a){return{source:a.source.id,target:a.target.id,size:a.size,type:a.type,weight:a.weight,displaySize:a.displaySize,label:a.label,hidden:a.hidden,id:a.id,attr:a.attr,color:a.color}}
9 function f(){c.nodes=[];c.nodesIndex={};c.edges=[];c.edgesIndex={};return c}sigma.classes.Cascade.call(this);sigma.classes.EventDispatcher.call(this);var c=this;this.p={minNodeSize:0,maxNodeSize:0,minEdgeSize:0,maxEdgeSize:0,scalingMode:"inside",nodesPowRatio:0.5,edgesPowRatio:0};this.borders={};f();this.addNode=function(a,b){if(c.nodesIndex[a])throw Error('Node "'+a+'" already exists.');b=b||{};var d={x:0,y:0,size:1,degree:0,inDegree:0,outDegree:0,fixed:!1,active:!1,hidden:!1,forceLabel:!1,label:a.toString(),
10 id:a.toString(),attr:{}},f;for(f in b)switch(f){case "id":break;case "x":case "y":case "size":d[f]=+b[f];break;case "fixed":case "active":case "hidden":case "forceLabel":d[f]=!!b[f];break;case "color":case "label":d[f]=b[f];break;default:d.attr[f]=b[f]}c.nodes.push(d);c.nodesIndex[a.toString()]=d;return c};this.addEdge=function(a,b,d,f){if(c.edgesIndex[a])throw Error('Edge "'+a+'" already exists.');if(!c.nodesIndex[b])throw Error("Edge's source \""+b+'" does not exist yet.');if(!c.nodesIndex[d])throw Error("Edge's target \""+
11 d+'" does not exist yet.');f=f||{};b={source:c.nodesIndex[b],target:c.nodesIndex[d],size:1,weight:1,displaySize:0.5,label:a.toString(),id:a.toString(),hidden:!1,attr:{}};b.source.degree++;b.source.outDegree++;b.target.degree++;b.target.inDegree++;for(var s in f)switch(s){case "id":case "source":case "target":break;case "hidden":b[s]=!!f[s];break;case "size":case "weight":b[s]=+f[s];break;case "color":b[s]=f[s].toString();break;case "type":b[s]=f[s].toString();break;case "label":b[s]=f[s];break;default:b.attr[s]=
12 f[s]}c.edges.push(b);c.edgesIndex[a.toString()]=b;return c};this.dropNode=function(a){var b={};((a instanceof Array?a:[a])||[]).forEach(function(a){c.nodesIndex[a]?b[a]=!0:sigma.log('Node "'+a+'" does not exist.')});var d=[];c.nodes.forEach(function(a,c){a.id in b&&(d.unshift(c),0==a.degree&&delete b[a.id])});d.forEach(function(a){c.nodes.splice(a,1)});c.edges=c.edges.filter(function(a){return a.source.id in b?(delete c.edgesIndex[a.id],a.target.degree--,a.target.inDegree--,!1):a.target.id in b?(delete c.edgesIndex[a.id],
13 a.source.degree--,a.source.outDegree--,!1):!0});return c};this.dropEdge=function(a){((a instanceof Array?a:[a])||[]).forEach(function(a){if(c.edgesIndex[a]){c.edgesIndex[a].source.degree--;c.edgesIndex[a].source.outDegree--;c.edgesIndex[a].target.degree--;c.edgesIndex[a].target.inDegree--;var d=null;c.edges.some(function(b,c){return b.id==a?(d=c,!0):!1});null!=d&&c.edges.splice(d,1);delete c.edgesIndex[a]}else sigma.log('Edge "'+a+'" does not exist.')});return c};this.iterEdges=function(a,b){var d=
14 b?b.map(function(a){return c.edgesIndex[a]}):c.edges,f=d.map(k);f.forEach(a);d.forEach(function(a,d){var b=f[d],n;for(n in b)switch(n){case "id":case "displaySize":break;case "weight":case "size":a[n]=+b[n];break;case "source":case "target":a[n]=c.nodesIndex[n]||a[n];break;case "hidden":a[n]=!!b[n];break;case "color":case "label":case "type":a[n]=(b[n]||"").toString();break;default:a.attr[n]=b[n]}});return c};this.iterNodes=function(a,f){var d=f?f.map(function(a){return c.nodesIndex[a]}):c.nodes,
15 k=d.map(b);k.forEach(a);d.forEach(function(a,b){var d=k[b],c;for(c in d)switch(c){case "id":case "attr":case "degree":case "inDegree":case "outDegree":case "displayX":case "displayY":case "displaySize":break;case "x":case "y":case "size":a[c]=+d[c];break;case "fixed":case "active":case "hidden":case "forceLabel":a[c]=!!d[c];break;case "color":case "label":a[c]=(d[c]||"").toString();break;default:a.attr[c]=d[c]}});return c};this.getEdges=function(a){var b=((a instanceof Array?a:[a])||[]).map(function(a){return k(c.edgesIndex[a])});
16 return a instanceof Array?b:b[0]};this.getNodes=function(a){var f=((a instanceof Array?a:[a])||[]).map(function(a){return b(c.nodesIndex[a])});return a instanceof Array?f:f[0]};this.empty=f;this.rescale=function(a,b,d,f){var s=0,g=0;d&&c.nodes.forEach(function(a){g=Math.max(a.size,g)});f&&c.edges.forEach(function(a){s=Math.max(a.size,s)});var g=g||1,s=s||1,k,n,q,t;d&&c.nodes.forEach(function(a){n=Math.max(a.x,n||a.x);k=Math.min(a.x,k||a.x);t=Math.max(a.y,t||a.y);q=Math.min(a.y,q||a.y)});var h="outside"==
17 c.p.scalingMode?Math.max(a/Math.max(n-k,1),b/Math.max(t-q,1)):Math.min(a/Math.max(n-k,1),b/Math.max(t-q,1)),l=(c.p.maxNodeSize||g)/h;n+=l;k-=l;t+=l;q-=l;var h="outside"==c.p.scalingMode?Math.max(a/Math.max(n-k,1),b/Math.max(t-q,1)):Math.min(a/Math.max(n-k,1),b/Math.max(t-q,1)),m,p;!c.p.maxNodeSize&&!c.p.minNodeSize?(m=1,p=0):c.p.maxNodeSize==c.p.minNodeSize?(m=0,p=c.p.maxNodeSize):(m=(c.p.maxNodeSize-c.p.minNodeSize)/g,p=c.p.minNodeSize);var B,D;!c.p.maxEdgeSize&&!c.p.minEdgeSize?(B=1,D=0):(B=c.p.maxEdgeSize==
18 c.p.minEdgeSize?0:(c.p.maxEdgeSize-c.p.minEdgeSize)/s,D=c.p.minEdgeSize);d&&c.nodes.forEach(function(d){d.displaySize=d.size*m+p;d.fixed||(d.displayX=(d.x-(n+k)/2)*h+a/2,d.displayY=(d.y-(t+q)/2)*h+b/2)});f&&c.edges.forEach(function(a){a.displaySize=a.size*B+D});return c};this.translate=function(a,b,d,f,s){var g=Math.pow(d,c.p.nodesPowRatio);f&&c.nodes.forEach(function(c){c.fixed||(c.displayX=c.displayX*d+a,c.displayY=c.displayY*d+b);c.displaySize*=g});g=Math.pow(d,c.p.edgesPowRatio);s&&c.edges.forEach(function(a){a.displaySize*=
19 g});return c};this.setBorders=function(){c.borders={};c.nodes.forEach(function(a){c.borders.minX=Math.min(void 0==c.borders.minX?a.displayX-a.displaySize:c.borders.minX,a.displayX-a.displaySize);c.borders.maxX=Math.max(void 0==c.borders.maxX?a.displayX+a.displaySize:c.borders.maxX,a.displayX+a.displaySize);c.borders.minY=Math.min(void 0==c.borders.minY?a.displayY-a.displaySize:c.borders.minY,a.displayY-a.displaySize);c.borders.maxY=Math.max(void 0==c.borders.maxY?a.displayY-a.displaySize:c.borders.maxY,
20 a.displayY-a.displaySize)})};this.checkHover=function(a,b){var d,f,s,g=[],k=[];c.nodes.forEach(function(c){if(c.hidden)c.hover=!1;else{d=Math.abs(c.displayX-a);f=Math.abs(c.displayY-b);s=c.displaySize;var q=c.hover,t=d<s&&f<s&&Math.sqrt(d*d+f*f)<s;q&&!t?(c.hover=!1,k.push(c.id)):t&&!q&&(c.hover=!0,g.push(c.id))}});g.length&&c.dispatch("overnodes",g);k.length&&c.dispatch("outnodes",k);return c}}function r(b,k){function f(){sigma.chronos.removeTask("node_"+d.id,2).removeTask("edge_"+d.id,2).removeTask("label_"+
21 d.id,2).stopTasks();return d}function c(a,b){d.domElements[a]=document.createElement(b);d.domElements[a].style.position="absolute";d.domElements[a].setAttribute("id","sigma_"+a+"_"+d.id);d.domElements[a].setAttribute("class","sigma_"+a+"_"+b);d.domElements[a].setAttribute("width",d.width+"px");d.domElements[a].setAttribute("height",d.height+"px");d.domRoot.appendChild(d.domElements[a]);return d}function a(){d.p.drawHoverNodes&&(d.graph.checkHover(d.mousecaptor.mouseX,d.mousecaptor.mouseY),d.graph.nodes.forEach(function(a){a.hover&&
22 !a.active&&d.plotter.drawHoverNode(a)}));return d}function h(){d.p.drawActiveNodes&&d.graph.nodes.forEach(function(a){a.active&&d.plotter.drawActiveNode(a)});return d}sigma.classes.Cascade.call(this);sigma.classes.EventDispatcher.call(this);var d=this;this.id=k.toString();this.p={auto:!0,drawNodes:2,drawEdges:1,drawLabels:2,lastNodes:2,lastEdges:0,lastLabels:2,drawHoverNodes:!0,drawActiveNodes:!0};this.domRoot=b;this.width=this.domRoot.offsetWidth;this.height=this.domRoot.offsetHeight;this.graph=
23 new l;this.domElements={};c("edges","canvas");c("nodes","canvas");c("labels","canvas");c("hover","canvas");c("monitor","div");c("mouse","canvas");this.plotter=new p(this.domElements.nodes.getContext("2d"),this.domElements.edges.getContext("2d"),this.domElements.labels.getContext("2d"),this.domElements.hover.getContext("2d"),this.graph,this.width,this.height);this.monitor=new x(this,this.domElements.monitor);this.mousecaptor=new m(this.domElements.mouse,this.id);this.mousecaptor.bind("drag interpolate",
24 function(a){d.draw(d.p.auto?2:d.p.drawNodes,d.p.auto?0:d.p.drawEdges,d.p.auto?2:d.p.drawLabels,!0)}).bind("stopdrag stopinterpolate",function(a){d.draw(d.p.auto?2:d.p.drawNodes,d.p.auto?1:d.p.drawEdges,d.p.auto?2:d.p.drawLabels,!0)}).bind("mousedown mouseup",function(a){var b=d.graph.nodes.filter(function(a){return!!a.hover}).map(function(a){return a.id});d.dispatch("mousedown"==a.type?"downgraph":"upgraph");b.length&&d.dispatch("mousedown"==a.type?"downnodes":"upnodes",b)}).bind("move",function(){d.domElements.hover.getContext("2d").clearRect(0,
25 0,d.domElements.hover.width,d.domElements.hover.height);a();h()});sigma.chronos.bind("startgenerators",function(){sigma.chronos.getGeneratorsIDs().some(function(a){return!!a.match(RegExp("_ext_"+d.id+"$",""))})&&d.draw(d.p.auto?2:d.p.drawNodes,d.p.auto?0:d.p.drawEdges,d.p.auto?2:d.p.drawLabels)}).bind("stopgenerators",function(){d.draw()});for(var E=0;E<G.plugins.length;E++)G.plugins[E](this);this.draw=function(a,b,c,k){if(k&&sigma.chronos.getGeneratorsIDs().some(function(a){return!!a.match(RegExp("_ext_"+
26 d.id+"$",""))}))return d;a=void 0==a?d.p.drawNodes:a;b=void 0==b?d.p.drawEdges:b;c=void 0==c?d.p.drawLabels:c;k={nodes:a,edges:b,labels:c};d.p.lastNodes=a;d.p.lastEdges=b;d.p.lastLabels=c;f();d.graph.rescale(d.width,d.height,0<a,0<b).setBorders();d.mousecaptor.checkBorders(d.graph.borders,d.width,d.height);d.graph.translate(d.mousecaptor.stageX,d.mousecaptor.stageY,d.mousecaptor.ratio,0<a,0<b);d.dispatch("graphscaled");for(var q in d.domElements)"canvas"==d.domElements[q].nodeName.toLowerCase()&&
27 (void 0==k[q]||0<=k[q])&&d.domElements[q].getContext("2d").clearRect(0,0,d.domElements[q].width,d.domElements[q].height);d.plotter.currentEdgeIndex=0;d.plotter.currentNodeIndex=0;d.plotter.currentLabelIndex=0;q=null;k=!1;if(a)if(1<a)for(;d.plotter.task_drawNode(););else sigma.chronos.addTask(d.plotter.task_drawNode,"node_"+d.id,!1),k=!0,q="node_"+d.id;if(c)if(1<c)for(;d.plotter.task_drawLabel(););else q?sigma.chronos.queueTask(d.plotter.task_drawLabel,"label_"+d.id,q):sigma.chronos.addTask(d.plotter.task_drawLabel,
28 "label_"+d.id,!1),k=!0,q="label_"+d.id;if(b)if(1<b)for(;d.plotter.task_drawEdge(););else q?sigma.chronos.queueTask(d.plotter.task_drawEdge,"edge_"+d.id,q):sigma.chronos.addTask(d.plotter.task_drawEdge,"edge_"+d.id,!1),k=!0,q="edge_"+d.id;d.dispatch("draw");d.refresh();k&&sigma.chronos.runTasks();return d};this.resize=function(a,b){var c=d.width,f=d.height;void 0!=a&&void 0!=b?(d.width=a,d.height=b):(d.width=d.domRoot.offsetWidth,d.height=d.domRoot.offsetHeight);if(c!=d.width||f!=d.height){for(var q in d.domElements)d.domElements[q].setAttribute("width",
29 d.width+"px"),d.domElements[q].setAttribute("height",d.height+"px");d.plotter.resize(d.width,d.height);d.draw(d.p.lastNodes,d.p.lastEdges,d.p.lastLabels,!0)}return d};this.refresh=function(){d.domElements.hover.getContext("2d").clearRect(0,0,d.domElements.hover.width,d.domElements.hover.height);a();h();return d};this.drawHover=a;this.drawActive=h;this.clearSchedule=f;window.addEventListener("resize",function(){d.resize()})}function h(b){var k=this;sigma.classes.EventDispatcher.call(this);this._core=
30 b;this.kill=function(){};this.getID=function(){return b.id};this.configProperties=function(f,c){var a=b.config(f,c);return a==b?k:a};this.drawingProperties=function(f,c){var a=b.plotter.config(f,c);return a==b.plotter?k:a};this.mouseProperties=function(f,c){var a=b.mousecaptor.config(f,c);return a==b.mousecaptor?k:a};this.graphProperties=function(f,c){var a=b.graph.config(f,c);return a==b.graph?k:a};this.getMouse=function(){return{mouseX:b.mousecaptor.mouseX,mouseY:b.mousecaptor.mouseY,down:b.mousecaptor.isMouseDown}};
31 this.position=function(f,c,a){if(0==arguments.length)return{stageX:b.mousecaptor.stageX,stageY:b.mousecaptor.stageY,ratio:b.mousecaptor.ratio};b.mousecaptor.stageX=void 0!=f?f:b.mousecaptor.stageX;b.mousecaptor.stageY=void 0!=c?c:b.mousecaptor.stageY;b.mousecaptor.ratio=void 0!=a?a:b.mousecaptor.ratio;return k};this.goTo=function(f,c,a){b.mousecaptor.interpolate(f,c,a);return k};this.zoomTo=function(f,c,a){a=Math.min(Math.max(b.mousecaptor.config("minRatio"),a),b.mousecaptor.config("maxRatio"));a==
32 b.mousecaptor.ratio?b.mousecaptor.interpolate(f-b.width/2+b.mousecaptor.stageX,c-b.height/2+b.mousecaptor.stageY):b.mousecaptor.interpolate((a*f-b.mousecaptor.ratio*b.width/2)/(a-b.mousecaptor.ratio),(a*c-b.mousecaptor.ratio*b.height/2)/(a-b.mousecaptor.ratio),a);return k};this.resize=function(f,c){b.resize(f,c);return k};this.draw=function(f,c,a,h){b.draw(f,c,a,h);return k};this.refresh=function(){b.refresh();return k};this.addGenerator=function(f,c,a){sigma.chronos.addGenerator(f+"_ext_"+b.id,c,
33 a);return k};this.removeGenerator=function(f){sigma.chronos.removeGenerator(f+"_ext_"+b.id);return k};this.addNode=function(f,c){b.graph.addNode(f,c);return k};this.addEdge=function(f,c,a,h){b.graph.addEdge(f,c,a,h);return k};this.dropNode=function(f){b.graph.dropNode(f);return k};this.dropEdge=function(f){b.graph.dropEdge(f);return k};this.pushGraph=function(f,c){f.nodes&&f.nodes.forEach(function(a){a.id&&(!c||!b.graph.nodesIndex[a.id])&&k.addNode(a.id,a)});f.edges&&f.edges.forEach(function(a){(validID=
34 a.source&&a.target&&a.id)&&(!c||!b.graph.edgesIndex[a.id])&&k.addEdge(a.id,a.source,a.target,a)});return k};this.emptyGraph=function(){b.graph.empty();return k};this.getNodesCount=function(){return b.graph.nodes.length};this.getEdgesCount=function(){return b.graph.edges.length};this.iterNodes=function(f,c){b.graph.iterNodes(f,c);return k};this.iterEdges=function(f,c){b.graph.iterEdges(f,c);return k};this.getNodes=function(f){return b.graph.getNodes(f)};this.getEdges=function(f){return b.graph.getEdges(f)};
35 this.activateMonitoring=function(){return b.monitor.activate()};this.desactivateMonitoring=function(){return b.monitor.desactivate()};b.bind("downnodes upnodes downgraph upgraph",function(b){k.dispatch(b.type,b.content)});b.graph.bind("overnodes outnodes",function(b){k.dispatch(b.type,b.content)})}function m(b){function k(b){a.p.mouseEnabled&&(f(a.mouseX,a.mouseY,a.ratio*(0<(void 0!=b.wheelDelta&&b.wheelDelta||void 0!=b.detail&&-b.detail)?a.p.zoomMultiply:1/a.p.zoomMultiply)),a.p.blockScroll&&(b.preventDefault?
36 b.preventDefault():b.returnValue=!1))}function f(b,d,f){if(!a.isMouseDown&&(window.clearInterval(a.interpolationID),A=void 0!=f,l=a.stageX,p=b,m=a.stageY,n=d,g=f||a.ratio,g=Math.min(Math.max(g,a.p.minRatio),a.p.maxRatio),y=a.p.directZooming?1-(A?a.p.zoomDelta:a.p.dragDelta):0,a.ratio!=g||a.stageX!=p||a.stageY!=n))c(),a.interpolationID=window.setInterval(c,50),a.dispatch("startinterpolate")}function c(){y+=A?a.p.zoomDelta:a.p.dragDelta;y=Math.min(y,1);var b=sigma.easing.quadratic.easeout(y),c=a.ratio;
37 a.ratio=c*(1-b)+g*b;A?(a.stageX=p+(a.stageX-p)*a.ratio/c,a.stageY=n+(a.stageY-n)*a.ratio/c):(a.stageX=l*(1-b)+p*b,a.stageY=m*(1-b)+n*b);a.dispatch("interpolate");1<=y&&(window.clearInterval(a.interpolationID),b=a.ratio,A?(a.ratio=g,a.stageX=p+(a.stageX-p)*a.ratio/b,a.stageY=n+(a.stageY-n)*a.ratio/b):(a.stageX=p,a.stageY=n),a.dispatch("stopinterpolate"))}sigma.classes.Cascade.call(this);sigma.classes.EventDispatcher.call(this);var a=this;this.p={minRatio:1,maxRatio:32,marginRatio:1,zoomDelta:0.1,dragDelta:0.3,
38 zoomMultiply:2,directZooming:!1,blockScroll:!0,inertia:1.1,mouseEnabled:!0};var h=0,d=0,l=0,m=0,g=1,p=0,n=0,q=0,t=0,F=0,r=0,y=0,A=!1;this.stageY=this.stageX=0;this.ratio=1;this.mouseY=this.mouseX=0;this.isMouseDown=!1;b.addEventListener("DOMMouseScroll",k,!0);b.addEventListener("mousewheel",k,!0);b.addEventListener("mousemove",function(b){a.mouseX=void 0!=b.offsetX&&b.offsetX||void 0!=b.layerX&&b.layerX||void 0!=b.clientX&&b.clientX;a.mouseY=void 0!=b.offsetY&&b.offsetY||void 0!=b.layerY&&b.layerY||
39 void 0!=b.clientY&&b.clientY;if(a.isMouseDown){var c=a.mouseX-h+l,f=a.mouseY-d+m;if(c!=a.stageX||f!=a.stageY)t=q,r=F,q=c,F=f,a.stageX=c,a.stageY=f,a.dispatch("drag")}a.dispatch("move");b.preventDefault?b.preventDefault():b.returnValue=!1},!0);b.addEventListener("mousedown",function(b){a.p.mouseEnabled&&(a.isMouseDown=!0,a.dispatch("mousedown"),l=a.stageX,m=a.stageY,h=a.mouseX,d=a.mouseY,t=q=a.stageX,r=F=a.stageY,a.dispatch("startdrag"),b.preventDefault?b.preventDefault():b.returnValue=!1)},!0);document.addEventListener("mouseup",
40 function(b){a.p.mouseEnabled&&a.isMouseDown&&(a.isMouseDown=!1,a.dispatch("mouseup"),(l!=a.stageX||m!=a.stageY)&&f(a.stageX+a.p.inertia*(a.stageX-t),a.stageY+a.p.inertia*(a.stageY-r)),b.preventDefault?b.preventDefault():b.returnValue=!1)},!0);this.checkBorders=function(b,c,d){return a};this.interpolate=f}function p(b,k,f,c,a,h,d){function l(a){var b=c,d="fixed"==g.p.labelSize?g.p.defaultLabelSize:g.p.labelSizeRatio*a.displaySize;b.font=(g.p.hoverFontStyle||g.p.fontStyle||"")+" "+d+"px "+(g.p.hoverFont||
41 g.p.font||"");b.fillStyle="node"==g.p.labelHoverBGColor?a.color||g.p.defaultNodeColor:g.p.defaultHoverLabelBGColor;b.beginPath();g.p.labelHoverShadow&&(b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=4,b.shadowColor=g.p.labelHoverShadowColor);sigma.tools.drawRoundRect(b,Math.round(a.displayX-d/2-2),Math.round(a.displayY-d/2-2),Math.round(b.measureText(a.label).width+1.5*a.displaySize+d/2+4),Math.round(d+4),Math.round(d/2+2),"left");b.closePath();b.fill();b.shadowOffsetX=0;b.shadowOffsetY=0;b.shadowBlur=
42 0;b.beginPath();b.fillStyle="node"==g.p.nodeBorderColor?a.color||g.p.defaultNodeColor:g.p.defaultNodeBorderColor;b.arc(Math.round(a.displayX),Math.round(a.displayY),a.displaySize+g.p.borderSize,0,2*Math.PI,!0);b.closePath();b.fill();b.beginPath();b.fillStyle="node"==g.p.nodeHoverColor?a.color||g.p.defaultNodeColor:g.p.defaultNodeHoverColor;b.arc(Math.round(a.displayX),Math.round(a.displayY),a.displaySize,0,2*Math.PI,!0);b.closePath();b.fill();b.fillStyle="node"==g.p.labelHoverColor?a.color||g.p.defaultNodeColor:
43 g.p.defaultLabelHoverColor;b.fillText(a.label,Math.round(a.displayX+1.5*a.displaySize),Math.round(a.displayY+d/2-3));return g}function m(a){if(isNaN(a.x)||isNaN(a.y))throw Error("A node's coordinate is not a number (id: "+a.id+")");return!a.hidden&&a.displayX+a.displaySize>-p/3&&a.displayX-a.displaySize<4*p/3&&a.displayY+a.displaySize>-n/3&&a.displayY-a.displaySize<4*n/3}sigma.classes.Cascade.call(this);var g=this;this.p={labelColor:"default",defaultLabelColor:"#000",labelHoverBGColor:"default",defaultHoverLabelBGColor:"#fff",
44 labelHoverShadow:!0,labelHoverShadowColor:"#000",labelHoverColor:"default",defaultLabelHoverColor:"#000",labelActiveBGColor:"default",defaultActiveLabelBGColor:"#fff",labelActiveShadow:!0,labelActiveShadowColor:"#000",labelActiveColor:"default",defaultLabelActiveColor:"#000",labelSize:"fixed",defaultLabelSize:12,labelSizeRatio:2,labelThreshold:6,font:"Arial",hoverFont:"",activeFont:"",fontStyle:"",hoverFontStyle:"",activeFontStyle:"",edgeColor:"source",defaultEdgeColor:"#aaa",defaultEdgeType:"line",
45 defaultNodeColor:"#aaa",nodeHoverColor:"node",defaultNodeHoverColor:"#fff",nodeActiveColor:"node",defaultNodeActiveColor:"#fff",borderSize:0,nodeBorderColor:"node",defaultNodeBorderColor:"#fff",edgesSpeed:200,nodesSpeed:200,labelsSpeed:200};var p=h,n=d;this.currentLabelIndex=this.currentNodeIndex=this.currentEdgeIndex=0;this.task_drawLabel=function(){for(var b=a.nodes.length,c=0;c++<g.p.labelsSpeed&&g.currentLabelIndex<b;)if(g.isOnScreen(a.nodes[g.currentLabelIndex])){var d=a.nodes[g.currentLabelIndex++],
46 k=f;if(d.displaySize>=g.p.labelThreshold||d.forceLabel){var h="fixed"==g.p.labelSize?g.p.defaultLabelSize:g.p.labelSizeRatio*d.displaySize;k.font=g.p.fontStyle+h+"px "+g.p.font;k.fillStyle="node"==g.p.labelColor?d.color||g.p.defaultNodeColor:g.p.defaultLabelColor;k.fillText(d.label,Math.round(d.displayX+1.5*d.displaySize),Math.round(d.displayY+h/2-3))}}else g.currentLabelIndex++;return g.currentLabelIndex<b};this.task_drawEdge=function(){for(var b=a.edges.length,c,d,f=0;f++<g.p.edgesSpeed&&g.currentEdgeIndex<
47 b;)if(e=a.edges[g.currentEdgeIndex],c=e.source,d=e.target,e.hidden||c.hidden||d.hidden||!g.isOnScreen(c)&&!g.isOnScreen(d))g.currentEdgeIndex++;else{c=a.edges[g.currentEdgeIndex++];d=c.source.displayX;var h=c.source.displayY,l=c.target.displayX,m=c.target.displayY,p=c.color;if(!p)switch(g.p.edgeColor){case "source":p=c.source.color||g.p.defaultNodeColor;break;case "target":p=c.target.color||g.p.defaultNodeColor;break;default:p=g.p.defaultEdgeColor}var n=k;switch(c.type||g.p.defaultEdgeType){case "curve":n.strokeStyle=
48 p;n.lineWidth=c.displaySize/3;n.beginPath();n.moveTo(d,h);n.quadraticCurveTo((d+l)/2+(m-h)/4,(h+m)/2+(d-l)/4,l,m);n.stroke();break;default:n.strokeStyle=p,n.lineWidth=c.displaySize/3,n.beginPath(),n.moveTo(d,h),n.lineTo(l,m),n.stroke()}}return g.currentEdgeIndex<b};this.task_drawNode=function(){for(var c=a.nodes.length,d=0;d++<g.p.nodesSpeed&&g.currentNodeIndex<c;)if(g.isOnScreen(a.nodes[g.currentNodeIndex])){var f=a.nodes[g.currentNodeIndex++],k=Math.round(10*f.displaySize)/10,h=b;h.fillStyle=f.color;
49 h.beginPath();h.arc(f.displayX,f.displayY,k,0,2*Math.PI,!0);h.closePath();h.fill();f.hover&&l(f)}else g.currentNodeIndex++;return g.currentNodeIndex<c};this.drawActiveNode=function(a){var b=c;if(!m(a))return g;var d="fixed"==g.p.labelSize?g.p.defaultLabelSize:g.p.labelSizeRatio*a.displaySize;b.font=(g.p.activeFontStyle||g.p.fontStyle||"")+" "+d+"px "+(g.p.activeFont||g.p.font||"");b.fillStyle="node"==g.p.labelHoverBGColor?a.color||g.p.defaultNodeColor:g.p.defaultActiveLabelBGColor;b.beginPath();g.p.labelActiveShadow&&
50 (b.shadowOffsetX=0,b.shadowOffsetY=0,b.shadowBlur=4,b.shadowColor=g.p.labelActiveShadowColor);sigma.tools.drawRoundRect(b,Math.round(a.displayX-d/2-2),Math.round(a.displayY-d/2-2),Math.round(b.measureText(a.label).width+1.5*a.displaySize+d/2+4),Math.round(d+4),Math.round(d/2+2),"left");b.closePath();b.fill();b.shadowOffsetX=0;b.shadowOffsetY=0;b.shadowBlur=0;b.beginPath();b.fillStyle="node"==g.p.nodeBorderColor?a.color||g.p.defaultNodeColor:g.p.defaultNodeBorderColor;b.arc(Math.round(a.displayX),
51 Math.round(a.displayY),a.displaySize+g.p.borderSize,0,2*Math.PI,!0);b.closePath();b.fill();b.beginPath();b.fillStyle="node"==g.p.nodeActiveColor?a.color||g.p.defaultNodeColor:g.p.defaultNodeActiveColor;b.arc(Math.round(a.displayX),Math.round(a.displayY),a.displaySize,0,2*Math.PI,!0);b.closePath();b.fill();b.fillStyle="node"==g.p.labelActiveColor?a.color||g.p.defaultNodeColor:g.p.defaultLabelActiveColor;b.fillText(a.label,Math.round(a.displayX+1.5*a.displaySize),Math.round(a.displayY+d/2-3));return g};
52 this.drawHoverNode=l;this.isOnScreen=m;this.resize=function(a,b){p=a;n=b;return g}}function x(b,k){function f(){var a;a="<p>GLOBAL :</p>";for(var b in c.p.globalProbes)a+="<p>"+b+" : "+c.p.globalProbes[b]()+"</p>";a+="<br><p>LOCAL :</p>";for(b in c.p.localProbes)a+="<p>"+b+" : "+c.p.localProbes[b]()+"</p>";c.p.dom.innerHTML=a;return c}sigma.classes.Cascade.call(this);var c=this;this.instance=b;this.monitoring=!1;this.p={fps:40,dom:k,globalProbes:{"Time (ms)":sigma.chronos.getExecutionTime,Queue:sigma.chronos.getQueuedTasksCount,
53 Tasks:sigma.chronos.getTasksCount,FPS:sigma.chronos.getFPS},localProbes:{"Nodes count":function(){return c.instance.graph.nodes.length},"Edges count":function(){return c.instance.graph.edges.length}}};this.activate=function(){c.monitoring||(c.monitoring=window.setInterval(f,1E3/c.p.fps));return c};this.desactivate=function(){c.monitoring&&(window.clearInterval(c.monitoring),c.monitoring=null,c.p.dom.innerHTML="");return c}}var v=0,G={plugins:[]};sigma.init=function(b){b=new r(b,(++v).toString());
54 sigma.instances[v]=new h(b);return sigma.instances[v]};sigma.addPlugin=function(b,k,f){h.prototype[b]=k;G.plugins.push(f)};sigma.tools.drawRoundRect=function(b,k,f,c,a,h,d){h=h?h:0;var l=d?d:[],l="string"==typeof l?l.split(" "):l;d=h&&(0<=l.indexOf("topleft")||0<=l.indexOf("top")||0<=l.indexOf("left"));var m=h&&(0<=l.indexOf("topright")||0<=l.indexOf("top")||0<=l.indexOf("right")),g=h&&(0<=l.indexOf("bottomleft")||0<=l.indexOf("bottom")||0<=l.indexOf("left")),l=h&&(0<=l.indexOf("bottomright")||0<=
55 l.indexOf("bottom")||0<=l.indexOf("right"));b.moveTo(k,f+h);d?b.arcTo(k,f,k+h,f,h):b.lineTo(k,f);m?(b.lineTo(k+c-h,f),b.arcTo(k+c,f,k+c,f+h,h)):b.lineTo(k+c,f);l?(b.lineTo(k+c,f+a-h),b.arcTo(k+c,f+a,k+c-h,f+a,h)):b.lineTo(k+c,f+a);g?(b.lineTo(k+h,f+a),b.arcTo(k,f+a,k,f+a-h,h)):b.lineTo(k,f+a);b.lineTo(k,f+h)};sigma.tools.getRGB=function(b,h){b=b.toString();var f={r:0,g:0,b:0};if(3<=b.length&&"#"==b.charAt(0)){var c=b.length-1;6==c?f={r:parseInt(b.charAt(1)+b.charAt(2),16),g:parseInt(b.charAt(3)+b.charAt(4),
56 16),b:parseInt(b.charAt(5)+b.charAt(5),16)}:3==c&&(f={r:parseInt(b.charAt(1)+b.charAt(1),16),g:parseInt(b.charAt(2)+b.charAt(2),16),b:parseInt(b.charAt(3)+b.charAt(3),16)})}h&&(f=[f.r,f.g,f.b]);return f};sigma.tools.rgbToHex=function(b,h,f){return sigma.tools.toHex(b)+sigma.tools.toHex(h)+sigma.tools.toHex(f)};sigma.tools.toHex=function(b){b=parseInt(b,10);if(isNaN(b))return"00";b=Math.max(0,Math.min(b,255));return"0123456789ABCDEF".charAt((b-b%16)/16)+"0123456789ABCDEF".charAt(b%16)};sigma.easing=
57 {linear:{},quadratic:{}};sigma.easing.linear.easenone=function(b){return b};sigma.easing.quadratic.easein=function(b){return b*b};sigma.easing.quadratic.easeout=function(b){return-b*(b-2)};sigma.easing.quadratic.easeinout=function(b){return 1>(b*=2)?0.5*b*b:-0.5*(--b*(b-2)-1)};sigma.chronos=new function(){function b(a){window.setTimeout(a,0);return g}function h(){for(g.dispatch("frameinserted");r&&w.length&&f(););!r||!w.length?a():(B=(new Date).getTime(),t++,D=y-v,x=v-D,g.dispatch("insertframe"),
58 b(h))}function f(){C%=w.length;if(!w[C].task()){var a=w[C].taskName;z=z.filter(function(b){b.taskParent==a&&w.push({taskName:b.taskName,task:b.task});return b.taskParent!=a});g.dispatch("killed",w.splice(C--,1)[0])}C++;y=(new Date).getTime()-B;return y<=x}function c(){r=!0;t=C=0;A=B=(new Date).getTime();g.dispatch("start");g.dispatch("insertframe");b(h);return g}function a(){g.dispatch("stop");r=!1;return g}function l(a,b,d){if("function"!=typeof a)throw Error('Task "'+b+'" is not a function');w.push({taskName:b,
59 task:a});r=!(!r&&!(d&&c()||1));return g}function d(a){return a?Object.keys(u).filter(function(a){return!!u[a].on}).length:Object.keys(u).length}function m(){Object.keys(u).length?(g.dispatch("startgenerators"),g.unbind("killed",p),b(function(){for(var a in u)u[a].on=!0,l(u[a].task,a,!1)}),g.bind("killed",p).runTasks()):g.dispatch("stopgenerators");return g}function p(a){void 0!=u[a.content.taskName]&&(u[a.content.taskName].del||!u[a.content.taskName].condition()?delete u[a.content.taskName]:u[a.content.taskName].on=
60 !1,0==d(!0)&&m())}sigma.classes.EventDispatcher.call(this);var g=this,r=!1,n=80,q=0,t=0,v=1E3/n,x=v,y=0,A=0,B=0,D=0,u={},w=[],z=[],C=0;this.frequency=function(a){return void 0!=a?(n=Math.abs(1*a),v=1E3/n,t=0,g):n};this.runTasks=c;this.stopTasks=a;this.insertFrame=b;this.addTask=l;this.queueTask=function(a,b,c){if("function"!=typeof a)throw Error('Task "'+b+'" is not a function');if(!w.concat(z).some(function(a){return a.taskName==c}))throw Error('Parent task "'+c+'" of "'+b+'" is not attached.');
61 z.push({taskParent:c,taskName:b,task:a});return g};this.removeTask=function(b,c){if(void 0==b)w=[],1==c?z=[]:2==c&&(w=z,z=[]),a();else{var d="string"==typeof b?b:"";w=w.filter(function(a){return("string"==typeof b?a.taskName==b:a.task==b)?(d=a.taskName,!1):!0});0<c&&(z=z.filter(function(a){1==c&&a.taskParent==d&&w.push(a);return a.taskParent!=d}))}r=!(w.length&&(!a()||1));return g};this.addGenerator=function(a,b,c){if(void 0!=u[a])return g;u[a]={task:b,condition:c};0==d(!0)&&m();return g};this.removeGenerator=
62 function(a){u[a]&&(u[a].on=!1,u[a].del=!0);return g};this.startGenerators=m;this.getGeneratorsIDs=function(){return Object.keys(u)};this.getFPS=function(){r&&(q=Math.round(1E4*(t/((new Date).getTime()-A)))/10);return q};this.getTasksCount=function(){return w.length};this.getQueuedTasksCount=function(){return z.length};this.getExecutionTime=function(){return B-A};return this};sigma.debugMode=0;sigma.log=function(){if(1==sigma.debugMode)for(var b in arguments)console.log(arguments[b]);else if(1<sigma.debugMode)for(b in arguments)throw Error(arguments[b]);
63 return sigma};sigma.publicPrototype=h.prototype})();