Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Added .sort() and ability to add a divider with .newLine() #1

Closed
wants to merge 3 commits into
from

Conversation

Projects
None yet
2 participants

Jimbly commented Mar 17, 2012

Added .sort() and ability to add a divider with .newLine() when it is called with no cell data.

Owner

eldargab commented Mar 18, 2012

Thank you for the sort suggestion. I'll merge it. But I disagree with the divider feature. Probably you want to accomplish groupBy like things. If so we can consider to implement it. I thought about group by at some point but decided to postpone just because didn't have such use case yet.

Jimbly commented Mar 18, 2012

The specific thing I used the divider for is putting it before adding a totals row at the bottom. In theory could add a function to add a total to the table automatically, but since some fields are strings that didn't seem to make as much sense as me totaling the fields myself and just adding the final divider and row (after sorting).

Owner

eldargab commented Mar 18, 2012

Is it easier just to draw plain line at the end? :)

Owner

eldargab commented Mar 18, 2012

Something like:

var s = t.toString()
var l = s.split(/\n/)[0].length
s += Table.RightPadder('-')('', l)

Jimbly commented Mar 18, 2012

I needed the line between the last row of data and the row of totals (which needs to be a Table row so each column's total gets spaced right, uses the right formatter, etc). Specifically, I'm putting together a node module for dumping and displaying memory usage in a native process. Output ends up being something like this:

Addr               Size       Count  Traffic  Module                            Symbol                            Offs
-----------------  ---------  -----  -------  --------------------------------  --------------------------------  ------
0x139671333806034   15 bytes      1    44795  /lib/libc.so.6                    __strdup                          +0x22
0x8424450          112 bytes      1        1  node                                                                und...
0x8169177            3.42 KB      4  1541348  node                              _ZN2v88internal8Malloced3NewEm    +0x9
0x139671344824909    1.18 MB    321   261273  /usr/lib/libstdc++.so.6           _Znwm                             +0x1d
0x139671296020065    2.91 MB    424   202854  ...les/native/bullet/bullet.node                                    und...
-----------------  ---------  -----  -------  --------------------------------  --------------------------------  ------
TOTAL                4.10 MB    751  2053229                                                                      und...
Owner

eldargab commented Mar 18, 2012

Looks nice... Let's just add total function with api like:

table.totals(['Size', 'Count', 'Traffic'])

Jimbly commented Mar 18, 2012

I'm a little wary of putting data-processing logic inside a module that's primarily display formatting, but I already crossed that line with .sort (could almost as easily call .sort on the input data before sending it into the Table), so, here's .totals() now as well. Though in my use case, I think there's a reasonable chance I'm going to want to use the totals for additional logic, so I'll end up either calculating them again outside the Table, or need to put in an accessor to get the values out.

@eldargab eldargab closed this in b1a9729 Jul 22, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment