new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

D3 · all subjects

d3-hierarchy/tree

8 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

d3.tree configuration

Tree layout configuration methods: tree.size (set layout size), tree.nodeSize (set node size), tree.separation (set separation between nodes).

tree() constructor creates new tree layout

The tree() function creates a new tree layout with default settings. It uses the Reingold–Tilford 'tidy' algorithm, improved to run in linear time by Buchheim et al. Tidy trees are typically more compact than dendrograms.

tree(root) lays out hierarchy and assigns coordinates

Calling tree(root) lays out the specified root hierarchy, assigning x and y properties on root and its descendants. The node.x property is the x-coordinate of the node, and node.y is the y-coordinate of the node. The coordinates x and y represent an arbitrary coordinate system; for example, you can treat x as an angle and y as a radius to produce a radial layout. You may want to call root.sort before passing the hierarchy to the tree layout.

tree.nodeSize(size) sets or gets node size

If size is specified, tree.nodeSize(size) sets the tree layout's node size to the specified two-element array of numbers [width, height] and returns the tree layout. If size is not specified, it returns the current node size, which defaults to null. A node size of null indicates that a layout size will be used instead. When a node size is specified, the root node is always positioned at ⟨0, 0⟩.

tree.separation(separation) sets or gets separation accessor

If separation is specified, tree.separation(separation) sets the separation accessor to the specified function and returns the tree layout. If separation is not specified, it returns the current separation accessor. The default separation accessor is a function that returns 1 if both nodes share the same parent, and 2 otherwise.

tree default separation function

The default separation function for tree layout is: function separation(a, b) { return a.parent == b.parent ? 1 : 2; }. This returns 1 if nodes a and b share the same parent, and 2 otherwise.

tree separation function for radial layouts

A variation of the separation function more appropriate for radial layouts is: function separation(a, b) { return (a.parent == b.parent ? 1 : 2) / a.depth; }. This reduces the separation gap proportionally to the radius by dividing by the node's depth.

tree separation function receives two nodes

The separation accessor function is passed two nodes a and b, and must return the desired separation as a number. The nodes are typically siblings, though the nodes may be more distantly related if the layout decides to place such nodes adjacent.

Give your agent this brain