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

d3.stratifyDot? d3.stratifySlash? #75

Closed
mbostock opened this issue Jan 11, 2017 · 7 comments
Closed

d3.stratifyDot? d3.stratifySlash? #75

mbostock opened this issue Jan 11, 2017 · 7 comments
Assignees
Labels

Comments

@mbostock
Copy link
Member

mbostock commented Jan 11, 2017

It’d be nice to have this convenience method for dot-separated ids such as Java class names:

d3.stratifyDot = d3.stratify().parentId(d => d.id.substring(0, d.id.lastIndexOf(".")));

Similarly for path names?

d3.stratifySlash = d3.stratify().parentId(d => d.id.substring(0, d.id.lastIndexOf("/")));
@mbostock
Copy link
Member Author

They should be immutable, of course:

var stratifyDot = d3.stratify().parentId(d => d.id.substring(0, d.id.lastIndexOf("."))),
    stratifySlash = d3.stratify().parentId(d => d.id.substring(0, d.id.lastIndexOf("/")));

d3.stratifyDot = function(data) {
  return stratifyDot(data);
};

d3.stratifySlash = function(data) {
  return stratifySlash(data);
};

@mbostock
Copy link
Member Author

Or with implied parents (#33):

var stratifyDot = d3.stratify().ancestorId(id => id.substring(0, id.lastIndexOf("."))),
    stratifySlash = d3.stratify().ancestorId(id => id.substring(0, id.lastIndexOf("/")));

d3.stratifyDot = function(data) {
  return stratifyDot(data);
};

d3.stratifySlash = function(data) {
  return stratifySlash(data);
};

@mbostock
Copy link
Member Author

mbostock commented Jan 12, 2017

So, it might be nice if it’s configurable, since you could have datum.path rather than datum.id (e.g., the D3 source treemap’s d3.csv). In that case, you might want to do something like this:

var root = d3.stratifySlash().id(d => d.path)(data);

Though perhaps it could be an optional accessor, like d3-array methods:

var root = d3.stratifySlash(data, d => d.path);

Either way it’s certainly simpler than:

var root = d3.stratify()
    .id(d => d.path)
    .parentId(d => d.path.substring(0, d.path.lastIndexOf("/")))
  (data);

@seemantk
Copy link

Hi @mbostock. This is a really cool module. Wondering if you'd consider having the delimiter be specifiable? Something like d3.stratify().delim('/') perhaps? Delimiters could be slashes, underscores, colons, etc (so far in my use cases, I've got colons and periods).

@ialarmedalien
Copy link

ialarmedalien commented Jul 28, 2018

It'd also be useful to pass in arrays -- e.g. for a taxonomic tree where the leaf nodes (species) have groupings at various levels, that data could be passed in array form as [ phylum, class, order, family, genus ] or (e.g.) [ phylum, class, order ] for nodes higher in the tree. The parentId is a slice(0,-1) operation on id.

Stratify is essentially creating a hierarchy using an array of items to group or classify the data—in the cases mentioned above, the array items are separated by dots or by slashes—so (to me) it makes more sense to have the most generic form, the array, and allow users to specify separators such as ., /, -, ::, or whatever else they might come across.

@mbostock
Copy link
Member Author

Those other approaches are all possible using d3.stratify directly as the general solution. If we generalize “d3.stratifySlash” too much the it won’t be more useful than the existing d3.stratify.

@Fil Fil added the idea label Aug 23, 2020
@mbostock
Copy link
Member Author

mbostock commented Dec 9, 2021

I feel this is mostly addressed by the new stratify.path #185. That could be extended to take a different delimiter, but you can also remap the input to use slashes, too (just be careful about escaping).

@mbostock mbostock closed this as completed Dec 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants