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

enable onClick for bar charts with quantitative scales. #633

Closed
gordonwoodhull opened this issue Jul 10, 2014 · 7 comments
Closed

enable onClick for bar charts with quantitative scales. #633

gordonwoodhull opened this issue Jul 10, 2014 · 7 comments
Milestone

Comments

@gordonwoodhull
Copy link
Contributor

title says it all.

seems to be enabled for all other charts except for line charts (where probably the dots would make the most sense).

@gordonwoodhull
Copy link
Contributor Author

I think the answer has to do with the way selection is baked into the charts. So, since bar charts with an ordinal x axis have click-to-select, whereas charts with quantitative x axes have brush-to-select, it was implemented this way.

If you want something besides those selection modes (or don't want selection at all), it might make sense to want to override onClick.

@emiguevara
Copy link

Hey there. Was looking for an explanation for this, and just found the answer in #168
Basically, NickQiZhu decided not to implement just because. Totally random, if you ask me.
I'm working more and more with dc.js, and I love it, but I'm frustrated by these completely idiosyncratic and undocumented bits... I'd like to get into the code, but my Javascript skills are a bit shaky.

@gordonwoodhull
Copy link
Contributor Author

@emiguevara: Sure... it was developed for a demo and became wildly popular because it provides a nice abstraction, wrapping the data. And a lot of different people contributed stuff, who all had different ideas how it should work.

So it was never really designed in any consistent way. I tell myself that I'll start over with a consistent design in 3.0, but there are a lot of charting libraries that died when someone started a rewrite, so for now I'm just trying to fix bugs. :-)

Although it's pretty easy to add this with a renderlet, I'll see about doing it automatically in 2.1. (If it conflicts with the brush, then only when brushing is off.)

@gordonwoodhull
Copy link
Contributor Author

Question answered. Retitling.

@gordonwoodhull gordonwoodhull added this to the v2.1 milestone Nov 30, 2014
@gordonwoodhull gordonwoodhull changed the title why is onClick only enabled for ordinal bar charts? enable onClick for bar charts with quantitative scales. Nov 30, 2014
@luukgruijs
Copy link

any updates on this? It still doesn't seem changed

@gordonwoodhull
Copy link
Contributor Author

Nope. But dc.js is an intentionally leaky abstraction, so you can almost always work around these quirks.

chart.on('pretransition', function(chart) {
    chart.selectAll('rect.bar').on('click.yourNamespace', function(d) {
        // do stuff here - d contains the datum
    });
});

Patches welcome!

@gordonwoodhull
Copy link
Contributor Author

The new ordinal range/focus example shows how to implement ordinal-style click-to-toggle on a linear scale chart.

I think the code should suffice for any place one wants to enable clicking instead of brushing on a bar chart. If not, we could add another example.

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

No branches or pull requests

3 participants