d3.treemap configuration
Treemap layout configuration methods: treemap.tile (set tiling method), treemap.size (set layout size), treemap.round (set whether output coordinates are rounded), treemap.padding (set padding), treemap.paddingInner (set padding between siblings), treemap.paddingOuter (set padding between parent and children), treemap.paddingTop, treemap.paddingRight, treemap.paddingBottom, treemap.paddingLeft (set individual edge padding).
d3 treemap tiling methods
Treemap tiling methods: d3.treemapBinary (balanced binary tree), d3.treemapDice (horizontal row), d3.treemapSlice (vertical column), d3.treemapSliceDice (alternate slice and dice), d3.treemapSquarify (squarified rows), d3.treemapResquarify (stable squarify updates). Squarify configuration: squarify.ratio (set desired aspect ratio).
treemap() constructor
treemap() creates a new treemap layout with default settings.
treemap(*root*) signature and properties assigned
treemap(*root*) lays out the specified root hierarchy, assigning four properties on root and its descendants: node.x0 (the left edge of the rectangle), node.y0 (the top edge of the rectangle), node.x1 (the right edge of the rectangle), and node.y1 (the bottom edge of the rectangle). You must call root.sum before passing the hierarchy to the treemap layout. You probably also want to call root.sort to order the hierarchy before computing the layout.
treemap.tile(*tile*) method
treemap.tile(*tile*) sets the tiling method to the specified function and returns the treemap layout. If tile is not specified, returns the current tiling method, which defaults to treemapSquarify with the golden ratio.
treemap.size(*size*) method
treemap.size(*size*) sets the treemap layout's size to the specified two-element array of numbers [width, height] and returns the treemap layout. If size is not specified, returns the current size, which defaults to [1, 1].
treemap.round(*round*) method
treemap.round(*round*) enables or disables rounding according to the given boolean and returns the treemap layout. If round is not specified, returns the current rounding state, which defaults to false.
treemap.padding(*padding*) method
treemap.padding(*padding*) sets both the inner and outer padding to the specified number or function and returns the treemap layout. If padding is not specified, returns the current inner padding function.
treemap.paddingInner(*padding*) method
treemap.paddingInner(*padding*) sets the inner padding to the specified number or function and returns the treemap layout. If padding is not specified, returns the current inner padding function, which defaults to the constant zero. If padding is a function, it is invoked for each node with children, being passed the current node. The inner padding is used to separate a node's adjacent children.
treemap.paddingOuter(*padding*) method
treemap.paddingOuter(*padding*) sets the top, right, bottom and left padding to the specified number or function and returns the treemap layout. If padding is not specified, returns the current top padding function.
treemap.paddingBottom(*padding*) method
treemap.paddingBottom(*padding*) sets the bottom padding to the specified number or function and returns the treemap layout. If padding is not specified, returns the current bottom padding function, which defaults to the constant zero. If padding is a function, it is invoked for each node with children, being passed the current node. The bottom padding is used to separate the bottom edge of a node from its children.
treemap.paddingLeft(*padding*) method
treemap.paddingLeft(*padding*) sets the left padding to the specified number or function and returns the treemap layout. If padding is not specified, returns the current left padding function, which defaults to the constant zero. If padding is a function, it is invoked for each node with children, being passed the current node. The left padding is used to separate the left edge of a node from its children.
treemapBinary(*node*, *x0*, *y0*, *x1*, *y1*) signature
treemapBinary(*node*, *x0*, *y0*, *x1*, *y1*) recursively partitions the specified nodes into an approximately-balanced binary tree, choosing horizontal partitioning for wide rectangles and vertical partitioning for tall rectangles.
treemapDice(*node*, *x0*, *y0*, *x1*, *y1*) signature
treemapDice(*node*, *x0*, *y0*, *x1*, *y1*) divides the rectangular area horizontally according to the value of each of the specified node's children. The children are positioned in order, starting with the left edge (x0) of the given rectangle. If the sum of the children's values is less than the specified node's value (if the specified node has a non-zero internal value), the remaining empty space will be positioned on the right edge (x1) of the given rectangle.
treemapSlice(*node*, *x0*, *y0*, *x1*, *y1*) signature
treemapSlice(*node*, *x0*, *y0*, *x1*, *y1*) divides the rectangular area vertically according to the value of each of the specified node's children. The children are positioned in order, starting with the top edge (y0) of the given rectangle. If the sum of the children's values is less than the specified node's value (if the specified node has a non-zero internal value), the remaining empty space will be positioned on the bottom edge (y1) of the given rectangle.
treemapSliceDice(*node*, *x0*, *y0*, *x1*, *y1*) signature
treemapSliceDice(*node*, *x0*, *y0*, *x1*, *y1*) delegates to treemapSlice if the specified node has odd depth, otherwise delegates to treemapDice.
treemapSquarify(*node*, *x0*, *y0*, *x1*, *y1*) signature
treemapSquarify(*node*, *x0*, *y0*, *x1*, *y1*) implements the squarified treemap algorithm by Bruls et al., which seeks to produce rectangles of a given aspect ratio.
treemapResquarify(*node*, *x0*, *y0*, *x1*, *y1*) signature
treemapResquarify(*node*, *x0*, *y0*, *x1*, *y1*) is like treemapSquarify, except it preserves the topology (node adjacencies) of the previous layout computed by d3.treemapResquarify, if there is one and it used the same target aspect ratio. This tiling method is good for animating changes to treemaps because it only changes node sizes and not their relative positions, thus avoiding distracting shuffling and occlusion. The downside of a stable update is a suboptimal layout for subsequent updates: only the first layout uses the Bruls et al. squarified algorithm.
squarify.ratio(*ratio*) method
squarify.ratio(*ratio*) specifies the desired aspect ratio of the generated rectangles. The ratio must be specified as a number greater than or equal to one. The orientation of the generated rectangles (tall or wide) is not implied by the ratio; for example, a ratio of two will attempt to produce a mixture of rectangles whose width:height ratio is either 2:1 or 1:2. The specified ratio is merely a hint to the tiling algorithm; the rectangles are not guaranteed to have the specified aspect ratio. If not specified, the aspect ratio defaults to the golden ratio, φ = (1 + sqrt(5)) / 2.
Treemap introduces recursively subdivided area layout
A treemap recursively subdivides area into rectangles according to each node's associated value. Introduced by Ben Shneiderman in 1991, D3's treemap implementation supports an extensible tiling method. The default squarified method seeks to generate rectangles with a golden aspect ratio, offering better readability and size estimation than slice-and-dice, which simply alternates between horizontal and vertical subdivision by depth.