// Generated by CoffeeScript 1.10.0 (function() { var arc, color, color_opacity, get_color, height, lod, partition, radius, set_size, svg, width, zoom, zoomable_layer; width = 960; height = 500; radius = Math.min(width, height) * 2; color_opacity = 0.7; 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 (20 / z < d.dx * Math.pow(d.dy, 0.4)) { return 'inline'; } else { return 'none'; } } }); }; partition = d3.layout.partition().size([2 * Math.PI, radius * radius]).sort(null).value(function(d) { return d.size; }); 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.category20(); get_color = function(node) { if (node['tree_root'] != null) { return color(node.name); } else { return get_color(node.parent); } }; set_size = function(d) { var sum; if (d.children == null) { d.size = 1; return 1; } else { sum = 1; d.children.forEach(function(c) { return sum += set_size(c); }); d.size = sum; return sum; } return d; }; d3.json('tree.json', function(error, root) { var enter_labels, labels, nodes, sectors; console.log(root); tree_utils.canonical_sort(root); set_size(root); nodes = partition.nodes(root); sectors = zoomable_layer.selectAll('.sector').data(nodes); sectors.enter().append('path').attr({ "class": 'sector', d: arc, fill: function(d) { if (d.name === "SemanticArts") { return '#cfcfcf'; } else { return get_color(d); } } }); sectors.exit().remove(); labels = zoomable_layer.selectAll('.label').data(nodes); enter_labels = labels.enter().append('g').attr({ "class": 'label', transform: function(d) { if (d.name === 'SemanticArts') { 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)) + ")"; } } }); enter_labels.append('text').attr({ "class": 'halo semantic_zoom', dy: '0.35em' }).text(function(d) { return d.name.replace('http://ontologies.semanticarts.com/', ''); }); enter_labels.append('text').attr({ "class": 'semantic_zoom', dy: '0.35em' }).text(function(d) { return d.name.replace('http://ontologies.semanticarts.com/', ''); }); return lod(1); }); }).call(this);