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

hierarchify #184

Closed
wants to merge 1 commit into from
Closed

hierarchify #184

wants to merge 1 commit into from

Conversation

mbostock
Copy link
Member

This helper for d3.stratify imputes internal nodes using the specified path function, which returns slash-separated ids (as per a typical UNIX-y file system). Fixes #33.

Now that JavaScript has all sorts of niceties for destructuring and optional arguments, I’d also like to start moving away from the D3 “getter-setter” pattern in favor of options objects. For example, instead of:

const root = d3.stratify().id(d => d.id).parentId(d => d.parentId)(data);

You’d say:

const root = d3.stratify(data, {id: d => d.id, parentId: d => d.parentId));

This allows D3 classes to favor immutability, and makes it easier to share options via the spread operator, too. I’ve done that internally here for d3.stratify, but the new option-based API is not exposed externally. I figure we can explore changing the internal API first, although I’m happy to revert this part if you think it’s too aggressive.

I originally thought about this being a path option for d3.stratify, but it’s a little awkward since if you specify the path option, it’ll ignore the id and parentId, so I thought maybe it would be better to separate the two. That said I might try a variant of this PR that is more minimal.

@mbostock mbostock requested a review from Fil October 24, 2021 19:48
@mbostock mbostock mentioned this pull request Oct 24, 2021
@mbostock
Copy link
Member Author

Closing this in favor of #185 to be more conservative, but I do think it may be worth adopting this options-based approach in the future. That said it would be a huge effort and would cause churn in the examples even if we do maintain backwards-compatibility (which I would strongly support doing).

@mbostock mbostock closed this Oct 24, 2021
@mbostock mbostock deleted the mbostock/stratify-path branch October 24, 2021 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Stratify could infer implied parent nodes?
1 participant