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

fix bars with maybe-ordinal reducers #1276

Merged
merged 1 commit into from
Feb 15, 2023
Merged

Conversation

mbostock
Copy link
Member

Fixes another bug where we assumed that reducers produce quantitative values. In some cases, e.g. with the mode reducer, reducing preserves the input value type. For example:

Plot.auto(penguins, {x: "island", y: {value: "species", reduce: "mode"}, mark: "bar"}).plot()

Before, barY is wrongly chosen, resulting in a degenerate plot:

Screenshot 2023-02-15 at 1 07 58 PM

After, cell is correctly chosen, since both x and y are ordinal:

Screenshot 2023-02-15 at 1 08 53 PM

@mbostock mbostock requested review from Fil and tophtucker February 15, 2023 21:09
Comment on lines +103 to +105
? isOrdinal(x) || isOrdinal(y) || (xReduce == null && yReduce == null && !isMonotonic(x) && !isMonotonic(y))
? "dot"
: "line"
Copy link
Member Author

Choose a reason for hiding this comment

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

(This is an unrelated change where I just wanted to get rid of isContinuous by replacing it with !isOrdinal. Sorry for the churn but hopefully it’s clear that this is not changing behavior!)

Copy link
Contributor

@tophtucker tophtucker left a comment

Choose a reason for hiding this comment

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

I love how this makes us think about the type signature of reducers like this! 😄

@mbostock mbostock merged commit d8378f0 into main Feb 15, 2023
@mbostock mbostock deleted the mbostock/fix-ordinal-reduce branch February 15, 2023 22:50
chaichontat pushed a commit to chaichontat/plot that referenced this pull request Jan 14, 2024
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