Fix stacked bars generating zero-width segments - #592
Open
luc-x41 wants to merge 1 commit into
Open
Conversation
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.
When generating a stacked bar chart using pygal, we noticed that it still generates bar segments that should not be visible in the first place. Some renderers show this (notice the yellow sliver on the right of the bar in this zoomed-in screenshot):
The grey part is correct and has the value drawn somewhere to the left (this is the screenshot as I got it from a colleague). We have
show_zeroes=Falseand so the 0 value for the yellow metric is not shown (correctly), but the corresponding bar should also not be shown.This patch prevents pygal from generating the zero-width segments in the first place. I chose to use
math.isclose(value, 0)instead ofvalue == 0to avoid potential floating point comparison issues. The default tolerance is 1e-9, presumably chosen with CPython's default precision in mind. This function is available as of Python 3.5, whereas pygal requires 3.8.The new
test_bar_stacked.pyis adapted fromtest_bar.py(test_stacked.pyis already in use for line charts). I assume the copyright notice should be repeated everywhere regardless of who contributed a file so I left it as-is.Per the contributing guidelines: