// Generated by CoffeeScript 1.4.0 (function() { var SIZE, height, matrix, simcolor, svg, width, zoom, zoomable_layer; svg = d3.select('svg'); width = svg.node().getBoundingClientRect().width; height = svg.node().getBoundingClientRect().height; simcolor = d3.scale.linear().domain([0, 1]).range([d3.hcl(80, 0, 100), d3.hcl(80, 75, 25)]).interpolate(d3.interpolateHcl); zoomable_layer = svg.append('g'); zoom = d3.behavior.zoom().scaleExtent([1, 10]).on('zoom', function() { return zoomable_layer.attr({ transform: "translate(" + (zoom.translate()) + ")scale(" + (zoom.scale()) + ")" }); }); svg.call(zoom); matrix = zoomable_layer.append('g').attr('transform', 'translate(230,12)'); SIZE = 1.9; d3.json('//wafi.iit.cnr.it/webvis/tmp/dbpedia/pink_floyd_matrix.json', function(data) { var cells, clusters, enter_rows, index, items, matrix_data, rows, sequence, tree; index = {}; items = []; data.forEach(function(e1) { items.push(e1.k1); index[e1.k1] = {}; return e1.similarities.forEach(function(e2) { return index[e1.k1][e2.k2] = e2.sim; }); }); console.debug('Computing hierarchical clustering...'); clusters = clusterfck.hcluster(items, function(a, b) { return 1 - index[a][b]; }, clusterfck.SINGLE_LINKAGE); tree = tree_utils.binary_to_std(clusters); sequence = tree_utils.get_leaves(tree).map(function(d) { return d.value; }); matrix_data = []; sequence.forEach(function(k1) { var e1; e1 = { k1: k1, similarities: [] }; matrix_data.push(e1); return sequence.forEach(function(k2) { return e1.similarities.push({ k2: k2, sim: index[k1][k2] }); }); }); rows = matrix.selectAll('.row').data(matrix_data); enter_rows = rows.enter().append('g').attr('class', 'row').attr('transform', function(d, i) { return "translate(0," + (SIZE * i) + ")"; }); cells = rows.selectAll('.cell').data(function(row) { return row.similarities; }); cells.enter().append('rect').attr('class', 'cell').attr('width', SIZE).attr('height', SIZE).attr('transform', function(d, i) { return "translate(" + (SIZE * i) + ",0)"; }).attr('fill', function(d) { return simcolor(d.sim); }).append('title').text(function(d) { var k1, k2; k1 = d3.select(this.parentNode.parentNode).datum().k1.replace('http://dbpedia.org/resource/', ''); k2 = d.k2.replace('http://dbpedia.org/resource/', ''); return "" + k1 + "\n [" + (d3.format('%')(d.sim)) + "]\n" + k2; }); return matrix.append('rect').attr('class', 'border').attr('x', -1).attr('y', -1).attr('width', SIZE * matrix_data.length + 2).attr('height', SIZE * matrix_data.length + 2); }); }).call(this);