All examples By author By category About

ialarmedalien

StackOverflow: treemap parent node grouping

Demonstration of a couple of possible methods for highlighting or labelling a group of elements in a treemap layout.

This treemap layout instantiation produces a g element for each item in a hierarchical data structure; leaf nodes have a text element with the item name in it, and a black stroke around the edge; the g node representing the parent term has a colour fill. Nodes are labelled with a class name derived from the item name with spaces and special characters removed, and leaf, internal, or root, depending on their position in the hierarchy.

The default highlighting scheme in this layout adds a highlight class to the g element representing the parent node for a certain country; e.g. clicking on China in the legend highlights the g element matching the selection criteria .internal.China. It could easily be adapted to apply the class to all .China nodes or .leaf.China elements. CSS can be used to change the appearance of the elements.

A second method of highlighting the parent element is to create an overlay which takes its position and dimensions from the parent. This can be styled as desired.

For Stack Overflow question how to group g elements in d3.