react-sigma
Version:
Lightweight but powerful library for drawing network graphs built on top of SigmaJS
1 lines • 12.4 kB
JavaScript
var Sigma=function(e){var t={};function s(i){if(t[i])return t[i].exports;var n=t[i]={i:i,l:!1,exports:{}};return e[i].call(n.exports,n,n.exports,s),n.l=!0,n.exports}return s.m=e,s.c=t,s.d=function(e,t,i){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(s.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)s.d(i,n,function(t){return e[t]}.bind(null,n));return i},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=150)}({150:function(e,t,s){"use strict";s.r(t);s(151),s(152),s(153),s(154),s(155),s(156),s(157)},151:function(e,t){(function(){(function(e){"use strict";if("undefined"==typeof sigma)throw"sigma is not declared";if("undefined"==typeof conrad)throw"conrad is not declared";sigma.utils.pkg("sigma.renderers"),sigma.renderers.svg=function(e,t,s,i){if("object"!=typeof i)throw"sigma.renderers.svg: Wrong arguments.";if(!(i.container instanceof HTMLElement))throw"Container not found.";var n,r,l,o,a=this;for(sigma.classes.dispatcher.extend(this),this.graph=e,this.camera=t,this.domElements={graph:null,groups:{},nodes:{},edges:{},labels:{},hovers:{}},this.measurementCanvas=null,this.options=i,this.container=this.options.container,this.settings="object"==typeof i.settings&&i.settings?s.embedObjects(i.settings):s,this.settings("freeStyle",!!this.options.freeStyle),this.settings("xmlns","http://www.w3.org/2000/svg"),this.nodesOnScreen=[],this.edgesOnScreen=[],this.options.prefix="renderer"+sigma.utils.id()+":",this.initDOM("svg"),this.captors=[],n=0,r=(l=this.options.captors||[sigma.captors.mouse,sigma.captors.touch]).length;n<r;n++)o="function"==typeof l[n]?l[n]:sigma.captors[l[n]],this.captors.push(new o(this.domElements.graph,this.camera,this.settings));window.addEventListener("resize",(function(){a.resize()})),sigma.misc.bindDOMEvents.call(this,this.domElements.graph),this.bindHovers(this.options.prefix),this.resize(!1)},sigma.renderers.svg.prototype.render=function(t){t=t||{};var s,i,n,r,l,o,a,d,u,h={},c=this.graph,g=this.graph.nodes,m=(this.options.prefix,this.settings(t,"drawEdges")),f=this.settings(t,"drawNodes"),p=(this.settings(t,"drawLabels"),this.settings.embedObjects(t,{prefix:this.options.prefix,forceLabels:this.options.forceLabels}));for(this.settings(t,"hideEdgesOnMove")&&(this.camera.isAnimated||this.camera.isMoving)&&(m=!1),this.camera.applyView(e,this.options.prefix,{width:this.width,height:this.height}),this.hideDOMElements(this.domElements.nodes),this.hideDOMElements(this.domElements.edges),this.hideDOMElements(this.domElements.labels),this.edgesOnScreen=[],this.nodesOnScreen=this.camera.quadtree.area(this.camera.getRectangle(this.width,this.height)),i=0,r=(s=this.nodesOnScreen).length;i<r;i++)h[s[i].id]=s[i];for(i=0,r=(s=c.edges()).length;i<r;i++)!h[(l=s[i]).source]&&!h[l.target]||l.hidden||g(l.source).hidden||g(l.target).hidden||this.edgesOnScreen.push(l);if(d=sigma.svg.nodes,u=sigma.svg.labels,f)for(i=0,r=(s=this.nodesOnScreen).length;i<r;i++)s[i].hidden||this.domElements.nodes[s[i].id]||(n=(d[s[i].type]||d.def).create(s[i],p),this.domElements.nodes[s[i].id]=n,this.domElements.groups.nodes.appendChild(n),n=(u[s[i].type]||u.def).create(s[i],p),this.domElements.labels[s[i].id]=n,this.domElements.groups.labels.appendChild(n));if(f)for(i=0,r=(s=this.nodesOnScreen).length;i<r;i++)s[i].hidden||((d[s[i].type]||d.def).update(s[i],this.domElements.nodes[s[i].id],p),(u[s[i].type]||u.def).update(s[i],this.domElements.labels[s[i].id],p));if(d=sigma.svg.edges,m)for(i=0,r=(s=this.edgesOnScreen).length;i<r;i++)this.domElements.edges[s[i].id]||(o=g(s[i].source),a=g(s[i].target),n=(d[s[i].type]||d.def).create(s[i],o,a,p),this.domElements.edges[s[i].id]=n,this.domElements.groups.edges.appendChild(n));if(m)for(i=0,r=(s=this.edgesOnScreen).length;i<r;i++)o=g(s[i].source),a=g(s[i].target),(d[s[i].type]||d.def).update(s[i],this.domElements.edges[s[i].id],o,a,p);return this.dispatchEvent("render"),this},sigma.renderers.svg.prototype.initDOM=function(e){var t,s,i,n=document.createElementNS(this.settings("xmlns"),e),r=this.settings("classPrefix");n.style.position="absolute",n.setAttribute("class",r+"-svg"),n.setAttribute("xmlns",this.settings("xmlns")),n.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),n.setAttribute("version","1.1");var l=document.createElement("canvas");l.setAttribute("class",r+"-measurement-canvas"),this.domElements.graph=this.container.appendChild(n);var o=["edges","nodes","labels","hovers"];for(i=0,s=o.length;i<s;i++)(t=document.createElementNS(this.settings("xmlns"),"g")).setAttributeNS(null,"id",r+"-group-"+o[i]),t.setAttributeNS(null,"class",r+"-group"),this.domElements.groups[o[i]]=this.domElements.graph.appendChild(t);this.container.appendChild(l),this.measurementCanvas=l.getContext("2d")},sigma.renderers.svg.prototype.hideDOMElements=function(e){var t,s;for(s in e)t=e[s],sigma.svg.utils.hide(t);return this},sigma.renderers.svg.prototype.bindHovers=function(e){var t,s=sigma.svg.hovers,i=this;this.bind("overNode",(function(n){var r=n.data.node,l=i.settings.embedObjects({prefix:e});if(l("enableHovering")){var o=(s[r.type]||s.def).create(r,i.domElements.nodes[r.id],i.measurementCanvas,l);i.domElements.hovers[r.id]=o,i.domElements.groups.hovers.appendChild(o),t=r}})),this.bind("outNode",(function(s){var n=s.data.node;i.settings.embedObjects({prefix:e})("enableHovering")&&(i.domElements.groups.hovers.removeChild(i.domElements.hovers[n.id]),t=null,delete i.domElements.hovers[n.id],i.domElements.groups.nodes.appendChild(i.domElements.nodes[n.id]))})),this.bind("render",(function(){if(t){var n=i.settings.embedObjects({prefix:e});i.domElements.groups.hovers.removeChild(i.domElements.hovers[t.id]),delete i.domElements.hovers[t.id];var r=(s[t.type]||s.def).create(t,i.domElements.nodes[t.id],i.measurementCanvas,n);i.domElements.hovers[t.id]=r,i.domElements.groups.hovers.appendChild(r)}}))},sigma.renderers.svg.prototype.resize=function(t,s){var i=this.width,n=this.height;return t!==e&&s!==e?(this.width=t,this.height=s):(this.width=this.container.offsetWidth,this.height=this.container.offsetHeight,t=this.width,s=this.height),i===this.width&&n===this.height||(this.domElements.graph.style.width=t+"px",this.domElements.graph.style.height=s+"px","svg"===this.domElements.graph.tagName.toLowerCase()&&(this.domElements.graph.setAttribute("width",1*t),this.domElements.graph.setAttribute("height",1*s))),this},sigma.utils.pkg("sigma.svg.nodes"),sigma.utils.pkg("sigma.svg.edges"),sigma.utils.pkg("sigma.svg.labels")}).call(this)}).call(window)},152:function(e,t){(function(){!function(){"use strict";sigma.utils.pkg("sigma.svg.utils"),sigma.svg.utils={show:function(e){return e.style.display="",this},hide:function(e){return e.style.display="none",this}}}()}).call(window)},153:function(e,t){(function(){!function(){"use strict";sigma.utils.pkg("sigma.svg.nodes"),sigma.svg.nodes.def={create:function(e,t){t("prefix");var s=document.createElementNS(t("xmlns"),"circle");return s.setAttributeNS(null,"data-node-id",e.id),s.setAttributeNS(null,"class",t("classPrefix")+"-node"),s.setAttributeNS(null,"fill",e.color||t("defaultNodeColor")),s},update:function(e,t,s){var i=s("prefix")||"";return t.setAttributeNS(null,"cx",e[i+"x"]),t.setAttributeNS(null,"cy",e[i+"y"]),t.setAttributeNS(null,"r",e[i+"size"]),s("freeStyle")||t.setAttributeNS(null,"fill",e.color||s("defaultNodeColor")),t.style.display="",this}}}()}).call(window)},154:function(e,t){(function(){!function(){"use strict";sigma.utils.pkg("sigma.svg.edges"),sigma.svg.edges.def={create:function(e,t,s,i){var n=e.color,r=(i("prefix"),i("edgeColor")),l=i("defaultNodeColor"),o=i("defaultEdgeColor");if(!n)switch(r){case"source":n=t.color||l;break;case"target":n=s.color||l;break;default:n=o}var a=document.createElementNS(i("xmlns"),"line");return a.setAttributeNS(null,"data-edge-id",e.id),a.setAttributeNS(null,"class",i("classPrefix")+"-edge"),a.setAttributeNS(null,"stroke",n),a},update:function(e,t,s,i,n){var r=n("prefix")||"";return t.setAttributeNS(null,"stroke-width",e[r+"size"]||1),t.setAttributeNS(null,"x1",s[r+"x"]),t.setAttributeNS(null,"y1",s[r+"y"]),t.setAttributeNS(null,"x2",i[r+"x"]),t.setAttributeNS(null,"y2",i[r+"y"]),t.style.display="",this}}}()}).call(window)},155:function(e,t){(function(){!function(){"use strict";sigma.utils.pkg("sigma.svg.edges"),sigma.svg.edges.curve={create:function(e,t,s,i){var n=e.color,r=(i("prefix"),i("edgeColor")),l=i("defaultNodeColor"),o=i("defaultEdgeColor");if(!n)switch(r){case"source":n=t.color||l;break;case"target":n=s.color||l;break;default:n=o}var a=document.createElementNS(i("xmlns"),"path");return a.setAttributeNS(null,"data-edge-id",e.id),a.setAttributeNS(null,"class",i("classPrefix")+"-edge"),a.setAttributeNS(null,"stroke",n),a},update:function(e,t,s,i,n){var r=n("prefix")||"";t.setAttributeNS(null,"stroke-width",e[r+"size"]||1);var l=(s[r+"x"]+i[r+"x"])/2+(i[r+"y"]-s[r+"y"])/4,o=(s[r+"y"]+i[r+"y"])/2+(s[r+"x"]-i[r+"x"])/4,a="M"+s[r+"x"]+","+s[r+"y"]+" Q"+l+","+o+" "+i[r+"x"]+","+i[r+"y"];return t.setAttributeNS(null,"d",a),t.setAttributeNS(null,"fill","none"),t.style.display="",this}}}()}).call(window)},156:function(e,t){(function(){(function(e){"use strict";if("undefined"==typeof sigma)throw"sigma is not declared";sigma.utils.pkg("sigma.svg.labels"),sigma.svg.labels.def={create:function(e,t){var s=e[(t("prefix")||"")+"size"],i=document.createElementNS(t("xmlns"),"text"),n="fixed"===t("labelSize")?t("defaultLabelSize"):t("labelSizeRatio")*s,r="node"===t("labelColor")?e.color||t("defaultNodeColor"):t("defaultLabelColor");return i.setAttributeNS(null,"data-label-target",e.id),i.setAttributeNS(null,"class",t("classPrefix")+"-label"),i.setAttributeNS(null,"font-size",n),i.setAttributeNS(null,"font-family",t("font")),i.setAttributeNS(null,"fill",r),i.innerHTML=e.label,i.textContent=e.label,i},update:function(e,t,s){var i=s("prefix")||"",n=e[i+"size"],r="fixed"===s("labelSize")?s("defaultLabelSize"):s("labelSizeRatio")*n;if((s("forceLabels")||!(n<s("labelThreshold")))&&"string"==typeof e.label)return t.setAttributeNS(null,"x",Math.round(e[i+"x"]+n+3)),t.setAttributeNS(null,"y",Math.round(e[i+"y"]+r/3)),t.style.display="",this}}}).call(this)}).call(window)},157:function(e,t){(function(){(function(e){"use strict";if("undefined"==typeof sigma)throw"sigma is not declared";sigma.utils.pkg("sigma.svg.hovers"),sigma.svg.hovers.def={create:function(e,t,s,i){i("hoverFontStyle")||i("fontStyle");var n,r,l,o=i("prefix")||"",a=e[o+"size"],d="fixed"===i("labelSize")?i("defaultLabelSize"):i("labelSizeRatio")*a,u="node"===i("labelHoverColor")?e.color||i("defaultNodeColor"):i("defaultLabelHoverColor"),h=document.createElementNS(i("xmlns"),"g"),c=document.createElementNS(i("xmlns"),"rect"),g=document.createElementNS(i("xmlns"),"circle"),m=document.createElementNS(i("xmlns"),"text");return h.setAttributeNS(null,"class",i("classPrefix")+"-hover"),h.setAttributeNS(null,"data-node-id",e.id),"string"==typeof e.label&&(m.innerHTML=e.label,m.textContent=e.label,m.setAttributeNS(null,"class",i("classPrefix")+"-hover-label"),m.setAttributeNS(null,"font-size",d),m.setAttributeNS(null,"font-family",i("font")),m.setAttributeNS(null,"fill",u),m.setAttributeNS(null,"x",Math.round(e[o+"x"]+a+3)),m.setAttributeNS(null,"y",Math.round(e[o+"y"]+d/3)),Math.round(e[o+"x"]-d/2-2),Math.round(e[o+"y"]-d/2-2),n=Math.round(s.measureText(e.label).width+d/2+a+9),r=Math.round(d+4),l=Math.round(d/2+2),g.setAttributeNS(null,"class",i("classPrefix")+"-hover-area"),g.setAttributeNS(null,"fill","#fff"),g.setAttributeNS(null,"cx",e[o+"x"]),g.setAttributeNS(null,"cy",e[o+"y"]),g.setAttributeNS(null,"r",l),c.setAttributeNS(null,"class",i("classPrefix")+"-hover-area"),c.setAttributeNS(null,"fill","#fff"),c.setAttributeNS(null,"x",e[o+"x"]+l/4),c.setAttributeNS(null,"y",e[o+"y"]-l),c.setAttributeNS(null,"width",n),c.setAttributeNS(null,"height",r)),h.appendChild(g),h.appendChild(c),h.appendChild(m),h.appendChild(t),h}}}).call(this)}).call(window)}});