Skip to content
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

Closed
DDDgfx opened this issue Dec 11, 2017 · 4 comments
Closed

Stratify > Hierarchy #102

DDDgfx opened this issue Dec 11, 2017 · 4 comments

Comments

@DDDgfx
Copy link

DDDgfx commented Dec 11, 2017

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?

@mbostock
Copy link
Member

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…

@DDDgfx
Copy link
Author

DDDgfx commented Dec 11, 2017

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.

@DDDgfx DDDgfx closed this as completed Dec 11, 2017
@mbostock
Copy link
Member

Thanks for the feedback; related #61 on that node.id issue.

@DDDgfx
Copy link
Author

DDDgfx commented Dec 11, 2017

#62 Understanding this would also have helped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants