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

The group transform always sorts groups naturally; should this be configurable? #1678

Closed
mbostock opened this issue Jun 7, 2023 · 1 comment · Fixed by #1959
Closed

The group transform always sorts groups naturally; should this be configurable? #1678

mbostock opened this issue Jun 7, 2023 · 1 comment · Fixed by #1959
Assignees
Labels
enhancement New feature or request question Further information is needed

Comments

@mbostock
Copy link
Member

mbostock commented Jun 7, 2023

maybeGroup always sorts by the group key:

export function maybeGroup(I, X) {
return X
? sort(
grouper(I, (i) => X[i]),
first
)
: [[, I]];
}

Maybe there should be a way to turn this off if you want to render the groups in input order? It’s confusing because if you set the sort option to null, you don’t get input order, you get ascending natural order, which is different from most other cases. (It makes sense with the bin transform, though.)

/**
* How to order groups; if null (default), groups are returned in ascending
* natural order along *x*, *y*, and *z* (or *fill* or *stroke*). Group order
* affects draw order of overlapping marks, and may be useful with the stack
* transform which defaults to input order. For example to place the smallest
* group within each stack on the baseline:
*
* ```js
* Plot.groupX({y: "count", sort: "count"}, {fill: "sex", x: "sport"})
* ```
*/
sort?: T | null;

Ref. https://talk.observablehq.com/t/facet-custom-sort/8002/6

@mbostock mbostock added enhancement New feature or request question Further information is needed labels Jun 7, 2023
@mbostock
Copy link
Member Author

It seems to me that it should preserve the input order by default. This way the sort option would behave as expected: if you sort the input, then the groups will likewise be sorted.

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

Successfully merging a pull request may close this issue.

1 participant