-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stratify > Hierarchy #102
Comments
d3.stratify and d3.hierarchy do the same thing: they return a root node. The difference is that d3.hierarchy constructs a hierarchy (a root node) from a hierarchical input data structure (typically derived from JSON), whereas d3.stratify constructs a hierarchy from a tabular input data structure (typically derived from CSV or TSV). Both d3.stratify and d3.hierarchy are documented in the Hierarchy section of the README, which includes an example of converting a table to a hierarchy: var root = d3.stratify()
.id(function(d) { return d.name; })
.parentId(function(d) { return d.parent; })
(table); And it explicitly says “This hierarchy can now be passed to a hierarchical layout, such as d3.tree, for visualization.” The constructor also says it “generates a new hierarchy.” Apologies for the confusion, but I’m not sure how I can make it clearer… |
Yes. I see now. Also - realize that even after a hierarchy has been pushed through a layout such as d3.tree you could still call .count() or .sum(). But I guess one way that a hierarchy from d3.stratify would be different than a hierarchy from d3.hierarchy would be the presence of reserved ID property. Thank you as always Mike. |
Thanks for the feedback; related #61 on that node.id issue. |
#62 Understanding this would also have helped. |
Just a comment here. Spent a long time today trying to make a layout from flat data by using d3.stratify but running into trouble when I then ran the output through d3.hierarchy. Its not clear in the docs that d3.stratify's output is a legit hierarchy object that you can run .count() and .sum() on. Since sum and count were not listed under stratify, I assumed I had to go through hierarchy to get them. The result was double nested data objects.
It seem like in fact, stratify is the same as hierarchy, with a preceeding d3.nest stage. Is that true?
The text was updated successfully, but these errors were encountered: