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

transition.selectChild[ren] #121

Closed
CodeSmith32 opened this issue Mar 23, 2021 · 2 comments
Closed

transition.selectChild[ren] #121

CodeSmith32 opened this issue Mar 23, 2021 · 2 comments

Comments

@CodeSmith32
Copy link

Similar to the recently added features in d3-selection, I noticed transitions lack the functions,

transition.selectChild(...)
transition.selectChildren(...)

I found it's often convenient to be able to rely on the tight coherencies between the selection and transition modules; e.g.:

var elem = d3.select('.my-elem');

if(condition) {
    elem = elem.transition()
        .duration(500)
        .ease(d3.easeExpOut);
}

elem.attr('opacity', 1)
    .selectChildren('rect')
        .attr('fill', 'green')
        .attr(...)
        ...

But, in this case it doesn't comply. Hope to see these get added soon!

@CodeSmith32
Copy link
Author

For those with the same issue, please note the following can be used for now as a work-around:

// define a helper function for conciseness
// (could be placed inline instead, but cannot be an arrow function)
function children() {
    return this.children;
}

var elem = d3.select('.my-elem');

if(condition) {
    elem = elem.transition()
        .duration(500)
        .ease(d3.easeExpOut);
}

elem.attr('opacity', 1)
    .selectAll(children).filter('rect') // use filter if selecting specific children
        .attr('fill', 'green')
        .attr(...)
        ...

@Fil
Copy link
Member

Fil commented Mar 24, 2021

We should do definitely do this, with d3/d3-selection#276

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