Skip to content

Commit

Permalink
Add finer-grained bars (matchai#7)
Browse files Browse the repository at this point in the history
uses octet unicode bar chars
  • Loading branch information
casperdcl authored and matchai committed Sep 22, 2019
1 parent 3b6c0d7 commit cfc7b78
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,18 @@ 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);
const syms = "░▏▎▍▌▋▊▉█";

const frac = size * 8 * percent / 100;
const barsFull = Math.floor(frac / 8);
const semi = frac % 8;
const barsEmpty = size - barsFull - 1;

return [
syms.substring(8,9).repeat(barsFull),
syms.substring(semi,semi+1),
syms.substring(0,1).repeat(barsEmpty),
].join('');
}

(async () => {
Expand Down

0 comments on commit cfc7b78

Please sign in to comment.