Skip to content

Commit

Permalink
Add bar charts
Browse files Browse the repository at this point in the history
  • Loading branch information
matchai committed Mar 17, 2019
1 parent 175ccf3 commit e93bd4f
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,25 @@ async function updateGist(stats) {
} catch (error) {
console.error(`Unable to get gist\n${error}`);
}
// Get original filename to update that same file
const filename = Object.keys(gist.data.files)[0];

const lines = [];
for (let i = 0; i < 5; i++) {
const data = stats.data.languages[i];
const name = data.name.padEnd(10);
const percent = data.percent;
const time = data.text;
const { name, percent, text: time } = data;

lines.push(`${name} - ${time}`);
const line = [
name.padEnd(11),
time.padEnd(14),
generateBarChart(percent, 12),
String(percent.toFixed(1)).padStart(5) + "%"
];

lines.push(line.join(" "));
}

try {
// Get original filename to update that same file
const filename = Object.keys(gist.data.files)[0];
await octokit.gists.update({
gist_id: gistId,
files: {
Expand All @@ -54,6 +59,13 @@ async function updateGist(stats) {
}
}

function generateBarChart(percent, size) {
const empty = "░";
const full = "█";
const barsFull = Math.round(size * (percent / 100));
return full.repeat(barsFull).padEnd(size, empty);
}

(async () => {
await main();
})();

0 comments on commit e93bd4f

Please sign in to comment.