tabled
tabled copied to clipboard
Vertically aligned tables and/or option to mirror/flip horizontally/vertically
@zhiburt if you currently have a table like this
A B C
-------
1 2 3
4 5 6
and want to display it like this instead
A 1 4
B 2 5
C 3 6
is there no way at all to do it?
If you use e.g. Rotate::Left
, you end up with
C 3 6
B 2 5
A 1 4
so you have to mirror it vertically to get it right.
Similarly, if you use Rotate::Right
, you have to mirror it horizontally.
Wonder if any of the following makes sense:
- Adding
Mirror::{Horizontal, Vertical}
(orFlip::*
) - An easier way for vertical alignment of the table and the header being vertical? (unless it already exists and I'm missing something)
Cheers.
Hi @aldanor
Thank you for opening the issue.
An easier way for vertical alignment of the table and the header being vertical? (unless it already exists and I'm missing something)
Actually I think you're right that it's not that easy and feels like we can do better.
Could you explain it a bit more how you'd see it to work?
#212 will allow building Style
es which are using the vertical split lines (will needed to modify Style
+ RawStyle
).
#126 it's an idea that table may have different arrangements. Yet I don't see how it shall work exactly. (is not on the map currently).
ref #130
is there no way at all to do it?
There's 2 ways which came to my mind. Both gives this result.
A 1 4
B 2 5
C 3 6
In both of these I am using Disable
which is probably not the best thing to do but it works as you may will see.
If you wonder if it's possible to flip borders, it is only manually using Border
+
Modify`.
using Rotate
You've mentioned already Rotate::Left
. Just do Rotate::Top
or Rotate::Bottom
next and it must work.
use tabled::{
style::{HorizontalLine, Line},
Disable, Rotate, Style, Table,
};
fn main() {
let data = [['A', 'B', 'C'], ['1', '2', '3'], ['4', '5', '6']];
let table = Table::new(data)
.with(Disable::Row(..1))
.with(Rotate::Left)
.with(Rotate::Top)
.with(Style::empty());
println!("{}", table);
}
using Builder::index
use tabled::{
style::{HorizontalLine, Line},
Disable, Style, Table,
};
fn main() {
let data = [['A', 'B', 'C'], ['1', '2', '3'], ['4', '5', '6']];
let mut builder = Table::builder(data).index();
builder.hide_index();
builder.transpose();
let table = builder
.build()
.with(Disable::Row(..1))
.with(Style::empty());
println!("{}", table);
}
Thanks, Rotate::Top
after Rotate::Left
actually works! (although is quite non-intuitive...)
Could you explain it a bit more how you'd see it to work?
What I meant is an easy flag of saying - hey, this is a vertical table, where headers are in first column and entries are columns and not rows (e.g. table.with(Vertical)
or something), so everything include the cells themselves and the borders etc gets flipped automatically without you having to manually adjust things. It's just a thought though, without looking too much into the internals...
What I meant is an easy flag of saying - hey, this is a vertical table, where headers are in first column and entries are columns and not rows (e.g. table.with(Vertical) or something), so everything include the cells themselves and the borders etc gets flipped automatically without you having to manually adjust things. It's just a thought though, without looking too much into the internals...
Yes, I think it's a good thing.
But how you'd see table got flipped when there's a set Border
for some Cell
.
When we do flip will you flip the Border for the cell or leave it?
And it gets more interesting with a Span::column
it should it became Span::row
after flip, or stay Span::column?
And should it be expanded
in case if previously it was taken the whole row via Panel
?
See this table. What should happen with first row after flip. And what should happen to the borders here. Could you show how you'd see it?
| Hello World |
| name | based_on | is_active | is_cool |
|---------|----------|-----------|---------|
| Debian | | true | true |
|---------|----------|-----------|---------|
| Arch | | true | true |
| Manjaro | Arch | true | true |
But maybe complete "flip" would do not what you'd expect. .
Imagine if we flip this to the left.
| name | based_on | is_active | is_cool |
|---------|----------|-----------|---------|
We would get this.
||||||||||||
name -
based_on -
is_active -
is_cool -
||||||||||||
Which actually something I'd guess not a lot of people would expect.
I am actually writting to let you know that I've merged VerticalLine
recently so you can better do your own style.
See.
https://github.com/zhiburt/tabled/blob/4999c94e8c75ea0716ad5f5a21dbfd97a6cafa1a/examples/custom_style.rs#L27-L47
┌────────────────────┬─────────────────────────────────┐
│ name │ first_release developer │
├────────────────────┼─────────────────────────────────┤
│ Sublime Text 3 │ 2008 Sublime HQ │
│ Visual Studio Code │ 2015 Microsoft │
│ Notepad++ │ 2003 Don Ho │
│ GNU Emacs │ 1984 Richard Stallman │
│ Neovim │ 2015 Vim community │
└────────────────────┴─────────────────────────────────┘
What should happen with first row after flip. And what should happen to the borders here. Could you show how you'd see it?
Well, I guess I'd expect everything to flip completely, like so:
| Hello World |
| name | based_on | is_active | is_cool |
|---------|----------|-----------|---------|
| Debian | | true | true |
|---------|----------|-----------|---------|
| Arch | | true | true |
| Manjaro | Arch | true | true |
=>
----------------------------------------------
Hello World name | Debian | Arch Manjaro
----------------------------------
based_on | | Arch
----------------------------------
is_active | true | true true
----------------------------------
is_cool | true | true true
----------------------------------------------