lib/society/formatter/report/templates/components/society-assets/society.js in society-1.1.1 vs lib/society/formatter/report/templates/components/society-assets/society.js in society-1.2.0
- old
+ new
@@ -22,18 +22,18 @@
this.data = this.transformData(data);
this.includeIsolatedNodes = true;
};
NetworkGraph.prototype.transformData = function(data) {
- var nodes = data.nodes.map(function(node) {
- return { name: node.name, relations: [] };
- });
- data.edges.forEach(function(edge) {
- var targetName = nodes[edge.to].name;
- nodes[edge.from].relations.push(targetName);
- });
- return nodes;
+ return(Object.keys(data).map(function(node) {
+ return {
+ name: node,
+ relations: Object.keys(data[node]).filter(function(edge) {
+ return(Object.keys(data).indexOf(edge) != -1);
+ })
+ };
+ }));
};
NetworkGraph.prototype.init = function() {
var label = this.element.append('label')
.attr('class', 'society-network-toggle')
@@ -247,15 +247,18 @@
};
var findCluster = data.clusters ? _findCluster : function() { return 0; };
return {
- nodes: data.nodes.map(function(node, index) {
- return { name: node.name, group: findCluster(index) };
+ nodes: Object.keys(data).map(function(node, index) {
+ return { name: node, group: findCluster(index) };
}),
- links: data.edges.map(function(edge) {
- return { source: edge.from, target: edge.to, value: 1 };
- })
+ links: Object.keys(data).reduce(function(edges, node, source) {
+ var new_edges = Object.keys(data[node]).map(function(edge, target) {
+ return { source: source, target: target, value: data[node][edge] };
+ });
+ return(edges.concat(new_edges));
+ }, [])
};
};
Heatmap.prototype.init = function() {
var x = d3.scale.ordinal().rangeBands([0, this.width]),