var Dataset = function(jsonData) { // declare memebers this.raw = null; this.nodes = null; this.links = null; this.colorScale = null; this.n = null; this.max = 0; var alias = this; // process data // group by and count champion types this.raw = {}; jsonData.forEach(function(champion) { alias.raw[champion.primary] = (alias.raw[champion.primary]) ? alias.raw[champion.primary] + 1 : 1; }); // prepare nodes this.nodes = []; for (key in this.raw) { this.nodes.push({ category: key, count: this.raw[key], radius: this.raw[key] * 5 }); if (this.raw[key] > this.max) { this.max = this.raw[key]; } } this.links = []; for (var i = 0; i < this.nodes.length; ++i) { for (var j = 0; j < this.nodes.length; ++j) { if (j != i) { this.links.push({ source: i, target: j, graph: 0 }); } } } this.colorScale = d3.scale.category10(); for (var i = 0; i < this.nodes.length; ++i) { this.nodes[i].color = this.colorScale(i); } this.n = this.nodes.length; } Dataset.prototype.getNodes = function() { return this.nodes; } Dataset.prototype.getLinks = function() { return this.links; }