// Generated by CoffeeScript 1.10.0 (function() { var HEADER, OFFSET, color, h, height, svg, treemap, vis, w, width, zoom, zoomable_layer; OFFSET = 0.1; HEADER = 0; svg = d3.select('svg'); width = svg.node().getBoundingClientRect().width; height = svg.node().getBoundingClientRect().height; w = width - 40; h = height - 40; treemap = d3.layout.treemap().size([w, h]).value(function(node) { return node.value; }).padding([OFFSET + HEADER, OFFSET, OFFSET, OFFSET]).sort(function(a, b) { h = d3.ascending(a.height, b.height); if (h === 0) { return d3.ascending(a.value, b.value); } return h; }); svg.attr({ viewBox: (-width / 2) + " " + (-height / 2) + " " + width + " " + height }); zoomable_layer = svg.append('g'); zoom = d3.behavior.zoom().scaleExtent([-Infinity, Infinity]).on('zoom', function() { return zoomable_layer.attr({ transform: "translate(" + (zoom.translate()) + ")scale(" + (zoom.scale()) + ")" }); }); svg.call(zoom); vis = zoomable_layer.append('g').attr({ transform: "translate(" + (-w / 2) + "," + (-h / 2) + ")" }); color = d3.scale.linear().domain([0, 17]).range([d3.hcl(320, 0, 20), d3.hcl(200, 70, 80)]).interpolate(d3.interpolateHcl); d3.json('isolario_power.json', function(tree) { var aggregate, cells, compute_height, compute_heights, data; aggregate = function(node) { if (node.children != null) { node.children.forEach(aggregate); return node.value = d3.sum(node.children, function(d) { return d.value; }); } }; aggregate(tree); compute_height = function(node) { if (node.children != null) { node.children.forEach(compute_height); return node.height = 1 + d3.max(node.children, function(d) { return d.height; }); } else { return node.height = 0; } }; compute_height(tree); data = treemap.nodes(tree); compute_heights = function(node) { var bchildren, bmax, rchildren, rmax; if (node.children != null) { node.children.forEach(compute_heights); rmax = d3.max(node.children, function(c) { return c.x + c.dx; }); rchildren = node.children.filter(function(d) { return (d.x + d.dx) >= rmax; }); node.height_r = 1 + d3.max(rchildren, function(d) { return d.height_r; }); bmax = d3.max(node.children, function(c) { return c.y + c.dy; }); bchildren = node.children.filter(function(d) { return (d.y + d.dy) >= bmax; }); return node.height_b = 1 + d3.max(bchildren, function(d) { return d.height_b; }); } else { node.height_r = 0; return node.height_b = 0; } }; compute_heights(tree); data.sort(function(a, b) { return d3.ascending(a.depth, b.depth); }); cells = vis.selectAll('.cell').data(data); return cells.enter().append('rect').attr({ "class": 'cell', x: function(d) { return d.x; }, y: function(d) { return d.y; }, width: function(d) { w = d.dx - 2 * OFFSET * d.height_r; if (w < 0) { return 0; } else { return w; } }, height: function(d) { h = d.dy - 2 * OFFSET * d.height_b; if (h < 0) { return 0; } else { return h; } }, fill: function(d) { return color(d.depth); }, stroke: function(d) { return color(d.depth + 0.5); } }).classed('leaf', function(d) { return (d.children == null) || d.children.length === 0; }); }); }).call(this);