Skip to content

Instantly share code, notes, and snippets.

@dweinstein
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dweinstein/d83210604f307cb80dc9 to your computer and use it in GitHub Desktop.
Save dweinstein/d83210604f307cb80dc9 to your computer and use it in GitHub Desktop.
tabulate d3
return client.shell(device.id, "pm list packages")
.then(adb.util.readAll)
.then(function (output) {
tabulate(
"#features",
_.chain(output.toString('utf8').split("\n"))
.without('', "\n", ' ')
.transform(function (accum, val, key) {
accum.push({count: key, val: val.split('package:')[1]});
}, [])
.value(),
["count", "val"]
);
});
function tabulate(target, data, columns) {
var table = d3.select(target)
.append("table");
var thead = table.append("thead");
var tbody = table.append("tbody");
// append the header row
thead.append("tr")
.selectAll("th")
.data(columns)
.enter()
.append("th")
.text(function(column) { return column; });
// create a row for each object in the data
var rows = tbody.selectAll("tr")
.data(data)
.enter()
.append("tr");
// create a cell in each row for each column
var cells = rows.selectAll("td")
.data(function(row) {
return columns.map(function(column) {
return {column: column, value: row[column]};
});
})
.enter()
.append("td")
.html(function(d) { return d.value; });
return table;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment