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

Ordinal series sorting #156

Closed
bchapuis opened this issue Apr 19, 2013 · 7 comments
Closed

Ordinal series sorting #156

bchapuis opened this issue Apr 19, 2013 · 7 comments

Comments

@bchapuis
Copy link

It would be great to add ordinal chart sorting. This could probably be achieved by creating a custom D3 scale based on the ordinal one that use a crossfilter group to manage the order of the absis.

d3.scale.ordinal().domain(["a", "b", "c", "..."]) 

May become:

dc.scale.ordinal().domain(crossfilterGroup)

The main application could be the creation of Pareto Charts.

@NickQiZhu
Copy link
Contributor

Interesting idea. I think you can do that with the existing implementation though probably not as usable. Sort your group in crossfilter then use sorted keys to generate the domain for your x scale. Does that solve your problem?

@bchapuis
Copy link
Author

Yes, I have already been able to produce ordered ordinal charts with something like that:

var domain = [];

group.top(Infinity).forEach(function(d) {
    domain[domain.length] = d.key;
});

chart
    .width(900)
    .height(250)
    .dimension(dimension)
    .group(group)
    .x(d3.scale.ordinal().domain(domain))
    .xUnits(dc.units.ordinal);

However, when this chart react to a selection made on another chart, this solution shows its limits. It is not possible to reorganise dynamically the ordinal axis. I wondered if a solution based on d3 scales would allows to handle this use case.

@NickQiZhu
Copy link
Contributor

What if you resets the x domain in .on("filtered", function(chart, filter){...}) hook, will that give you the desired effect?

@bchapuis
Copy link
Author

Great, thank you, it seems to be a good start. The bars are well sorted, however the legends remains at the same place. Any idea?

@bchapuis
Copy link
Author

It seem's to work when I call the render method that reset the chart completely.

@bchapuis
Copy link
Author

Thank you very much, dc.js is a fantastic tool.

It's even possible to use the redraw function to render the chart. The only requirement is to make the x axis elastic and everything works perfectly.

@NickQiZhu
Copy link
Contributor

Glad you have found to way to make it work :-) If you want to force a x axis re-render you can use the following code in postRedraw hook:

chart.renderXAxis(chart.g());

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

2 participants