react-sigma
Version:
Lightweight but powerful library for drawing network graphs built on top of SigmaJS
1 lines • 5.57 kB
JavaScript
var Sigma=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=185)}({185:function(module,exports){(function(){(function(undefined){"use strict";if("undefined"==typeof sigma)throw"sigma is not declared";sigma.utils.pkg("sigma.plugins"),sigma.classes.graph.hasMethod("adjacentNodes")||sigma.classes.graph.addMethod("adjacentNodes",(function(e){if("string"!=typeof e)throw"adjacentNodes: the node id must be a string.";var r,t=[];for(r in this.allNeighborsIndex[e])t.push(this.nodesIndex[r]);return t})),sigma.classes.graph.hasMethod("adjacentEdges")||sigma.classes.graph.addMethod("adjacentEdges",(function(e){if("string"!=typeof e)throw"adjacentEdges: the node id must be a string.";var r,t,n=this.allNeighborsIndex[e],o=[];for(t in n)for(r in n[t])o.push(n[t][r]);return o}));var _g=undefined,_s=undefined,_chain=[],_keysIndex=Object.create(null),Processors={};function register(e,r,t){if(t!=undefined&&"string"!=typeof t)throw'The filter key "'+t.toString()+'" must be a string.';if(t!=undefined&&!t.length)throw"The filter key must be a non-empty string.";if("function"!=typeof e)throw'The predicate of key "'+t+'" must be a function.';if("undo"===t)throw'"undo" is a reserved key.';if(_keysIndex[t])throw'The filter "'+t+'" already exists.';t&&(_keysIndex[t]=!0),_chain.push({key:t,processor:e,predicate:r})}function unregister(e){for(var r in _chain=_chain.filter((function(r){return!(r.key in e)})),e)delete _keysIndex[r]}function Filter(e){_s=e,_g=e.graph}function deepCopy(o){var copy=Object.create(null);for(var i in o)"object"==typeof o[i]&&null!==o[i]?copy[i]=deepCopy(o[i]):"function"==typeof o[i]&&null!==o[i]?eval(" copy[i] = "+o[i].toString()):copy[i]=o[i];return copy}function cloneChain(e){for(var r=e.slice(0),t=0,n=r.length;t<n;t++)r[t]=deepCopy(r[t]),"function"==typeof r[t].processor&&(r[t].processor="filter.processors."+r[t].processor.name);return r}Processors.nodes=function(e){for(var r=_g.nodes(),t=r.length,n=_g.edges(),o=n.length;t--;)r[t].hidden=!e.call(_g,r[t])||r[t].hidden;for(;o--;)(_g.nodes(n[o].source).hidden||_g.nodes(n[o].target).hidden)&&(n[o].hidden=!0)},Processors.edges=function(e){for(var r=_g.edges(),t=r.length;t--;)r[t].hidden=!e.call(_g,r[t])||r[t].hidden},Processors.neighbors=function(e){for(var r=_g.nodes(),t=r.length,n=_g.edges(),o=n.length,i=_g.adjacentNodes(e),s=i.length,c={};s--;)c[i[s].id]=!0;for(;t--;)r[t].id===e||r[t].id in c||(r[t].hidden=!0);for(;o--;)(_g.nodes(n[o].source).hidden||_g.nodes(n[o].target).hidden)&&(n[o].hidden=!0)},Filter.prototype.nodesBy=function(e,r){return register(Processors.nodes,e,r),this},Filter.prototype.edgesBy=function(e,r){return register(Processors.edges,e,r),this},Filter.prototype.neighborsOf=function(e,r){if("string"!=typeof e)throw'The node id "'+e.toString()+'" must be a string.';if(!e.length)throw"The node id must be a non-empty string.";return register(Processors.neighbors,e,r),this},Filter.prototype.apply=function(){for(var e=0,r=_chain.length;e<r;++e)_chain[e].processor(_chain[e].predicate);return _chain[0]&&"undo"===_chain[0].key&&_chain.shift(),_s.refresh(),this},Filter.prototype.undo=function(e){var r=Object.create(null),t=arguments.length;if(1===t)if("[object Array]"===Object.prototype.toString.call(e))for(var n=0,o=e.length;n<o;n++)r[e[n]]=!0;else r[e]=!0;else if(t>1)for(n=0;n<t;n++)r[arguments[n]]=!0;else this.clear();function i(){for(var e=_g.nodes(),r=e.length,t=_g.edges(),n=t.length;r--;)e[r].hidden=!1;for(;n--;)t[n].hidden=!1}return unregister(r),_chain.unshift({key:"undo",processor:i}),this},Filter.prototype.clear=function(){return _chain.length=0,_keysIndex=Object.create(null),this},Filter.prototype.export=function(){return cloneChain(_chain)},Filter.prototype.import=function(e){if(e===undefined)throw"Wrong arguments.";if("[object Array]"!==Object.prototype.toString.call(e))throw'The chain" must be an array.';for(var r=cloneChain(e),t=0,n=r.length;t<n;t++){if(r[t].predicate===undefined||r[t].processor===undefined)throw"Wrong arguments.";if(r[t].key!=undefined&&"string"!=typeof r[t].key)throw'The filter key "'+r[t].key.toString()+'" must be a string.';if("function"!=typeof r[t].predicate)throw'The predicate of key "'+r[t].key+'" must be a function.';if("string"!=typeof r[t].processor)throw'The processor of key "'+r[t].key+'" must be a string.';switch(r[t].processor){case"filter.processors.nodes":r[t].processor=Processors.nodes;break;case"filter.processors.edges":r[t].processor=Processors.edges;break;case"filter.processors.neighbors":r[t].processor=Processors.neighbors;break;default:throw"Unknown processor "+r[t].processor}}return _chain=r,this};var filter=null;sigma.plugins.filter=function(e){return filter=new Filter(e)}}).call(this)}).call(window)}});