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

Columns are not rendered when the table width exceeds the currently set width.Defaulting #35

Open
stillhart opened this issue Oct 13, 2020 · 1 comment

Comments

@stillhart
Copy link

N trailing columns are hidden when the table size exceeds the currently set width. I would assume that they should be vertically rendered as it is already happening with the non hidden columns.

Steps to reproduce the problem

Case 1

require 'tty-table'
rows = [(1..15).to_a.map(&:to_s)]
table = TTY::Table.new rows
puts table.render(width: 30)

Case 2

rows = [(1..15).to_a.map(&:to_s) * 10]
table = TTY::Table.new rows
puts table.render(width: 30)

The width of 30 is artifical. You can also resize your terminal window to a size smaller than all rows combined.

Actual behaviour

Case 1

The table size exceeds the currently set width.Defaulting to vertical orientation.
1 1
2 2

Case 2

The table size exceeds the currently set width.Defaulting to vertical orientation.
1 1
2 2
3 3
4 4
1 1
2 2
3 3
4 4
1 1
2 2
3 3
4 4

I do not see the reason for this behaviour in the code yet. It does not make sense to render more or less columns depending on the amount of given rows and columns.

Expected behaviour

Case 1

The table size exceeds the currently set width.Defaulting to vertical orientation.
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
13 13
14 14
15 15

Case 2

1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
13 13
14 14
15 15
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
13 13
14 14
15 15
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
13 13
14 14
15 15
...  # total 10 times

Describe your environment

  • OS version: Redhat, MacOS Catalina
  • Ruby version: 2.7.0
  • TTY::Table version: 0.12.0 & master

Thanks

Thank you for your great tty gems. I truly love them all and they provide joy to my job. I do not expect a bugfix but merely want to provide a report of the bug.

pgorgita pushed a commit to pgorgita/tty-table that referenced this issue Mar 17, 2021
@pgorgita
Copy link

pgorgita commented Mar 17, 2021

Hi,

i think that the issue lies at TTY::Table::Orientation::Vertical::slice called by TTY::Table::rotate_vertical when the header is nil and it generates a 'head' to number the columns as rows:

head = header ? header : (0..rows_size).map { |n| (n + 1).to_s }

Without header it gets limited to the rows_size:

t_rows = ['H', 'a', 'b', 'c'].map{|l| 9.times.map{|n| [l, n].join('_') } }
table = TTY::Table.new(t_rows)
puts table.render(width: 18)
The table size exceeds the currently set width.Defaulting to vertical orientation.
1 H_0
2 H_1
3 H_2
4 H_3
5 H_4
1 a_0
2 a_1
3 a_2
4 a_3
5 a_4
1 b_0
2 b_1
3 b_2
4 b_3
5 b_4
1 c_0
2 c_1
3 c_2
4 c_3
5 c_4
=>   ##nil

Providing a header it prints all columns:

table = TTY::Table.new(t_rows.shift, t_rows)
puts table.render(width: 18)
The table size exceeds the currently set width.Defaulting to vertical orientation.
H_0 a_0
H_1 a_1
H_2 a_2
H_3 a_3
H_4 a_4
H_5 a_5
H_6 a_6
H_7 a_7
H_8 a_8
H_0 b_0
H_1 b_1
H_2 b_2
H_3 b_3
H_4 b_4
H_5 b_5
H_6 b_6
H_7 b_7
H_8 b_8
H_0 c_0
H_1 c_1
H_2 c_2
H_3 c_3
H_4 c_4
H_5 c_5
H_6 c_6
H_7 c_7
H_8 c_8
=>   ##nil

Generating the head at vertical.rb#L29 with the columns_count instead:

 head = header ? header : (1..table.columns_count).map(&:to_s)

seems to fix the issue:

puts table.render(width: 18)
The table size exceeds the currently set width.Defaulting to vertical orientation.
1 H_0
2 H_1
3 H_2
4 H_3
5 H_4
6 H_5
7 H_6
8 H_7
9 H_8
1 a_0
2 a_1
3 a_2
4 a_3
5 a_4
6 a_5
7 a_6
8 a_7
9 a_8
1 b_0
2 b_1
3 b_2
4 b_3
5 b_4
6 b_5
7 b_6
8 b_7
9 b_8
1 c_0
2 c_1
3 c_2
4 c_3
5 c_4
6 c_5
7 c_6
8 c_7
9 c_8
=> nil

Please tell me if you would wish a pull request.

Cheers,

Paulo

pgorgita pushed a commit to pgorgita/tty-table that referenced this issue Mar 19, 2021
pgorgita pushed a commit to pgorgita/tty-table that referenced this issue Mar 19, 2021
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

No branches or pull requests

2 participants