Skip to content

An alternative approach for auto column widths #155

@jtrim-ons

Description

@jtrim-ons

Is your feature request related to a problem? Please describe.
Automatically calculated column widths don't take account of numeric values in columns, and sometimes don't quite match the width of the widest text in a column.

Describe the solution you'd like
Auto column widths calculated by summing the widths of the Arial characters that make up a string.

Describe alternatives you've considered
I've tried to implement a prototype of this in the PR linked below.

I measured Arial characters using JavaScript, and modified the calculation function in wrappers.py to use these character widths.

I've also changed the code to measure widths of numbers, assuming no more than 3 decimal places. I thought this might be useful if a column contains big numbers but has a very short heading.

Calculating the width of a string by adding up the widths of individual characters isn't completely accurate. For example, the width of 'Ta' is less than the the sum of the widths of 'T' and 'a'. However, the simple approach seems to do a good job. If you wanted, there might be a really accurate way to measure string width by looking at the width of each character when it appears after each other possible character.

Another possibility would be to use Pillow to find text widths. I think this would be slower.

Additional context
N/A

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions