// Generated by CoffeeScript 1.4.0 (function() { var RADIUS, arc, height, partition, svg, treechroma, treehue, treelum, vis, width, zoom, zoomable_layer; treehue = function(node, hue_range, fraction, rev) { var child, child_hue_ranges, half_n, i, n, r, ri, _i, _j, _len, _ref, _results; r = hue_range[1] - hue_range[0]; node.hue = hue_range[0] + r / 2; if (node.children != null) { n = node.children.length; ri = r / n; child_hue_ranges = []; half_n = Math.floor(n / 2); for (i = _i = 0; 0 <= half_n ? _i < half_n : _i > half_n; i = 0 <= half_n ? ++_i : --_i) { child_hue_ranges.push([hue_range[0] + ri * i + ri * (1 - fraction) / 2, hue_range[0] + ri * (i + 1) - ri * (1 - fraction) / 2]); child_hue_ranges.push([hue_range[0] + ri * (i + half_n) + ri * (1 - fraction) / 2, hue_range[0] + ri * (i + 1 + half_n) - ri * (1 - fraction) / 2]); } if (n % 2 === 1) { child_hue_ranges.push([hue_range[0] + ri * half_n + ri * (1 - fraction) / 2, hue_range[0] + ri * (1 + half_n) - ri * (1 - fraction) / 2]); } if (rev) { child_hue_ranges.reverse(); } _ref = node.children; _results = []; for (i = _j = 0, _len = _ref.length; _j < _len; i = ++_j) { child = _ref[i]; _results.push(treehue(child, child_hue_ranges[i], fraction, i % 2 === 0)); } return _results; } }; treelum = d3.scale.linear().range([80, 10]); treechroma = d3.scale.sqrt().range([0, 90]); RADIUS = 250; partition = d3.layout.partition().sort(null).size([2 * Math.PI, RADIUS * RADIUS]).value(function(node) { return node.leaf_count; }); arc = d3.svg.arc().startAngle(function(d) { return d.x; }).endAngle(function(d) { return d.x + d.dx; }).innerRadius(function(d) { return Math.sqrt(d.y); }).outerRadius(function(d) { return Math.sqrt(d.y + d.dy); }); svg = d3.select('svg'); width = svg.node().getBoundingClientRect().width; height = svg.node().getBoundingClientRect().height; svg.attr({ viewBox: "" + (-width / 2) + " " + (-height / 2) + " " + width + " " + height }); 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); vis = zoomable_layer.append('g'); d3.json('dbpedia_canonical.json', function(tree) { var enter_nodes, nodes; treehue(tree, [0, 360], 0.7); treelum.domain([0, 5]); treechroma.domain([0, 5]); vis.datum(tree); nodes = vis.selectAll('.node').data(function(t) { return partition.nodes(t); }); enter_nodes = nodes.enter().insert('path', 'path').attr({ "class": 'node', d: arc, fill: function(n) { return d3.hcl(n.hue, treechroma(n.depth), treelum(n.depth)); } }); enter_nodes.append('title').text(function(node) { return node.name.split('/').reverse()[0]; }); return vis.append('text').text(function(tree) { return tree.name.split('/').reverse()[0]; }).attr({ "class": 'label', dy: '0.35em' }); }); }).call(this);