Skip to content

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

Closed
@mbostock

Description

@mbostock

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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestquestionFurther information is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions