(sel, node)
| 21 | // based on http://bl.ocks.org/mbostock/4339083 |
| 22 | // https://twitter.com/bizweekgraphics/status/608467609416298496 |
| 23 | function treeMe(sel, node) { |
| 24 | |
| 25 | var margin = {top: 20, right: 120, bottom: 20, left: 120}, |
| 26 | width = sel.node().offsetWidth - margin.right - margin.left, |
| 27 | height = 800 - margin.top - margin.bottom; |
| 28 | |
| 29 | var i = 0, |
| 30 | duration = 1000, |
| 31 | nodeSize = 30, |
| 32 | hoverCoef = 5, |
| 33 | root; |
| 34 | |
| 35 | var tree = d3.layout.tree() |
| 36 | .size([height, width]); |
| 37 | |
| 38 | var diagonal = d3.svg.diagonal() |
| 39 | .projection(function(d) { return [d.y, d.x]; }); |
| 40 | |
| 41 | var svg = sel.append("div.svg-container").append("svg") |
| 42 | .attr("width", width + margin.right + margin.left) |
| 43 | .attr("height", height + margin.top + margin.bottom) |
| 44 | .append("g") |
| 45 | .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); |
| 46 | |
| 47 | // invisible rect to capture mousemoves |
| 48 | svg.append("rect") |
| 49 | .attr("x", -margin.left) |
| 50 | .attr("y", -margin.top) |
| 51 | .attr("width", width + margin.right + margin.left) |
| 52 | .attr("height", height + margin.top + margin.bottom) |
| 53 | .style("visibility", "hidden") |
| 54 | .style("pointer-events", "all"); |
| 55 | |
| 56 | root = getDomTree(node); |
| 57 | root.x0 = height / 2; |
| 58 | root.y0 = 0; |
| 59 | |
| 60 | // TOO MANY CHILDREN |
| 61 | function truncate(d) { |
| 62 | if (d.children) { |
| 63 | d.children = d.children.slice(0,20); |
| 64 | d.children.forEach(truncate); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | function collapse(d) { |
| 69 | if (d.children) { |
| 70 | d._children = d.children; |
| 71 | d._children.forEach(collapse); |
| 72 | d.children = null; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | function findMaxDepth(nodes) { |
| 77 | return _.max(nodes.map(function(node, index) { |
| 78 | return node.children ? findMaxDepth(node.children) : node.depth; |
| 79 | })); |
| 80 | } |
no test coverage detected