concept dendrogram in category d3

This is an excerpt from Manning's book D3.js in Action, Second Edition: Data visualization with JavaScript.
Figure 1.6. D3 includes a library of common data visualization layouts, such as the dendrogram (explained in chapter 6), that let you represent data, such as this word tree.
![]()
The dendrogram is a generic way of displaying information. It can be repurposed for menus or information you may not think of as traditionally hierarchical. One example (figure 6.14) is from the work of Jason Davies, who used the dendrogram functionality in D3 to create word trees. A few hierarchical structures that follow this pattern are genealogies, sentence trees, and decision trees.
Figure 6.14. Example of using a dendrogram in a word tree by Jason Davies (www.jasondavies.com/wordtree/).
![]()
As with the other hierarchical charts, we need to first nest and process our data using d3.nest and d3.hierarchy. Unlike with the dendrogram we should use the partition layout’s sum function to set the size of the individual pieces to reflect the value of the underlying data (as we did with the final circle pack piece). After we pass the processed data to d3.partition, we can draw the rectangles, as described in the following listing.
Listing 6.4. Drawing a simple partition layout
var root = d3.hierarchy(packableTweets, d => d.values) .sum(d => d.retweets ? d.retweets.length + d.favorites.length + 1 : undefined) var partitionLayout = d3.partition() .size([500,300]) partitionLayout(root) #1 d3.select("svg") .selectAll("rect") .data(root.descendants()) .enter() .append("rect") .attr("x", d => d.x0) #2 .attr("y", d => d.y0) #2 .attr("width", d => d.x1 - d.x0) #3 .attr("height", d => d.y1 - d.y0) #3 .style("fill", d => depthScale(d.depth)) .style("stroke", "black")The result of that code is shown in figure 6.16, which shows the nodes in our hierarchical dataset in a new visual metaphor. Instead of parents being connected to children by lines like we see with dendrograms, or being visually enclosed in their parent like the circle packing does, the parent is stacked on top of its children and has a length equal to the sum of lengths of its children (which in our case is based on the number of retweets and favorites of a tweet).
Because the tweet labels are the content of the tweet, it’s pretty hard to read the labels drawing the dendrogram vertically like that. To turn it on its side, we need to adjust the positioning of the <g> elements by flipping the x and y coordinates, which orients the nodes horizontally. We also need to flip the x1, x2, y1, and y2 references for the svg:line element to orient the lines horizontally: