eldargab / easy-table

Nice text table for Node.js
312 stars 31 forks source link

Add an option to switch between datarows and datacolumns #2

Closed thejh closed 12 years ago

thejh commented 12 years ago

How about adding an option for switching between the normal format and one where rows and columns are reversed?

E.g. turn


byte  count
----  -----
10    475  
32    6689 
33    12   
34    134  
35    11   
36    1    
37    1    
38    29   
39    417  
40    110  
41    110  
42    49   
43    7    
44    505  

into

byte  | 10  32   33 34  35 36 37 38 39  40  41  42 43 44
count | 475 6689 12 134 11 1  1  29 417 110 110 49 7  505
eldargab commented 12 years ago

It will be a kind of mess whereas doing this manualy for the concrete use case is as simple as:

var table = {
    "byte": [],
    "count": []
}

data.forEach(function (line) {
    table["byte"].push(line["byte"])
    table["count"].push(line["count"])
})

var t = new EasyTable

for (var key in table) {
    t.cell('Prop / SampleNo', key)
    table[key].forEach(function (sample, index) {
        t.cell(index + 1, sample)
    })
    t.newLine()
}

console.log(t.toString())

Just few extra lines of code