Skip to content

Sort the secondary dimension of bars by maximum value of the first dimension? #32

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

Closed
mbostock opened this issue Nov 4, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@mbostock
Copy link
Member

mbostock commented Nov 4, 2020

And for facets, the maximum across all facets?

@mbostock mbostock added the enhancement New feature or request label Nov 4, 2020
@mbostock
Copy link
Member Author

This can be done by manually specifying the scale’s domain, but it’s a bit of a pain.

@mbostock
Copy link
Member Author

Some examples:

domain: d3.sort(alphabet, (a, b) => d3.descending(a.frequency, b.frequency)).map(d => d.letter)
domain: d3.sort(data, (a, b) => d3.descending(a[2019] - a[2010], b[2019] - b[2010])).map(d => d.State)
domain: d3.rollups(data, group => d3.max(group, d => d.unemployment), d => d.division)
  .sort(([, a], [, b]) => d3.descending(a, b))
  .map(([key]) => key)
domain: d3.rollups(movies, movies => d3.median(movies, Profit), Genre)
  .sort(([, a], [, b]) => d3.descending(a, b))
  .map(([key]) => key)

Feels like there are at least two cases to consider — with and without aggregation — though perhaps we could generalize.

@mbostock
Copy link
Member Author

We did a lot of exploration on this and decided to add d3.groupSort. Doing this as part of the mark specification felt too implicit and brittle.

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

No branches or pull requests

1 participant