Skip to content

descending order #1607

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

Merged
merged 3 commits into from
May 22, 2023
Merged

descending order #1607

merged 3 commits into from
May 22, 2023

Conversation

mbostock
Copy link
Member

@mbostock mbostock commented May 22, 2023

Instead of interpreting reverse: true as “sort by descending natural order”, the ChannelDomainOptions interface now has an order option which can be ascending, descending, or a comparator function (which compares two [name, value] tuples). This better matches the SortOrder interface, and enables two new features:

  1. If you set order: null you get input order (order of first occurrence in the data).
  2. If you set reverse: true you get true reverse order, putting null/unorderable values first when sorting, or reverse input order when not sorting, in the same manner as the basic sort transform.

I’m leaving this as draft because we should probably add tests for both of these new features. Added tests!

Fixes #1460. Ref. #1606 (comment)

@mbostock mbostock requested a review from Fil May 22, 2023 00:11
@mbostock mbostock force-pushed the mbostock/sort-order branch from 2d13457 to 04e993a Compare May 22, 2023 15:43
@mbostock mbostock marked this pull request as ready for review May 22, 2023 15:43
@@ -46,6 +45,7 @@ export * from "./cars-hexbin.js";
export * from "./cars-jitter.js";
export * from "./cars-mpg.js";
export * from "./cars-parcoords.js";
export * from "./channel-domain.js";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m following the principle here that test names should indicate which features are being tested, rather than tests being feature-agnostic examples. We can have the latter, too, but here the tests are intended to test imputed channel domains so it’s better to call them that.

@mbostock mbostock mentioned this pull request May 22, 2023
Copy link
Contributor

@Fil Fil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an aside, we can now do this if we need to use the raw grouped values for sorting (not that I'd recommend it, but…)

  channels: {index: (d, i) => i},
  sort: {
    fy: "index",
    reduce: (index) => index,
    order: ([group, index]) => console.warn(Array.from(index, (i) => movies[i])) // replace with a comparator on ([groupA, indexA], [groupB, indexB])
  }

Co-authored-by: Philippe Rivière <[email protected]>
@mbostock mbostock enabled auto-merge (squash) May 22, 2023 16:39
@mbostock mbostock merged commit 5c5acb7 into main May 22, 2023
@mbostock mbostock deleted the mbostock/sort-order branch May 22, 2023 16:40
chaichontat pushed a commit to chaichontat/plot that referenced this pull request Jan 14, 2024
* descending order

* fix null order; add tests

* Update src/channel.d.ts

Co-authored-by: Philippe Rivière <[email protected]>

---------

Co-authored-by: Philippe Rivière <[email protected]>
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.

The SortOrder interface could support a reverse option?
2 participants