// Generated by CoffeeScript 1.10.0 (function() { var by_value, height, svg, width; svg = d3.select('body').append('svg'); width = d3.select('svg').node().getBoundingClientRect().width - 50; height = d3.select('svg').node().getBoundingClientRect().height - 50; by_value = function(a, b) { if (a.value < b.value) { return -1; } else if (a.value > b.value) { return 1; } else { return 0; } }; d3.csv('links.csv', function(error, data) { var margin_left, node_info, point_group, points, root, vis, x, y; data.forEach(function(d) { if (d.parent === "") { return d.parent = "root"; } }); data.push({ name: "root", parent: "" }); root = (d3.stratify().id(function(d) { return d.name; }).parentId(function(d) { return d.parent; }))(data); root.count(); /* Vis */ vis = svg.append('g'); margin_left = 40; data = root.children.map(function(child) { return { id: child.id, value: child.value, height: child.height }; }).sort(by_value); x = d3.scaleLinear().domain([2, 8500]).range([0, width]); y = d3.scaleLinear().domain([1, 19]).range([height, 0]); vis.append('g').attrs({ transform: "translate(" + margin_left + ", " + height + ")" }).call(d3.axisBottom(x)).append('text').attrs({ fill: '#000', transform: "translate(" + width + ", 30)", 'text-anchor': 'end' }).text("Power Node Leaf Count"); vis.append('g').attrs({ transform: "translate(" + margin_left + ", 0)" }).call(d3.axisLeft(y)).append('text').attrs({ fill: '#000', transform: 'rotate(-90)', y: 6, dy: '0.71em', 'text-anchor': 'end' }).text("Power Node Depth"); point_group = vis.append('g').attrs({ transform: "translate(" + margin_left + ", 0)" }); points = point_group.selectAll('.point').data(data); points.enter().append('circle').attrs({ "class": 'point', r: 2, cx: function(d) { return x(d.value); }, cy: function(d) { return y(d.height); } }).on('mouseover', function(d) { d3.select(this).attrs({ r: 5 }); d3.select('.info').attrs({ transform: "translate(" + (x(d.value)) + ", " + (y(d.height)) + ")" }); return d3.select('.info text').text(d.id + " " + d.value + " " + d.height); }).on('mouseout', function(d) { d3.select(this).attrs({ r: 2 }); return d3.select('.info text').text(''); }); node_info = vis.append('g').attrs({ "class": 'info' }); return node_info.append('text').attrs({ y: -10 }).text(''); }); }).call(this);