-
Notifications
You must be signed in to change notification settings - Fork 0
Cluster Layout
The cluster layout produces dendrograms: node-link diagrams that place leaf nodes of the tree at the same depth. For example, a cluster layout can be used to organize software classes in a package hierarchy:
The cluster layout is part of D3's family of hierarchical layouts. These layouts follow the same basic structure: the input argument to the layout is the root node of the hierarchy, and the output return value is an array representing the computed positions of all nodes. The layout has a size in x and y, but this represents an arbitrary coordinate system; for example, you can treat x as a radius and y as an angle to produce a radial rather than Cartesian layout.
The layout object returned by d3.layout.cluster is both an object and a function. That is: you can call the layout like any other function, and the layout has additional methods that change its behavior. Like other classes in D3, layouts follow the method chaining pattern where setter methods return the layout itself, allowing multiple setters to be invoked in a concise statement.
# d3.layout.cluster()
Creates a new cluster layout with the default settings. The default sort order is null. The default children accessor assumes each input node is an object with a children
array. The default separation function uses one node width for siblings, and two node widths for non-siblings. The default size is 1×1.
# cluster.sort([comparator])
If comparator is specified, sets the sort order of sibling nodes for the layout using the specified comparator function. If comparator is not specified, returns the current group sort order, which defaults to null for no sorting. The comparator function is invoked for pairs of nodes, being passed the input data for each node. The default comparator is null, which disables sorting and uses tree traversal order. For example, to sort sibling nodes in descending order by the associated input data's numeric value attribute, say:
function comparator(a, b) {
return b.value - a.value;
}
Sorting by the node's name or key is also common. This can be done easily using d3.ascending or d3.descending.
# cluster.children([children])
# cluster.links(nodes)
# cluster.separation([separation])
# cluster.size([size])