Skip to content

Commit

Permalink
Fix 100% bar display (matchai#18)
Browse files Browse the repository at this point in the history
Co-authored-by: MarchWorks <[email protected]>
  • Loading branch information
2 people authored and matchai committed Nov 20, 2019
1 parent e6014a3 commit 074660f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function updateGist(stats) {
}

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

Expand Down Expand Up @@ -60,16 +60,17 @@ async function updateGist(stats) {
function generateBarChart(percent, size) {
const syms = "░▏▎▍▌▋▊▉█";

const frac = (size * 8 * percent) / 100;
const frac = Math.floor((size * 8 * percent) / 100);
const barsFull = Math.floor(frac / 8);
if (barsFull >= size) {
return syms.substring(8, 9).repeat(size);
}
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("");
].join("").padEnd(size, syms.substring(0, 1));
}

(async () => {
Expand Down

0 comments on commit 074660f

Please sign in to comment.