// Generated by CoffeeScript 1.4.0 (function() { var DIST, SIDE, height, svg, vis, width; SIDE = 7; DIST = 8; svg = d3.select('svg'); width = svg.node().getBoundingClientRect().width; height = svg.node().getBoundingClientRect().height; vis = svg.append('g').attr({ transform: "translate(" + (width / 2) + ", " + (height - 10) + ")" }); d3.json('miserables.json', function(data) { var PAD, cellcolor, cells, icells, interactive_cells, labels_a, labels_b, length, max; length = data.nodes.length; max = d3.max(data.links, function(d) { return d.value; }); cellcolor = function(x) { return d3.hcl(270 - 40 * x / max, 30 - Math.pow(max / 2 - x, 2) / 400, 100 - 100 * x / max); }; data.links.forEach(function(l) { l.source = data.nodes[l.source]; return l.target = data.nodes[l.target]; }); data.nodes.forEach(function(d, i) { return d.i = i; }); cells = vis.selectAll('.cell').data(data.links); cells.enter().append('rect').attr({ "class": 'cell', x: -SIDE / 2, y: -SIDE / 2, width: SIDE, height: SIDE, transform: function(d) { return "rotate(-45) translate(" + ((d.source.i - length / 2) * DIST) + "," + ((d.target.i - length / 2) * DIST) + ")"; }, fill: function(d) { return cellcolor(d.value); } }); PAD = 4; labels_a = vis.selectAll('.label_a').data(data.nodes.slice(1)); labels_a.enter().append('text').each(function(d) { return d.label_a = d3.select(this); }).text(function(d) { return d.name; }).attr({ "class": 'label label_a', dy: '0.35em', transform: function(d) { return "rotate(45) translate(" + (-length / 2 * DIST - PAD - DIST / 2) + "," + ((-d.i + length / 2) * DIST) + ")"; } }); labels_b = vis.selectAll('.label_b').data(data.nodes.slice(0, -1)); labels_b.enter().append('text').each(function(d) { return d.label_b = d3.select(this); }).text(function(d) { return d.name; }).attr({ "class": 'label label_b', dy: '0.35em', transform: function(d) { return "rotate(-45) translate(" + (length / 2 * DIST + PAD - DIST / 2) + "," + ((d.i - length / 2) * DIST) + ")"; } }); icells = []; d3.range(0, length).forEach(function(y) { return d3.range(y + 1, length).forEach(function(x) { return icells.push({ x: x, y: y, source: data.nodes[x], target: data.nodes[y] }); }); }); interactive_cells = vis.selectAll('.interactive_cell').data(icells); return interactive_cells.enter().append('rect').attr({ "class": 'interactive_cell', x: -DIST / 2, y: -DIST / 2, width: DIST, height: DIST, transform: function(d) { return "rotate(-45) translate(" + ((d.x - length / 2) * DIST) + "," + ((d.y - length / 2) * DIST) + ")"; } }).on('mouseenter', function(d) { d.source.label_a.classed('highlighted_x', true); return d.target.label_b.classed('highlighted_y', true); }).on('mouseleave', function(d) { d.source.label_a.classed('highlighted_x', false); return d.target.label_b.classed('highlighted_y', false); }); }); }).call(this);