(source)
| 88 | d3.select(self.frameElement).style("height", "800px"); |
| 89 | |
| 90 | function update(source) { |
| 91 | |
| 92 | // Compute the new tree layout. |
| 93 | var nodes = tree.nodes(root).reverse(), |
| 94 | links = tree.links(nodes); |
| 95 | |
| 96 | maxDepth = findMaxDepth(nodes); |
| 97 | |
| 98 | // Normalize for fixed-depth. |
| 99 | nodes.forEach(function(d) { |
| 100 | d.y = maxDepth ? d.depth * (width / maxDepth) : 0; |
| 101 | }); |
| 102 | |
| 103 | // Update the nodes… |
| 104 | var node = svg.selectAll("g.node") |
| 105 | .data(nodes, function(d) { return d.id || (d.id = ++i); }); |
| 106 | |
| 107 | // Enter any new nodes at the parent's previous position. |
| 108 | var nodeEnter = node.enter().append("g") |
| 109 | .classed("node", true) |
| 110 | .classed("child", function(d) { return !d.children; }) |
| 111 | .classed("parent", function(d) { return d.children; }) |
| 112 | .classed("expandable", function(d) { return d._children && d._children.length; }) |
| 113 | .attr("transform", function(d) { return "translate(" + source.x0 + "," + source.y0 + ")"; }) |
| 114 | .on("click", click) |
| 115 | .on("mouseover", mouseover) |
| 116 | .on("mouseout", mouseout); |
| 117 | |
| 118 | nodeEnter.append("rect") |
| 119 | .attr("x", 1e-6) |
| 120 | .attr("y", 1e-6) |
| 121 | .attr("width", 1e-6) |
| 122 | .attr("height", 1e-6); |
| 123 | |
| 124 | nodeEnter.append("text") |
| 125 | .attr("x", function(d) { return d.children || d._children ? -nodeSize/2 : nodeSize/2; }) |
| 126 | .attr("dy", ".35em") |
| 127 | .attr("text-anchor", function(d) { return d.children || d._children ? "end" : "start"; }) |
| 128 | .text(function(d) { return d.name; }) |
| 129 | .style("fill-opacity", 1e-6) |
| 130 | .style("font-size", function(d) { return nodeSize/2 + "px" }); |
| 131 | |
| 132 | nodeEnter.each(appendIframe); |
| 133 | |
| 134 | // Update classes |
| 135 | node |
| 136 | .classed("child", function(d) { return !d.children; }) |
| 137 | .classed("parent", function(d) { return d.children; }) |
| 138 | .classed("expandable", function(d) { return d._children && d._children.length; }) |
| 139 | |
| 140 | // Transition nodes to their new position. |
| 141 | var nodeUpdate = node.transition() |
| 142 | .duration(duration) |
| 143 | .attr("transform", function(d) { |
| 144 | return "translate(" + d.y + "," + d.x + ")"; |
| 145 | }); |
| 146 | |
| 147 | nodeUpdate.select("rect") |
no test coverage detected