Skip to content

Conversation

@mbostock
Copy link
Member

@mbostock mbostock commented Apr 6, 2022

Introduces two new options transforms: Plot.treeNode, for laying out tree nodes, and Plot.treeLink, for laying out tree links. The new convenience mark Plot.tree combines a link, dot, and text with these options transforms to generate a tree diagram.

The Plot.treeNode options transform supports special evaluators for tree nodes. If a channel is defined as a string starting with “node:” then it is interpreted as one of the built-in node evaluators:

  • node:path - the normalized, slash-delimited path to this node
  • node:name - the last part of this node’s path
  • node:depth - this node’s distance from its furthest ascendant
  • node:height - this node’s distance from its furthest descendant
  • node:internal - true if this is an internal node; false if this is a leaf node

Alternatively you can specify a channel as an {node} object where node is a function. This function is then passed the d3-hierarchy node instance.

The Plot.treeLink options transform similarly supports special evaluators for tree links. If the “node:” prefix or {node} syntax is used, it refers to child node of the link; if the “parent:” prefix syntax is used, it refers to the parent node of the link. If the {link} syntax is used, the function is passed two arguments (child, parent) and can compute the desired corresponding value.

TODO

  • Use root.count or root.sum and expose a node:value somehow? Not now.
  • Support different sort orders (as a treeSort option?)
  • Support different separations (as a treeSeparation option?)
  • Support different orientations of the tree (as a treeAnchor option?)
  • Support faceting
  • Support imputed nodes
  • Documentation
  • Fix escaped backslashes when evaluating node:name
  • Have the path option default to identity
  • Ignore data with undefined path values

Related #136.

@mbostock mbostock requested a review from Fil April 6, 2022 23:49
@mbostock
Copy link
Member Author

Okay, I figured out how to get faceting and imputed nodes to work: now the tree transforms generate one element per node or per link, respectively, and for imputed nodes the associated data is null (but you can still access node-related metadata using a node accessor). Here’s a little example of the flare dataset with small nodes (<5000 bytes) on the left and large nodes (≥5000 bytes) on the right. Fun!

Screen Shot 2022-04-10 at 11 31 56 AM

Copy link
Contributor

@Fil Fil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! I've added a few suggestions (which can all be addressed later) in #843.

@mbostock mbostock merged commit e5bb1d6 into main Apr 11, 2022
@mbostock mbostock deleted the mbostock/tree branch April 11, 2022 21:40
@Fil Fil mentioned this pull request May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants