Skip to content

sort groups #414

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
wants to merge 3 commits into from
Closed

sort groups #414

wants to merge 3 commits into from

Conversation

Fil
Copy link
Contributor

@Fil Fil commented May 23, 2021

Don't sort the groups in Plot.group(); the only case where it makes a difference is when the groups are stacked, and the stacking order can be made explicit (see test: penguins-species-island).

Ordinal scales now accept a sort option, which can be:

  • "ascending": default, sorts in ascending order with undefined first
  • false, null (or input): sort in input order
  • "count": sort by the number of times each ordinal value is present in the marks.

Note: when using Plot.barY the "count" is equal to 1 for each bar—it is not the number of times each value is present in the data. However {sort: "count"} works well to sort facets, or an ordinal scale for a Plot.dot chart. See the discussion in #388 for more details.

The build and a few examples are available at https://observablehq.com/d/d797c5a9572385bd

…erence is when the groups are stacked, and the stacking order can be made explicit

related: #388
@Fil Fil force-pushed the fil/sort-groups branch from dbe399e to 277579a Compare May 23, 2021 16:03
@Fil Fil mentioned this pull request May 27, 2021
3 tasks
@Fil
Copy link
Contributor Author

Fil commented Jun 23, 2021

90% obsolete after #442 ; but not sorting groups is probably still a good idea. And sorting by count or input may still be useful for facet ordering.

@Fil Fil mentioned this pull request Jul 14, 2021
@Fil
Copy link
Contributor Author

Fil commented Jul 21, 2021

Note that #332 also takes care of facet sorting (by count, by input, or by value).

@mbostock
Copy link
Member

There’s a lot of overlap here with the new sort and filter options for bin and group #495. But related to #435, we don’t pass the key(s) to the group reducer, so it’s not currently possible to implement the default natural ordering of groups and hence there’s a separate internal sorting that happens prior to the user-specified sort reducer. But I think we can make it work…

@mbostock
Copy link
Member

Removing the sort here also affects the bin transform, since the bin transform groups internally, too (e.g., on z). So this is extra tricky: maybe the sort reducer would also need to be passed the group keys in addition to the bin extents.

@mbostock
Copy link
Member

Going to close this as covered by #495, but I recognize there are still things to do (mostly covered by #435).

@mbostock mbostock closed this Aug 11, 2021
@Fil Fil mentioned this pull request Aug 14, 2021
8 tasks
@Fil Fil deleted the fil/sort-groups branch June 7, 2023 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants