├── .gitignore ├── index.js ├── example ├── modularity.png └── example.html ├── webpack.config.js ├── package.json ├── README.md ├── src └── main.js └── dist ├── echarts-graph-modularity.min.js ├── echarts-graph-modularity.js.map ├── echarts-graph-modularity.js └── echarts-graph-modularity.min.js.map /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./src/main'); -------------------------------------------------------------------------------- /example/modularity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ecomfe/echarts-graph-modularity/HEAD/example/modularity.png -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | module.exports = (env, options) => { 2 | return { 3 | entry: { 4 | 'echarts-graph-modularity': __dirname + '/index.js' 5 | }, 6 | output: { 7 | libraryTarget: 'umd', 8 | library: ['echarts-graph-modularity'], 9 | path: __dirname + '/dist', 10 | filename: options.mode === 'production' ? '[name].min.js' : '[name].js' 11 | }, 12 | optimization: { 13 | concatenateModules: true 14 | }, 15 | devtool: 'source-map', 16 | externals: { 17 | 'echarts/core': 'echarts' 18 | } 19 | }; 20 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "echarts-graph-modularity", 3 | "version": "2.1.0", 4 | "description": "ECharts graph modularity extension for community detection", 5 | "main": "index.js", 6 | "author": "", 7 | "license": "ISC", 8 | "dependencies": { 9 | "ngraph.graph": "0.0.12", 10 | "ngraph.modularity": "1.0.5" 11 | }, 12 | "scripts": { 13 | "dev": "npx webpack --mode development --watch", 14 | "build": "npx webpack --mode development", 15 | "release": "npx webpack --mode production && npx webpack --mode development" 16 | }, 17 | "peerDependencies": { 18 | "echarts": "^5.2.1" 19 | }, 20 | "devDependencies": { 21 | "echarts": "^5.2.1", 22 | "webpack": "^5.58.2", 23 | "webpack-cli": "^4.9.0" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "https://github.com/ecomfe/echarts-graph-modularity.git" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # graph modularity extension for [Apache ECharts](https://github.com/apache/echarts) 2 | 3 | Graph modularity extension will do community detection and partition a graph's vertices in several subsets. Each subset will be assigned a different color. 4 | 5 | ![](./example/modularity.png) 6 | 7 | ## Install 8 | 9 | ```html 10 | 11 | 12 | ``` 13 | 14 | Or 15 | 16 | ```shell 17 | npm install echarts-graph-modularity 18 | ``` 19 | 20 | ```js 21 | import * as echarts from 'echarts'; 22 | import 'echarts-graph-modularity'; 23 | ``` 24 | 25 | NOTE: 26 | 27 | V2.x is for ECharts 5.x 28 | 29 | ## Usage 30 | 31 | ```js 32 | setOption({ 33 | 34 | ... 35 | 36 | series: [{ 37 | type: 'graph', 38 | layout: 'force', 39 | // Set modularity property true and extension will automatically detect different communities 40 | // and assign each different color. 41 | modularity: true 42 | 43 | // Specify resolution. Higher resolution will produce less communities 44 | modularity: { 45 | resolution: 5, 46 | // If sort the communities 47 | sort: false 48 | } 49 | 50 | ... 51 | }] 52 | }) 53 | ``` 54 | 55 | ## Notice 56 | 57 | The Apache Software Foundation [Apache ECharts, ECharts](https://echarts.apache.org/), Apache, the Apache feather, and the Apache ECharts project logo are either registered trademarks or trademarks of the [Apache Software Foundation](https://www.apache.org/). 58 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import Modularity from 'ngraph.modularity/Modularity'; 2 | import * as echarts from 'echarts/core'; 3 | import createNGraph from 'ngraph.graph'; 4 | 5 | function createModularityVisual(chartType) { 6 | return function (ecModel, api) { 7 | var paletteScope = {}; 8 | ecModel.eachSeriesByType(chartType, function (seriesModel) { 9 | var modularityOpt = seriesModel.get('modularity'); 10 | if (modularityOpt) { 11 | var graph = seriesModel.getGraph(); 12 | var idIndexMap = {}; 13 | var ng = createNGraph(); 14 | graph.data.each(function (idx) { 15 | var node = graph.getNodeByIndex(idx); 16 | idIndexMap[node.id] = idx; 17 | ng.addNode(node.id); 18 | return node.id; 19 | }); 20 | graph.edgeData.each('value', function (val, idx) { 21 | var edge = graph.getEdgeByIndex(idx); 22 | ng.addLink(edge.node1.id, edge.node2.id); 23 | return { 24 | source: edge.node1.id, 25 | target: edge.node2.id, 26 | value: val 27 | }; 28 | }); 29 | 30 | var modularity = new Modularity(seriesModel.get('modularity.resolution') || 1); 31 | var result = modularity.execute(ng); 32 | 33 | var communities = {}; 34 | for (var id in result) { 35 | var comm = result[id]; 36 | communities[comm] = communities[comm] || 0; 37 | communities[comm]++; 38 | } 39 | var communitiesList = Object.keys(communities); 40 | if (seriesModel.get('modularity.sort')) { 41 | communitiesList.sort(function (a, b) { 42 | return b - a; 43 | }); 44 | } 45 | var colors = {}; 46 | communitiesList.forEach(function (comm) { 47 | colors[comm] = seriesModel.getColorFromPalette(comm, paletteScope); 48 | }); 49 | 50 | for (var id in result) { 51 | var comm = result[id]; 52 | var style = graph.data.ensureUniqueItemVisual(idIndexMap[id], 'style'); 53 | style.fill = colors[comm]; 54 | } 55 | 56 | graph.edgeData.each(function (idx) { 57 | var itemModel = graph.edgeData.getItemModel(idx); 58 | var edge = graph.getEdgeByIndex(idx); 59 | var color = itemModel.get(['lineStyle', 'normal', 'color']) 60 | || itemModel.get(['lineStyle', 'color']); 61 | 62 | switch (color) { 63 | case 'source': 64 | color = edge.node1.getVisual('style').fill; 65 | break; 66 | case 'target': 67 | color = edge.node2.getVisual('style').fill; 68 | break; 69 | } 70 | 71 | if (color != null) { 72 | graph.edgeData.ensureUniqueItemVisual(idx, 'style').stroke = color; 73 | } 74 | }); 75 | } 76 | }); 77 | }; 78 | } 79 | 80 | echarts.registerVisual(echarts.PRIORITY.VISUAL.CHART + 1, createModularityVisual('graph')); 81 | echarts.registerVisual(echarts.PRIORITY.VISUAL.CHART + 1, createModularityVisual('graphGL')); -------------------------------------------------------------------------------- /example/example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 15 |
16 | 92 | 93 | -------------------------------------------------------------------------------- /dist/echarts-graph-modularity.min.js: -------------------------------------------------------------------------------- 1 | !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("echarts")):"function"==typeof define&&define.amd?define(["echarts"],e):"object"==typeof exports?exports["echarts-graph-modularity"]=e(require("echarts")):t["echarts-graph-modularity"]=e(t.echarts)}(self,(function(t){return(()=>{var e={10:(t,e,n)=>{t.exports=n(225)},216:(t,e,n)=>{t.exports.degree=n(176),t.exports.betweenness=n(476)},476:t=>{t.exports=function(t,e){var n,o=[],i=[],r=Object.create(null),s=Object.create(null),u=Object.create(null),c=Object.create(null),h=Object.create(null);return t.forEachNode((function(t){h[t.id]=0})),t.forEachNode((function(d){(function(n){for(t.forEachNode((function(t){var e=t.id;r[e]=[],s[e]=-1,u[e]=0})),s[n]=0,u[n]=1,o.push(n);o.length;){var c=o.shift();i.push(c),t.forEachLinkedNode(c,h,e)}function h(t){var e;e=t.id,-1===s[e]&&(s[e]=s[c]+1,o.push(e)),s[e]===s[c]+1&&(u[e]+=u[c],r[e].push(c))}})(n=d.id),function(){for(t.forEachNode(a);i.length;){for(var e=i.pop(),o=(1+c[e])/u[e],s=r[e],d=0;d{function e(t,e){var n=0;if(!t)return n;for(var o=0;o{t.exports=function(t){!function(t){if(!t)throw new Error("Eventify cannot use falsy object as events subject");for(var e=["on","fire","off"],n=0;n1&&(o=Array.prototype.splice.call(arguments,1));for(var r=0;r{t.exports=function(t){void 0===(t=t||{}).uniqueLinkId&&(t.uniqueLinkId=!0);var e,n="function"==typeof Object.create?Object.create(null):{},h=[],a={},d=0,f=0,g=Object.keys?function(t){if("function"==typeof t)for(var e=Object.keys(n),o=0;o=0&&n.links.splice(e,1),o&&(e=i(t,o.links))>=0&&o.links.splice(e,1),m(t,"remove"),y(),!0}function I(t,e){var n,o=N(t);if(!o||!o.links)return null;for(n=0;n0&&(w.fire("changed",p),p.length=0)}};var o=n(245);function i(t,e){if(!e)return-1;if(e.indexOf)return e.indexOf(t);var n,o=e.length;for(n=0;n{function e(t){this.structure=t.structure?t.structure:t,this.connectionsWeight=new Map,this.connectionsCount=new Map,this.nodes=new Set,this.weightSum=0}e.prototype.size=function(){return this.nodes.size},e.prototype.seed=function(t){this.nodes.add(t),this.weightSum+=this.structure.weights[t]},e.prototype.add=function(t){return this.nodes.add(t),this.weightSum+=this.structure.weights[t],!0},e.prototype.remove=function(t){var e=this.nodes.delete(t);if(this.weightSum-=this.structure.weights[t],!this.nodes.size){var n=this.structure.communities.indexOf(this);delete this.structure.communities[n]}return e},t.exports=e},997:(t,e,n)=>{"use strict";var o=n(410),i=n(623);function r(t,e){this.N=t.getNodesCount(),this.graphWeightSum=0,this.structure=this,this.invMap=new Map,this.nodeConnectionsWeight=new Array(this.N),this.nodeConnectionsCount=new Array(this.N),this.nodeCommunities=new Array(this.N),this.map=new Map,this.topology=new Array(this.N);for(var n=0;n{t.exports=function(t,e,n){this.source=t,this.target=e,this.weight=n}},109:(t,e,n)=>{var o=n(997),i=n(216);function r(t,e){this.isRandomized=!1,this.useWeight=e,this.resolution=t||1,this.structure=null}r.prototype.execute=function(t){this.structure=new o(t,this.useWeight);var e=new Array(t.getNodesCount()),n=(this.computeModularity(t,this.structure,e,this.resolution,this.isRandomized,this.useWeight),{});return this.structure.map.forEach((function(t,o){n[o]=e[t]})),n},r.prototype.computeModularity=function(t,e,n,o,i,r){e.graphWeightSum,e.weights.slice();for(var s,u=Object.create(null),c=!0;c;){c=!1;for(var h=!0;h;){h=!1;var a=0;i&&(0,s=e.N,a=Math.floor(Math.random()*(s-0))+0);for(var d=0,f=a;do&&(o=u,i=s)}),this),i},r.prototype.fillComStructure=function(t,e,n){var o=0;return e.communities.forEach((function(t){t.nodes.forEach((function(t){e.invMap.get(t).nodes.forEach((function(t){n[t]=o}))})),o++})),n},r.prototype.fillDegreeCount=function(t,e,n,o,r){var s=new Array(e.communities.length),u=i.degree(t);return t.forEachNode((function(t){var i=e.map.get(t);s[n[i]]+=r?o[i]:u[t.id]})),s},r.prototype._finalQ=function(t,e,n,o,i,r,s){throw new Error("not implemented properly")},r.prototype.q=function(t,e,n,o){var i=n.nodeConnectionsWeight[t].get(e),r=0;null!=i&&(r=i);var s=e.weightSum,u=n.weights[t],c=o*r-u*s/(2*n.graphWeightSum);return n.nodeCommunities[t]==e&&n.nodeCommunities[t].size()>1&&(c=o*r-u*(s-u)/(2*n.graphWeightSum)),n.nodeCommunities[t]==e&&1==n.nodeCommunities[t].size()&&(c=0),c},t.exports=r},225:(t,e,n)=>{"use strict";n.r(e);var o=n(109),i=n.n(o),r=n(550),s=n(736),u=n.n(s);function c(t){return function(e,n){var o={};e.eachSeriesByType(t,(function(t){if(t.get("modularity")){var e=t.getGraph(),n={},r=u()();e.data.each((function(t){var o=e.getNodeByIndex(t);return n[o.id]=t,r.addNode(o.id),o.id})),e.edgeData.each("value",(function(t,n){var o=e.getEdgeByIndex(n);return r.addLink(o.node1.id,o.node2.id),{source:o.node1.id,target:o.node2.id,value:t}}));var s=new(i())(t.get("modularity.resolution")||1).execute(r),c={};for(var h in s)c[f=s[h]]=c[f]||0,c[f]++;var a=Object.keys(c);t.get("modularity.sort")&&a.sort((function(t,e){return e-t}));var d={};for(var h in a.forEach((function(e){d[e]=t.getColorFromPalette(e,o)})),s){var f=s[h];e.data.ensureUniqueItemVisual(n[h],"style").fill=d[f]}e.edgeData.each((function(t){var n=e.edgeData.getItemModel(t),o=e.getEdgeByIndex(t),i=n.get(["lineStyle","normal","color"])||n.get(["lineStyle","color"]);switch(i){case"source":i=o.node1.getVisual("style").fill;break;case"target":i=o.node2.getVisual("style").fill}null!=i&&(e.edgeData.ensureUniqueItemVisual(t,"style").stroke=i)}))}}))}}r.registerVisual(r.PRIORITY.VISUAL.CHART+1,c("graph")),r.registerVisual(r.PRIORITY.VISUAL.CHART+1,c("graphGL"))},550:e=>{"use strict";e.exports=t}},n={};function o(t){var i=n[t];if(void 0!==i)return i.exports;var r=n[t]={exports:{}};return e[t](r,r.exports,o),r.exports}return o.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return o.d(e,{a:e}),e},o.d=(t,e)=>{for(var n in e)o.o(e,n)&&!o.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),o.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o(10)})()})); 2 | //# sourceMappingURL=echarts-graph-modularity.min.js.map -------------------------------------------------------------------------------- /dist/echarts-graph-modularity.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"echarts-graph-modularity.js","mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;;;;;;;;;ACVA,uEAAsC;;;;;;;;;;ACAtC,oHAAkD;AAClD,mIAA4D;;;;;;;;;;;ACD5D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,YAAY;AACZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,wBAAwB,0BAA0B;AAClD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,yBAAyB;AACzB;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;AC5GA;;AAEA;AACA;AACA;AACA;AACA;AACA,WAAW,cAAc;AACzB,WAAW,QAAQ;AACnB;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,IAAI;AACJ;AACA,IAAI;AACJ;AACA,IAAI;AACJ;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA,kBAAkB,kBAAkB;AACpC;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA,kBAAkB,kBAAkB;AACpC;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;;;;;AC9DA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,iBAAiB,gCAAgC;AACxD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,qBAAqB,6BAA6B;;AAElD;AACA,KAAK;;AAEL;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA,0BAA0B,sBAAsB;AAChD;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,KAAK;;AAEL;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,qBAAqB,sBAAsB;AAC3C;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,kBAAkB,0BAA0B;AAC5C;AACA;AACA;AACA;AACA;;;;;;;;;;;ACvFA;AACA;AACA;;AAEA;AACA;AACA;AACA,0BAA0B;AAC1B,0BAA0B;AAC1B;AACA;AACA;;AAEA,eAAe,mBAAO,CAAC,4DAAe;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,4EAA4E;AAC5E;AACA;AACA,mBAAmB;AACnB;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAgB,MAAM;AACtB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAgB,MAAM;AACtB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,0CAA0C;AAC1C;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,0CAA0C;AAC1C;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,gBAAgB,MAAM;AACtB;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,eAAe,gBAAgB;AAC/B;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,eAAe,sBAAsB;AACrC;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,eAAe,gBAAgB;AAC/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,eAAe,QAAQ;AACvB,eAAe,QAAQ;AACvB;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,KAAK;AACL;;AAEA;AACA;AACA;AACA;AACA,KAAK;AACL;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA,MAAM;AACN;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,gBAAgB,uBAAuB;AACvC;AACA;AACA;AACA;AACA;;AAEA,iBAAiB;AACjB;;AAEA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;;AAEA;AACA;AACA;AACA,yCAAyC,YAAY;AACrD;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,QAAQ;AACR;AACA;AACA;AACA;;AAEA;AACA;AACA,oBAAoB,kBAAkB;AACtC;AACA;;AAEA;AACA;AACA,qBAAqB;AACrB;AACA;AACA;;AAEA;AACA;AACA,oBAAoB,kBAAkB;AACtC;AACA;AACA;AACA;AACA,uBAAuB;AACvB;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,oBAAoB,iBAAiB;AACrC;AACA,qBAAqB;AACrB;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,qBAAqB;AACrB;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;;AAEA,cAAc,SAAS;AACvB;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,IAAI;AACJ;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,gCAAgC,SAAS;AACzC;AACA;AACA,eAAe;AACf;AACA;AACA;;AAEA;AACA;AACA;;;;;;;;;;;AChkBA;AACA,WAAW,8BAA8B;AACzC;AACA;AACA;AACA;AACA,eAAe,oBAAoB;AACnC;AACA;AACA,eAAe,yBAAyB;AACxC;AACA;AACA,eAAe,yBAAyB;AACxC;AACA;AACA,eAAe,cAAc;AAC7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,QAAQ;AACnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACvEa;AACb,gBAAgB,mBAAO,CAAC,kEAAa;AACrC,gBAAgB,mBAAO,CAAC,8DAAW;AACnC;AACA;AACA;AACA;AACA,WAAW,QAAQ;AACnB;AACA,WAAW,oBAAoB;AAC/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,yBAAyB;AACxC;AACA;AACA,eAAe,mCAAmC;AAClD;AACA;AACA,eAAe,mCAAmC;AAClD;AACA;AACA,eAAe,mBAAmB;AAClC;AACA;AACA,eAAe,oBAAoB;AACnC;AACA;AACA,eAAe,2BAA2B;AAC1C;AACA,oBAAoB,YAAY;AAChC;AACA,eAAe,mBAAmB;AAClC;AACA;AACA,cAAc,gBAAgB;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mBAAmB,SAAS;AAC5B;AACA,mBAAmB,WAAW;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,WAAW,WAAW;AACtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,uBAAuB,SAAS;AAChC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA;AACA,uBAAuB,WAAW;AAClC;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAc;AACd;AACA;AACA;AACA;AACA;AACA;AACA,cAAc;AACd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,WAAW,WAAW;AACtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,uBAAuB,SAAS;AAChC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAc;AACd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,WAAW,WAAW;AACtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL,oCAAoC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAc;AACd;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA,oBAAoB,OAAO;AAC3B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;ACnWA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,QAAQ;AACvB;AACA,eAAe,QAAQ;AACvB;AACA,eAAe,QAAQ;AACvB;AACA;AACA;AACA;;;;;;;;;;;AChBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,yBAAyB,mBAAO,CAAC,oFAAsB;AACvD,mBAAmB,mBAAO,CAAC,oEAAmB;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAc;AACd;AACA;AACA;AACA;AACA;AACA,WAAW,QAAQ;AACnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,WAAW,oBAAoB;AAC/B,WAAW,gBAAgB;AAC3B,WAAW,QAAQ;AACnB,WAAW,SAAS;AACpB,WAAW,SAAS;AACpB,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,mBAAmB,yBAAyB;AAC5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gCAAgC,uBAAuB;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,oBAAoB;AAC/B,WAAW,QAAQ;AACnB,WAAW,QAAQ;AACnB,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,WAAW,oBAAoB;AAC/B,WAAW,gBAAgB;AAC3B,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA,SAAS;AACT;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,WAAW,oBAAoB;AAC/B,WAAW,gBAAgB;AAC3B,WAAW,gBAAgB;AAC3B,WAAW,SAAS;AACpB,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,UAAU;AACV;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,gBAAgB;AAC3B,WAAW,gBAAgB;AAC3B,WAAW,QAAQ;AACnB,WAAW,oBAAoB;AAC/B,WAAW,QAAQ;AACnB,WAAW,QAAQ;AACnB,WAAW,SAAS;AACpB,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkB;AAClB;AACA;AACA;AACA,SAAS;AACT;AACA,KAAK;AACL;AACA,oBAAoB,oBAAoB;AACxC;AACA,0GAA0G;AAC1G;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,QAAQ;AACnB,WAAW,WAAW;AACtB,WAAW,oBAAoB;AAC/B,WAAW,QAAQ;AACnB,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;AC3TsD;AACd;AACA;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,yBAAyB,mDAAY;AACrC;AACA;AACA;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB;;AAEjB,qCAAqC,qEAAU;AAC/C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,qBAAqB;AACrB;AACA;AACA;AACA;AACA,iBAAiB;;AAEjB;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,iBAAiB;AACjB;AACA,SAAS;AACT;AACA;;AAEA,wDAAsB,CAAC,+DAA6B;AACpD,wDAAsB,CAAC,+DAA6B;;;;;;;;;;;AChFpD;;;;;;UCAA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA;WACA,iCAAiC,WAAW;WAC5C;WACA;;;;;WCPA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;UENA;UACA;UACA;UACA","sources":["webpack://echarts-graph-modularity/webpack/universalModuleDefinition","webpack://echarts-graph-modularity/./index.js","webpack://echarts-graph-modularity/./node_modules/ngraph.centrality/index.js","webpack://echarts-graph-modularity/./node_modules/ngraph.centrality/src/betweenness.js","webpack://echarts-graph-modularity/./node_modules/ngraph.centrality/src/degree.js","webpack://echarts-graph-modularity/./node_modules/ngraph.events/index.js","webpack://echarts-graph-modularity/./node_modules/ngraph.graph/index.js","webpack://echarts-graph-modularity/./node_modules/ngraph.modularity/Community.js","webpack://echarts-graph-modularity/./node_modules/ngraph.modularity/CommunityStructure.js","webpack://echarts-graph-modularity/./node_modules/ngraph.modularity/ModEdge.js","webpack://echarts-graph-modularity/./node_modules/ngraph.modularity/Modularity.js","webpack://echarts-graph-modularity/./src/main.js","webpack://echarts-graph-modularity/external umd \"echarts\"","webpack://echarts-graph-modularity/webpack/bootstrap","webpack://echarts-graph-modularity/webpack/runtime/compat get default export","webpack://echarts-graph-modularity/webpack/runtime/define property getters","webpack://echarts-graph-modularity/webpack/runtime/hasOwnProperty shorthand","webpack://echarts-graph-modularity/webpack/runtime/make namespace object","webpack://echarts-graph-modularity/webpack/before-startup","webpack://echarts-graph-modularity/webpack/startup","webpack://echarts-graph-modularity/webpack/after-startup"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"echarts\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"echarts\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"echarts-graph-modularity\"] = factory(require(\"echarts\"));\n\telse\n\t\troot[\"echarts-graph-modularity\"] = factory(root[\"echarts\"]);\n})(self, function(__WEBPACK_EXTERNAL_MODULE_echarts_core__) {\nreturn ","module.exports = require('./src/main');","module.exports.degree = require('./src/degree.js');\nmodule.exports.betweenness = require('./src/betweenness.js');\n","module.exports = betweennes;\n\n/**\n * I'm using http://www.inf.uni-konstanz.de/algo/publications/b-vspbc-08.pdf\n * as a reference for this implementation\n */\nfunction betweennes(graph, oriented) {\n var Q = [],\n S = []; // Queue and Stack\n // list of predcessors on shorteest paths from source\n var pred = Object.create(null);\n // distance from source\n var dist = Object.create(null);\n // number of shortest paths from source to key\n var sigma = Object.create(null);\n // dependency of source on key\n var delta = Object.create(null);\n\n var currentNode;\n var centrality = Object.create(null);\n\n graph.forEachNode(setCentralityToZero);\n graph.forEachNode(calculateCentrality);\n\n if (!oriented) {\n // The centrality scores need to be divided by two if the graph is not oriented,\n // since all shortest paths are considered twice\n Object.keys(centrality).forEach(divideByTwo);\n }\n\n return centrality;\n\n function divideByTwo(key) {\n centrality[key] /= 2;\n }\n\n function setCentralityToZero(node) {\n centrality[node.id] = 0;\n }\n\n function calculateCentrality(node) {\n currentNode = node.id;\n singleSourceShortestPath(currentNode);\n accumulate();\n }\n\n function accumulate() {\n graph.forEachNode(setDeltaToZero);\n while (S.length) {\n var w = S.pop();\n var coeff = (1 + delta[w])/sigma[w];\n var predcessors = pred[w];\n for (var idx = 0; idx < predcessors.length; ++idx) {\n var v = predcessors[idx];\n delta[v] += sigma[v] * coeff;\n }\n if (w !== currentNode) {\n centrality[w] += delta[w];\n }\n }\n }\n\n function setDeltaToZero(node) {\n delta[node.id] = 0;\n }\n\n function singleSourceShortestPath(source) {\n graph.forEachNode(initNode);\n dist[source] = 0;\n sigma[source] = 1;\n Q.push(source);\n\n while (Q.length) {\n var v = Q.shift();\n S.push(v);\n graph.forEachLinkedNode(v, toId, oriented);\n }\n\n function toId(otherNode) {\n // NOTE: This code will also consider multi-edges, which are often\n // ignored by popular software (Gephi/NetworkX). Depending on your use\n // case this may not be desired and deduping needs to be performed. To\n // save memory I'm not deduping here...\n processNode(otherNode.id);\n }\n\n function initNode(node) {\n var nodeId = node.id;\n pred[nodeId] = []; // empty list\n dist[nodeId] = -1;\n sigma[nodeId] = 0;\n }\n\n function processNode(w) {\n // path discovery\n if (dist[w] === -1) {\n // Node w is found for the first time\n dist[w] = dist[v] + 1;\n Q.push(w);\n }\n // path counting\n if (dist[w] === dist[v] + 1) {\n // edge (v, w) on a shortest path\n sigma[w] += sigma[v];\n pred[w].push(v);\n }\n }\n }\n}\n","module.exports = degree;\n\n/**\n * Calculates graph nodes degree centrality (in/out or both).\n *\n * @see http://en.wikipedia.org/wiki/Centrality#Degree_centrality\n *\n * @param {ngraph.graph} graph object for which we are calculating centrality.\n * @param {string} [kind=both] What kind of degree centrality needs to be calculated:\n * 'in' - calculate in-degree centrality\n * 'out' - calculate out-degree centrality\n * 'inout' - (default) generic degree centrality is calculated\n */\nfunction degree(graph, kind) {\n var getNodeDegree;\n var result = Object.create(null);\n\n kind = (kind || 'both').toLowerCase();\n if (kind === 'both' || kind === 'inout') {\n getNodeDegree = inoutDegreeCalculator;\n } else if (kind === 'in') {\n getNodeDegree = inDegreeCalculator;\n } else if (kind === 'out') {\n getNodeDegree = outDegreeCalculator;\n } else {\n throw new Error('Expected centrality degree kind is: in, out or both');\n }\n\n graph.forEachNode(calculateNodeDegree);\n\n return result;\n\n function calculateNodeDegree(node) {\n var links = graph.getLinks(node.id);\n result[node.id] = getNodeDegree(links, node.id);\n }\n}\n\nfunction inDegreeCalculator(links, nodeId) {\n var total = 0;\n if (!links) return total;\n\n for (var i = 0; i < links.length; i += 1) {\n total += (links[i].toId === nodeId) ? 1 : 0;\n }\n return total;\n}\n\nfunction outDegreeCalculator(links, nodeId) {\n var total = 0;\n if (!links) return total;\n\n for (var i = 0; i < links.length; i += 1) {\n total += (links[i].fromId === nodeId) ? 1 : 0;\n }\n return total;\n}\n\nfunction inoutDegreeCalculator(links) {\n if (!links) return 0;\n\n return links.length;\n}\n","module.exports = function(subject) {\n validateSubject(subject);\n\n var eventsStorage = createEventsStorage(subject);\n subject.on = eventsStorage.on;\n subject.off = eventsStorage.off;\n subject.fire = eventsStorage.fire;\n return subject;\n};\n\nfunction createEventsStorage(subject) {\n // Store all event listeners to this hash. Key is event name, value is array\n // of callback records.\n //\n // A callback record consists of callback function and its optional context:\n // { 'eventName' => [{callback: function, ctx: object}] }\n var registeredEvents = Object.create(null);\n\n return {\n on: function (eventName, callback, ctx) {\n if (typeof callback !== 'function') {\n throw new Error('callback is expected to be a function');\n }\n var handlers = registeredEvents[eventName];\n if (!handlers) {\n handlers = registeredEvents[eventName] = [];\n }\n handlers.push({callback: callback, ctx: ctx});\n\n return subject;\n },\n\n off: function (eventName, callback) {\n var wantToRemoveAll = (typeof eventName === 'undefined');\n if (wantToRemoveAll) {\n // Killing old events storage should be enough in this case:\n registeredEvents = Object.create(null);\n return subject;\n }\n\n if (registeredEvents[eventName]) {\n var deleteAllCallbacksForEvent = (typeof callback !== 'function');\n if (deleteAllCallbacksForEvent) {\n delete registeredEvents[eventName];\n } else {\n var callbacks = registeredEvents[eventName];\n for (var i = 0; i < callbacks.length; ++i) {\n if (callbacks[i].callback === callback) {\n callbacks.splice(i, 1);\n }\n }\n }\n }\n\n return subject;\n },\n\n fire: function (eventName) {\n var callbacks = registeredEvents[eventName];\n if (!callbacks) {\n return subject;\n }\n\n var fireArguments;\n if (arguments.length > 1) {\n fireArguments = Array.prototype.splice.call(arguments, 1);\n }\n for(var i = 0; i < callbacks.length; ++i) {\n var callbackInfo = callbacks[i];\n callbackInfo.callback.apply(callbackInfo.ctx, fireArguments);\n }\n\n return subject;\n }\n };\n}\n\nfunction validateSubject(subject) {\n if (!subject) {\n throw new Error('Eventify cannot use falsy object as events subject');\n }\n var reservedWords = ['on', 'fire', 'off'];\n for (var i = 0; i < reservedWords.length; ++i) {\n if (subject.hasOwnProperty(reservedWords[i])) {\n throw new Error(\"Subject cannot be eventified, since it already has property '\" + reservedWords[i] + \"'\");\n }\n }\n}\n","/**\n * @fileOverview Contains definition of the core graph object.\n */\n\n/**\n * @example\n * var graph = require('ngraph.graph')();\n * graph.addNode(1); // graph has one node.\n * graph.addLink(2, 3); // now graph contains three nodes and one link.\n *\n */\nmodule.exports = createGraph;\n\nvar eventify = require('ngraph.events');\n\n/**\n * Creates a new graph\n */\nfunction createGraph(options) {\n // Graph structure is maintained as dictionary of nodes\n // and array of links. Each node has 'links' property which\n // hold all links related to that node. And general links\n // array is used to speed up all links enumeration. This is inefficient\n // in terms of memory, but simplifies coding.\n options = options || {};\n if (options.uniqueLinkId === undefined) {\n // Request each link id to be unique between same nodes. This negatively\n // impacts `addLink()` performance (O(n), where n - number of edges of each\n // vertex), but makes operations with multigraphs more accessible.\n options.uniqueLinkId = true;\n }\n\n var nodes = typeof Object.create === 'function' ? Object.create(null) : {},\n links = [],\n // Hash of multi-edges. Used to track ids of edges between same nodes\n multiEdges = {},\n nodesCount = 0,\n suspendEvents = 0,\n\n forEachNode = createNodeIterator(),\n createLink = options.uniqueLinkId ? createUniqueLink : createSingleLink,\n\n // Our graph API provides means to listen to graph changes. Users can subscribe\n // to be notified about changes in the graph by using `on` method. However\n // in some cases they don't use it. To avoid unnecessary memory consumption\n // we will not record graph changes until we have at least one subscriber.\n // Code below supports this optimization.\n //\n // Accumulates all changes made during graph updates.\n // Each change element contains:\n // changeType - one of the strings: 'add', 'remove' or 'update';\n // node - if change is related to node this property is set to changed graph's node;\n // link - if change is related to link this property is set to changed graph's link;\n changes = [],\n recordLinkChange = noop,\n recordNodeChange = noop,\n enterModification = noop,\n exitModification = noop;\n\n // this is our public API:\n var graphPart = {\n /**\n * Adds node to the graph. If node with given id already exists in the graph\n * its data is extended with whatever comes in 'data' argument.\n *\n * @param nodeId the node's identifier. A string or number is preferred.\n * @param [data] additional data for the node being added. If node already\n * exists its data object is augmented with the new one.\n *\n * @return {node} The newly added node or node with given id if it already exists.\n */\n addNode: addNode,\n\n /**\n * Adds a link to the graph. The function always create a new\n * link between two nodes. If one of the nodes does not exists\n * a new node is created.\n *\n * @param fromId link start node id;\n * @param toId link end node id;\n * @param [data] additional data to be set on the new link;\n *\n * @return {link} The newly created link\n */\n addLink: addLink,\n\n /**\n * Removes link from the graph. If link does not exist does nothing.\n *\n * @param link - object returned by addLink() or getLinks() methods.\n *\n * @returns true if link was removed; false otherwise.\n */\n removeLink: removeLink,\n\n /**\n * Removes node with given id from the graph. If node does not exist in the graph\n * does nothing.\n *\n * @param nodeId node's identifier passed to addNode() function.\n *\n * @returns true if node was removed; false otherwise.\n */\n removeNode: removeNode,\n\n /**\n * Gets node with given identifier. If node does not exist undefined value is returned.\n *\n * @param nodeId requested node identifier;\n *\n * @return {node} in with requested identifier or undefined if no such node exists.\n */\n getNode: getNode,\n\n /**\n * Gets number of nodes in this graph.\n *\n * @return number of nodes in the graph.\n */\n getNodesCount: function() {\n return nodesCount;\n },\n\n /**\n * Gets total number of links in the graph.\n */\n getLinksCount: function() {\n return links.length;\n },\n\n /**\n * Gets all links (inbound and outbound) from the node with given id.\n * If node with given id is not found null is returned.\n *\n * @param nodeId requested node identifier.\n *\n * @return Array of links from and to requested node if such node exists;\n * otherwise null is returned.\n */\n getLinks: getLinks,\n\n /**\n * Invokes callback on each node of the graph.\n *\n * @param {Function(node)} callback Function to be invoked. The function\n * is passed one argument: visited node.\n */\n forEachNode: forEachNode,\n\n /**\n * Invokes callback on every linked (adjacent) node to the given one.\n *\n * @param nodeId Identifier of the requested node.\n * @param {Function(node, link)} callback Function to be called on all linked nodes.\n * The function is passed two parameters: adjacent node and link object itself.\n * @param oriented if true graph treated as oriented.\n */\n forEachLinkedNode: forEachLinkedNode,\n\n /**\n * Enumerates all links in the graph\n *\n * @param {Function(link)} callback Function to be called on all links in the graph.\n * The function is passed one parameter: graph's link object.\n *\n * Link object contains at least the following fields:\n * fromId - node id where link starts;\n * toId - node id where link ends,\n * data - additional data passed to graph.addLink() method.\n */\n forEachLink: forEachLink,\n\n /**\n * Suspend all notifications about graph changes until\n * endUpdate is called.\n */\n beginUpdate: enterModification,\n\n /**\n * Resumes all notifications about graph changes and fires\n * graph 'changed' event in case there are any pending changes.\n */\n endUpdate: exitModification,\n\n /**\n * Removes all nodes and links from the graph.\n */\n clear: clear,\n\n /**\n * Detects whether there is a link between two nodes.\n * Operation complexity is O(n) where n - number of links of a node.\n * NOTE: this function is synonim for getLink()\n *\n * @returns link if there is one. null otherwise.\n */\n hasLink: getLink,\n\n /**\n * Gets an edge between two nodes.\n * Operation complexity is O(n) where n - number of links of a node.\n *\n * @param {string} fromId link start identifier\n * @param {string} toId link end identifier\n *\n * @returns link if there is one. null otherwise.\n */\n getLink: getLink\n };\n\n // this will add `on()` and `fire()` methods.\n eventify(graphPart);\n\n monitorSubscribers();\n\n return graphPart;\n\n function monitorSubscribers() {\n var realOn = graphPart.on;\n\n // replace real `on` with our temporary on, which will trigger change\n // modification monitoring:\n graphPart.on = on;\n\n function on() {\n // now it's time to start tracking stuff:\n graphPart.beginUpdate = enterModification = enterModificationReal;\n graphPart.endUpdate = exitModification = exitModificationReal;\n recordLinkChange = recordLinkChangeReal;\n recordNodeChange = recordNodeChangeReal;\n\n // this will replace current `on` method with real pub/sub from `eventify`.\n graphPart.on = realOn;\n // delegate to real `on` handler:\n return realOn.apply(graphPart, arguments);\n }\n }\n\n function recordLinkChangeReal(link, changeType) {\n changes.push({\n link: link,\n changeType: changeType\n });\n }\n\n function recordNodeChangeReal(node, changeType) {\n changes.push({\n node: node,\n changeType: changeType\n });\n }\n\n function addNode(nodeId, data) {\n if (nodeId === undefined) {\n throw new Error('Invalid node identifier');\n }\n\n enterModification();\n\n var node = getNode(nodeId);\n if (!node) {\n node = new Node(nodeId);\n nodesCount++;\n recordNodeChange(node, 'add');\n } else {\n recordNodeChange(node, 'update');\n }\n\n node.data = data;\n\n nodes[nodeId] = node;\n\n exitModification();\n return node;\n }\n\n function getNode(nodeId) {\n return nodes[nodeId];\n }\n\n function removeNode(nodeId) {\n var node = getNode(nodeId);\n if (!node) {\n return false;\n }\n\n enterModification();\n\n if (node.links) {\n while (node.links.length) {\n var link = node.links[0];\n removeLink(link);\n }\n }\n\n delete nodes[nodeId];\n nodesCount--;\n\n recordNodeChange(node, 'remove');\n\n exitModification();\n\n return true;\n }\n\n\n function addLink(fromId, toId, data) {\n enterModification();\n\n var fromNode = getNode(fromId) || addNode(fromId);\n var toNode = getNode(toId) || addNode(toId);\n\n var link = createLink(fromId, toId, data);\n\n links.push(link);\n\n // TODO: this is not cool. On large graphs potentially would consume more memory.\n addLinkToNode(fromNode, link);\n if (fromId !== toId) {\n // make sure we are not duplicating links for self-loops\n addLinkToNode(toNode, link);\n }\n\n recordLinkChange(link, 'add');\n\n exitModification();\n\n return link;\n }\n\n function createSingleLink(fromId, toId, data) {\n var linkId = makeLinkId(fromId, toId);\n return new Link(fromId, toId, data, linkId);\n }\n\n function createUniqueLink(fromId, toId, data) {\n // TODO: Get rid of this method.\n var linkId = makeLinkId(fromId, toId);\n var isMultiEdge = multiEdges.hasOwnProperty(linkId);\n if (isMultiEdge || getLink(fromId, toId)) {\n if (!isMultiEdge) {\n multiEdges[linkId] = 0;\n }\n var suffix = '@' + (++multiEdges[linkId]);\n linkId = makeLinkId(fromId + suffix, toId + suffix);\n }\n\n return new Link(fromId, toId, data, linkId);\n }\n\n function getLinks(nodeId) {\n var node = getNode(nodeId);\n return node ? node.links : null;\n }\n\n function removeLink(link) {\n if (!link) {\n return false;\n }\n var idx = indexOfElementInArray(link, links);\n if (idx < 0) {\n return false;\n }\n\n enterModification();\n\n links.splice(idx, 1);\n\n var fromNode = getNode(link.fromId);\n var toNode = getNode(link.toId);\n\n if (fromNode) {\n idx = indexOfElementInArray(link, fromNode.links);\n if (idx >= 0) {\n fromNode.links.splice(idx, 1);\n }\n }\n\n if (toNode) {\n idx = indexOfElementInArray(link, toNode.links);\n if (idx >= 0) {\n toNode.links.splice(idx, 1);\n }\n }\n\n recordLinkChange(link, 'remove');\n\n exitModification();\n\n return true;\n }\n\n function getLink(fromNodeId, toNodeId) {\n // TODO: Use sorted links to speed this up\n var node = getNode(fromNodeId),\n i;\n if (!node || !node.links) {\n return null;\n }\n\n for (i = 0; i < node.links.length; ++i) {\n var link = node.links[i];\n if (link.fromId === fromNodeId && link.toId === toNodeId) {\n return link;\n }\n }\n\n return null; // no link.\n }\n\n function clear() {\n enterModification();\n forEachNode(function(node) {\n removeNode(node.id);\n });\n exitModification();\n }\n\n function forEachLink(callback) {\n var i, length;\n if (typeof callback === 'function') {\n for (i = 0, length = links.length; i < length; ++i) {\n callback(links[i]);\n }\n }\n }\n\n function forEachLinkedNode(nodeId, callback, oriented) {\n var node = getNode(nodeId);\n\n if (node && node.links && typeof callback === 'function') {\n if (oriented) {\n return forEachOrientedLink(node.links, nodeId, callback);\n } else {\n return forEachNonOrientedLink(node.links, nodeId, callback);\n }\n }\n }\n\n function forEachNonOrientedLink(links, nodeId, callback) {\n var quitFast;\n for (var i = 0; i < links.length; ++i) {\n var link = links[i];\n var linkedNodeId = link.fromId === nodeId ? link.toId : link.fromId;\n\n quitFast = callback(nodes[linkedNodeId], link);\n if (quitFast) {\n return true; // Client does not need more iterations. Break now.\n }\n }\n }\n\n function forEachOrientedLink(links, nodeId, callback) {\n var quitFast;\n for (var i = 0; i < links.length; ++i) {\n var link = links[i];\n if (link.fromId === nodeId) {\n quitFast = callback(nodes[link.toId], link);\n if (quitFast) {\n return true; // Client does not need more iterations. Break now.\n }\n }\n }\n }\n\n // we will not fire anything until users of this library explicitly call `on()`\n // method.\n function noop() {}\n\n // Enter, Exit modification allows bulk graph updates without firing events.\n function enterModificationReal() {\n suspendEvents += 1;\n }\n\n function exitModificationReal() {\n suspendEvents -= 1;\n if (suspendEvents === 0 && changes.length > 0) {\n graphPart.fire('changed', changes);\n changes.length = 0;\n }\n }\n\n function createNodeIterator() {\n // Object.keys iterator is 1.3x faster than `for in` loop.\n // See `https://github.com/anvaka/ngraph.graph/tree/bench-for-in-vs-obj-keys`\n // branch for perf test\n return Object.keys ? objectKeysIterator : forInIterator;\n }\n\n function objectKeysIterator(callback) {\n if (typeof callback !== 'function') {\n return;\n }\n\n var keys = Object.keys(nodes);\n for (var i = 0; i < keys.length; ++i) {\n if (callback(nodes[keys[i]])) {\n return true; // client doesn't want to proceed. Return.\n }\n }\n }\n\n function forInIterator(callback) {\n if (typeof callback !== 'function') {\n return;\n }\n var node;\n\n for (node in nodes) {\n if (callback(nodes[node])) {\n return true; // client doesn't want to proceed. Return.\n }\n }\n }\n}\n\n// need this for old browsers. Should this be a separate module?\nfunction indexOfElementInArray(element, array) {\n if (!array) return -1;\n\n if (array.indexOf) {\n return array.indexOf(element);\n }\n\n var len = array.length,\n i;\n\n for (i = 0; i < len; i += 1) {\n if (array[i] === element) {\n return i;\n }\n }\n\n return -1;\n}\n\n/**\n * Internal structure to represent node;\n */\nfunction Node(id) {\n this.id = id;\n this.links = null;\n this.data = null;\n}\n\nfunction addLinkToNode(node, link) {\n if (node.links) {\n node.links.push(link);\n } else {\n node.links = [link];\n }\n}\n\n/**\n * Internal structure to represent links;\n */\nfunction Link(fromId, toId, data, id) {\n this.fromId = fromId;\n this.toId = toId;\n this.data = data;\n this.id = id;\n}\n\nfunction hashCode(str) {\n var hash = 0, i, chr, len;\n if (str.length == 0) return hash;\n for (i = 0, len = str.length; i < len; i++) {\n chr = str.charCodeAt(i);\n hash = ((hash << 5) - hash) + chr;\n hash |= 0; // Convert to 32bit integer\n }\n return hash;\n}\n\nfunction makeLinkId(fromId, toId) {\n return hashCode(fromId.toString() + '👉 ' + toId.toString());\n}\n","/**\r\n * @param {CommunityStructure|Community} com\r\n * @constructor\r\n */\r\nfunction Community(com) {\r\n\r\n /** @type {CommunityStructure} */\r\n this.structure = com.structure ? com.structure : com;\r\n\r\n /** @type {Map.} */\r\n this.connectionsWeight = new Map();\r\n\r\n /** @type {Map.} */\r\n this.connectionsCount = new Map();\r\n\r\n /** @type {Set.} */\r\n this.nodes = new Set;\r\n\r\n this.weightSum = 0;\r\n\r\n\r\n}\r\n\r\n/**\r\n * @public\r\n * @returns {Number}\r\n */\r\nCommunity.prototype.size = function() {\r\n return this.nodes.size;\r\n};\r\n\r\n\r\n/**\r\n * @param {Number} node\r\n */\r\nCommunity.prototype.seed = function(node) {\r\n\r\n this.nodes.add(node);\r\n this.weightSum += this.structure.weights[node];\r\n\r\n};\r\n\r\n/**\r\n * @param {Number} nodeId\r\n * @returns {boolean}\r\n */\r\nCommunity.prototype.add = function(nodeId) {\r\n\r\n this.nodes.add(nodeId);\r\n this.weightSum += this.structure.weights[nodeId];\r\n return true;\r\n\r\n};\r\n\r\n/**\r\n * @param {Number} node\r\n * @returns {boolean}\r\n */\r\nCommunity.prototype.remove = function(node) {\r\n\r\n var result = this.nodes.delete(node);\r\n\r\n this.weightSum -= this.structure.weights[node];\r\n if (!this.nodes.size) {\r\n var index = this.structure.communities.indexOf(this);\r\n delete this.structure.communities[index];\r\n }\r\n\r\n return result;\r\n};\r\n\r\nmodule.exports = Community;\r\n","\"use strict\";\r\nvar Community = require('./Community')\r\n , ModEdge = require('./ModEdge')\r\n ;\r\n\r\n/**\r\n *\r\n * @param {IGraph} graph\r\n * @param useWeight\r\n * @param {CommunityStructure} structure\r\n * @constructor\r\n */\r\nfunction CommunityStructure(graph, useWeight) {\r\n\r\n //this.graph = graph;\r\n this.N = graph.getNodesCount();\r\n this.graphWeightSum = 0;\r\n this.structure = this;\r\n\r\n /** @type {Map.} */\r\n this.invMap = new Map();\r\n\r\n /** @type {Array.< Map. >} */\r\n this.nodeConnectionsWeight = new Array(this.N);\r\n\r\n /** @type {Array.< Map. >} */\r\n this.nodeConnectionsCount = new Array(this.N);\r\n\r\n /** @type {Array.} */\r\n this.nodeCommunities = new Array(this.N);\r\n\r\n /** @type {Map.} */\r\n this.map = new Map();\r\n\r\n /** @type {Array.< Array. >} */\r\n this.topology = new Array(this.N);\r\n for (var i = 0; i < this.N; i++) this.topology[i] = [];\r\n\r\n /** @type {Array.} */\r\n this.communities = [];\r\n\r\n /**@type {Array.} */\r\n this.weights = new Array(this.N);\r\n\r\n var index = 0;\r\n\r\n graph.forEachNode(function (node) {\r\n\r\n this.map.set(node.id, index);\r\n this.nodeCommunities[index] = new Community(this);\r\n this.nodeConnectionsWeight[index] = new Map();\r\n this.nodeConnectionsCount[index] = new Map();\r\n this.weights[index] = 0;\r\n this.nodeCommunities[index].seed(index);\r\n var hidden = new Community(this);\r\n hidden.nodes.add(index);\r\n this.invMap.set(index, hidden);\r\n this.communities.push(this.nodeCommunities[index]);\r\n index++;\r\n\r\n }.bind(this));\r\n\r\n\r\n graph.forEachLink(function (link) {\r\n\r\n var node_index = this.map.get(link.fromId)\r\n , neighbor_index = this.map.get(link.toId)\r\n , weight = 1\r\n ;\r\n\r\n if (node_index === neighbor_index) {\r\n return;\r\n }\r\n\r\n if (useWeight) {\r\n weight = link.data.weight;\r\n }\r\n\r\n this.setUpLink(node_index, neighbor_index, weight);\r\n this.setUpLink(neighbor_index, node_index, weight);\r\n\r\n\r\n }.bind(this));\r\n\r\n\r\n this.graphWeightSum /= 2.0;\r\n}\r\n\r\n\r\nCommunityStructure.prototype.setUpLink = function (node_index, neighbor_index, weight) {\r\n\r\n this.weights[node_index] += weight;\r\n var /** @type {ModEdge} */ me = new ModEdge(node_index, neighbor_index, weight);\r\n this.topology[node_index].push(me);\r\n var /** @type {Community} **/ adjCom = this.nodeCommunities[neighbor_index];\r\n this.nodeConnectionsWeight[node_index].set(adjCom, weight);\r\n this.nodeConnectionsCount[node_index].set(adjCom, 1);\r\n this.nodeCommunities[node_index].connectionsWeight.set(adjCom, weight);\r\n this.nodeCommunities[node_index].connectionsCount.set(adjCom, 1);\r\n this.nodeConnectionsWeight[neighbor_index].set(this.nodeCommunities[node_index], weight);\r\n this.nodeConnectionsCount[neighbor_index].set(this.nodeCommunities[node_index], 1);\r\n this.nodeCommunities[neighbor_index].connectionsWeight.set(this.nodeCommunities[node_index], weight);\r\n this.nodeCommunities[neighbor_index].connectionsCount.set(this.nodeCommunities[node_index], 1);\r\n this.graphWeightSum += weight;\r\n\r\n};\r\n\r\n/**\r\n * @param {Number} node\r\n * @param {Community} to\r\n */\r\nCommunityStructure.prototype.addNodeTo = function (node, to) {\r\n\r\n to.add(node);\r\n this.nodeCommunities[node] = to;\r\n\r\n var nodeTopology = this.topology[node];\r\n for (var topologyKey in nodeTopology) {\r\n\r\n //noinspection JSUnfilteredForInLoop\r\n var /** @type {ModEdge} */ e = nodeTopology[topologyKey];\r\n\r\n var neighbor = e.target;\r\n\r\n\r\n //Remove Node Connection to this community\r\n var neighEdgesTo = this.nodeConnectionsWeight[neighbor].get(to);\r\n if (neighEdgesTo === undefined) {\r\n this.nodeConnectionsWeight[neighbor].set(to, e.weight);\r\n } else {\r\n this.nodeConnectionsWeight[neighbor].set(to, neighEdgesTo + e.weight);\r\n }\r\n\r\n var neighCountEdgesTo = this.nodeConnectionsCount[neighbor].get(to);\r\n if (neighCountEdgesTo === undefined) {\r\n this.nodeConnectionsCount[neighbor].set(to, 1);\r\n } else {\r\n this.nodeConnectionsCount[neighbor].set(to, neighCountEdgesTo + 1);\r\n }\r\n\r\n\r\n var /** @type {Community} */ adjCom = this.nodeCommunities[neighbor];\r\n var wEdgesto = adjCom.connectionsWeight.get(to);\r\n if (wEdgesto === undefined) {\r\n adjCom.connectionsWeight.set(to, e.weight);\r\n } else {\r\n adjCom.connectionsWeight.set(to, wEdgesto + e.weight);\r\n }\r\n\r\n var cEdgesto = adjCom.connectionsCount.get(to);\r\n if (cEdgesto === undefined) {\r\n adjCom.connectionsCount.set(to, 1);\r\n } else {\r\n adjCom.connectionsCount.set(to, cEdgesto + 1);\r\n }\r\n\r\n var nodeEdgesTo = this.nodeConnectionsWeight[node].get(adjCom);\r\n if (nodeEdgesTo === undefined) {\r\n this.nodeConnectionsWeight[node].set(adjCom, e.weight);\r\n } else {\r\n this.nodeConnectionsWeight[node].set(adjCom, nodeEdgesTo + e.weight);\r\n }\r\n\r\n var nodeCountEdgesTo = this.nodeConnectionsCount[node].get(adjCom);\r\n if (nodeCountEdgesTo === undefined) {\r\n this.nodeConnectionsCount[node].set(adjCom, 1);\r\n } else {\r\n this.nodeConnectionsCount[node].set(adjCom, nodeCountEdgesTo + 1);\r\n }\r\n\r\n if (to != adjCom) {\r\n var comEdgesto = to.connectionsWeight.get(adjCom);\r\n if (comEdgesto === undefined) {\r\n to.connectionsWeight.set(adjCom, e.weight);\r\n } else {\r\n to.connectionsWeight.set(adjCom, comEdgesto + e.weight);\r\n }\r\n\r\n var comCountEdgesto = to.connectionsCount.get(adjCom);\r\n if (comCountEdgesto === undefined) {\r\n to.connectionsCount.set(adjCom, 1);\r\n } else {\r\n to.connectionsCount.set(adjCom, comCountEdgesto + 1);\r\n }\r\n\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * @param {Number} node\r\n * @param {Community} source\r\n */\r\nCommunityStructure.prototype.removeNodeFrom = function (node, source) {\r\n\r\n var community = this.nodeCommunities[node];\r\n\r\n\r\n var nodeTopology = this.topology[node];\r\n for (var topologyKey in nodeTopology) {\r\n\r\n //noinspection JSUnfilteredForInLoop\r\n var /** @type {ModEdge} */ e = nodeTopology[topologyKey];\r\n\r\n var neighbor = e.target;\r\n\r\n //Remove Node Connection to this community\r\n var edgesTo = this.nodeConnectionsWeight[neighbor].get(community);\r\n var countEdgesTo = this.nodeConnectionsCount[neighbor].get(community);\r\n\r\n if ((countEdgesTo - 1) == 0) {\r\n this.nodeConnectionsWeight[neighbor].delete(community);\r\n this.nodeConnectionsCount[neighbor].delete(community);\r\n } else {\r\n this.nodeConnectionsWeight[neighbor].set(community, edgesTo - e.weight);\r\n this.nodeConnectionsCount[neighbor].set(community, countEdgesTo - 1);\r\n }\r\n\r\n\r\n //Remove Adjacency Community's connection to this community\r\n var adjCom = this.nodeCommunities[neighbor];\r\n var oEdgesto = adjCom.connectionsWeight.get(community);\r\n var oCountEdgesto = adjCom.connectionsCount.get(community);\r\n if ((oCountEdgesto - 1) == 0) {\r\n adjCom.connectionsWeight.delete(community);\r\n adjCom.connectionsCount.delete(community);\r\n } else {\r\n adjCom.connectionsWeight.set(community, oEdgesto - e.weight);\r\n adjCom.connectionsCount.set(community, oCountEdgesto - 1);\r\n }\r\n\r\n if (node == neighbor) {\r\n continue;\r\n }\r\n\r\n if (adjCom != community) {\r\n\r\n var comEdgesto = community.connectionsWeight.get(adjCom);\r\n var comCountEdgesto = community.connectionsCount.get(adjCom);\r\n\r\n if (comCountEdgesto - 1 == 0) {\r\n community.connectionsWeight.delete(adjCom);\r\n community.connectionsCount.delete(adjCom);\r\n } else {\r\n community.connectionsWeight.set(adjCom, comEdgesto - e.weight);\r\n community.connectionsCount.set(adjCom, comCountEdgesto - 1);\r\n }\r\n\r\n }\r\n\r\n var nodeEdgesTo = this.nodeConnectionsWeight[node].get(adjCom);\r\n var nodeCountEdgesTo = this.nodeConnectionsCount[node].get(adjCom);\r\n\r\n if ((nodeCountEdgesTo - 1) == 0) {\r\n this.nodeConnectionsWeight[node].delete(adjCom);\r\n this.nodeConnectionsCount[node].delete(adjCom);\r\n } else {\r\n this.nodeConnectionsWeight[node].set(adjCom, nodeEdgesTo - e.weight);\r\n this.nodeConnectionsCount[node].set(adjCom, nodeCountEdgesTo - 1);\r\n }\r\n\r\n }\r\n\r\n source.remove(node);\r\n};\r\n\r\n/**\r\n * @param {Number} node\r\n * @param {Community} to\r\n */\r\nCommunityStructure.prototype.moveNodeTo = function (node, to) {\r\n\r\n var source = this.nodeCommunities[node];\r\n this.removeNodeFrom(node, source);\r\n this.addNodeTo(node, to);\r\n\r\n};\r\n\r\n\r\nCommunityStructure.prototype.zoomOut = function () {\r\n var realCommunities = this.communities.reduce(function (arr, value) {\r\n arr.push(value);\r\n return arr;\r\n }, []);\r\n var M = realCommunities.length; // size\r\n var /** @type Array.< Array. > */ newTopology = new Array(M);\r\n var index = 0;\r\n\r\n this.nodeCommunities = new Array(M);\r\n this.nodeConnectionsWeight = new Array(M);\r\n this.nodeConnectionsCount = new Array(M);\r\n\r\n var /** @type Map.*/ newInvMap = new Map();\r\n realCommunities.forEach(function (com) {\r\n\r\n var weightSum = 0;\r\n this.nodeConnectionsWeight[index] = new Map();\r\n this.nodeConnectionsCount[index] = new Map();\r\n newTopology[index] = [];\r\n this.nodeCommunities[index] = new Community(com);\r\n //var iter = com.connectionsWeight.keySet();\r\n\r\n var hidden = new Community(this.structure);\r\n\r\n com.nodes.forEach(function (nodeInt) {\r\n\r\n var oldHidden = this.invMap.get(nodeInt);\r\n oldHidden.nodes.forEach(hidden.nodes.add.bind(hidden.nodes));\r\n\r\n }, this);\r\n\r\n newInvMap.set(index, hidden);\r\n com.connectionsWeight.forEach(function (weight, adjCom) {\r\n\r\n var target = realCommunities.indexOf(adjCom);\r\n if (!~target) return;\r\n if (target == index) {\r\n weightSum += 2. * weight;\r\n } else {\r\n weightSum += weight;\r\n }\r\n var e = new ModEdge(index, target, weight);\r\n newTopology[index].push(e);\r\n\r\n }, this);\r\n\r\n this.weights[index] = weightSum;\r\n this.nodeCommunities[index].seed(index);\r\n\r\n index++;\r\n\r\n }.bind(this));\r\n\r\n this.communities = [];\r\n\r\n for (var i = 0; i < M; i++) {\r\n var com = this.nodeCommunities[i];\r\n this.communities.push(com);\r\n for (var ei in newTopology[i]) {\r\n //noinspection JSUnfilteredForInLoop\r\n var e = newTopology[i][ei];\r\n this.nodeConnectionsWeight[i].set(this.nodeCommunities[e.target], e.weight);\r\n this.nodeConnectionsCount[i].set(this.nodeCommunities[e.target], 1);\r\n com.connectionsWeight.set(this.nodeCommunities[e.target], e.weight);\r\n com.connectionsCount.set(this.nodeCommunities[e.target], 1);\r\n }\r\n\r\n }\r\n\r\n this.N = M;\r\n this.topology = newTopology;\r\n this.invMap = newInvMap;\r\n\r\n};\r\n\r\nmodule.exports = CommunityStructure;","/**\r\n *\r\n * @param s\r\n * @param t\r\n * @param w\r\n * @constructor\r\n */\r\nfunction ModEdge(s, t, w) {\r\n /** @type {Number} */\r\n this.source = s;\r\n /** @type {Number} */\r\n this.target = t;\r\n /** @type {Number} */\r\n this.weight = w;\r\n}\r\n\r\nmodule.exports = ModEdge;\r\n","/*\r\n Copyright 2008-2011 Gephi\r\n Authors : Patick J. McSweeney , Sebastien Heymann \r\n Website : http://www.gephi.org\r\n\r\n This file is part of Gephi.\r\n\r\n DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.\r\n\r\n Copyright 2011 Gephi Consortium. All rights reserved.\r\n\r\n The contents of this file are subject to the terms of either the GNU\r\n General Public License Version 3 only (\"GPL\") or the Common\r\n Development and Distribution License(\"CDDL\") (collectively, the\r\n \"License\"). You may not use this file except in compliance with the\r\n License. You can obtain a copy of the License at\r\n http://gephi.org/about/legal/license-notice/\r\n or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the\r\n specific language governing permissions and limitations under the\r\n License. When distributing the software, include this License Header\r\n Notice in each file and include the License files at\r\n /cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the\r\n License Header, with the fields enclosed by brackets [] replaced by\r\n your own identifying information:\r\n \"Portions Copyrighted [year] [name of copyright owner]\"\r\n\r\n If you wish your version of this file to be governed by only the CDDL\r\n or only the GPL Version 3, indicate your decision by adding\r\n \"[Contributor] elects to include this software in this distribution\r\n under the [CDDL or GPL Version 3] license.\" If you do not indicate a\r\n single choice of license, a recipient has the option to distribute\r\n your version of this file under either the CDDL, the GPL Version 3 or\r\n to extend the choice of license to its licensees as provided above.\r\n However, if you add GPL Version 3 code and therefore, elected the GPL\r\n Version 3 license, then the option applies only if the new code is\r\n made subject to such option by the copyright holder.\r\n\r\n Contributor(s): Thomas Aynaud \r\n\r\n Portions Copyrighted 2011 Gephi Consortium.\r\n */\r\nvar CommunityStructure = require('./CommunityStructure')\r\n , centrality = require('ngraph.centrality')\r\n ;\r\n\r\n/**\r\n * @constructor\r\n */\r\nfunction Modularity (resolution, useWeight) {\r\n this.isRandomized = false;\r\n this.useWeight = useWeight;\r\n this.resolution = resolution || 1.;\r\n /**\r\n * @type {CommunityStructure}\r\n */\r\n this.structure = null;\r\n}\r\n\r\n/**\r\n * @param {IGraph} graph\r\n */\r\nModularity.prototype.execute = function (graph/*, AttributeModel attributeModel*/) {\r\n\r\n\r\n this.structure = new CommunityStructure(graph, this.useWeight);\r\n\r\n var comStructure = new Array(graph.getNodesCount());\r\n\r\n var computedModularityMetrics = this.computeModularity(\r\n graph\r\n , this.structure\r\n , comStructure\r\n , this.resolution\r\n , this.isRandomized\r\n , this.useWeight\r\n );\r\n\r\n var result = {};\r\n this.structure.map.forEach(function (i, node) {\r\n result[node] = comStructure[i];\r\n });\r\n\r\n return result;\r\n\r\n};\r\n\r\n\r\n/**\r\n *\r\n * @param {IGraph} graph\r\n * @param {CommunityStructure} theStructure\r\n * @param {Array.} comStructure\r\n * @param {Number} currentResolution\r\n * @param {Boolean} randomized\r\n * @param {Boolean} weighted\r\n * @returns {Object.}\r\n */\r\nModularity.prototype.computeModularity = function(graph, theStructure, comStructure, currentResolution, randomized, weighted) {\r\n\r\n\r\n function getRandomInt(min, max) {\r\n return Math.floor(Math.random() * (max - min)) + min;\r\n }\r\n\r\n var totalWeight = theStructure.graphWeightSum;\r\n var nodeDegrees = theStructure.weights.slice();\r\n\r\n\r\n var /** @type {Object.} */ results = Object.create(null);\r\n\r\n\r\n var someChange = true;\r\n\r\n while (someChange) {\r\n someChange = false;\r\n var localChange = true;\r\n while (localChange) {\r\n localChange = false;\r\n var start = 0;\r\n if (randomized) {\r\n //start = Math.abs(rand.nextInt()) % theStructure.N;\r\n start = getRandomInt(0,theStructure.N);\r\n }\r\n var step = 0;\r\n for (var i = start; step < theStructure.N; i = (i + 1) % theStructure.N) {\r\n step++;\r\n var bestCommunity = this.updateBestCommunity(theStructure, i, currentResolution);\r\n if ((theStructure.nodeCommunities[i] != bestCommunity) && (bestCommunity != null)) {\r\n theStructure.moveNodeTo(i, bestCommunity);\r\n localChange = true;\r\n }\r\n\r\n }\r\n\r\n someChange = localChange || someChange;\r\n\r\n }\r\n\r\n if (someChange) {\r\n theStructure.zoomOut();\r\n }\r\n }\r\n\r\n this.fillComStructure(graph, theStructure, comStructure);\r\n\r\n /*\r\n //TODO: uncomment when finalQ will be implemented\r\n var degreeCount = this.fillDegreeCount(graph, theStructure, comStructure, nodeDegrees, weighted);\r\n\r\n\r\n var computedModularity = this._finalQ(comStructure, degreeCount, graph, theStructure, totalWeight, 1., weighted);\r\n var computedModularityResolution = this._finalQ(comStructure, degreeCount, graph, theStructure, totalWeight, currentResolution, weighted);\r\n\r\n results[\"modularity\"] = computedModularity;\r\n results[\"modularityResolution\"] = computedModularityResolution;\r\n */\r\n\r\n return results;\r\n};\r\n\r\n\r\n/**\r\n * @param {CommunityStructure} theStructure\r\n * @param {Number} i\r\n * @param {Number} currentResolution\r\n * @returns {Community}\r\n */\r\nModularity.prototype.updateBestCommunity = function(theStructure, i, currentResolution) {\r\n var best = this.q(i, theStructure.nodeCommunities[i], theStructure, currentResolution);\r\n var bestCommunity = theStructure.nodeCommunities[i];\r\n //var /*Set*/ iter = theStructure.nodeConnectionsWeight[i].keySet();\r\n theStructure.nodeConnectionsWeight[i].forEach(function (_$$val, com) {\r\n\r\n var qValue = this.q(i, com, theStructure, currentResolution);\r\n if (qValue > best) {\r\n best = qValue;\r\n bestCommunity = com;\r\n }\r\n\r\n }, this);\r\n return bestCommunity;\r\n};\r\n\r\n/**\r\n *\r\n * @param {IGraph} graph\r\n * @param {CommunityStructure} theStructure\r\n * @param {Array.} comStructure\r\n * @returns {Array.}\r\n */\r\nModularity.prototype.fillComStructure = function(graph, theStructure, comStructure) {\r\n\r\n var count = 0;\r\n\r\n theStructure.communities.forEach(function (com) {\r\n\r\n com.nodes.forEach(function (node) {\r\n\r\n var hidden = theStructure.invMap.get(node);\r\n hidden.nodes.forEach( function (nodeInt){\r\n comStructure[nodeInt] = count;\r\n });\r\n\r\n });\r\n count++;\r\n\r\n });\r\n\r\n\r\n return comStructure;\r\n};\r\n\r\n/**\r\n * @param {IGraph} graph\r\n * @param {CommunityStructure} theStructure\r\n * @param {Array.} comStructure\r\n * @param {Array.} nodeDegrees\r\n * @param {Boolean} weighted\r\n * @returns {Array.}\r\n */\r\nModularity.prototype.fillDegreeCount = function(graph, theStructure, comStructure, nodeDegrees, weighted) {\r\n\r\n var degreeCount = new Array(theStructure.communities.length);\r\n var degreeCentrality = centrality.degree(graph);\r\n\r\n graph.forEachNode(function(node){\r\n\r\n var index = theStructure.map.get(node);\r\n if (weighted) {\r\n degreeCount[comStructure[index]] += nodeDegrees[index];\r\n } else {\r\n degreeCount[comStructure[index]] += degreeCentrality[node.id];\r\n }\r\n\r\n });\r\n return degreeCount;\r\n\r\n};\r\n\r\n\r\n/**\r\n *\r\n * @param {Array.} struct\r\n * @param {Array.} degrees\r\n * @param {IGraph} graph\r\n * @param {CommunityStructure} theStructure\r\n * @param {Number} totalWeight\r\n * @param {Number} usedResolution\r\n * @param {Boolean} weighted\r\n * @returns {Number}\r\n */\r\nModularity.prototype._finalQ = function(struct, degrees, graph, theStructure, totalWeight, usedResolution, weighted) {\r\n\r\n //TODO: rewrite for wighted version of algorithm\r\n throw new Error(\"not implemented properly\");\r\n var res = 0;\r\n var internal = new Array(degrees.length);\r\n\r\n graph.forEachNode(function(n){\r\n var n_index = theStructure.map.get(n);\r\n\r\n graph.forEachLinkedNode(n.id, function(neighbor){\r\n if (n == neighbor) {\r\n return;\r\n }\r\n var neigh_index = theStructure.map.get(neighbor);\r\n if (struct[neigh_index] == struct[n_index]) {\r\n if (weighted) {\r\n //throw new Error(\"weighted aren't implemented\");\r\n //internal[struct[neigh_index]] += graph.getEdge(n, neighbor).getWeight();\r\n } else {\r\n internal[struct[neigh_index]]++;\r\n }\r\n }\r\n }.bind(this), false);\r\n\r\n }.bind(this));\r\n\r\n for (var i = 0; i < degrees.length; i++) {\r\n internal[i] /= 2.0;\r\n res += usedResolution * (internal[i] / totalWeight) - Math.pow(degrees[i] / (2 * totalWeight), 2);//HERE\r\n }\r\n return res;\r\n};\r\n\r\n\r\n\r\n/**\r\n *\r\n * @param {Number} nodeId\r\n * @param {Community} community\r\n * @param {CommunityStructure} theStructure\r\n * @param {Number} currentResolution\r\n * @returns {Number}\r\n */\r\nModularity.prototype.q = function(nodeId, community, theStructure, currentResolution) {\r\n\r\n var edgesToFloat = theStructure.nodeConnectionsWeight[nodeId].get(community);\r\n var edgesTo = 0;\r\n if (edgesToFloat != null) {\r\n edgesTo = edgesToFloat;\r\n }\r\n var weightSum = community.weightSum;\r\n var nodeWeight = theStructure.weights[nodeId];\r\n var qValue = currentResolution * edgesTo - (nodeWeight * weightSum) / (2.0 * theStructure.graphWeightSum);\r\n if ((theStructure.nodeCommunities[nodeId] == community) && (theStructure.nodeCommunities[nodeId].size() > 1)) {\r\n qValue = currentResolution * edgesTo - (nodeWeight * (weightSum - nodeWeight)) / (2.0 * theStructure.graphWeightSum);\r\n }\r\n if ((theStructure.nodeCommunities[nodeId] == community) && (theStructure.nodeCommunities[nodeId].size() == 1)) {\r\n qValue = 0.;\r\n }\r\n return qValue;\r\n\r\n};\r\n\r\nmodule.exports = Modularity;","import Modularity from 'ngraph.modularity/Modularity';\nimport * as echarts from 'echarts/core';\nimport createNGraph from 'ngraph.graph';\n\nfunction createModularityVisual(chartType) {\n return function (ecModel, api) {\n var paletteScope = {};\n ecModel.eachSeriesByType(chartType, function (seriesModel) {\n var modularityOpt = seriesModel.get('modularity');\n if (modularityOpt) {\n var graph = seriesModel.getGraph();\n var idIndexMap = {};\n var ng = createNGraph();\n graph.data.each(function (idx) {\n var node = graph.getNodeByIndex(idx);\n idIndexMap[node.id] = idx;\n ng.addNode(node.id);\n return node.id;\n });\n graph.edgeData.each('value', function (val, idx) {\n var edge = graph.getEdgeByIndex(idx);\n ng.addLink(edge.node1.id, edge.node2.id);\n return {\n source: edge.node1.id,\n target: edge.node2.id,\n value: val\n };\n });\n\n var modularity = new Modularity(seriesModel.get('modularity.resolution') || 1);\n var result = modularity.execute(ng);\n\n var communities = {};\n for (var id in result) {\n var comm = result[id];\n communities[comm] = communities[comm] || 0;\n communities[comm]++;\n }\n var communitiesList = Object.keys(communities);\n if (seriesModel.get('modularity.sort')) {\n communitiesList.sort(function (a, b) {\n return b - a;\n });\n }\n var colors = {};\n communitiesList.forEach(function (comm) {\n colors[comm] = seriesModel.getColorFromPalette(comm, paletteScope);\n });\n\n for (var id in result) {\n var comm = result[id];\n var style = graph.data.ensureUniqueItemVisual(idIndexMap[id], 'style');\n style.fill = colors[comm];\n }\n\n graph.edgeData.each(function (idx) {\n var itemModel = graph.edgeData.getItemModel(idx);\n var edge = graph.getEdgeByIndex(idx);\n var color = itemModel.get(['lineStyle', 'normal', 'color'])\n || itemModel.get(['lineStyle', 'color']);\n\n switch (color) {\n case 'source':\n color = edge.node1.getVisual('style').fill;\n break;\n case 'target':\n color = edge.node2.getVisual('style').fill;\n break;\n }\n\n if (color != null) {\n graph.edgeData.ensureUniqueItemVisual(idx, 'style').stroke = color;\n }\n });\n }\n });\n };\n}\n\necharts.registerVisual(echarts.PRIORITY.VISUAL.CHART + 1, createModularityVisual('graph'));\necharts.registerVisual(echarts.PRIORITY.VISUAL.CHART + 1, createModularityVisual('graphGL'));","module.exports = __WEBPACK_EXTERNAL_MODULE_echarts_core__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","","// startup\n// Load entry module and return exports\n// This entry module used 'module' so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(\"./index.js\");\n",""],"names":[],"sourceRoot":""} -------------------------------------------------------------------------------- /dist/echarts-graph-modularity.js: -------------------------------------------------------------------------------- 1 | (function webpackUniversalModuleDefinition(root, factory) { 2 | if(typeof exports === 'object' && typeof module === 'object') 3 | module.exports = factory(require("echarts")); 4 | else if(typeof define === 'function' && define.amd) 5 | define(["echarts"], factory); 6 | else if(typeof exports === 'object') 7 | exports["echarts-graph-modularity"] = factory(require("echarts")); 8 | else 9 | root["echarts-graph-modularity"] = factory(root["echarts"]); 10 | })(self, function(__WEBPACK_EXTERNAL_MODULE_echarts_core__) { 11 | return /******/ (() => { // webpackBootstrap 12 | /******/ var __webpack_modules__ = ({ 13 | 14 | /***/ "./index.js": 15 | /*!******************!*\ 16 | !*** ./index.js ***! 17 | \******************/ 18 | /***/ ((module, __unused_webpack_exports, __webpack_require__) => { 19 | 20 | module.exports = __webpack_require__(/*! ./src/main */ "./src/main.js"); 21 | 22 | /***/ }), 23 | 24 | /***/ "./node_modules/ngraph.centrality/index.js": 25 | /*!*************************************************!*\ 26 | !*** ./node_modules/ngraph.centrality/index.js ***! 27 | \*************************************************/ 28 | /***/ ((module, __unused_webpack_exports, __webpack_require__) => { 29 | 30 | module.exports.degree = __webpack_require__(/*! ./src/degree.js */ "./node_modules/ngraph.centrality/src/degree.js"); 31 | module.exports.betweenness = __webpack_require__(/*! ./src/betweenness.js */ "./node_modules/ngraph.centrality/src/betweenness.js"); 32 | 33 | 34 | /***/ }), 35 | 36 | /***/ "./node_modules/ngraph.centrality/src/betweenness.js": 37 | /*!***********************************************************!*\ 38 | !*** ./node_modules/ngraph.centrality/src/betweenness.js ***! 39 | \***********************************************************/ 40 | /***/ ((module) => { 41 | 42 | module.exports = betweennes; 43 | 44 | /** 45 | * I'm using http://www.inf.uni-konstanz.de/algo/publications/b-vspbc-08.pdf 46 | * as a reference for this implementation 47 | */ 48 | function betweennes(graph, oriented) { 49 | var Q = [], 50 | S = []; // Queue and Stack 51 | // list of predcessors on shorteest paths from source 52 | var pred = Object.create(null); 53 | // distance from source 54 | var dist = Object.create(null); 55 | // number of shortest paths from source to key 56 | var sigma = Object.create(null); 57 | // dependency of source on key 58 | var delta = Object.create(null); 59 | 60 | var currentNode; 61 | var centrality = Object.create(null); 62 | 63 | graph.forEachNode(setCentralityToZero); 64 | graph.forEachNode(calculateCentrality); 65 | 66 | if (!oriented) { 67 | // The centrality scores need to be divided by two if the graph is not oriented, 68 | // since all shortest paths are considered twice 69 | Object.keys(centrality).forEach(divideByTwo); 70 | } 71 | 72 | return centrality; 73 | 74 | function divideByTwo(key) { 75 | centrality[key] /= 2; 76 | } 77 | 78 | function setCentralityToZero(node) { 79 | centrality[node.id] = 0; 80 | } 81 | 82 | function calculateCentrality(node) { 83 | currentNode = node.id; 84 | singleSourceShortestPath(currentNode); 85 | accumulate(); 86 | } 87 | 88 | function accumulate() { 89 | graph.forEachNode(setDeltaToZero); 90 | while (S.length) { 91 | var w = S.pop(); 92 | var coeff = (1 + delta[w])/sigma[w]; 93 | var predcessors = pred[w]; 94 | for (var idx = 0; idx < predcessors.length; ++idx) { 95 | var v = predcessors[idx]; 96 | delta[v] += sigma[v] * coeff; 97 | } 98 | if (w !== currentNode) { 99 | centrality[w] += delta[w]; 100 | } 101 | } 102 | } 103 | 104 | function setDeltaToZero(node) { 105 | delta[node.id] = 0; 106 | } 107 | 108 | function singleSourceShortestPath(source) { 109 | graph.forEachNode(initNode); 110 | dist[source] = 0; 111 | sigma[source] = 1; 112 | Q.push(source); 113 | 114 | while (Q.length) { 115 | var v = Q.shift(); 116 | S.push(v); 117 | graph.forEachLinkedNode(v, toId, oriented); 118 | } 119 | 120 | function toId(otherNode) { 121 | // NOTE: This code will also consider multi-edges, which are often 122 | // ignored by popular software (Gephi/NetworkX). Depending on your use 123 | // case this may not be desired and deduping needs to be performed. To 124 | // save memory I'm not deduping here... 125 | processNode(otherNode.id); 126 | } 127 | 128 | function initNode(node) { 129 | var nodeId = node.id; 130 | pred[nodeId] = []; // empty list 131 | dist[nodeId] = -1; 132 | sigma[nodeId] = 0; 133 | } 134 | 135 | function processNode(w) { 136 | // path discovery 137 | if (dist[w] === -1) { 138 | // Node w is found for the first time 139 | dist[w] = dist[v] + 1; 140 | Q.push(w); 141 | } 142 | // path counting 143 | if (dist[w] === dist[v] + 1) { 144 | // edge (v, w) on a shortest path 145 | sigma[w] += sigma[v]; 146 | pred[w].push(v); 147 | } 148 | } 149 | } 150 | } 151 | 152 | 153 | /***/ }), 154 | 155 | /***/ "./node_modules/ngraph.centrality/src/degree.js": 156 | /*!******************************************************!*\ 157 | !*** ./node_modules/ngraph.centrality/src/degree.js ***! 158 | \******************************************************/ 159 | /***/ ((module) => { 160 | 161 | module.exports = degree; 162 | 163 | /** 164 | * Calculates graph nodes degree centrality (in/out or both). 165 | * 166 | * @see http://en.wikipedia.org/wiki/Centrality#Degree_centrality 167 | * 168 | * @param {ngraph.graph} graph object for which we are calculating centrality. 169 | * @param {string} [kind=both] What kind of degree centrality needs to be calculated: 170 | * 'in' - calculate in-degree centrality 171 | * 'out' - calculate out-degree centrality 172 | * 'inout' - (default) generic degree centrality is calculated 173 | */ 174 | function degree(graph, kind) { 175 | var getNodeDegree; 176 | var result = Object.create(null); 177 | 178 | kind = (kind || 'both').toLowerCase(); 179 | if (kind === 'both' || kind === 'inout') { 180 | getNodeDegree = inoutDegreeCalculator; 181 | } else if (kind === 'in') { 182 | getNodeDegree = inDegreeCalculator; 183 | } else if (kind === 'out') { 184 | getNodeDegree = outDegreeCalculator; 185 | } else { 186 | throw new Error('Expected centrality degree kind is: in, out or both'); 187 | } 188 | 189 | graph.forEachNode(calculateNodeDegree); 190 | 191 | return result; 192 | 193 | function calculateNodeDegree(node) { 194 | var links = graph.getLinks(node.id); 195 | result[node.id] = getNodeDegree(links, node.id); 196 | } 197 | } 198 | 199 | function inDegreeCalculator(links, nodeId) { 200 | var total = 0; 201 | if (!links) return total; 202 | 203 | for (var i = 0; i < links.length; i += 1) { 204 | total += (links[i].toId === nodeId) ? 1 : 0; 205 | } 206 | return total; 207 | } 208 | 209 | function outDegreeCalculator(links, nodeId) { 210 | var total = 0; 211 | if (!links) return total; 212 | 213 | for (var i = 0; i < links.length; i += 1) { 214 | total += (links[i].fromId === nodeId) ? 1 : 0; 215 | } 216 | return total; 217 | } 218 | 219 | function inoutDegreeCalculator(links) { 220 | if (!links) return 0; 221 | 222 | return links.length; 223 | } 224 | 225 | 226 | /***/ }), 227 | 228 | /***/ "./node_modules/ngraph.events/index.js": 229 | /*!*********************************************!*\ 230 | !*** ./node_modules/ngraph.events/index.js ***! 231 | \*********************************************/ 232 | /***/ ((module) => { 233 | 234 | module.exports = function(subject) { 235 | validateSubject(subject); 236 | 237 | var eventsStorage = createEventsStorage(subject); 238 | subject.on = eventsStorage.on; 239 | subject.off = eventsStorage.off; 240 | subject.fire = eventsStorage.fire; 241 | return subject; 242 | }; 243 | 244 | function createEventsStorage(subject) { 245 | // Store all event listeners to this hash. Key is event name, value is array 246 | // of callback records. 247 | // 248 | // A callback record consists of callback function and its optional context: 249 | // { 'eventName' => [{callback: function, ctx: object}] } 250 | var registeredEvents = Object.create(null); 251 | 252 | return { 253 | on: function (eventName, callback, ctx) { 254 | if (typeof callback !== 'function') { 255 | throw new Error('callback is expected to be a function'); 256 | } 257 | var handlers = registeredEvents[eventName]; 258 | if (!handlers) { 259 | handlers = registeredEvents[eventName] = []; 260 | } 261 | handlers.push({callback: callback, ctx: ctx}); 262 | 263 | return subject; 264 | }, 265 | 266 | off: function (eventName, callback) { 267 | var wantToRemoveAll = (typeof eventName === 'undefined'); 268 | if (wantToRemoveAll) { 269 | // Killing old events storage should be enough in this case: 270 | registeredEvents = Object.create(null); 271 | return subject; 272 | } 273 | 274 | if (registeredEvents[eventName]) { 275 | var deleteAllCallbacksForEvent = (typeof callback !== 'function'); 276 | if (deleteAllCallbacksForEvent) { 277 | delete registeredEvents[eventName]; 278 | } else { 279 | var callbacks = registeredEvents[eventName]; 280 | for (var i = 0; i < callbacks.length; ++i) { 281 | if (callbacks[i].callback === callback) { 282 | callbacks.splice(i, 1); 283 | } 284 | } 285 | } 286 | } 287 | 288 | return subject; 289 | }, 290 | 291 | fire: function (eventName) { 292 | var callbacks = registeredEvents[eventName]; 293 | if (!callbacks) { 294 | return subject; 295 | } 296 | 297 | var fireArguments; 298 | if (arguments.length > 1) { 299 | fireArguments = Array.prototype.splice.call(arguments, 1); 300 | } 301 | for(var i = 0; i < callbacks.length; ++i) { 302 | var callbackInfo = callbacks[i]; 303 | callbackInfo.callback.apply(callbackInfo.ctx, fireArguments); 304 | } 305 | 306 | return subject; 307 | } 308 | }; 309 | } 310 | 311 | function validateSubject(subject) { 312 | if (!subject) { 313 | throw new Error('Eventify cannot use falsy object as events subject'); 314 | } 315 | var reservedWords = ['on', 'fire', 'off']; 316 | for (var i = 0; i < reservedWords.length; ++i) { 317 | if (subject.hasOwnProperty(reservedWords[i])) { 318 | throw new Error("Subject cannot be eventified, since it already has property '" + reservedWords[i] + "'"); 319 | } 320 | } 321 | } 322 | 323 | 324 | /***/ }), 325 | 326 | /***/ "./node_modules/ngraph.graph/index.js": 327 | /*!********************************************!*\ 328 | !*** ./node_modules/ngraph.graph/index.js ***! 329 | \********************************************/ 330 | /***/ ((module, __unused_webpack_exports, __webpack_require__) => { 331 | 332 | /** 333 | * @fileOverview Contains definition of the core graph object. 334 | */ 335 | 336 | /** 337 | * @example 338 | * var graph = require('ngraph.graph')(); 339 | * graph.addNode(1); // graph has one node. 340 | * graph.addLink(2, 3); // now graph contains three nodes and one link. 341 | * 342 | */ 343 | module.exports = createGraph; 344 | 345 | var eventify = __webpack_require__(/*! ngraph.events */ "./node_modules/ngraph.events/index.js"); 346 | 347 | /** 348 | * Creates a new graph 349 | */ 350 | function createGraph(options) { 351 | // Graph structure is maintained as dictionary of nodes 352 | // and array of links. Each node has 'links' property which 353 | // hold all links related to that node. And general links 354 | // array is used to speed up all links enumeration. This is inefficient 355 | // in terms of memory, but simplifies coding. 356 | options = options || {}; 357 | if (options.uniqueLinkId === undefined) { 358 | // Request each link id to be unique between same nodes. This negatively 359 | // impacts `addLink()` performance (O(n), where n - number of edges of each 360 | // vertex), but makes operations with multigraphs more accessible. 361 | options.uniqueLinkId = true; 362 | } 363 | 364 | var nodes = typeof Object.create === 'function' ? Object.create(null) : {}, 365 | links = [], 366 | // Hash of multi-edges. Used to track ids of edges between same nodes 367 | multiEdges = {}, 368 | nodesCount = 0, 369 | suspendEvents = 0, 370 | 371 | forEachNode = createNodeIterator(), 372 | createLink = options.uniqueLinkId ? createUniqueLink : createSingleLink, 373 | 374 | // Our graph API provides means to listen to graph changes. Users can subscribe 375 | // to be notified about changes in the graph by using `on` method. However 376 | // in some cases they don't use it. To avoid unnecessary memory consumption 377 | // we will not record graph changes until we have at least one subscriber. 378 | // Code below supports this optimization. 379 | // 380 | // Accumulates all changes made during graph updates. 381 | // Each change element contains: 382 | // changeType - one of the strings: 'add', 'remove' or 'update'; 383 | // node - if change is related to node this property is set to changed graph's node; 384 | // link - if change is related to link this property is set to changed graph's link; 385 | changes = [], 386 | recordLinkChange = noop, 387 | recordNodeChange = noop, 388 | enterModification = noop, 389 | exitModification = noop; 390 | 391 | // this is our public API: 392 | var graphPart = { 393 | /** 394 | * Adds node to the graph. If node with given id already exists in the graph 395 | * its data is extended with whatever comes in 'data' argument. 396 | * 397 | * @param nodeId the node's identifier. A string or number is preferred. 398 | * @param [data] additional data for the node being added. If node already 399 | * exists its data object is augmented with the new one. 400 | * 401 | * @return {node} The newly added node or node with given id if it already exists. 402 | */ 403 | addNode: addNode, 404 | 405 | /** 406 | * Adds a link to the graph. The function always create a new 407 | * link between two nodes. If one of the nodes does not exists 408 | * a new node is created. 409 | * 410 | * @param fromId link start node id; 411 | * @param toId link end node id; 412 | * @param [data] additional data to be set on the new link; 413 | * 414 | * @return {link} The newly created link 415 | */ 416 | addLink: addLink, 417 | 418 | /** 419 | * Removes link from the graph. If link does not exist does nothing. 420 | * 421 | * @param link - object returned by addLink() or getLinks() methods. 422 | * 423 | * @returns true if link was removed; false otherwise. 424 | */ 425 | removeLink: removeLink, 426 | 427 | /** 428 | * Removes node with given id from the graph. If node does not exist in the graph 429 | * does nothing. 430 | * 431 | * @param nodeId node's identifier passed to addNode() function. 432 | * 433 | * @returns true if node was removed; false otherwise. 434 | */ 435 | removeNode: removeNode, 436 | 437 | /** 438 | * Gets node with given identifier. If node does not exist undefined value is returned. 439 | * 440 | * @param nodeId requested node identifier; 441 | * 442 | * @return {node} in with requested identifier or undefined if no such node exists. 443 | */ 444 | getNode: getNode, 445 | 446 | /** 447 | * Gets number of nodes in this graph. 448 | * 449 | * @return number of nodes in the graph. 450 | */ 451 | getNodesCount: function() { 452 | return nodesCount; 453 | }, 454 | 455 | /** 456 | * Gets total number of links in the graph. 457 | */ 458 | getLinksCount: function() { 459 | return links.length; 460 | }, 461 | 462 | /** 463 | * Gets all links (inbound and outbound) from the node with given id. 464 | * If node with given id is not found null is returned. 465 | * 466 | * @param nodeId requested node identifier. 467 | * 468 | * @return Array of links from and to requested node if such node exists; 469 | * otherwise null is returned. 470 | */ 471 | getLinks: getLinks, 472 | 473 | /** 474 | * Invokes callback on each node of the graph. 475 | * 476 | * @param {Function(node)} callback Function to be invoked. The function 477 | * is passed one argument: visited node. 478 | */ 479 | forEachNode: forEachNode, 480 | 481 | /** 482 | * Invokes callback on every linked (adjacent) node to the given one. 483 | * 484 | * @param nodeId Identifier of the requested node. 485 | * @param {Function(node, link)} callback Function to be called on all linked nodes. 486 | * The function is passed two parameters: adjacent node and link object itself. 487 | * @param oriented if true graph treated as oriented. 488 | */ 489 | forEachLinkedNode: forEachLinkedNode, 490 | 491 | /** 492 | * Enumerates all links in the graph 493 | * 494 | * @param {Function(link)} callback Function to be called on all links in the graph. 495 | * The function is passed one parameter: graph's link object. 496 | * 497 | * Link object contains at least the following fields: 498 | * fromId - node id where link starts; 499 | * toId - node id where link ends, 500 | * data - additional data passed to graph.addLink() method. 501 | */ 502 | forEachLink: forEachLink, 503 | 504 | /** 505 | * Suspend all notifications about graph changes until 506 | * endUpdate is called. 507 | */ 508 | beginUpdate: enterModification, 509 | 510 | /** 511 | * Resumes all notifications about graph changes and fires 512 | * graph 'changed' event in case there are any pending changes. 513 | */ 514 | endUpdate: exitModification, 515 | 516 | /** 517 | * Removes all nodes and links from the graph. 518 | */ 519 | clear: clear, 520 | 521 | /** 522 | * Detects whether there is a link between two nodes. 523 | * Operation complexity is O(n) where n - number of links of a node. 524 | * NOTE: this function is synonim for getLink() 525 | * 526 | * @returns link if there is one. null otherwise. 527 | */ 528 | hasLink: getLink, 529 | 530 | /** 531 | * Gets an edge between two nodes. 532 | * Operation complexity is O(n) where n - number of links of a node. 533 | * 534 | * @param {string} fromId link start identifier 535 | * @param {string} toId link end identifier 536 | * 537 | * @returns link if there is one. null otherwise. 538 | */ 539 | getLink: getLink 540 | }; 541 | 542 | // this will add `on()` and `fire()` methods. 543 | eventify(graphPart); 544 | 545 | monitorSubscribers(); 546 | 547 | return graphPart; 548 | 549 | function monitorSubscribers() { 550 | var realOn = graphPart.on; 551 | 552 | // replace real `on` with our temporary on, which will trigger change 553 | // modification monitoring: 554 | graphPart.on = on; 555 | 556 | function on() { 557 | // now it's time to start tracking stuff: 558 | graphPart.beginUpdate = enterModification = enterModificationReal; 559 | graphPart.endUpdate = exitModification = exitModificationReal; 560 | recordLinkChange = recordLinkChangeReal; 561 | recordNodeChange = recordNodeChangeReal; 562 | 563 | // this will replace current `on` method with real pub/sub from `eventify`. 564 | graphPart.on = realOn; 565 | // delegate to real `on` handler: 566 | return realOn.apply(graphPart, arguments); 567 | } 568 | } 569 | 570 | function recordLinkChangeReal(link, changeType) { 571 | changes.push({ 572 | link: link, 573 | changeType: changeType 574 | }); 575 | } 576 | 577 | function recordNodeChangeReal(node, changeType) { 578 | changes.push({ 579 | node: node, 580 | changeType: changeType 581 | }); 582 | } 583 | 584 | function addNode(nodeId, data) { 585 | if (nodeId === undefined) { 586 | throw new Error('Invalid node identifier'); 587 | } 588 | 589 | enterModification(); 590 | 591 | var node = getNode(nodeId); 592 | if (!node) { 593 | node = new Node(nodeId); 594 | nodesCount++; 595 | recordNodeChange(node, 'add'); 596 | } else { 597 | recordNodeChange(node, 'update'); 598 | } 599 | 600 | node.data = data; 601 | 602 | nodes[nodeId] = node; 603 | 604 | exitModification(); 605 | return node; 606 | } 607 | 608 | function getNode(nodeId) { 609 | return nodes[nodeId]; 610 | } 611 | 612 | function removeNode(nodeId) { 613 | var node = getNode(nodeId); 614 | if (!node) { 615 | return false; 616 | } 617 | 618 | enterModification(); 619 | 620 | if (node.links) { 621 | while (node.links.length) { 622 | var link = node.links[0]; 623 | removeLink(link); 624 | } 625 | } 626 | 627 | delete nodes[nodeId]; 628 | nodesCount--; 629 | 630 | recordNodeChange(node, 'remove'); 631 | 632 | exitModification(); 633 | 634 | return true; 635 | } 636 | 637 | 638 | function addLink(fromId, toId, data) { 639 | enterModification(); 640 | 641 | var fromNode = getNode(fromId) || addNode(fromId); 642 | var toNode = getNode(toId) || addNode(toId); 643 | 644 | var link = createLink(fromId, toId, data); 645 | 646 | links.push(link); 647 | 648 | // TODO: this is not cool. On large graphs potentially would consume more memory. 649 | addLinkToNode(fromNode, link); 650 | if (fromId !== toId) { 651 | // make sure we are not duplicating links for self-loops 652 | addLinkToNode(toNode, link); 653 | } 654 | 655 | recordLinkChange(link, 'add'); 656 | 657 | exitModification(); 658 | 659 | return link; 660 | } 661 | 662 | function createSingleLink(fromId, toId, data) { 663 | var linkId = makeLinkId(fromId, toId); 664 | return new Link(fromId, toId, data, linkId); 665 | } 666 | 667 | function createUniqueLink(fromId, toId, data) { 668 | // TODO: Get rid of this method. 669 | var linkId = makeLinkId(fromId, toId); 670 | var isMultiEdge = multiEdges.hasOwnProperty(linkId); 671 | if (isMultiEdge || getLink(fromId, toId)) { 672 | if (!isMultiEdge) { 673 | multiEdges[linkId] = 0; 674 | } 675 | var suffix = '@' + (++multiEdges[linkId]); 676 | linkId = makeLinkId(fromId + suffix, toId + suffix); 677 | } 678 | 679 | return new Link(fromId, toId, data, linkId); 680 | } 681 | 682 | function getLinks(nodeId) { 683 | var node = getNode(nodeId); 684 | return node ? node.links : null; 685 | } 686 | 687 | function removeLink(link) { 688 | if (!link) { 689 | return false; 690 | } 691 | var idx = indexOfElementInArray(link, links); 692 | if (idx < 0) { 693 | return false; 694 | } 695 | 696 | enterModification(); 697 | 698 | links.splice(idx, 1); 699 | 700 | var fromNode = getNode(link.fromId); 701 | var toNode = getNode(link.toId); 702 | 703 | if (fromNode) { 704 | idx = indexOfElementInArray(link, fromNode.links); 705 | if (idx >= 0) { 706 | fromNode.links.splice(idx, 1); 707 | } 708 | } 709 | 710 | if (toNode) { 711 | idx = indexOfElementInArray(link, toNode.links); 712 | if (idx >= 0) { 713 | toNode.links.splice(idx, 1); 714 | } 715 | } 716 | 717 | recordLinkChange(link, 'remove'); 718 | 719 | exitModification(); 720 | 721 | return true; 722 | } 723 | 724 | function getLink(fromNodeId, toNodeId) { 725 | // TODO: Use sorted links to speed this up 726 | var node = getNode(fromNodeId), 727 | i; 728 | if (!node || !node.links) { 729 | return null; 730 | } 731 | 732 | for (i = 0; i < node.links.length; ++i) { 733 | var link = node.links[i]; 734 | if (link.fromId === fromNodeId && link.toId === toNodeId) { 735 | return link; 736 | } 737 | } 738 | 739 | return null; // no link. 740 | } 741 | 742 | function clear() { 743 | enterModification(); 744 | forEachNode(function(node) { 745 | removeNode(node.id); 746 | }); 747 | exitModification(); 748 | } 749 | 750 | function forEachLink(callback) { 751 | var i, length; 752 | if (typeof callback === 'function') { 753 | for (i = 0, length = links.length; i < length; ++i) { 754 | callback(links[i]); 755 | } 756 | } 757 | } 758 | 759 | function forEachLinkedNode(nodeId, callback, oriented) { 760 | var node = getNode(nodeId); 761 | 762 | if (node && node.links && typeof callback === 'function') { 763 | if (oriented) { 764 | return forEachOrientedLink(node.links, nodeId, callback); 765 | } else { 766 | return forEachNonOrientedLink(node.links, nodeId, callback); 767 | } 768 | } 769 | } 770 | 771 | function forEachNonOrientedLink(links, nodeId, callback) { 772 | var quitFast; 773 | for (var i = 0; i < links.length; ++i) { 774 | var link = links[i]; 775 | var linkedNodeId = link.fromId === nodeId ? link.toId : link.fromId; 776 | 777 | quitFast = callback(nodes[linkedNodeId], link); 778 | if (quitFast) { 779 | return true; // Client does not need more iterations. Break now. 780 | } 781 | } 782 | } 783 | 784 | function forEachOrientedLink(links, nodeId, callback) { 785 | var quitFast; 786 | for (var i = 0; i < links.length; ++i) { 787 | var link = links[i]; 788 | if (link.fromId === nodeId) { 789 | quitFast = callback(nodes[link.toId], link); 790 | if (quitFast) { 791 | return true; // Client does not need more iterations. Break now. 792 | } 793 | } 794 | } 795 | } 796 | 797 | // we will not fire anything until users of this library explicitly call `on()` 798 | // method. 799 | function noop() {} 800 | 801 | // Enter, Exit modification allows bulk graph updates without firing events. 802 | function enterModificationReal() { 803 | suspendEvents += 1; 804 | } 805 | 806 | function exitModificationReal() { 807 | suspendEvents -= 1; 808 | if (suspendEvents === 0 && changes.length > 0) { 809 | graphPart.fire('changed', changes); 810 | changes.length = 0; 811 | } 812 | } 813 | 814 | function createNodeIterator() { 815 | // Object.keys iterator is 1.3x faster than `for in` loop. 816 | // See `https://github.com/anvaka/ngraph.graph/tree/bench-for-in-vs-obj-keys` 817 | // branch for perf test 818 | return Object.keys ? objectKeysIterator : forInIterator; 819 | } 820 | 821 | function objectKeysIterator(callback) { 822 | if (typeof callback !== 'function') { 823 | return; 824 | } 825 | 826 | var keys = Object.keys(nodes); 827 | for (var i = 0; i < keys.length; ++i) { 828 | if (callback(nodes[keys[i]])) { 829 | return true; // client doesn't want to proceed. Return. 830 | } 831 | } 832 | } 833 | 834 | function forInIterator(callback) { 835 | if (typeof callback !== 'function') { 836 | return; 837 | } 838 | var node; 839 | 840 | for (node in nodes) { 841 | if (callback(nodes[node])) { 842 | return true; // client doesn't want to proceed. Return. 843 | } 844 | } 845 | } 846 | } 847 | 848 | // need this for old browsers. Should this be a separate module? 849 | function indexOfElementInArray(element, array) { 850 | if (!array) return -1; 851 | 852 | if (array.indexOf) { 853 | return array.indexOf(element); 854 | } 855 | 856 | var len = array.length, 857 | i; 858 | 859 | for (i = 0; i < len; i += 1) { 860 | if (array[i] === element) { 861 | return i; 862 | } 863 | } 864 | 865 | return -1; 866 | } 867 | 868 | /** 869 | * Internal structure to represent node; 870 | */ 871 | function Node(id) { 872 | this.id = id; 873 | this.links = null; 874 | this.data = null; 875 | } 876 | 877 | function addLinkToNode(node, link) { 878 | if (node.links) { 879 | node.links.push(link); 880 | } else { 881 | node.links = [link]; 882 | } 883 | } 884 | 885 | /** 886 | * Internal structure to represent links; 887 | */ 888 | function Link(fromId, toId, data, id) { 889 | this.fromId = fromId; 890 | this.toId = toId; 891 | this.data = data; 892 | this.id = id; 893 | } 894 | 895 | function hashCode(str) { 896 | var hash = 0, i, chr, len; 897 | if (str.length == 0) return hash; 898 | for (i = 0, len = str.length; i < len; i++) { 899 | chr = str.charCodeAt(i); 900 | hash = ((hash << 5) - hash) + chr; 901 | hash |= 0; // Convert to 32bit integer 902 | } 903 | return hash; 904 | } 905 | 906 | function makeLinkId(fromId, toId) { 907 | return hashCode(fromId.toString() + '👉 ' + toId.toString()); 908 | } 909 | 910 | 911 | /***/ }), 912 | 913 | /***/ "./node_modules/ngraph.modularity/Community.js": 914 | /*!*****************************************************!*\ 915 | !*** ./node_modules/ngraph.modularity/Community.js ***! 916 | \*****************************************************/ 917 | /***/ ((module) => { 918 | 919 | /** 920 | * @param {CommunityStructure|Community} com 921 | * @constructor 922 | */ 923 | function Community(com) { 924 | 925 | /** @type {CommunityStructure} */ 926 | this.structure = com.structure ? com.structure : com; 927 | 928 | /** @type {Map.} */ 929 | this.connectionsWeight = new Map(); 930 | 931 | /** @type {Map.} */ 932 | this.connectionsCount = new Map(); 933 | 934 | /** @type {Set.} */ 935 | this.nodes = new Set; 936 | 937 | this.weightSum = 0; 938 | 939 | 940 | } 941 | 942 | /** 943 | * @public 944 | * @returns {Number} 945 | */ 946 | Community.prototype.size = function() { 947 | return this.nodes.size; 948 | }; 949 | 950 | 951 | /** 952 | * @param {Number} node 953 | */ 954 | Community.prototype.seed = function(node) { 955 | 956 | this.nodes.add(node); 957 | this.weightSum += this.structure.weights[node]; 958 | 959 | }; 960 | 961 | /** 962 | * @param {Number} nodeId 963 | * @returns {boolean} 964 | */ 965 | Community.prototype.add = function(nodeId) { 966 | 967 | this.nodes.add(nodeId); 968 | this.weightSum += this.structure.weights[nodeId]; 969 | return true; 970 | 971 | }; 972 | 973 | /** 974 | * @param {Number} node 975 | * @returns {boolean} 976 | */ 977 | Community.prototype.remove = function(node) { 978 | 979 | var result = this.nodes.delete(node); 980 | 981 | this.weightSum -= this.structure.weights[node]; 982 | if (!this.nodes.size) { 983 | var index = this.structure.communities.indexOf(this); 984 | delete this.structure.communities[index]; 985 | } 986 | 987 | return result; 988 | }; 989 | 990 | module.exports = Community; 991 | 992 | 993 | /***/ }), 994 | 995 | /***/ "./node_modules/ngraph.modularity/CommunityStructure.js": 996 | /*!**************************************************************!*\ 997 | !*** ./node_modules/ngraph.modularity/CommunityStructure.js ***! 998 | \**************************************************************/ 999 | /***/ ((module, __unused_webpack_exports, __webpack_require__) => { 1000 | 1001 | "use strict"; 1002 | 1003 | var Community = __webpack_require__(/*! ./Community */ "./node_modules/ngraph.modularity/Community.js") 1004 | , ModEdge = __webpack_require__(/*! ./ModEdge */ "./node_modules/ngraph.modularity/ModEdge.js") 1005 | ; 1006 | 1007 | /** 1008 | * 1009 | * @param {IGraph} graph 1010 | * @param useWeight 1011 | * @param {CommunityStructure} structure 1012 | * @constructor 1013 | */ 1014 | function CommunityStructure(graph, useWeight) { 1015 | 1016 | //this.graph = graph; 1017 | this.N = graph.getNodesCount(); 1018 | this.graphWeightSum = 0; 1019 | this.structure = this; 1020 | 1021 | /** @type {Map.} */ 1022 | this.invMap = new Map(); 1023 | 1024 | /** @type {Array.< Map. >} */ 1025 | this.nodeConnectionsWeight = new Array(this.N); 1026 | 1027 | /** @type {Array.< Map. >} */ 1028 | this.nodeConnectionsCount = new Array(this.N); 1029 | 1030 | /** @type {Array.} */ 1031 | this.nodeCommunities = new Array(this.N); 1032 | 1033 | /** @type {Map.} */ 1034 | this.map = new Map(); 1035 | 1036 | /** @type {Array.< Array. >} */ 1037 | this.topology = new Array(this.N); 1038 | for (var i = 0; i < this.N; i++) this.topology[i] = []; 1039 | 1040 | /** @type {Array.} */ 1041 | this.communities = []; 1042 | 1043 | /**@type {Array.} */ 1044 | this.weights = new Array(this.N); 1045 | 1046 | var index = 0; 1047 | 1048 | graph.forEachNode(function (node) { 1049 | 1050 | this.map.set(node.id, index); 1051 | this.nodeCommunities[index] = new Community(this); 1052 | this.nodeConnectionsWeight[index] = new Map(); 1053 | this.nodeConnectionsCount[index] = new Map(); 1054 | this.weights[index] = 0; 1055 | this.nodeCommunities[index].seed(index); 1056 | var hidden = new Community(this); 1057 | hidden.nodes.add(index); 1058 | this.invMap.set(index, hidden); 1059 | this.communities.push(this.nodeCommunities[index]); 1060 | index++; 1061 | 1062 | }.bind(this)); 1063 | 1064 | 1065 | graph.forEachLink(function (link) { 1066 | 1067 | var node_index = this.map.get(link.fromId) 1068 | , neighbor_index = this.map.get(link.toId) 1069 | , weight = 1 1070 | ; 1071 | 1072 | if (node_index === neighbor_index) { 1073 | return; 1074 | } 1075 | 1076 | if (useWeight) { 1077 | weight = link.data.weight; 1078 | } 1079 | 1080 | this.setUpLink(node_index, neighbor_index, weight); 1081 | this.setUpLink(neighbor_index, node_index, weight); 1082 | 1083 | 1084 | }.bind(this)); 1085 | 1086 | 1087 | this.graphWeightSum /= 2.0; 1088 | } 1089 | 1090 | 1091 | CommunityStructure.prototype.setUpLink = function (node_index, neighbor_index, weight) { 1092 | 1093 | this.weights[node_index] += weight; 1094 | var /** @type {ModEdge} */ me = new ModEdge(node_index, neighbor_index, weight); 1095 | this.topology[node_index].push(me); 1096 | var /** @type {Community} **/ adjCom = this.nodeCommunities[neighbor_index]; 1097 | this.nodeConnectionsWeight[node_index].set(adjCom, weight); 1098 | this.nodeConnectionsCount[node_index].set(adjCom, 1); 1099 | this.nodeCommunities[node_index].connectionsWeight.set(adjCom, weight); 1100 | this.nodeCommunities[node_index].connectionsCount.set(adjCom, 1); 1101 | this.nodeConnectionsWeight[neighbor_index].set(this.nodeCommunities[node_index], weight); 1102 | this.nodeConnectionsCount[neighbor_index].set(this.nodeCommunities[node_index], 1); 1103 | this.nodeCommunities[neighbor_index].connectionsWeight.set(this.nodeCommunities[node_index], weight); 1104 | this.nodeCommunities[neighbor_index].connectionsCount.set(this.nodeCommunities[node_index], 1); 1105 | this.graphWeightSum += weight; 1106 | 1107 | }; 1108 | 1109 | /** 1110 | * @param {Number} node 1111 | * @param {Community} to 1112 | */ 1113 | CommunityStructure.prototype.addNodeTo = function (node, to) { 1114 | 1115 | to.add(node); 1116 | this.nodeCommunities[node] = to; 1117 | 1118 | var nodeTopology = this.topology[node]; 1119 | for (var topologyKey in nodeTopology) { 1120 | 1121 | //noinspection JSUnfilteredForInLoop 1122 | var /** @type {ModEdge} */ e = nodeTopology[topologyKey]; 1123 | 1124 | var neighbor = e.target; 1125 | 1126 | 1127 | //Remove Node Connection to this community 1128 | var neighEdgesTo = this.nodeConnectionsWeight[neighbor].get(to); 1129 | if (neighEdgesTo === undefined) { 1130 | this.nodeConnectionsWeight[neighbor].set(to, e.weight); 1131 | } else { 1132 | this.nodeConnectionsWeight[neighbor].set(to, neighEdgesTo + e.weight); 1133 | } 1134 | 1135 | var neighCountEdgesTo = this.nodeConnectionsCount[neighbor].get(to); 1136 | if (neighCountEdgesTo === undefined) { 1137 | this.nodeConnectionsCount[neighbor].set(to, 1); 1138 | } else { 1139 | this.nodeConnectionsCount[neighbor].set(to, neighCountEdgesTo + 1); 1140 | } 1141 | 1142 | 1143 | var /** @type {Community} */ adjCom = this.nodeCommunities[neighbor]; 1144 | var wEdgesto = adjCom.connectionsWeight.get(to); 1145 | if (wEdgesto === undefined) { 1146 | adjCom.connectionsWeight.set(to, e.weight); 1147 | } else { 1148 | adjCom.connectionsWeight.set(to, wEdgesto + e.weight); 1149 | } 1150 | 1151 | var cEdgesto = adjCom.connectionsCount.get(to); 1152 | if (cEdgesto === undefined) { 1153 | adjCom.connectionsCount.set(to, 1); 1154 | } else { 1155 | adjCom.connectionsCount.set(to, cEdgesto + 1); 1156 | } 1157 | 1158 | var nodeEdgesTo = this.nodeConnectionsWeight[node].get(adjCom); 1159 | if (nodeEdgesTo === undefined) { 1160 | this.nodeConnectionsWeight[node].set(adjCom, e.weight); 1161 | } else { 1162 | this.nodeConnectionsWeight[node].set(adjCom, nodeEdgesTo + e.weight); 1163 | } 1164 | 1165 | var nodeCountEdgesTo = this.nodeConnectionsCount[node].get(adjCom); 1166 | if (nodeCountEdgesTo === undefined) { 1167 | this.nodeConnectionsCount[node].set(adjCom, 1); 1168 | } else { 1169 | this.nodeConnectionsCount[node].set(adjCom, nodeCountEdgesTo + 1); 1170 | } 1171 | 1172 | if (to != adjCom) { 1173 | var comEdgesto = to.connectionsWeight.get(adjCom); 1174 | if (comEdgesto === undefined) { 1175 | to.connectionsWeight.set(adjCom, e.weight); 1176 | } else { 1177 | to.connectionsWeight.set(adjCom, comEdgesto + e.weight); 1178 | } 1179 | 1180 | var comCountEdgesto = to.connectionsCount.get(adjCom); 1181 | if (comCountEdgesto === undefined) { 1182 | to.connectionsCount.set(adjCom, 1); 1183 | } else { 1184 | to.connectionsCount.set(adjCom, comCountEdgesto + 1); 1185 | } 1186 | 1187 | } 1188 | } 1189 | }; 1190 | 1191 | /** 1192 | * @param {Number} node 1193 | * @param {Community} source 1194 | */ 1195 | CommunityStructure.prototype.removeNodeFrom = function (node, source) { 1196 | 1197 | var community = this.nodeCommunities[node]; 1198 | 1199 | 1200 | var nodeTopology = this.topology[node]; 1201 | for (var topologyKey in nodeTopology) { 1202 | 1203 | //noinspection JSUnfilteredForInLoop 1204 | var /** @type {ModEdge} */ e = nodeTopology[topologyKey]; 1205 | 1206 | var neighbor = e.target; 1207 | 1208 | //Remove Node Connection to this community 1209 | var edgesTo = this.nodeConnectionsWeight[neighbor].get(community); 1210 | var countEdgesTo = this.nodeConnectionsCount[neighbor].get(community); 1211 | 1212 | if ((countEdgesTo - 1) == 0) { 1213 | this.nodeConnectionsWeight[neighbor].delete(community); 1214 | this.nodeConnectionsCount[neighbor].delete(community); 1215 | } else { 1216 | this.nodeConnectionsWeight[neighbor].set(community, edgesTo - e.weight); 1217 | this.nodeConnectionsCount[neighbor].set(community, countEdgesTo - 1); 1218 | } 1219 | 1220 | 1221 | //Remove Adjacency Community's connection to this community 1222 | var adjCom = this.nodeCommunities[neighbor]; 1223 | var oEdgesto = adjCom.connectionsWeight.get(community); 1224 | var oCountEdgesto = adjCom.connectionsCount.get(community); 1225 | if ((oCountEdgesto - 1) == 0) { 1226 | adjCom.connectionsWeight.delete(community); 1227 | adjCom.connectionsCount.delete(community); 1228 | } else { 1229 | adjCom.connectionsWeight.set(community, oEdgesto - e.weight); 1230 | adjCom.connectionsCount.set(community, oCountEdgesto - 1); 1231 | } 1232 | 1233 | if (node == neighbor) { 1234 | continue; 1235 | } 1236 | 1237 | if (adjCom != community) { 1238 | 1239 | var comEdgesto = community.connectionsWeight.get(adjCom); 1240 | var comCountEdgesto = community.connectionsCount.get(adjCom); 1241 | 1242 | if (comCountEdgesto - 1 == 0) { 1243 | community.connectionsWeight.delete(adjCom); 1244 | community.connectionsCount.delete(adjCom); 1245 | } else { 1246 | community.connectionsWeight.set(adjCom, comEdgesto - e.weight); 1247 | community.connectionsCount.set(adjCom, comCountEdgesto - 1); 1248 | } 1249 | 1250 | } 1251 | 1252 | var nodeEdgesTo = this.nodeConnectionsWeight[node].get(adjCom); 1253 | var nodeCountEdgesTo = this.nodeConnectionsCount[node].get(adjCom); 1254 | 1255 | if ((nodeCountEdgesTo - 1) == 0) { 1256 | this.nodeConnectionsWeight[node].delete(adjCom); 1257 | this.nodeConnectionsCount[node].delete(adjCom); 1258 | } else { 1259 | this.nodeConnectionsWeight[node].set(adjCom, nodeEdgesTo - e.weight); 1260 | this.nodeConnectionsCount[node].set(adjCom, nodeCountEdgesTo - 1); 1261 | } 1262 | 1263 | } 1264 | 1265 | source.remove(node); 1266 | }; 1267 | 1268 | /** 1269 | * @param {Number} node 1270 | * @param {Community} to 1271 | */ 1272 | CommunityStructure.prototype.moveNodeTo = function (node, to) { 1273 | 1274 | var source = this.nodeCommunities[node]; 1275 | this.removeNodeFrom(node, source); 1276 | this.addNodeTo(node, to); 1277 | 1278 | }; 1279 | 1280 | 1281 | CommunityStructure.prototype.zoomOut = function () { 1282 | var realCommunities = this.communities.reduce(function (arr, value) { 1283 | arr.push(value); 1284 | return arr; 1285 | }, []); 1286 | var M = realCommunities.length; // size 1287 | var /** @type Array.< Array. > */ newTopology = new Array(M); 1288 | var index = 0; 1289 | 1290 | this.nodeCommunities = new Array(M); 1291 | this.nodeConnectionsWeight = new Array(M); 1292 | this.nodeConnectionsCount = new Array(M); 1293 | 1294 | var /** @type Map.*/ newInvMap = new Map(); 1295 | realCommunities.forEach(function (com) { 1296 | 1297 | var weightSum = 0; 1298 | this.nodeConnectionsWeight[index] = new Map(); 1299 | this.nodeConnectionsCount[index] = new Map(); 1300 | newTopology[index] = []; 1301 | this.nodeCommunities[index] = new Community(com); 1302 | //var iter = com.connectionsWeight.keySet(); 1303 | 1304 | var hidden = new Community(this.structure); 1305 | 1306 | com.nodes.forEach(function (nodeInt) { 1307 | 1308 | var oldHidden = this.invMap.get(nodeInt); 1309 | oldHidden.nodes.forEach(hidden.nodes.add.bind(hidden.nodes)); 1310 | 1311 | }, this); 1312 | 1313 | newInvMap.set(index, hidden); 1314 | com.connectionsWeight.forEach(function (weight, adjCom) { 1315 | 1316 | var target = realCommunities.indexOf(adjCom); 1317 | if (!~target) return; 1318 | if (target == index) { 1319 | weightSum += 2. * weight; 1320 | } else { 1321 | weightSum += weight; 1322 | } 1323 | var e = new ModEdge(index, target, weight); 1324 | newTopology[index].push(e); 1325 | 1326 | }, this); 1327 | 1328 | this.weights[index] = weightSum; 1329 | this.nodeCommunities[index].seed(index); 1330 | 1331 | index++; 1332 | 1333 | }.bind(this)); 1334 | 1335 | this.communities = []; 1336 | 1337 | for (var i = 0; i < M; i++) { 1338 | var com = this.nodeCommunities[i]; 1339 | this.communities.push(com); 1340 | for (var ei in newTopology[i]) { 1341 | //noinspection JSUnfilteredForInLoop 1342 | var e = newTopology[i][ei]; 1343 | this.nodeConnectionsWeight[i].set(this.nodeCommunities[e.target], e.weight); 1344 | this.nodeConnectionsCount[i].set(this.nodeCommunities[e.target], 1); 1345 | com.connectionsWeight.set(this.nodeCommunities[e.target], e.weight); 1346 | com.connectionsCount.set(this.nodeCommunities[e.target], 1); 1347 | } 1348 | 1349 | } 1350 | 1351 | this.N = M; 1352 | this.topology = newTopology; 1353 | this.invMap = newInvMap; 1354 | 1355 | }; 1356 | 1357 | module.exports = CommunityStructure; 1358 | 1359 | /***/ }), 1360 | 1361 | /***/ "./node_modules/ngraph.modularity/ModEdge.js": 1362 | /*!***************************************************!*\ 1363 | !*** ./node_modules/ngraph.modularity/ModEdge.js ***! 1364 | \***************************************************/ 1365 | /***/ ((module) => { 1366 | 1367 | /** 1368 | * 1369 | * @param s 1370 | * @param t 1371 | * @param w 1372 | * @constructor 1373 | */ 1374 | function ModEdge(s, t, w) { 1375 | /** @type {Number} */ 1376 | this.source = s; 1377 | /** @type {Number} */ 1378 | this.target = t; 1379 | /** @type {Number} */ 1380 | this.weight = w; 1381 | } 1382 | 1383 | module.exports = ModEdge; 1384 | 1385 | 1386 | /***/ }), 1387 | 1388 | /***/ "./node_modules/ngraph.modularity/Modularity.js": 1389 | /*!******************************************************!*\ 1390 | !*** ./node_modules/ngraph.modularity/Modularity.js ***! 1391 | \******************************************************/ 1392 | /***/ ((module, __unused_webpack_exports, __webpack_require__) => { 1393 | 1394 | /* 1395 | Copyright 2008-2011 Gephi 1396 | Authors : Patick J. McSweeney , Sebastien Heymann 1397 | Website : http://www.gephi.org 1398 | 1399 | This file is part of Gephi. 1400 | 1401 | DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 1402 | 1403 | Copyright 2011 Gephi Consortium. All rights reserved. 1404 | 1405 | The contents of this file are subject to the terms of either the GNU 1406 | General Public License Version 3 only ("GPL") or the Common 1407 | Development and Distribution License("CDDL") (collectively, the 1408 | "License"). You may not use this file except in compliance with the 1409 | License. You can obtain a copy of the License at 1410 | http://gephi.org/about/legal/license-notice/ 1411 | or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the 1412 | specific language governing permissions and limitations under the 1413 | License. When distributing the software, include this License Header 1414 | Notice in each file and include the License files at 1415 | /cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the 1416 | License Header, with the fields enclosed by brackets [] replaced by 1417 | your own identifying information: 1418 | "Portions Copyrighted [year] [name of copyright owner]" 1419 | 1420 | If you wish your version of this file to be governed by only the CDDL 1421 | or only the GPL Version 3, indicate your decision by adding 1422 | "[Contributor] elects to include this software in this distribution 1423 | under the [CDDL or GPL Version 3] license." If you do not indicate a 1424 | single choice of license, a recipient has the option to distribute 1425 | your version of this file under either the CDDL, the GPL Version 3 or 1426 | to extend the choice of license to its licensees as provided above. 1427 | However, if you add GPL Version 3 code and therefore, elected the GPL 1428 | Version 3 license, then the option applies only if the new code is 1429 | made subject to such option by the copyright holder. 1430 | 1431 | Contributor(s): Thomas Aynaud 1432 | 1433 | Portions Copyrighted 2011 Gephi Consortium. 1434 | */ 1435 | var CommunityStructure = __webpack_require__(/*! ./CommunityStructure */ "./node_modules/ngraph.modularity/CommunityStructure.js") 1436 | , centrality = __webpack_require__(/*! ngraph.centrality */ "./node_modules/ngraph.centrality/index.js") 1437 | ; 1438 | 1439 | /** 1440 | * @constructor 1441 | */ 1442 | function Modularity (resolution, useWeight) { 1443 | this.isRandomized = false; 1444 | this.useWeight = useWeight; 1445 | this.resolution = resolution || 1.; 1446 | /** 1447 | * @type {CommunityStructure} 1448 | */ 1449 | this.structure = null; 1450 | } 1451 | 1452 | /** 1453 | * @param {IGraph} graph 1454 | */ 1455 | Modularity.prototype.execute = function (graph/*, AttributeModel attributeModel*/) { 1456 | 1457 | 1458 | this.structure = new CommunityStructure(graph, this.useWeight); 1459 | 1460 | var comStructure = new Array(graph.getNodesCount()); 1461 | 1462 | var computedModularityMetrics = this.computeModularity( 1463 | graph 1464 | , this.structure 1465 | , comStructure 1466 | , this.resolution 1467 | , this.isRandomized 1468 | , this.useWeight 1469 | ); 1470 | 1471 | var result = {}; 1472 | this.structure.map.forEach(function (i, node) { 1473 | result[node] = comStructure[i]; 1474 | }); 1475 | 1476 | return result; 1477 | 1478 | }; 1479 | 1480 | 1481 | /** 1482 | * 1483 | * @param {IGraph} graph 1484 | * @param {CommunityStructure} theStructure 1485 | * @param {Array.} comStructure 1486 | * @param {Number} currentResolution 1487 | * @param {Boolean} randomized 1488 | * @param {Boolean} weighted 1489 | * @returns {Object.} 1490 | */ 1491 | Modularity.prototype.computeModularity = function(graph, theStructure, comStructure, currentResolution, randomized, weighted) { 1492 | 1493 | 1494 | function getRandomInt(min, max) { 1495 | return Math.floor(Math.random() * (max - min)) + min; 1496 | } 1497 | 1498 | var totalWeight = theStructure.graphWeightSum; 1499 | var nodeDegrees = theStructure.weights.slice(); 1500 | 1501 | 1502 | var /** @type {Object.} */ results = Object.create(null); 1503 | 1504 | 1505 | var someChange = true; 1506 | 1507 | while (someChange) { 1508 | someChange = false; 1509 | var localChange = true; 1510 | while (localChange) { 1511 | localChange = false; 1512 | var start = 0; 1513 | if (randomized) { 1514 | //start = Math.abs(rand.nextInt()) % theStructure.N; 1515 | start = getRandomInt(0,theStructure.N); 1516 | } 1517 | var step = 0; 1518 | for (var i = start; step < theStructure.N; i = (i + 1) % theStructure.N) { 1519 | step++; 1520 | var bestCommunity = this.updateBestCommunity(theStructure, i, currentResolution); 1521 | if ((theStructure.nodeCommunities[i] != bestCommunity) && (bestCommunity != null)) { 1522 | theStructure.moveNodeTo(i, bestCommunity); 1523 | localChange = true; 1524 | } 1525 | 1526 | } 1527 | 1528 | someChange = localChange || someChange; 1529 | 1530 | } 1531 | 1532 | if (someChange) { 1533 | theStructure.zoomOut(); 1534 | } 1535 | } 1536 | 1537 | this.fillComStructure(graph, theStructure, comStructure); 1538 | 1539 | /* 1540 | //TODO: uncomment when finalQ will be implemented 1541 | var degreeCount = this.fillDegreeCount(graph, theStructure, comStructure, nodeDegrees, weighted); 1542 | 1543 | 1544 | var computedModularity = this._finalQ(comStructure, degreeCount, graph, theStructure, totalWeight, 1., weighted); 1545 | var computedModularityResolution = this._finalQ(comStructure, degreeCount, graph, theStructure, totalWeight, currentResolution, weighted); 1546 | 1547 | results["modularity"] = computedModularity; 1548 | results["modularityResolution"] = computedModularityResolution; 1549 | */ 1550 | 1551 | return results; 1552 | }; 1553 | 1554 | 1555 | /** 1556 | * @param {CommunityStructure} theStructure 1557 | * @param {Number} i 1558 | * @param {Number} currentResolution 1559 | * @returns {Community} 1560 | */ 1561 | Modularity.prototype.updateBestCommunity = function(theStructure, i, currentResolution) { 1562 | var best = this.q(i, theStructure.nodeCommunities[i], theStructure, currentResolution); 1563 | var bestCommunity = theStructure.nodeCommunities[i]; 1564 | //var /*Set*/ iter = theStructure.nodeConnectionsWeight[i].keySet(); 1565 | theStructure.nodeConnectionsWeight[i].forEach(function (_$$val, com) { 1566 | 1567 | var qValue = this.q(i, com, theStructure, currentResolution); 1568 | if (qValue > best) { 1569 | best = qValue; 1570 | bestCommunity = com; 1571 | } 1572 | 1573 | }, this); 1574 | return bestCommunity; 1575 | }; 1576 | 1577 | /** 1578 | * 1579 | * @param {IGraph} graph 1580 | * @param {CommunityStructure} theStructure 1581 | * @param {Array.} comStructure 1582 | * @returns {Array.} 1583 | */ 1584 | Modularity.prototype.fillComStructure = function(graph, theStructure, comStructure) { 1585 | 1586 | var count = 0; 1587 | 1588 | theStructure.communities.forEach(function (com) { 1589 | 1590 | com.nodes.forEach(function (node) { 1591 | 1592 | var hidden = theStructure.invMap.get(node); 1593 | hidden.nodes.forEach( function (nodeInt){ 1594 | comStructure[nodeInt] = count; 1595 | }); 1596 | 1597 | }); 1598 | count++; 1599 | 1600 | }); 1601 | 1602 | 1603 | return comStructure; 1604 | }; 1605 | 1606 | /** 1607 | * @param {IGraph} graph 1608 | * @param {CommunityStructure} theStructure 1609 | * @param {Array.} comStructure 1610 | * @param {Array.} nodeDegrees 1611 | * @param {Boolean} weighted 1612 | * @returns {Array.} 1613 | */ 1614 | Modularity.prototype.fillDegreeCount = function(graph, theStructure, comStructure, nodeDegrees, weighted) { 1615 | 1616 | var degreeCount = new Array(theStructure.communities.length); 1617 | var degreeCentrality = centrality.degree(graph); 1618 | 1619 | graph.forEachNode(function(node){ 1620 | 1621 | var index = theStructure.map.get(node); 1622 | if (weighted) { 1623 | degreeCount[comStructure[index]] += nodeDegrees[index]; 1624 | } else { 1625 | degreeCount[comStructure[index]] += degreeCentrality[node.id]; 1626 | } 1627 | 1628 | }); 1629 | return degreeCount; 1630 | 1631 | }; 1632 | 1633 | 1634 | /** 1635 | * 1636 | * @param {Array.} struct 1637 | * @param {Array.} degrees 1638 | * @param {IGraph} graph 1639 | * @param {CommunityStructure} theStructure 1640 | * @param {Number} totalWeight 1641 | * @param {Number} usedResolution 1642 | * @param {Boolean} weighted 1643 | * @returns {Number} 1644 | */ 1645 | Modularity.prototype._finalQ = function(struct, degrees, graph, theStructure, totalWeight, usedResolution, weighted) { 1646 | 1647 | //TODO: rewrite for wighted version of algorithm 1648 | throw new Error("not implemented properly"); 1649 | var res = 0; 1650 | var internal = new Array(degrees.length); 1651 | 1652 | graph.forEachNode(function(n){ 1653 | var n_index = theStructure.map.get(n); 1654 | 1655 | graph.forEachLinkedNode(n.id, function(neighbor){ 1656 | if (n == neighbor) { 1657 | return; 1658 | } 1659 | var neigh_index = theStructure.map.get(neighbor); 1660 | if (struct[neigh_index] == struct[n_index]) { 1661 | if (weighted) { 1662 | //throw new Error("weighted aren't implemented"); 1663 | //internal[struct[neigh_index]] += graph.getEdge(n, neighbor).getWeight(); 1664 | } else { 1665 | internal[struct[neigh_index]]++; 1666 | } 1667 | } 1668 | }.bind(this), false); 1669 | 1670 | }.bind(this)); 1671 | 1672 | for (var i = 0; i < degrees.length; i++) { 1673 | internal[i] /= 2.0; 1674 | res += usedResolution * (internal[i] / totalWeight) - Math.pow(degrees[i] / (2 * totalWeight), 2);//HERE 1675 | } 1676 | return res; 1677 | }; 1678 | 1679 | 1680 | 1681 | /** 1682 | * 1683 | * @param {Number} nodeId 1684 | * @param {Community} community 1685 | * @param {CommunityStructure} theStructure 1686 | * @param {Number} currentResolution 1687 | * @returns {Number} 1688 | */ 1689 | Modularity.prototype.q = function(nodeId, community, theStructure, currentResolution) { 1690 | 1691 | var edgesToFloat = theStructure.nodeConnectionsWeight[nodeId].get(community); 1692 | var edgesTo = 0; 1693 | if (edgesToFloat != null) { 1694 | edgesTo = edgesToFloat; 1695 | } 1696 | var weightSum = community.weightSum; 1697 | var nodeWeight = theStructure.weights[nodeId]; 1698 | var qValue = currentResolution * edgesTo - (nodeWeight * weightSum) / (2.0 * theStructure.graphWeightSum); 1699 | if ((theStructure.nodeCommunities[nodeId] == community) && (theStructure.nodeCommunities[nodeId].size() > 1)) { 1700 | qValue = currentResolution * edgesTo - (nodeWeight * (weightSum - nodeWeight)) / (2.0 * theStructure.graphWeightSum); 1701 | } 1702 | if ((theStructure.nodeCommunities[nodeId] == community) && (theStructure.nodeCommunities[nodeId].size() == 1)) { 1703 | qValue = 0.; 1704 | } 1705 | return qValue; 1706 | 1707 | }; 1708 | 1709 | module.exports = Modularity; 1710 | 1711 | /***/ }), 1712 | 1713 | /***/ "./src/main.js": 1714 | /*!*********************!*\ 1715 | !*** ./src/main.js ***! 1716 | \*********************/ 1717 | /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { 1718 | 1719 | "use strict"; 1720 | __webpack_require__.r(__webpack_exports__); 1721 | /* harmony import */ var ngraph_modularity_Modularity__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ngraph.modularity/Modularity */ "./node_modules/ngraph.modularity/Modularity.js"); 1722 | /* harmony import */ var ngraph_modularity_Modularity__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(ngraph_modularity_Modularity__WEBPACK_IMPORTED_MODULE_0__); 1723 | /* harmony import */ var echarts_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! echarts/core */ "echarts/core"); 1724 | /* harmony import */ var echarts_core__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(echarts_core__WEBPACK_IMPORTED_MODULE_1__); 1725 | /* harmony import */ var ngraph_graph__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ngraph.graph */ "./node_modules/ngraph.graph/index.js"); 1726 | /* harmony import */ var ngraph_graph__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(ngraph_graph__WEBPACK_IMPORTED_MODULE_2__); 1727 | 1728 | 1729 | 1730 | 1731 | function createModularityVisual(chartType) { 1732 | return function (ecModel, api) { 1733 | var paletteScope = {}; 1734 | ecModel.eachSeriesByType(chartType, function (seriesModel) { 1735 | var modularityOpt = seriesModel.get('modularity'); 1736 | if (modularityOpt) { 1737 | var graph = seriesModel.getGraph(); 1738 | var idIndexMap = {}; 1739 | var ng = ngraph_graph__WEBPACK_IMPORTED_MODULE_2___default()(); 1740 | graph.data.each(function (idx) { 1741 | var node = graph.getNodeByIndex(idx); 1742 | idIndexMap[node.id] = idx; 1743 | ng.addNode(node.id); 1744 | return node.id; 1745 | }); 1746 | graph.edgeData.each('value', function (val, idx) { 1747 | var edge = graph.getEdgeByIndex(idx); 1748 | ng.addLink(edge.node1.id, edge.node2.id); 1749 | return { 1750 | source: edge.node1.id, 1751 | target: edge.node2.id, 1752 | value: val 1753 | }; 1754 | }); 1755 | 1756 | var modularity = new (ngraph_modularity_Modularity__WEBPACK_IMPORTED_MODULE_0___default())(seriesModel.get('modularity.resolution') || 1); 1757 | var result = modularity.execute(ng); 1758 | 1759 | var communities = {}; 1760 | for (var id in result) { 1761 | var comm = result[id]; 1762 | communities[comm] = communities[comm] || 0; 1763 | communities[comm]++; 1764 | } 1765 | var communitiesList = Object.keys(communities); 1766 | if (seriesModel.get('modularity.sort')) { 1767 | communitiesList.sort(function (a, b) { 1768 | return b - a; 1769 | }); 1770 | } 1771 | var colors = {}; 1772 | communitiesList.forEach(function (comm) { 1773 | colors[comm] = seriesModel.getColorFromPalette(comm, paletteScope); 1774 | }); 1775 | 1776 | for (var id in result) { 1777 | var comm = result[id]; 1778 | var style = graph.data.ensureUniqueItemVisual(idIndexMap[id], 'style'); 1779 | style.fill = colors[comm]; 1780 | } 1781 | 1782 | graph.edgeData.each(function (idx) { 1783 | var itemModel = graph.edgeData.getItemModel(idx); 1784 | var edge = graph.getEdgeByIndex(idx); 1785 | var color = itemModel.get(['lineStyle', 'normal', 'color']) 1786 | || itemModel.get(['lineStyle', 'color']); 1787 | 1788 | switch (color) { 1789 | case 'source': 1790 | color = edge.node1.getVisual('style').fill; 1791 | break; 1792 | case 'target': 1793 | color = edge.node2.getVisual('style').fill; 1794 | break; 1795 | } 1796 | 1797 | if (color != null) { 1798 | graph.edgeData.ensureUniqueItemVisual(idx, 'style').stroke = color; 1799 | } 1800 | }); 1801 | } 1802 | }); 1803 | }; 1804 | } 1805 | 1806 | echarts_core__WEBPACK_IMPORTED_MODULE_1__.registerVisual(echarts_core__WEBPACK_IMPORTED_MODULE_1__.PRIORITY.VISUAL.CHART + 1, createModularityVisual('graph')); 1807 | echarts_core__WEBPACK_IMPORTED_MODULE_1__.registerVisual(echarts_core__WEBPACK_IMPORTED_MODULE_1__.PRIORITY.VISUAL.CHART + 1, createModularityVisual('graphGL')); 1808 | 1809 | /***/ }), 1810 | 1811 | /***/ "echarts/core": 1812 | /*!**************************!*\ 1813 | !*** external "echarts" ***! 1814 | \**************************/ 1815 | /***/ ((module) => { 1816 | 1817 | "use strict"; 1818 | module.exports = __WEBPACK_EXTERNAL_MODULE_echarts_core__; 1819 | 1820 | /***/ }) 1821 | 1822 | /******/ }); 1823 | /************************************************************************/ 1824 | /******/ // The module cache 1825 | /******/ var __webpack_module_cache__ = {}; 1826 | /******/ 1827 | /******/ // The require function 1828 | /******/ function __webpack_require__(moduleId) { 1829 | /******/ // Check if module is in cache 1830 | /******/ var cachedModule = __webpack_module_cache__[moduleId]; 1831 | /******/ if (cachedModule !== undefined) { 1832 | /******/ return cachedModule.exports; 1833 | /******/ } 1834 | /******/ // Create a new module (and put it into the cache) 1835 | /******/ var module = __webpack_module_cache__[moduleId] = { 1836 | /******/ // no module.id needed 1837 | /******/ // no module.loaded needed 1838 | /******/ exports: {} 1839 | /******/ }; 1840 | /******/ 1841 | /******/ // Execute the module function 1842 | /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); 1843 | /******/ 1844 | /******/ // Return the exports of the module 1845 | /******/ return module.exports; 1846 | /******/ } 1847 | /******/ 1848 | /************************************************************************/ 1849 | /******/ /* webpack/runtime/compat get default export */ 1850 | /******/ (() => { 1851 | /******/ // getDefaultExport function for compatibility with non-harmony modules 1852 | /******/ __webpack_require__.n = (module) => { 1853 | /******/ var getter = module && module.__esModule ? 1854 | /******/ () => (module['default']) : 1855 | /******/ () => (module); 1856 | /******/ __webpack_require__.d(getter, { a: getter }); 1857 | /******/ return getter; 1858 | /******/ }; 1859 | /******/ })(); 1860 | /******/ 1861 | /******/ /* webpack/runtime/define property getters */ 1862 | /******/ (() => { 1863 | /******/ // define getter functions for harmony exports 1864 | /******/ __webpack_require__.d = (exports, definition) => { 1865 | /******/ for(var key in definition) { 1866 | /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { 1867 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); 1868 | /******/ } 1869 | /******/ } 1870 | /******/ }; 1871 | /******/ })(); 1872 | /******/ 1873 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ 1874 | /******/ (() => { 1875 | /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) 1876 | /******/ })(); 1877 | /******/ 1878 | /******/ /* webpack/runtime/make namespace object */ 1879 | /******/ (() => { 1880 | /******/ // define __esModule on exports 1881 | /******/ __webpack_require__.r = (exports) => { 1882 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { 1883 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); 1884 | /******/ } 1885 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); 1886 | /******/ }; 1887 | /******/ })(); 1888 | /******/ 1889 | /************************************************************************/ 1890 | /******/ 1891 | /******/ // startup 1892 | /******/ // Load entry module and return exports 1893 | /******/ // This entry module used 'module' so it can't be inlined 1894 | /******/ var __webpack_exports__ = __webpack_require__("./index.js"); 1895 | /******/ 1896 | /******/ return __webpack_exports__; 1897 | /******/ })() 1898 | ; 1899 | }); 1900 | //# sourceMappingURL=echarts-graph-modularity.js.map -------------------------------------------------------------------------------- /dist/echarts-graph-modularity.min.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"echarts-graph-modularity.min.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,EAAQG,QAAQ,YACR,mBAAXC,QAAyBA,OAAOC,IAC9CD,OAAO,CAAC,WAAYJ,GACM,iBAAZC,QACdA,QAAQ,4BAA8BD,EAAQG,QAAQ,YAEtDJ,EAAK,4BAA8BC,EAAQD,EAAc,SAR3D,CASGO,MAAM,SAASC,GAClB,M,0BCVAL,EAAOD,QAAU,EAA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AHAgS,EAAoBF,GAAU7R,EAAQA,EAAOD,QAAS6R,GAG/C5R,EAAOD,Q,OCpBf6R,EAAoBI,EAAKhS,IACxB,IAAIiS,EAASjS,GAAUA,EAAOkS,WAC7B,IAAOlS,EAAiB,QACxB,IAAM,EAEP,OADA4R,EAAoBO,EAAEF,EAAQ,CAAEjB,EAAGiB,IAC5BA,GCLRL,EAAoBO,EAAI,CAACpS,EAASqS,KACjC,IAAI,IAAI1P,KAAO0P,EACXR,EAAoBS,EAAED,EAAY1P,KAASkP,EAAoBS,EAAEtS,EAAS2C,IAC5E5B,OAAOwR,eAAevS,EAAS2C,EAAK,CAAE6P,YAAY,EAAM3H,IAAKwH,EAAW1P,MCJ3EkP,EAAoBS,EAAI,CAACG,EAAKC,IAAU3R,OAAO4D,UAAUhB,eAAeiB,KAAK6N,EAAKC,GCClFb,EAAoBc,EAAK3S,IACH,oBAAX4S,QAA0BA,OAAOC,aAC1C9R,OAAOwR,eAAevS,EAAS4S,OAAOC,YAAa,CAAEhG,MAAO,WAE7D9L,OAAOwR,eAAevS,EAAS,aAAc,CAAE6M,OAAO,KCF7BgF,EAAoB,K","sources":["webpack://echarts-graph-modularity/webpack/universalModuleDefinition","webpack://echarts-graph-modularity/./index.js","webpack://echarts-graph-modularity/./node_modules/ngraph.centrality/index.js","webpack://echarts-graph-modularity/./node_modules/ngraph.centrality/src/betweenness.js","webpack://echarts-graph-modularity/./node_modules/ngraph.centrality/src/degree.js","webpack://echarts-graph-modularity/./node_modules/ngraph.events/index.js","webpack://echarts-graph-modularity/./node_modules/ngraph.graph/index.js","webpack://echarts-graph-modularity/./node_modules/ngraph.modularity/Community.js","webpack://echarts-graph-modularity/./node_modules/ngraph.modularity/CommunityStructure.js","webpack://echarts-graph-modularity/./node_modules/ngraph.modularity/ModEdge.js","webpack://echarts-graph-modularity/./node_modules/ngraph.modularity/Modularity.js","webpack://echarts-graph-modularity/./src/main.js","webpack://echarts-graph-modularity/external umd \"echarts\"","webpack://echarts-graph-modularity/webpack/bootstrap","webpack://echarts-graph-modularity/webpack/runtime/compat get default export","webpack://echarts-graph-modularity/webpack/runtime/define property getters","webpack://echarts-graph-modularity/webpack/runtime/hasOwnProperty shorthand","webpack://echarts-graph-modularity/webpack/runtime/make namespace object","webpack://echarts-graph-modularity/webpack/startup"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"echarts\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"echarts\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"echarts-graph-modularity\"] = factory(require(\"echarts\"));\n\telse\n\t\troot[\"echarts-graph-modularity\"] = factory(root[\"echarts\"]);\n})(self, function(__WEBPACK_EXTERNAL_MODULE__550__) {\nreturn ","module.exports = require('./src/main');","module.exports.degree = require('./src/degree.js');\nmodule.exports.betweenness = require('./src/betweenness.js');\n","module.exports = betweennes;\n\n/**\n * I'm using http://www.inf.uni-konstanz.de/algo/publications/b-vspbc-08.pdf\n * as a reference for this implementation\n */\nfunction betweennes(graph, oriented) {\n var Q = [],\n S = []; // Queue and Stack\n // list of predcessors on shorteest paths from source\n var pred = Object.create(null);\n // distance from source\n var dist = Object.create(null);\n // number of shortest paths from source to key\n var sigma = Object.create(null);\n // dependency of source on key\n var delta = Object.create(null);\n\n var currentNode;\n var centrality = Object.create(null);\n\n graph.forEachNode(setCentralityToZero);\n graph.forEachNode(calculateCentrality);\n\n if (!oriented) {\n // The centrality scores need to be divided by two if the graph is not oriented,\n // since all shortest paths are considered twice\n Object.keys(centrality).forEach(divideByTwo);\n }\n\n return centrality;\n\n function divideByTwo(key) {\n centrality[key] /= 2;\n }\n\n function setCentralityToZero(node) {\n centrality[node.id] = 0;\n }\n\n function calculateCentrality(node) {\n currentNode = node.id;\n singleSourceShortestPath(currentNode);\n accumulate();\n }\n\n function accumulate() {\n graph.forEachNode(setDeltaToZero);\n while (S.length) {\n var w = S.pop();\n var coeff = (1 + delta[w])/sigma[w];\n var predcessors = pred[w];\n for (var idx = 0; idx < predcessors.length; ++idx) {\n var v = predcessors[idx];\n delta[v] += sigma[v] * coeff;\n }\n if (w !== currentNode) {\n centrality[w] += delta[w];\n }\n }\n }\n\n function setDeltaToZero(node) {\n delta[node.id] = 0;\n }\n\n function singleSourceShortestPath(source) {\n graph.forEachNode(initNode);\n dist[source] = 0;\n sigma[source] = 1;\n Q.push(source);\n\n while (Q.length) {\n var v = Q.shift();\n S.push(v);\n graph.forEachLinkedNode(v, toId, oriented);\n }\n\n function toId(otherNode) {\n // NOTE: This code will also consider multi-edges, which are often\n // ignored by popular software (Gephi/NetworkX). Depending on your use\n // case this may not be desired and deduping needs to be performed. To\n // save memory I'm not deduping here...\n processNode(otherNode.id);\n }\n\n function initNode(node) {\n var nodeId = node.id;\n pred[nodeId] = []; // empty list\n dist[nodeId] = -1;\n sigma[nodeId] = 0;\n }\n\n function processNode(w) {\n // path discovery\n if (dist[w] === -1) {\n // Node w is found for the first time\n dist[w] = dist[v] + 1;\n Q.push(w);\n }\n // path counting\n if (dist[w] === dist[v] + 1) {\n // edge (v, w) on a shortest path\n sigma[w] += sigma[v];\n pred[w].push(v);\n }\n }\n }\n}\n","module.exports = degree;\n\n/**\n * Calculates graph nodes degree centrality (in/out or both).\n *\n * @see http://en.wikipedia.org/wiki/Centrality#Degree_centrality\n *\n * @param {ngraph.graph} graph object for which we are calculating centrality.\n * @param {string} [kind=both] What kind of degree centrality needs to be calculated:\n * 'in' - calculate in-degree centrality\n * 'out' - calculate out-degree centrality\n * 'inout' - (default) generic degree centrality is calculated\n */\nfunction degree(graph, kind) {\n var getNodeDegree;\n var result = Object.create(null);\n\n kind = (kind || 'both').toLowerCase();\n if (kind === 'both' || kind === 'inout') {\n getNodeDegree = inoutDegreeCalculator;\n } else if (kind === 'in') {\n getNodeDegree = inDegreeCalculator;\n } else if (kind === 'out') {\n getNodeDegree = outDegreeCalculator;\n } else {\n throw new Error('Expected centrality degree kind is: in, out or both');\n }\n\n graph.forEachNode(calculateNodeDegree);\n\n return result;\n\n function calculateNodeDegree(node) {\n var links = graph.getLinks(node.id);\n result[node.id] = getNodeDegree(links, node.id);\n }\n}\n\nfunction inDegreeCalculator(links, nodeId) {\n var total = 0;\n if (!links) return total;\n\n for (var i = 0; i < links.length; i += 1) {\n total += (links[i].toId === nodeId) ? 1 : 0;\n }\n return total;\n}\n\nfunction outDegreeCalculator(links, nodeId) {\n var total = 0;\n if (!links) return total;\n\n for (var i = 0; i < links.length; i += 1) {\n total += (links[i].fromId === nodeId) ? 1 : 0;\n }\n return total;\n}\n\nfunction inoutDegreeCalculator(links) {\n if (!links) return 0;\n\n return links.length;\n}\n","module.exports = function(subject) {\n validateSubject(subject);\n\n var eventsStorage = createEventsStorage(subject);\n subject.on = eventsStorage.on;\n subject.off = eventsStorage.off;\n subject.fire = eventsStorage.fire;\n return subject;\n};\n\nfunction createEventsStorage(subject) {\n // Store all event listeners to this hash. Key is event name, value is array\n // of callback records.\n //\n // A callback record consists of callback function and its optional context:\n // { 'eventName' => [{callback: function, ctx: object}] }\n var registeredEvents = Object.create(null);\n\n return {\n on: function (eventName, callback, ctx) {\n if (typeof callback !== 'function') {\n throw new Error('callback is expected to be a function');\n }\n var handlers = registeredEvents[eventName];\n if (!handlers) {\n handlers = registeredEvents[eventName] = [];\n }\n handlers.push({callback: callback, ctx: ctx});\n\n return subject;\n },\n\n off: function (eventName, callback) {\n var wantToRemoveAll = (typeof eventName === 'undefined');\n if (wantToRemoveAll) {\n // Killing old events storage should be enough in this case:\n registeredEvents = Object.create(null);\n return subject;\n }\n\n if (registeredEvents[eventName]) {\n var deleteAllCallbacksForEvent = (typeof callback !== 'function');\n if (deleteAllCallbacksForEvent) {\n delete registeredEvents[eventName];\n } else {\n var callbacks = registeredEvents[eventName];\n for (var i = 0; i < callbacks.length; ++i) {\n if (callbacks[i].callback === callback) {\n callbacks.splice(i, 1);\n }\n }\n }\n }\n\n return subject;\n },\n\n fire: function (eventName) {\n var callbacks = registeredEvents[eventName];\n if (!callbacks) {\n return subject;\n }\n\n var fireArguments;\n if (arguments.length > 1) {\n fireArguments = Array.prototype.splice.call(arguments, 1);\n }\n for(var i = 0; i < callbacks.length; ++i) {\n var callbackInfo = callbacks[i];\n callbackInfo.callback.apply(callbackInfo.ctx, fireArguments);\n }\n\n return subject;\n }\n };\n}\n\nfunction validateSubject(subject) {\n if (!subject) {\n throw new Error('Eventify cannot use falsy object as events subject');\n }\n var reservedWords = ['on', 'fire', 'off'];\n for (var i = 0; i < reservedWords.length; ++i) {\n if (subject.hasOwnProperty(reservedWords[i])) {\n throw new Error(\"Subject cannot be eventified, since it already has property '\" + reservedWords[i] + \"'\");\n }\n }\n}\n","/**\n * @fileOverview Contains definition of the core graph object.\n */\n\n/**\n * @example\n * var graph = require('ngraph.graph')();\n * graph.addNode(1); // graph has one node.\n * graph.addLink(2, 3); // now graph contains three nodes and one link.\n *\n */\nmodule.exports = createGraph;\n\nvar eventify = require('ngraph.events');\n\n/**\n * Creates a new graph\n */\nfunction createGraph(options) {\n // Graph structure is maintained as dictionary of nodes\n // and array of links. Each node has 'links' property which\n // hold all links related to that node. And general links\n // array is used to speed up all links enumeration. This is inefficient\n // in terms of memory, but simplifies coding.\n options = options || {};\n if (options.uniqueLinkId === undefined) {\n // Request each link id to be unique between same nodes. This negatively\n // impacts `addLink()` performance (O(n), where n - number of edges of each\n // vertex), but makes operations with multigraphs more accessible.\n options.uniqueLinkId = true;\n }\n\n var nodes = typeof Object.create === 'function' ? Object.create(null) : {},\n links = [],\n // Hash of multi-edges. Used to track ids of edges between same nodes\n multiEdges = {},\n nodesCount = 0,\n suspendEvents = 0,\n\n forEachNode = createNodeIterator(),\n createLink = options.uniqueLinkId ? createUniqueLink : createSingleLink,\n\n // Our graph API provides means to listen to graph changes. Users can subscribe\n // to be notified about changes in the graph by using `on` method. However\n // in some cases they don't use it. To avoid unnecessary memory consumption\n // we will not record graph changes until we have at least one subscriber.\n // Code below supports this optimization.\n //\n // Accumulates all changes made during graph updates.\n // Each change element contains:\n // changeType - one of the strings: 'add', 'remove' or 'update';\n // node - if change is related to node this property is set to changed graph's node;\n // link - if change is related to link this property is set to changed graph's link;\n changes = [],\n recordLinkChange = noop,\n recordNodeChange = noop,\n enterModification = noop,\n exitModification = noop;\n\n // this is our public API:\n var graphPart = {\n /**\n * Adds node to the graph. If node with given id already exists in the graph\n * its data is extended with whatever comes in 'data' argument.\n *\n * @param nodeId the node's identifier. A string or number is preferred.\n * @param [data] additional data for the node being added. If node already\n * exists its data object is augmented with the new one.\n *\n * @return {node} The newly added node or node with given id if it already exists.\n */\n addNode: addNode,\n\n /**\n * Adds a link to the graph. The function always create a new\n * link between two nodes. If one of the nodes does not exists\n * a new node is created.\n *\n * @param fromId link start node id;\n * @param toId link end node id;\n * @param [data] additional data to be set on the new link;\n *\n * @return {link} The newly created link\n */\n addLink: addLink,\n\n /**\n * Removes link from the graph. If link does not exist does nothing.\n *\n * @param link - object returned by addLink() or getLinks() methods.\n *\n * @returns true if link was removed; false otherwise.\n */\n removeLink: removeLink,\n\n /**\n * Removes node with given id from the graph. If node does not exist in the graph\n * does nothing.\n *\n * @param nodeId node's identifier passed to addNode() function.\n *\n * @returns true if node was removed; false otherwise.\n */\n removeNode: removeNode,\n\n /**\n * Gets node with given identifier. If node does not exist undefined value is returned.\n *\n * @param nodeId requested node identifier;\n *\n * @return {node} in with requested identifier or undefined if no such node exists.\n */\n getNode: getNode,\n\n /**\n * Gets number of nodes in this graph.\n *\n * @return number of nodes in the graph.\n */\n getNodesCount: function() {\n return nodesCount;\n },\n\n /**\n * Gets total number of links in the graph.\n */\n getLinksCount: function() {\n return links.length;\n },\n\n /**\n * Gets all links (inbound and outbound) from the node with given id.\n * If node with given id is not found null is returned.\n *\n * @param nodeId requested node identifier.\n *\n * @return Array of links from and to requested node if such node exists;\n * otherwise null is returned.\n */\n getLinks: getLinks,\n\n /**\n * Invokes callback on each node of the graph.\n *\n * @param {Function(node)} callback Function to be invoked. The function\n * is passed one argument: visited node.\n */\n forEachNode: forEachNode,\n\n /**\n * Invokes callback on every linked (adjacent) node to the given one.\n *\n * @param nodeId Identifier of the requested node.\n * @param {Function(node, link)} callback Function to be called on all linked nodes.\n * The function is passed two parameters: adjacent node and link object itself.\n * @param oriented if true graph treated as oriented.\n */\n forEachLinkedNode: forEachLinkedNode,\n\n /**\n * Enumerates all links in the graph\n *\n * @param {Function(link)} callback Function to be called on all links in the graph.\n * The function is passed one parameter: graph's link object.\n *\n * Link object contains at least the following fields:\n * fromId - node id where link starts;\n * toId - node id where link ends,\n * data - additional data passed to graph.addLink() method.\n */\n forEachLink: forEachLink,\n\n /**\n * Suspend all notifications about graph changes until\n * endUpdate is called.\n */\n beginUpdate: enterModification,\n\n /**\n * Resumes all notifications about graph changes and fires\n * graph 'changed' event in case there are any pending changes.\n */\n endUpdate: exitModification,\n\n /**\n * Removes all nodes and links from the graph.\n */\n clear: clear,\n\n /**\n * Detects whether there is a link between two nodes.\n * Operation complexity is O(n) where n - number of links of a node.\n * NOTE: this function is synonim for getLink()\n *\n * @returns link if there is one. null otherwise.\n */\n hasLink: getLink,\n\n /**\n * Gets an edge between two nodes.\n * Operation complexity is O(n) where n - number of links of a node.\n *\n * @param {string} fromId link start identifier\n * @param {string} toId link end identifier\n *\n * @returns link if there is one. null otherwise.\n */\n getLink: getLink\n };\n\n // this will add `on()` and `fire()` methods.\n eventify(graphPart);\n\n monitorSubscribers();\n\n return graphPart;\n\n function monitorSubscribers() {\n var realOn = graphPart.on;\n\n // replace real `on` with our temporary on, which will trigger change\n // modification monitoring:\n graphPart.on = on;\n\n function on() {\n // now it's time to start tracking stuff:\n graphPart.beginUpdate = enterModification = enterModificationReal;\n graphPart.endUpdate = exitModification = exitModificationReal;\n recordLinkChange = recordLinkChangeReal;\n recordNodeChange = recordNodeChangeReal;\n\n // this will replace current `on` method with real pub/sub from `eventify`.\n graphPart.on = realOn;\n // delegate to real `on` handler:\n return realOn.apply(graphPart, arguments);\n }\n }\n\n function recordLinkChangeReal(link, changeType) {\n changes.push({\n link: link,\n changeType: changeType\n });\n }\n\n function recordNodeChangeReal(node, changeType) {\n changes.push({\n node: node,\n changeType: changeType\n });\n }\n\n function addNode(nodeId, data) {\n if (nodeId === undefined) {\n throw new Error('Invalid node identifier');\n }\n\n enterModification();\n\n var node = getNode(nodeId);\n if (!node) {\n node = new Node(nodeId);\n nodesCount++;\n recordNodeChange(node, 'add');\n } else {\n recordNodeChange(node, 'update');\n }\n\n node.data = data;\n\n nodes[nodeId] = node;\n\n exitModification();\n return node;\n }\n\n function getNode(nodeId) {\n return nodes[nodeId];\n }\n\n function removeNode(nodeId) {\n var node = getNode(nodeId);\n if (!node) {\n return false;\n }\n\n enterModification();\n\n if (node.links) {\n while (node.links.length) {\n var link = node.links[0];\n removeLink(link);\n }\n }\n\n delete nodes[nodeId];\n nodesCount--;\n\n recordNodeChange(node, 'remove');\n\n exitModification();\n\n return true;\n }\n\n\n function addLink(fromId, toId, data) {\n enterModification();\n\n var fromNode = getNode(fromId) || addNode(fromId);\n var toNode = getNode(toId) || addNode(toId);\n\n var link = createLink(fromId, toId, data);\n\n links.push(link);\n\n // TODO: this is not cool. On large graphs potentially would consume more memory.\n addLinkToNode(fromNode, link);\n if (fromId !== toId) {\n // make sure we are not duplicating links for self-loops\n addLinkToNode(toNode, link);\n }\n\n recordLinkChange(link, 'add');\n\n exitModification();\n\n return link;\n }\n\n function createSingleLink(fromId, toId, data) {\n var linkId = makeLinkId(fromId, toId);\n return new Link(fromId, toId, data, linkId);\n }\n\n function createUniqueLink(fromId, toId, data) {\n // TODO: Get rid of this method.\n var linkId = makeLinkId(fromId, toId);\n var isMultiEdge = multiEdges.hasOwnProperty(linkId);\n if (isMultiEdge || getLink(fromId, toId)) {\n if (!isMultiEdge) {\n multiEdges[linkId] = 0;\n }\n var suffix = '@' + (++multiEdges[linkId]);\n linkId = makeLinkId(fromId + suffix, toId + suffix);\n }\n\n return new Link(fromId, toId, data, linkId);\n }\n\n function getLinks(nodeId) {\n var node = getNode(nodeId);\n return node ? node.links : null;\n }\n\n function removeLink(link) {\n if (!link) {\n return false;\n }\n var idx = indexOfElementInArray(link, links);\n if (idx < 0) {\n return false;\n }\n\n enterModification();\n\n links.splice(idx, 1);\n\n var fromNode = getNode(link.fromId);\n var toNode = getNode(link.toId);\n\n if (fromNode) {\n idx = indexOfElementInArray(link, fromNode.links);\n if (idx >= 0) {\n fromNode.links.splice(idx, 1);\n }\n }\n\n if (toNode) {\n idx = indexOfElementInArray(link, toNode.links);\n if (idx >= 0) {\n toNode.links.splice(idx, 1);\n }\n }\n\n recordLinkChange(link, 'remove');\n\n exitModification();\n\n return true;\n }\n\n function getLink(fromNodeId, toNodeId) {\n // TODO: Use sorted links to speed this up\n var node = getNode(fromNodeId),\n i;\n if (!node || !node.links) {\n return null;\n }\n\n for (i = 0; i < node.links.length; ++i) {\n var link = node.links[i];\n if (link.fromId === fromNodeId && link.toId === toNodeId) {\n return link;\n }\n }\n\n return null; // no link.\n }\n\n function clear() {\n enterModification();\n forEachNode(function(node) {\n removeNode(node.id);\n });\n exitModification();\n }\n\n function forEachLink(callback) {\n var i, length;\n if (typeof callback === 'function') {\n for (i = 0, length = links.length; i < length; ++i) {\n callback(links[i]);\n }\n }\n }\n\n function forEachLinkedNode(nodeId, callback, oriented) {\n var node = getNode(nodeId);\n\n if (node && node.links && typeof callback === 'function') {\n if (oriented) {\n return forEachOrientedLink(node.links, nodeId, callback);\n } else {\n return forEachNonOrientedLink(node.links, nodeId, callback);\n }\n }\n }\n\n function forEachNonOrientedLink(links, nodeId, callback) {\n var quitFast;\n for (var i = 0; i < links.length; ++i) {\n var link = links[i];\n var linkedNodeId = link.fromId === nodeId ? link.toId : link.fromId;\n\n quitFast = callback(nodes[linkedNodeId], link);\n if (quitFast) {\n return true; // Client does not need more iterations. Break now.\n }\n }\n }\n\n function forEachOrientedLink(links, nodeId, callback) {\n var quitFast;\n for (var i = 0; i < links.length; ++i) {\n var link = links[i];\n if (link.fromId === nodeId) {\n quitFast = callback(nodes[link.toId], link);\n if (quitFast) {\n return true; // Client does not need more iterations. Break now.\n }\n }\n }\n }\n\n // we will not fire anything until users of this library explicitly call `on()`\n // method.\n function noop() {}\n\n // Enter, Exit modification allows bulk graph updates without firing events.\n function enterModificationReal() {\n suspendEvents += 1;\n }\n\n function exitModificationReal() {\n suspendEvents -= 1;\n if (suspendEvents === 0 && changes.length > 0) {\n graphPart.fire('changed', changes);\n changes.length = 0;\n }\n }\n\n function createNodeIterator() {\n // Object.keys iterator is 1.3x faster than `for in` loop.\n // See `https://github.com/anvaka/ngraph.graph/tree/bench-for-in-vs-obj-keys`\n // branch for perf test\n return Object.keys ? objectKeysIterator : forInIterator;\n }\n\n function objectKeysIterator(callback) {\n if (typeof callback !== 'function') {\n return;\n }\n\n var keys = Object.keys(nodes);\n for (var i = 0; i < keys.length; ++i) {\n if (callback(nodes[keys[i]])) {\n return true; // client doesn't want to proceed. Return.\n }\n }\n }\n\n function forInIterator(callback) {\n if (typeof callback !== 'function') {\n return;\n }\n var node;\n\n for (node in nodes) {\n if (callback(nodes[node])) {\n return true; // client doesn't want to proceed. Return.\n }\n }\n }\n}\n\n// need this for old browsers. Should this be a separate module?\nfunction indexOfElementInArray(element, array) {\n if (!array) return -1;\n\n if (array.indexOf) {\n return array.indexOf(element);\n }\n\n var len = array.length,\n i;\n\n for (i = 0; i < len; i += 1) {\n if (array[i] === element) {\n return i;\n }\n }\n\n return -1;\n}\n\n/**\n * Internal structure to represent node;\n */\nfunction Node(id) {\n this.id = id;\n this.links = null;\n this.data = null;\n}\n\nfunction addLinkToNode(node, link) {\n if (node.links) {\n node.links.push(link);\n } else {\n node.links = [link];\n }\n}\n\n/**\n * Internal structure to represent links;\n */\nfunction Link(fromId, toId, data, id) {\n this.fromId = fromId;\n this.toId = toId;\n this.data = data;\n this.id = id;\n}\n\nfunction hashCode(str) {\n var hash = 0, i, chr, len;\n if (str.length == 0) return hash;\n for (i = 0, len = str.length; i < len; i++) {\n chr = str.charCodeAt(i);\n hash = ((hash << 5) - hash) + chr;\n hash |= 0; // Convert to 32bit integer\n }\n return hash;\n}\n\nfunction makeLinkId(fromId, toId) {\n return hashCode(fromId.toString() + '👉 ' + toId.toString());\n}\n","/**\r\n * @param {CommunityStructure|Community} com\r\n * @constructor\r\n */\r\nfunction Community(com) {\r\n\r\n /** @type {CommunityStructure} */\r\n this.structure = com.structure ? com.structure : com;\r\n\r\n /** @type {Map.} */\r\n this.connectionsWeight = new Map();\r\n\r\n /** @type {Map.} */\r\n this.connectionsCount = new Map();\r\n\r\n /** @type {Set.} */\r\n this.nodes = new Set;\r\n\r\n this.weightSum = 0;\r\n\r\n\r\n}\r\n\r\n/**\r\n * @public\r\n * @returns {Number}\r\n */\r\nCommunity.prototype.size = function() {\r\n return this.nodes.size;\r\n};\r\n\r\n\r\n/**\r\n * @param {Number} node\r\n */\r\nCommunity.prototype.seed = function(node) {\r\n\r\n this.nodes.add(node);\r\n this.weightSum += this.structure.weights[node];\r\n\r\n};\r\n\r\n/**\r\n * @param {Number} nodeId\r\n * @returns {boolean}\r\n */\r\nCommunity.prototype.add = function(nodeId) {\r\n\r\n this.nodes.add(nodeId);\r\n this.weightSum += this.structure.weights[nodeId];\r\n return true;\r\n\r\n};\r\n\r\n/**\r\n * @param {Number} node\r\n * @returns {boolean}\r\n */\r\nCommunity.prototype.remove = function(node) {\r\n\r\n var result = this.nodes.delete(node);\r\n\r\n this.weightSum -= this.structure.weights[node];\r\n if (!this.nodes.size) {\r\n var index = this.structure.communities.indexOf(this);\r\n delete this.structure.communities[index];\r\n }\r\n\r\n return result;\r\n};\r\n\r\nmodule.exports = Community;\r\n","\"use strict\";\r\nvar Community = require('./Community')\r\n , ModEdge = require('./ModEdge')\r\n ;\r\n\r\n/**\r\n *\r\n * @param {IGraph} graph\r\n * @param useWeight\r\n * @param {CommunityStructure} structure\r\n * @constructor\r\n */\r\nfunction CommunityStructure(graph, useWeight) {\r\n\r\n //this.graph = graph;\r\n this.N = graph.getNodesCount();\r\n this.graphWeightSum = 0;\r\n this.structure = this;\r\n\r\n /** @type {Map.} */\r\n this.invMap = new Map();\r\n\r\n /** @type {Array.< Map. >} */\r\n this.nodeConnectionsWeight = new Array(this.N);\r\n\r\n /** @type {Array.< Map. >} */\r\n this.nodeConnectionsCount = new Array(this.N);\r\n\r\n /** @type {Array.} */\r\n this.nodeCommunities = new Array(this.N);\r\n\r\n /** @type {Map.} */\r\n this.map = new Map();\r\n\r\n /** @type {Array.< Array. >} */\r\n this.topology = new Array(this.N);\r\n for (var i = 0; i < this.N; i++) this.topology[i] = [];\r\n\r\n /** @type {Array.} */\r\n this.communities = [];\r\n\r\n /**@type {Array.} */\r\n this.weights = new Array(this.N);\r\n\r\n var index = 0;\r\n\r\n graph.forEachNode(function (node) {\r\n\r\n this.map.set(node.id, index);\r\n this.nodeCommunities[index] = new Community(this);\r\n this.nodeConnectionsWeight[index] = new Map();\r\n this.nodeConnectionsCount[index] = new Map();\r\n this.weights[index] = 0;\r\n this.nodeCommunities[index].seed(index);\r\n var hidden = new Community(this);\r\n hidden.nodes.add(index);\r\n this.invMap.set(index, hidden);\r\n this.communities.push(this.nodeCommunities[index]);\r\n index++;\r\n\r\n }.bind(this));\r\n\r\n\r\n graph.forEachLink(function (link) {\r\n\r\n var node_index = this.map.get(link.fromId)\r\n , neighbor_index = this.map.get(link.toId)\r\n , weight = 1\r\n ;\r\n\r\n if (node_index === neighbor_index) {\r\n return;\r\n }\r\n\r\n if (useWeight) {\r\n weight = link.data.weight;\r\n }\r\n\r\n this.setUpLink(node_index, neighbor_index, weight);\r\n this.setUpLink(neighbor_index, node_index, weight);\r\n\r\n\r\n }.bind(this));\r\n\r\n\r\n this.graphWeightSum /= 2.0;\r\n}\r\n\r\n\r\nCommunityStructure.prototype.setUpLink = function (node_index, neighbor_index, weight) {\r\n\r\n this.weights[node_index] += weight;\r\n var /** @type {ModEdge} */ me = new ModEdge(node_index, neighbor_index, weight);\r\n this.topology[node_index].push(me);\r\n var /** @type {Community} **/ adjCom = this.nodeCommunities[neighbor_index];\r\n this.nodeConnectionsWeight[node_index].set(adjCom, weight);\r\n this.nodeConnectionsCount[node_index].set(adjCom, 1);\r\n this.nodeCommunities[node_index].connectionsWeight.set(adjCom, weight);\r\n this.nodeCommunities[node_index].connectionsCount.set(adjCom, 1);\r\n this.nodeConnectionsWeight[neighbor_index].set(this.nodeCommunities[node_index], weight);\r\n this.nodeConnectionsCount[neighbor_index].set(this.nodeCommunities[node_index], 1);\r\n this.nodeCommunities[neighbor_index].connectionsWeight.set(this.nodeCommunities[node_index], weight);\r\n this.nodeCommunities[neighbor_index].connectionsCount.set(this.nodeCommunities[node_index], 1);\r\n this.graphWeightSum += weight;\r\n\r\n};\r\n\r\n/**\r\n * @param {Number} node\r\n * @param {Community} to\r\n */\r\nCommunityStructure.prototype.addNodeTo = function (node, to) {\r\n\r\n to.add(node);\r\n this.nodeCommunities[node] = to;\r\n\r\n var nodeTopology = this.topology[node];\r\n for (var topologyKey in nodeTopology) {\r\n\r\n //noinspection JSUnfilteredForInLoop\r\n var /** @type {ModEdge} */ e = nodeTopology[topologyKey];\r\n\r\n var neighbor = e.target;\r\n\r\n\r\n //Remove Node Connection to this community\r\n var neighEdgesTo = this.nodeConnectionsWeight[neighbor].get(to);\r\n if (neighEdgesTo === undefined) {\r\n this.nodeConnectionsWeight[neighbor].set(to, e.weight);\r\n } else {\r\n this.nodeConnectionsWeight[neighbor].set(to, neighEdgesTo + e.weight);\r\n }\r\n\r\n var neighCountEdgesTo = this.nodeConnectionsCount[neighbor].get(to);\r\n if (neighCountEdgesTo === undefined) {\r\n this.nodeConnectionsCount[neighbor].set(to, 1);\r\n } else {\r\n this.nodeConnectionsCount[neighbor].set(to, neighCountEdgesTo + 1);\r\n }\r\n\r\n\r\n var /** @type {Community} */ adjCom = this.nodeCommunities[neighbor];\r\n var wEdgesto = adjCom.connectionsWeight.get(to);\r\n if (wEdgesto === undefined) {\r\n adjCom.connectionsWeight.set(to, e.weight);\r\n } else {\r\n adjCom.connectionsWeight.set(to, wEdgesto + e.weight);\r\n }\r\n\r\n var cEdgesto = adjCom.connectionsCount.get(to);\r\n if (cEdgesto === undefined) {\r\n adjCom.connectionsCount.set(to, 1);\r\n } else {\r\n adjCom.connectionsCount.set(to, cEdgesto + 1);\r\n }\r\n\r\n var nodeEdgesTo = this.nodeConnectionsWeight[node].get(adjCom);\r\n if (nodeEdgesTo === undefined) {\r\n this.nodeConnectionsWeight[node].set(adjCom, e.weight);\r\n } else {\r\n this.nodeConnectionsWeight[node].set(adjCom, nodeEdgesTo + e.weight);\r\n }\r\n\r\n var nodeCountEdgesTo = this.nodeConnectionsCount[node].get(adjCom);\r\n if (nodeCountEdgesTo === undefined) {\r\n this.nodeConnectionsCount[node].set(adjCom, 1);\r\n } else {\r\n this.nodeConnectionsCount[node].set(adjCom, nodeCountEdgesTo + 1);\r\n }\r\n\r\n if (to != adjCom) {\r\n var comEdgesto = to.connectionsWeight.get(adjCom);\r\n if (comEdgesto === undefined) {\r\n to.connectionsWeight.set(adjCom, e.weight);\r\n } else {\r\n to.connectionsWeight.set(adjCom, comEdgesto + e.weight);\r\n }\r\n\r\n var comCountEdgesto = to.connectionsCount.get(adjCom);\r\n if (comCountEdgesto === undefined) {\r\n to.connectionsCount.set(adjCom, 1);\r\n } else {\r\n to.connectionsCount.set(adjCom, comCountEdgesto + 1);\r\n }\r\n\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * @param {Number} node\r\n * @param {Community} source\r\n */\r\nCommunityStructure.prototype.removeNodeFrom = function (node, source) {\r\n\r\n var community = this.nodeCommunities[node];\r\n\r\n\r\n var nodeTopology = this.topology[node];\r\n for (var topologyKey in nodeTopology) {\r\n\r\n //noinspection JSUnfilteredForInLoop\r\n var /** @type {ModEdge} */ e = nodeTopology[topologyKey];\r\n\r\n var neighbor = e.target;\r\n\r\n //Remove Node Connection to this community\r\n var edgesTo = this.nodeConnectionsWeight[neighbor].get(community);\r\n var countEdgesTo = this.nodeConnectionsCount[neighbor].get(community);\r\n\r\n if ((countEdgesTo - 1) == 0) {\r\n this.nodeConnectionsWeight[neighbor].delete(community);\r\n this.nodeConnectionsCount[neighbor].delete(community);\r\n } else {\r\n this.nodeConnectionsWeight[neighbor].set(community, edgesTo - e.weight);\r\n this.nodeConnectionsCount[neighbor].set(community, countEdgesTo - 1);\r\n }\r\n\r\n\r\n //Remove Adjacency Community's connection to this community\r\n var adjCom = this.nodeCommunities[neighbor];\r\n var oEdgesto = adjCom.connectionsWeight.get(community);\r\n var oCountEdgesto = adjCom.connectionsCount.get(community);\r\n if ((oCountEdgesto - 1) == 0) {\r\n adjCom.connectionsWeight.delete(community);\r\n adjCom.connectionsCount.delete(community);\r\n } else {\r\n adjCom.connectionsWeight.set(community, oEdgesto - e.weight);\r\n adjCom.connectionsCount.set(community, oCountEdgesto - 1);\r\n }\r\n\r\n if (node == neighbor) {\r\n continue;\r\n }\r\n\r\n if (adjCom != community) {\r\n\r\n var comEdgesto = community.connectionsWeight.get(adjCom);\r\n var comCountEdgesto = community.connectionsCount.get(adjCom);\r\n\r\n if (comCountEdgesto - 1 == 0) {\r\n community.connectionsWeight.delete(adjCom);\r\n community.connectionsCount.delete(adjCom);\r\n } else {\r\n community.connectionsWeight.set(adjCom, comEdgesto - e.weight);\r\n community.connectionsCount.set(adjCom, comCountEdgesto - 1);\r\n }\r\n\r\n }\r\n\r\n var nodeEdgesTo = this.nodeConnectionsWeight[node].get(adjCom);\r\n var nodeCountEdgesTo = this.nodeConnectionsCount[node].get(adjCom);\r\n\r\n if ((nodeCountEdgesTo - 1) == 0) {\r\n this.nodeConnectionsWeight[node].delete(adjCom);\r\n this.nodeConnectionsCount[node].delete(adjCom);\r\n } else {\r\n this.nodeConnectionsWeight[node].set(adjCom, nodeEdgesTo - e.weight);\r\n this.nodeConnectionsCount[node].set(adjCom, nodeCountEdgesTo - 1);\r\n }\r\n\r\n }\r\n\r\n source.remove(node);\r\n};\r\n\r\n/**\r\n * @param {Number} node\r\n * @param {Community} to\r\n */\r\nCommunityStructure.prototype.moveNodeTo = function (node, to) {\r\n\r\n var source = this.nodeCommunities[node];\r\n this.removeNodeFrom(node, source);\r\n this.addNodeTo(node, to);\r\n\r\n};\r\n\r\n\r\nCommunityStructure.prototype.zoomOut = function () {\r\n var realCommunities = this.communities.reduce(function (arr, value) {\r\n arr.push(value);\r\n return arr;\r\n }, []);\r\n var M = realCommunities.length; // size\r\n var /** @type Array.< Array. > */ newTopology = new Array(M);\r\n var index = 0;\r\n\r\n this.nodeCommunities = new Array(M);\r\n this.nodeConnectionsWeight = new Array(M);\r\n this.nodeConnectionsCount = new Array(M);\r\n\r\n var /** @type Map.*/ newInvMap = new Map();\r\n realCommunities.forEach(function (com) {\r\n\r\n var weightSum = 0;\r\n this.nodeConnectionsWeight[index] = new Map();\r\n this.nodeConnectionsCount[index] = new Map();\r\n newTopology[index] = [];\r\n this.nodeCommunities[index] = new Community(com);\r\n //var iter = com.connectionsWeight.keySet();\r\n\r\n var hidden = new Community(this.structure);\r\n\r\n com.nodes.forEach(function (nodeInt) {\r\n\r\n var oldHidden = this.invMap.get(nodeInt);\r\n oldHidden.nodes.forEach(hidden.nodes.add.bind(hidden.nodes));\r\n\r\n }, this);\r\n\r\n newInvMap.set(index, hidden);\r\n com.connectionsWeight.forEach(function (weight, adjCom) {\r\n\r\n var target = realCommunities.indexOf(adjCom);\r\n if (!~target) return;\r\n if (target == index) {\r\n weightSum += 2. * weight;\r\n } else {\r\n weightSum += weight;\r\n }\r\n var e = new ModEdge(index, target, weight);\r\n newTopology[index].push(e);\r\n\r\n }, this);\r\n\r\n this.weights[index] = weightSum;\r\n this.nodeCommunities[index].seed(index);\r\n\r\n index++;\r\n\r\n }.bind(this));\r\n\r\n this.communities = [];\r\n\r\n for (var i = 0; i < M; i++) {\r\n var com = this.nodeCommunities[i];\r\n this.communities.push(com);\r\n for (var ei in newTopology[i]) {\r\n //noinspection JSUnfilteredForInLoop\r\n var e = newTopology[i][ei];\r\n this.nodeConnectionsWeight[i].set(this.nodeCommunities[e.target], e.weight);\r\n this.nodeConnectionsCount[i].set(this.nodeCommunities[e.target], 1);\r\n com.connectionsWeight.set(this.nodeCommunities[e.target], e.weight);\r\n com.connectionsCount.set(this.nodeCommunities[e.target], 1);\r\n }\r\n\r\n }\r\n\r\n this.N = M;\r\n this.topology = newTopology;\r\n this.invMap = newInvMap;\r\n\r\n};\r\n\r\nmodule.exports = CommunityStructure;","/**\r\n *\r\n * @param s\r\n * @param t\r\n * @param w\r\n * @constructor\r\n */\r\nfunction ModEdge(s, t, w) {\r\n /** @type {Number} */\r\n this.source = s;\r\n /** @type {Number} */\r\n this.target = t;\r\n /** @type {Number} */\r\n this.weight = w;\r\n}\r\n\r\nmodule.exports = ModEdge;\r\n","/*\r\n Copyright 2008-2011 Gephi\r\n Authors : Patick J. McSweeney , Sebastien Heymann \r\n Website : http://www.gephi.org\r\n\r\n This file is part of Gephi.\r\n\r\n DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.\r\n\r\n Copyright 2011 Gephi Consortium. All rights reserved.\r\n\r\n The contents of this file are subject to the terms of either the GNU\r\n General Public License Version 3 only (\"GPL\") or the Common\r\n Development and Distribution License(\"CDDL\") (collectively, the\r\n \"License\"). You may not use this file except in compliance with the\r\n License. You can obtain a copy of the License at\r\n http://gephi.org/about/legal/license-notice/\r\n or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the\r\n specific language governing permissions and limitations under the\r\n License. When distributing the software, include this License Header\r\n Notice in each file and include the License files at\r\n /cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the\r\n License Header, with the fields enclosed by brackets [] replaced by\r\n your own identifying information:\r\n \"Portions Copyrighted [year] [name of copyright owner]\"\r\n\r\n If you wish your version of this file to be governed by only the CDDL\r\n or only the GPL Version 3, indicate your decision by adding\r\n \"[Contributor] elects to include this software in this distribution\r\n under the [CDDL or GPL Version 3] license.\" If you do not indicate a\r\n single choice of license, a recipient has the option to distribute\r\n your version of this file under either the CDDL, the GPL Version 3 or\r\n to extend the choice of license to its licensees as provided above.\r\n However, if you add GPL Version 3 code and therefore, elected the GPL\r\n Version 3 license, then the option applies only if the new code is\r\n made subject to such option by the copyright holder.\r\n\r\n Contributor(s): Thomas Aynaud \r\n\r\n Portions Copyrighted 2011 Gephi Consortium.\r\n */\r\nvar CommunityStructure = require('./CommunityStructure')\r\n , centrality = require('ngraph.centrality')\r\n ;\r\n\r\n/**\r\n * @constructor\r\n */\r\nfunction Modularity (resolution, useWeight) {\r\n this.isRandomized = false;\r\n this.useWeight = useWeight;\r\n this.resolution = resolution || 1.;\r\n /**\r\n * @type {CommunityStructure}\r\n */\r\n this.structure = null;\r\n}\r\n\r\n/**\r\n * @param {IGraph} graph\r\n */\r\nModularity.prototype.execute = function (graph/*, AttributeModel attributeModel*/) {\r\n\r\n\r\n this.structure = new CommunityStructure(graph, this.useWeight);\r\n\r\n var comStructure = new Array(graph.getNodesCount());\r\n\r\n var computedModularityMetrics = this.computeModularity(\r\n graph\r\n , this.structure\r\n , comStructure\r\n , this.resolution\r\n , this.isRandomized\r\n , this.useWeight\r\n );\r\n\r\n var result = {};\r\n this.structure.map.forEach(function (i, node) {\r\n result[node] = comStructure[i];\r\n });\r\n\r\n return result;\r\n\r\n};\r\n\r\n\r\n/**\r\n *\r\n * @param {IGraph} graph\r\n * @param {CommunityStructure} theStructure\r\n * @param {Array.} comStructure\r\n * @param {Number} currentResolution\r\n * @param {Boolean} randomized\r\n * @param {Boolean} weighted\r\n * @returns {Object.}\r\n */\r\nModularity.prototype.computeModularity = function(graph, theStructure, comStructure, currentResolution, randomized, weighted) {\r\n\r\n\r\n function getRandomInt(min, max) {\r\n return Math.floor(Math.random() * (max - min)) + min;\r\n }\r\n\r\n var totalWeight = theStructure.graphWeightSum;\r\n var nodeDegrees = theStructure.weights.slice();\r\n\r\n\r\n var /** @type {Object.} */ results = Object.create(null);\r\n\r\n\r\n var someChange = true;\r\n\r\n while (someChange) {\r\n someChange = false;\r\n var localChange = true;\r\n while (localChange) {\r\n localChange = false;\r\n var start = 0;\r\n if (randomized) {\r\n //start = Math.abs(rand.nextInt()) % theStructure.N;\r\n start = getRandomInt(0,theStructure.N);\r\n }\r\n var step = 0;\r\n for (var i = start; step < theStructure.N; i = (i + 1) % theStructure.N) {\r\n step++;\r\n var bestCommunity = this.updateBestCommunity(theStructure, i, currentResolution);\r\n if ((theStructure.nodeCommunities[i] != bestCommunity) && (bestCommunity != null)) {\r\n theStructure.moveNodeTo(i, bestCommunity);\r\n localChange = true;\r\n }\r\n\r\n }\r\n\r\n someChange = localChange || someChange;\r\n\r\n }\r\n\r\n if (someChange) {\r\n theStructure.zoomOut();\r\n }\r\n }\r\n\r\n this.fillComStructure(graph, theStructure, comStructure);\r\n\r\n /*\r\n //TODO: uncomment when finalQ will be implemented\r\n var degreeCount = this.fillDegreeCount(graph, theStructure, comStructure, nodeDegrees, weighted);\r\n\r\n\r\n var computedModularity = this._finalQ(comStructure, degreeCount, graph, theStructure, totalWeight, 1., weighted);\r\n var computedModularityResolution = this._finalQ(comStructure, degreeCount, graph, theStructure, totalWeight, currentResolution, weighted);\r\n\r\n results[\"modularity\"] = computedModularity;\r\n results[\"modularityResolution\"] = computedModularityResolution;\r\n */\r\n\r\n return results;\r\n};\r\n\r\n\r\n/**\r\n * @param {CommunityStructure} theStructure\r\n * @param {Number} i\r\n * @param {Number} currentResolution\r\n * @returns {Community}\r\n */\r\nModularity.prototype.updateBestCommunity = function(theStructure, i, currentResolution) {\r\n var best = this.q(i, theStructure.nodeCommunities[i], theStructure, currentResolution);\r\n var bestCommunity = theStructure.nodeCommunities[i];\r\n //var /*Set*/ iter = theStructure.nodeConnectionsWeight[i].keySet();\r\n theStructure.nodeConnectionsWeight[i].forEach(function (_$$val, com) {\r\n\r\n var qValue = this.q(i, com, theStructure, currentResolution);\r\n if (qValue > best) {\r\n best = qValue;\r\n bestCommunity = com;\r\n }\r\n\r\n }, this);\r\n return bestCommunity;\r\n};\r\n\r\n/**\r\n *\r\n * @param {IGraph} graph\r\n * @param {CommunityStructure} theStructure\r\n * @param {Array.} comStructure\r\n * @returns {Array.}\r\n */\r\nModularity.prototype.fillComStructure = function(graph, theStructure, comStructure) {\r\n\r\n var count = 0;\r\n\r\n theStructure.communities.forEach(function (com) {\r\n\r\n com.nodes.forEach(function (node) {\r\n\r\n var hidden = theStructure.invMap.get(node);\r\n hidden.nodes.forEach( function (nodeInt){\r\n comStructure[nodeInt] = count;\r\n });\r\n\r\n });\r\n count++;\r\n\r\n });\r\n\r\n\r\n return comStructure;\r\n};\r\n\r\n/**\r\n * @param {IGraph} graph\r\n * @param {CommunityStructure} theStructure\r\n * @param {Array.} comStructure\r\n * @param {Array.} nodeDegrees\r\n * @param {Boolean} weighted\r\n * @returns {Array.}\r\n */\r\nModularity.prototype.fillDegreeCount = function(graph, theStructure, comStructure, nodeDegrees, weighted) {\r\n\r\n var degreeCount = new Array(theStructure.communities.length);\r\n var degreeCentrality = centrality.degree(graph);\r\n\r\n graph.forEachNode(function(node){\r\n\r\n var index = theStructure.map.get(node);\r\n if (weighted) {\r\n degreeCount[comStructure[index]] += nodeDegrees[index];\r\n } else {\r\n degreeCount[comStructure[index]] += degreeCentrality[node.id];\r\n }\r\n\r\n });\r\n return degreeCount;\r\n\r\n};\r\n\r\n\r\n/**\r\n *\r\n * @param {Array.} struct\r\n * @param {Array.} degrees\r\n * @param {IGraph} graph\r\n * @param {CommunityStructure} theStructure\r\n * @param {Number} totalWeight\r\n * @param {Number} usedResolution\r\n * @param {Boolean} weighted\r\n * @returns {Number}\r\n */\r\nModularity.prototype._finalQ = function(struct, degrees, graph, theStructure, totalWeight, usedResolution, weighted) {\r\n\r\n //TODO: rewrite for wighted version of algorithm\r\n throw new Error(\"not implemented properly\");\r\n var res = 0;\r\n var internal = new Array(degrees.length);\r\n\r\n graph.forEachNode(function(n){\r\n var n_index = theStructure.map.get(n);\r\n\r\n graph.forEachLinkedNode(n.id, function(neighbor){\r\n if (n == neighbor) {\r\n return;\r\n }\r\n var neigh_index = theStructure.map.get(neighbor);\r\n if (struct[neigh_index] == struct[n_index]) {\r\n if (weighted) {\r\n //throw new Error(\"weighted aren't implemented\");\r\n //internal[struct[neigh_index]] += graph.getEdge(n, neighbor).getWeight();\r\n } else {\r\n internal[struct[neigh_index]]++;\r\n }\r\n }\r\n }.bind(this), false);\r\n\r\n }.bind(this));\r\n\r\n for (var i = 0; i < degrees.length; i++) {\r\n internal[i] /= 2.0;\r\n res += usedResolution * (internal[i] / totalWeight) - Math.pow(degrees[i] / (2 * totalWeight), 2);//HERE\r\n }\r\n return res;\r\n};\r\n\r\n\r\n\r\n/**\r\n *\r\n * @param {Number} nodeId\r\n * @param {Community} community\r\n * @param {CommunityStructure} theStructure\r\n * @param {Number} currentResolution\r\n * @returns {Number}\r\n */\r\nModularity.prototype.q = function(nodeId, community, theStructure, currentResolution) {\r\n\r\n var edgesToFloat = theStructure.nodeConnectionsWeight[nodeId].get(community);\r\n var edgesTo = 0;\r\n if (edgesToFloat != null) {\r\n edgesTo = edgesToFloat;\r\n }\r\n var weightSum = community.weightSum;\r\n var nodeWeight = theStructure.weights[nodeId];\r\n var qValue = currentResolution * edgesTo - (nodeWeight * weightSum) / (2.0 * theStructure.graphWeightSum);\r\n if ((theStructure.nodeCommunities[nodeId] == community) && (theStructure.nodeCommunities[nodeId].size() > 1)) {\r\n qValue = currentResolution * edgesTo - (nodeWeight * (weightSum - nodeWeight)) / (2.0 * theStructure.graphWeightSum);\r\n }\r\n if ((theStructure.nodeCommunities[nodeId] == community) && (theStructure.nodeCommunities[nodeId].size() == 1)) {\r\n qValue = 0.;\r\n }\r\n return qValue;\r\n\r\n};\r\n\r\nmodule.exports = Modularity;","import Modularity from 'ngraph.modularity/Modularity';\nimport * as echarts from 'echarts/core';\nimport createNGraph from 'ngraph.graph';\n\nfunction createModularityVisual(chartType) {\n return function (ecModel, api) {\n var paletteScope = {};\n ecModel.eachSeriesByType(chartType, function (seriesModel) {\n var modularityOpt = seriesModel.get('modularity');\n if (modularityOpt) {\n var graph = seriesModel.getGraph();\n var idIndexMap = {};\n var ng = createNGraph();\n graph.data.each(function (idx) {\n var node = graph.getNodeByIndex(idx);\n idIndexMap[node.id] = idx;\n ng.addNode(node.id);\n return node.id;\n });\n graph.edgeData.each('value', function (val, idx) {\n var edge = graph.getEdgeByIndex(idx);\n ng.addLink(edge.node1.id, edge.node2.id);\n return {\n source: edge.node1.id,\n target: edge.node2.id,\n value: val\n };\n });\n\n var modularity = new Modularity(seriesModel.get('modularity.resolution') || 1);\n var result = modularity.execute(ng);\n\n var communities = {};\n for (var id in result) {\n var comm = result[id];\n communities[comm] = communities[comm] || 0;\n communities[comm]++;\n }\n var communitiesList = Object.keys(communities);\n if (seriesModel.get('modularity.sort')) {\n communitiesList.sort(function (a, b) {\n return b - a;\n });\n }\n var colors = {};\n communitiesList.forEach(function (comm) {\n colors[comm] = seriesModel.getColorFromPalette(comm, paletteScope);\n });\n\n for (var id in result) {\n var comm = result[id];\n var style = graph.data.ensureUniqueItemVisual(idIndexMap[id], 'style');\n style.fill = colors[comm];\n }\n\n graph.edgeData.each(function (idx) {\n var itemModel = graph.edgeData.getItemModel(idx);\n var edge = graph.getEdgeByIndex(idx);\n var color = itemModel.get(['lineStyle', 'normal', 'color'])\n || itemModel.get(['lineStyle', 'color']);\n\n switch (color) {\n case 'source':\n color = edge.node1.getVisual('style').fill;\n break;\n case 'target':\n color = edge.node2.getVisual('style').fill;\n break;\n }\n\n if (color != null) {\n graph.edgeData.ensureUniqueItemVisual(idx, 'style').stroke = color;\n }\n });\n }\n });\n };\n}\n\necharts.registerVisual(echarts.PRIORITY.VISUAL.CHART + 1, createModularityVisual('graph'));\necharts.registerVisual(echarts.PRIORITY.VISUAL.CHART + 1, createModularityVisual('graphGL'));","module.exports = __WEBPACK_EXTERNAL_MODULE__550__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","// startup\n// Load entry module and return exports\n// This entry module used 'module' so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(10);\n"],"names":["root","factory","exports","module","require","define","amd","self","__WEBPACK_EXTERNAL_MODULE__550__","degree","betweenness","graph","oriented","currentNode","Q","S","pred","Object","create","dist","sigma","delta","centrality","forEachNode","node","id","source","nodeId","push","length","v","shift","forEachLinkedNode","toId","otherNode","w","singleSourceShortestPath","setDeltaToZero","pop","coeff","predcessors","idx","accumulate","keys","forEach","key","inDegreeCalculator","links","total","i","outDegreeCalculator","fromId","inoutDegreeCalculator","kind","getNodeDegree","result","toLowerCase","Error","getLinks","subject","reservedWords","hasOwnProperty","validateSubject","eventsStorage","registeredEvents","on","eventName","callback","ctx","handlers","off","callbacks","splice","fire","fireArguments","arguments","Array","prototype","call","callbackInfo","apply","createEventsStorage","options","undefined","uniqueLinkId","realOn","nodes","multiEdges","nodesCount","suspendEvents","createLink","data","linkId","makeLinkId","isMultiEdge","getLink","suffix","Link","changes","recordLinkChange","noop","recordNodeChange","enterModification","exitModification","graphPart","addNode","addLink","fromNode","getNode","toNode","link","addLinkToNode","removeLink","removeNode","getNodesCount","getLinksCount","forEachOrientedLink","linkedNodeId","forEachNonOrientedLink","forEachLink","beginUpdate","endUpdate","clear","hasLink","eventify","enterModificationReal","exitModificationReal","recordLinkChangeReal","recordNodeChangeReal","changeType","Node","indexOfElementInArray","fromNodeId","toNodeId","element","array","indexOf","len","this","str","hash","charCodeAt","hashCode","toString","Community","com","structure","connectionsWeight","Map","connectionsCount","Set","weightSum","size","seed","add","weights","remove","delete","index","communities","ModEdge","CommunityStructure","useWeight","N","graphWeightSum","invMap","nodeConnectionsWeight","nodeConnectionsCount","nodeCommunities","map","topology","set","hidden","bind","node_index","get","neighbor_index","weight","setUpLink","me","adjCom","addNodeTo","to","nodeTopology","topologyKey","e","neighbor","target","neighEdgesTo","neighCountEdgesTo","wEdgesto","cEdgesto","nodeEdgesTo","nodeCountEdgesTo","comEdgesto","comCountEdgesto","removeNodeFrom","community","edgesTo","countEdgesTo","oEdgesto","oCountEdgesto","moveNodeTo","zoomOut","realCommunities","reduce","arr","value","M","newTopology","newInvMap","nodeInt","ei","s","t","Modularity","resolution","isRandomized","execute","comStructure","computeModularity","theStructure","currentResolution","randomized","weighted","slice","max","results","someChange","localChange","start","Math","floor","random","step","bestCommunity","updateBestCommunity","fillComStructure","best","q","_$$val","qValue","count","fillDegreeCount","nodeDegrees","degreeCount","degreeCentrality","_finalQ","struct","degrees","totalWeight","usedResolution","edgesToFloat","nodeWeight","createModularityVisual","chartType","ecModel","api","paletteScope","eachSeriesByType","seriesModel","getGraph","idIndexMap","ng","each","getNodeByIndex","edgeData","val","edge","getEdgeByIndex","node1","node2","comm","communitiesList","sort","a","b","colors","getColorFromPalette","ensureUniqueItemVisual","fill","itemModel","getItemModel","color","getVisual","stroke","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__","n","getter","__esModule","d","definition","o","defineProperty","enumerable","obj","prop","r","Symbol","toStringTag"],"sourceRoot":""} --------------------------------------------------------------------------------