Skip to content

fix: display values for Y-axis when data points are all identical #65

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: master
Choose a base branch
from

Conversation

viiccwen
Copy link

Problem Description

When all data points in a series have identical values (e.g., [1, 1, 1, 1, 1]), the Y-axis would not display the correct value labels. This occurred because when the interval between minimum and maximum values is zero, the calculation for Y-axis labels would fail to produce meaningful output.

Issues

resolves #61

Root Cause

The issue was in the Y-axis label calculation logic in asciigraph.go. When interval = 0 (all data points are identical), the code would set ratio = 1 but the subsequent calculations for rows and Y-axis label positioning would not handle this edge case properly, resulting in missing or incorrect Y-axis values.

Fix Details

The fix ensures that when all data points are identical:

  • The Y-axis properly displays the single value that all data points represent
  • The graph maintains a minimum height to show the value clearly
  • The axis labels are correctly positioned and formatted

Impact

  • Y-axis now correctly displays values when all data points are identical
  • Graphs with flat data (all same values) are now properly rendered
  • Maintains backward compatibility for all other use cases
  • Improves the visual representation of constant data series

I already asked about solving this in #61 comments~
If have any concerns, pls comment below! I'll reply ASAP.

- Fix Y-axis label rounding issue when interval is zero
- Use actual minimum value instead of calculated magnitude for Y-axis labels
- Improve visual clarity for constant data series

Closes guptarohit#61
@coveralls
Copy link

Pull Request Test Coverage Report for Build 16435238690

Details

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.5%) to 95.561%

Files with Coverage Reduction New Missed Lines %
asciigraph.go 2 99.05%
Totals Coverage Status
Change from base Build 11530076975: -0.5%
Covered Lines: 366
Relevant Lines: 383

💛 - Coveralls

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.

How to avoid rounding when data points are of the same value
2 participants