Skip to content

Make N+1 bin optional in histogram #1831

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Make N+1 bin optional in histogram #1831

wants to merge 1 commit into from

Conversation

axelboc
Copy link
Contributor

@axelboc axelboc commented Jun 26, 2025

It's the same issue we had with the heatmap vis: the x axis needs to go up to the right-hand edge of the last bin; otherwise we can't compute the width of the last bar and we get a NaN width warning in the browser console.

This PR makes the extra value in the bins array optional. If it's not present, we assume we want the same step value as between the last and second last bins.

@axelboc axelboc changed the title Make N+1 bin optional Make N+1 bin optional in histogram Jun 26, 2025
@@ -41,6 +41,7 @@ function Histogram(props: Props) {
} = props;
const { colorMap, invertColorMap } = props;

const bins = usePixelEdgeValues(rawBins, values.length);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps no longer the best name for this hook 😅

@axelboc axelboc requested a review from loichuder June 26, 2025 10:30
@loichuder
Copy link
Member

Sorry, I don't get why it should be optional from the description of the issue:

the x axis needs to go up to the right-hand edge of the last bin; otherwise we can't compute the width of the last bar and we get a NaN width warning in the browser console.

Sounds like you do want the last bin, then ? How making it optional helps ?

@axelboc
Copy link
Contributor Author

axelboc commented Jun 26, 2025

Sounds like you do want the last bin, then ? How making it optional helps ?

It depends what you consider to be the "last bin". Basically here, I'm allowing the bins array to have the same size as the values array, which feels more logical (i.e. one bin = one value). The extra item in the bins array (if passed) is purely for plotting purposes, so the idea is for consumers not to have to worry about it.

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