Fix too many bins protection for histogram distribution back end calls#1745
Merged
Conversation
bobular
commented
Jun 8, 2026
Member
Author
There was a problem hiding this comment.
This is the bug fix! Everything else is test-related. See the PR description for why I added tests
aurreco-uga
approved these changes
Jun 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
In
getSafeLowerBound(default-axis-range.ts), the "max bins" protection only triggered whenrangeMin === rangeMax. The real-world year variable hasrangeMin: 2000, rangeMax: 2004— not equal — so the guard was skipped, the lower bound defaulted to0, and adistributionrequest for0..2004withbinWidth: 1produced 2004 bins, exceeding the backend's 2000-bin limit.The equality check was a red herring: the actual danger is purely "would anchoring the lower bound at 0 produce too many bins?" — which is
rangeMax / binWidth > 2000, regardless of whetherrangeMinequalsrangeMax.The fix
Dropped the
rangeMin === rangeMax &&condition. Now whenever anchoring at 0 would blow the bin budget, the lower bound falls back torangeMin - binWidth(giving1999..2004→ 5 bins for the year case). The ordinary case (small positive variable) still starts at 0.No tests
Complex spaghetti logic can easily break (this bug being an example). The bin range code desperately needs refactoring but the only safe way to do this is build a wall of tests and make sure the refactor has no regressions. This is a big TODO but I thought it would be a good idea to start now. It turns out the test machinery had been neglected for some time, so we fixed that here (though the
useAnalysistest has been ignored for now because there arejesttransform problems with a transitive dependency tojquery- we already fixed one ford3)The test
packages/libs/eda/src/lib/core/utils/default-axis-range.test.ts— two cases againstnumberDateDefaultAxisRangedirectly: