// Generated by CoffeeScript 1.10.0 (function() { var arc, arcTween, color, color_opacity, duration, get_color, height, lod, partition, radius, redraw, svg, width, zoom, zoomable_layer; width = 960; height = 500; radius = Math.min(width, height) * 2; color_opacity = 0.7; duration = 2000; svg = d3.select('svg').attr({ width: width, height: height, viewBox: (-width / 2) + " " + (-height / 2) + " " + width + " " + height }); zoomable_layer = svg.append('g'); zoom = d3.behavior.zoom().scaleExtent([0.5, 64]).on('zoom', function() { zoomable_layer.attr({ transform: "translate(" + (zoom.translate()) + ")scale(" + (zoom.scale()) + ")" }); zoomable_layer.selectAll('.semantic_zoom').attr({ transform: "scale(" + (1 / zoom.scale()) + ")" }); return lod(zoom.scale()); }); svg.call(zoom); lod = function(z) { return zoomable_layer.selectAll('.semantic_zoom').attr({ display: function(d) { if (30 / z < d.dx * Math.pow(d.dy, 0.4)) { return 'inline'; } else { return 'none'; } } }); }; partition = d3.layout.partition().sort(null).size([2 * Math.PI, radius * radius]).value(function() { return 1; }); arc = d3.svg.arc().startAngle(function(d) { return d.x; }).endAngle(function(d) { return d.x + d.dx; }).innerRadius(function(d) { return Math.pow(d.y, 0.4); }).outerRadius(function(d) { return Math.pow(d.y + d.dy, 0.4); }); color = d3.scale.category10(); get_color = function(node) { return color(node.name.split('.')[0]); }; arcTween = function(a) { var i; i = d3.interpolate({ x: a.x0, dx: a.dx0 }, a); return function(t) { var b; b = i(t); a.x0 = b.x; a.dx0 = b.dx; return arc(b); }; }; redraw = function(flag) { return d3.json('tree.json', function(error, root) { var enter_labels, enter_sectors, enter_sectors_one, labels, nodes, sectors, sectors_one, value; tree_utils.canonical_sort(root); value = flag ? (function() { return 1; }) : (function(d) { return d.size; }); nodes = partition.value(value).nodes(root); sectors_one = zoomable_layer.selectAll('.sector_one').data(nodes.filter(function(d) { return d.depth < 2; })); enter_sectors_one = sectors_one.enter().append('path').attr({ "class": 'sector_one' }).each(function(d) { d.x0 = d.x; return d.dx0 = d.dx; }); enter_sectors_one.append('title'); sectors_one.attr({ d: arc, fill: function(d) { if (d.depth > 0) { return get_color(d); } else { return '#fff'; } } }); /*.transition() .duration duration .attrTween 'd', arcTween */ sectors_one.select('title').text(function(d) { return d.name + (d.desc != null ? "\n" + d.desc : ""); }); sectors_one.exit().remove(); sectors = zoomable_layer.selectAll('.s_link').data(nodes.filter(function(d) { return d.depth > 1; }), (function(d) { return d.name + "_" + flag; })); enter_sectors = sectors.enter().append('a').attr({ "class": 's_link', target: '_blank', 'xlink:href': function(d) { return d.url; } }); enter_sectors.append('path').attr({ "class": 'sector' }); enter_sectors.append('title'); sectors.select('path').attr({ d: arc, fill: function(d) { if (d.depth > 0) { return get_color(d); } else { return '#fff'; } } }); sectors.select('title').text(function(d) { return d.name + (d.desc != null ? "\n" + d.desc : ''); }); sectors.exit().remove(); labels = zoomable_layer.selectAll('.label').data(nodes, function(d) { return d.name + "_" + flag; }); enter_labels = labels.enter().append('g').attr({ "class": 'label' }); enter_labels.append('text').attr({ "class": 'halo semantic_zoom' }); enter_labels.append('text').attr({ "class": 'halo_text semantic_zoom' }); labels.attr({ transform: function(d) { if (d.name === 'DoGi') { return 'translate(0,0)'; } else { return "translate(" + ((Math.pow(d.y + d.dy / 2, 0.4)) * Math.cos(d.x + d.dx / 2 - Math.PI / 2)) + ", " + ((Math.pow(d.y + d.dy / 2, 0.4)) * Math.sin(d.x + d.dx / 2 - Math.PI / 2)) + ")"; } } }); labels.select('.halo').attr({ dy: '0.35em' }).text(function(d) { return d.name; }); labels.select('.halo_text').attr({ dy: '0.35em' }).text(function(d) { return d.name; }); d3.selectAll('input').on('change', function() { return redraw(this.value === 'count'); }); return lod(1); }); }; redraw(d3.select('input[checked]').node().value === 'count'); }).call(this);