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

can't pass d3 selection to chart constructor #1006

Closed
rjmorris opened this issue Sep 12, 2015 · 5 comments
Closed

can't pass d3 selection to chart constructor #1006

rjmorris opened this issue Sep 12, 2015 · 5 comments
Labels
Milestone

Comments

@rjmorris
Copy link

The documentation says the parent argument for dc chart constructors can be:

Any valid d3 single selector specifying a dom block element such as a div; or a dom element or d3 selection.

However, passing in a d3 selection doesn't work for me. Here's an illustration: http://jsfiddle.net/rjmorris/uv28k803. (This example uses the stable version of dc, but the same thing happens with the latest 2.0.0 beta.) Examining the source, it appears that in baseChart.anchor(), dc is select()ing my selection under the assumption that it's a selector string or a dom element. This causes an error later (TypeError: node.getAttribute is not a function) when d3 tries to add a class to the parent div.

@gordonwoodhull
Copy link
Contributor

Thanks for reporting, @rjmorris.

At some point I had the impression that d3.select was idempotent, that selecting a selection returns the selection. But that does not seem to be the case. The implementation should either detect this, or the documentation should be fixed.

Obviously the workaround is to pass selection.node() instead.

@gordonwoodhull gordonwoodhull added this to the v2.0 milestone Sep 12, 2015
@gordonwoodhull
Copy link
Contributor

So, yeah, superficially d3.select on a d3 selection appears to work, because d3 assumes the object is an HTML element and wraps it in another selection-array. Then stuff breaks later on.

I'm adding something to detect d3 selections based on what methods they support, and treat them appropriately.

@rjmorris
Copy link
Author

Great! Thanks for looking into this.

@gordonwoodhull
Copy link
Contributor

Closed (a few weeks ago) by 4d68611

@gordonwoodhull
Copy link
Contributor

gordonwoodhull commented Jun 8, 2016

For closure and rationale: d3/d3-selection#76

Fair enough, and that shows the right way to test if something is a selection (instanceof selection), which we should use.

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

No branches or pull requests

2 participants