0 purchases
tabular
Tabular #
Dart library for displaying tabular data in a visually appealing
ASCII table format.
It converts a two-dimensional array of cells into a string with a text
table.
Tabular is specifically designed to create tables in the Markdown format that
GitHub understands.
The library is inspired by python's tabulate
and pretty_table.
import 'package:tabular/tabular.dart';
var data = [
['Season', '#', 'Name', 'Days', 'Sun'],
['Winter', 1, 'January', 31, 94],
['Winter', 2, 'February', 28, 123],
['Spring', 3, 'March', 31, 42],
['Spring', 4, 'April', 30, 243],
['Spring', 5, 'May', 31, 5523],
['Summer', 6, 'June', 30, 11251],
['Summer', 7, 'July', 31, 17451],
['Summer', 8, 'August', 31, 18707],
['Autumn', 9, 'September', 30, 7025],
['Autumn', 10, 'October', 31, 5041],
['Autumn', 11, 'November', 30, 2302],
['Winter', 12, 'December', 31, 258],
];
var string = tabular(data);
print(string);
copied to clipboard
Season | # | Name | Days | Sun
-------|----|-----------|------|------
Winter | 1 | January | 31 | 94
Winter | 2 | February | 28 | 123
Spring | 3 | March | 31 | 42
Spring | 4 | April | 30 | 243
Spring | 5 | May | 31 | 5523
Summer | 6 | June | 30 | 11251
Summer | 7 | July | 31 | 17451
Summer | 8 | August | 31 | 18707
Autumn | 9 | September | 30 | 7025
Autumn | 10 | October | 31 | 5041
Autumn | 11 | November | 30 | 2302
Winter | 12 | December | 31 | 258
copied to clipboard
Formatting #
Modify alignment #
tabular(data, align: {'Name': Side.center, 'Sun': Side.start})
copied to clipboard
Season | # | Name | Days | Sun
-------|----|-----------|------|------
Winter | 1 | January | 31 | 94
Winter | 2 | February | 28 | 123
Spring | 3 | March | 31 | 42
Spring | 4 | April | 30 | 243
Spring | 5 | May | 31 | 5523
Summer | 6 | June | 30 | 11251
Summer | 7 | July | 31 | 17451
Summer | 8 | August | 31 | 18707
Autumn | 9 | September | 30 | 7025
Autumn | 10 | October | 31 | 5041
Autumn | 11 | November | 30 | 2302
Winter | 12 | December | 31 | 258
copied to clipboard
Add markdown ':' alignment marks #
tabular(data, markdownAlign: true)
copied to clipboard
Season | # | Name | Days | Sun
-------|---:|-----------|-----:|-----:
Winter | 1 | January | 31 | 94
Winter | 2 | February | 28 | 123
Spring | 3 | March | 31 | 42
Spring | 4 | April | 30 | 243
Spring | 5 | May | 31 | 5523
Summer | 6 | June | 30 | 11251
Summer | 7 | July | 31 | 17451
Summer | 8 | August | 31 | 18707
Autumn | 9 | September | 30 | 7025
Autumn | 10 | October | 31 | 5041
Autumn | 11 | November | 30 | 2302
Winter | 12 | December | 31 | 258
copied to clipboard
Add horizontal dividers #
tabular(data, rowDividers: [1, 3, 6, 9, 12])
copied to clipboard
Season | # | Name | Days | Sun
-------|----|-----------|------|------
Winter | 1 | January | 31 | 94
Winter | 2 | February | 28 | 123
-------|----|-----------|------|------
Spring | 3 | March | 31 | 42
Spring | 4 | April | 30 | 243
Spring | 5 | May | 31 | 5523
-------|----|-----------|------|------
Summer | 6 | June | 30 | 11251
Summer | 7 | July | 31 | 17451
Summer | 8 | August | 31 | 18707
-------|----|-----------|------|------
Autumn | 9 | September | 30 | 7025
Autumn | 10 | October | 31 | 5041
Autumn | 11 | November | 30 | 2302
-------|----|-----------|------|------
Winter | 12 | December | 31 | 258
copied to clipboard
Please be aware that dividers can make the table not conform to the
Markdown standard.
Add outer border #
tabular(data, border: Border.vertical);
copied to clipboard
| Season | # | Name | Days | Sun |
|--------|----|-----------|------|-------|
| Winter | 1 | January | 31 | 94 |
| Winter | 2 | February | 28 | 123 |
| Spring | 3 | March | 31 | 42 |
| Spring | 4 | April | 30 | 243 |
| Spring | 5 | May | 31 | 5523 |
| Summer | 6 | June | 30 | 11251 |
| Summer | 7 | July | 31 | 17451 |
| Summer | 8 | August | 31 | 18707 |
| Autumn | 9 | September | 30 | 7025 |
| Autumn | 10 | October | 31 | 5041 |
| Autumn | 11 | November | 30 | 2302 |
| Winter | 12 | December | 31 | 258 |
copied to clipboard
In the same way, you can add Border.horizontal or Border.all. But it can
make the table not conform to the Markdown standard.
Switch border style #
tabular(data, style: Style.mysql, border: Border.all)
copied to clipboard
+--------+----+-----------+------+-------+
| Season | # | Name | Days | Sun |
+--------+----+-----------+------+-------+
| Winter | 1 | January | 31 | 94 |
| Winter | 2 | February | 28 | 123 |
| Spring | 3 | March | 31 | 42 |
| Spring | 4 | April | 30 | 243 |
| Spring | 5 | May | 31 | 5523 |
| Summer | 6 | June | 30 | 11251 |
| Summer | 7 | July | 31 | 17451 |
| Summer | 8 | August | 31 | 18707 |
| Autumn | 9 | September | 30 | 7025 |
| Autumn | 10 | October | 31 | 5041 |
| Autumn | 11 | November | 30 | 2302 |
| Winter | 12 | December | 31 | 258 |
+--------+----+-----------+------+-------+
copied to clipboard
Custom column formatting #
tabular(data,
format: {
'Name': (value) => value.toUpperCase(),
'Sun': (value) => '+ '+value.toString() })
copied to clipboard
Season | # | Name | Days | Sun
-------|----|-----------|------|--------
Winter | 1 | JANUARY | 31 | + 94
Winter | 2 | FEBRUARY | 28 | + 123
Spring | 3 | MARCH | 31 | + 42
Spring | 4 | APRIL | 30 | + 243
Spring | 5 | MAY | 31 | + 5523
Summer | 6 | JUNE | 30 | + 11251
Summer | 7 | JULY | 31 | + 17451
Summer | 8 | AUGUST | 31 | + 18707
Autumn | 9 | SEPTEMBER | 30 | + 7025
Autumn | 10 | OCTOBER | 31 | + 5041
Autumn | 11 | NOVEMBER | 30 | + 2302
Winter | 12 | DECEMBER | 31 | + 258
copied to clipboard
Sorting #
Sort alphabetically by column 0 #
tabular(data, sort: [Sort(0)]) // 0 is 'Season'
copied to clipboard
Season | # | Name | Days | Sun
-------|----|-----------|------|------
Autumn | 9 | September | 30 | 7025
Autumn | 10 | October | 31 | 5041
Autumn | 11 | November | 30 | 2302
Spring | 3 | March | 31 | 42
Spring | 4 | April | 30 | 243
Spring | 5 | May | 31 | 5523
Summer | 6 | June | 30 | 11251
Summer | 7 | July | 31 | 17451
Summer | 8 | August | 31 | 18707
Winter | 1 | January | 31 | 94
Winter | 2 | February | 28 | 123
Winter | 12 | December | 31 | 258
copied to clipboard
Sort by 'Days' descending, and then by 'Sun' ascending #
tabular(data, sort: [Sort('Days', ascending: false), Sort('Sun')])
copied to clipboard
Season | # | Name | Days | Sun
-------|----|-----------|------|------
Spring | 3 | March | 31 | 42
Winter | 1 | January | 31 | 94
Winter | 12 | December | 31 | 258
Autumn | 10 | October | 31 | 5041
Spring | 5 | May | 31 | 5523
Summer | 7 | July | 31 | 17451
Summer | 8 | August | 31 | 18707
Spring | 4 | April | 30 | 243
Autumn | 11 | November | 30 | 2302
Autumn | 9 | September | 30 | 7025
Summer | 6 | June | 30 | 11251
Winter | 2 | February | 28 | 123
copied to clipboard
Sort with custom comparison #
Ordering the rows by the length of the month name.
tabular(data,
sort: [Sort('Name', compare: (a, b) => a.length.compareTo(b.length))])
copied to clipboard
Season | # | Name | Days | Sun
-------|----|-----------|------|------
Spring | 5 | May | 31 | 5523
Summer | 6 | June | 30 | 11251
Summer | 7 | July | 31 | 17451
Spring | 3 | March | 31 | 42
Spring | 4 | April | 30 | 243
Summer | 8 | August | 31 | 18707
Winter | 1 | January | 31 | 94
Autumn | 10 | October | 31 | 5041
Winter | 2 | February | 28 | 123
Autumn | 11 | November | 30 | 2302
Winter | 12 | December | 31 | 258
Autumn | 9 | September | 30 | 7025
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.