Repository navigation
Fit stacked bars to the requested width - #134
Merged
Merged
Conversation
Data.normalize() scales the largest single value to the width, so a stacked bar, which is the sum of its segments, could be several times wider than --width. Scale stacked charts by the largest row total and round the running total so that each bar's length follows its total.
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.
--stackedignored--width:Data.normalize()scales the largest single value to the width, but a stacked bar is the sum of its segments, so bars could be several times wider than requested.This overrides
StackedChart._normalize()to scale by the largest row total instead, so the longest stacked bar spans--widthand the others stay proportional to their totals. The running total is rounded rather than each segment, so a bar doesn't lose a block per segment to truncation.--scale(fixed units per tick) is unchanged.Fixes #69. This also covers the "bar wider than width" part of #83.
Before (example from the issue):
After:
Tests: two regression tests in
tests/test_charts.py(longest bar equals the width; bar lengths follow row totals). Both fail onmainand pass with the change.uv run python -m pytest: 90 passeduv run python -m ruff check .: passeduv run python -m mypy termgraph/: no issuestests/module-test*.pyall run