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

Select all child elements using selectAll() with no arguments #63

Closed
mindrones opened this issue Feb 28, 2016 · 7 comments
Closed

Select all child elements using selectAll() with no arguments #63

mindrones opened this issue Feb 28, 2016 · 7 comments

Comments

@mindrones
Copy link

I'd like to select all child elements using sel.selectAll() with no arguments, instead of having to use sel.selectAll('*'), because it's more concise and expressive: it just reads "select all", perfect to me.

What do you think?

@mbostock
Copy link
Member

I’m in favor of parsimony and explicitness, and I think selection.selectAll("*") is both clear and easy to type if that’s the behavior you want. Making that the default behavior when there is no argument would make the behavior less obvious to someone reading the code.

@mindrones
Copy link
Author

OK, thanks!

@adumesny
Copy link

adumesny commented Apr 16, 2020

would have to agree with @mindrones . I expected selectAll() to just work (I was doing selectAll('g') but now need to support different children), and instead had to find this solution.
But then again I want to select just immediate children not all nested nodes... so looks like I need to look somewhere else anyway...

@mbostock
Copy link
Member

I’d support selection.selectAll() throwing an error, though I’d want to use arguments.length to check because selection.selectAll(undefined) should be equivalent to selection.selectAll("undefined").

@adumesny
Copy link

adumesny commented Apr 16, 2020

while I have your attention :) seems like selecting all your immediate children ought to be dead simple... this is what I had to use, and complains in Typescript even with latest @types/selection (so have to cast to any - yuck)

this.container.selectAll(function() {return this.childNodes;} as any)

(where container is selection of my svg root).
Would have been nice to have a selectChildren() (which could take for example 'g' for immediate node instead of all nested g, or empty for '*') shortcut for what might be very common - see https://stackoverflow.com/questions/20569670/d3-selector-for-immediate-children

@mbostock
Copy link
Member

Yeah, I could see selection.selectChildren (and selection.selectChild?) as being useful, and I could imagine the selector being optional there. I’d use element.children instead of element.childNodes, however, since you wouldn’t want to select text nodes.

@adumesny
Copy link

should I file a separate request to have selection.selectChildren ?

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

3 participants