Skip to content
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

table: fix rebalancing of long merged columns, fixes #350 #353

Merged
merged 1 commit into from
Feb 10, 2025

Conversation

knrc
Copy link
Contributor

@knrc knrc commented Feb 10, 2025

Firstly, thanks very much for making this code available as it proved to be very useful for one of my projects. By way of a thank you I took a look at #350 and believe I have a solution for rebalancing the space from the merged cells. Please take a look. There may be some edge cases I have not considered, if you can think of any please let me know and I can rework the changes.

Proposed Changes

  • separate merged cell information from maximum column width calculation
  • calculate horizontal merged cell widths after header, body, foot complete
  • padding applied to smaller cells

Fixes #350.

Signed-off-by: Kevin Conner <kev.conner@gmail.com>
Copy link
Owner

@jedib0t jedib0t left a comment

Choose a reason for hiding this comment

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

I appreciate the compliments. Started out as my first "learn-golang" project, and I needed a table writer library with more control over the styles and sorting. 👍🏽

As to this PR, this is awesome. Thanks for fixing this bug. Before I merge it, can you take a look to see if the one comment below is a genuine bug and if it can be fixed?

│ 2 │ a.a.a.a │ Pod 1A │ NS 1A │ C 2 │ Y
├───┼──────────┼──────────┼──────────┼──────────┼─────────────────────────────────────────────────────────
│ 3 │ a.a.a.a │ Pod 1A │ NS 1A │ C 2 │ Y
└───┴──────────┴──────────┴──────────┴──────────┴─────────────────────────────────────────────────────────┘`)
Copy link
Owner

Choose a reason for hiding this comment

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

It looks like there might be a tiny bug with centering, or measuring the max length. In Row 1, merged Column 5/6 and merged Column 7/8 contents can be shrunk down further by 2 spaces (1 on each side).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can take a look at the details later this evening, will let you know what I find out.

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks! Not a deal breaker, but we may as well try while this code is fresh in our minds.

Copy link
Contributor Author

@knrc knrc Feb 10, 2025

Choose a reason for hiding this comment

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

It's a slight difference in implementation, the previous code was rounding down the mergedColumnLength when dividing by the numMergedColumns

maxLengthSplitAcrossColumns := mergedColumnLength / numMergedColumns

In this instance mergedColumnLength was 23, numMergedColums 2 and maxLengthSplitAcrossColumns was therefore 11 (22 instead of 23, missing one space).

The new code keeps track of the remaining space by subtracting each time, so is still padding out to 23 spaces length.

@jedib0t jedib0t merged commit 2b859b4 into jedib0t:main Feb 10, 2025
3 checks passed
@jedib0t
Copy link
Owner

jedib0t commented Feb 10, 2025

Thanks for the bug-fix @knrc !

@coveralls
Copy link

Pull Request Test Coverage Report for Build 13244372959

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 92 of 94 (97.87%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.05%) to 99.948%

Changes Missing Coverage Covered Lines Changed/Added Lines %
table/render_init.go 68 70 97.14%
Totals Coverage Status
Change from base Build 13083568565: -0.05%
Covered Lines: 3869
Relevant Lines: 3871

💛 - 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.

Bug: a size of columns with merged cells is not calculated correctly
3 participants