Skip to content

Commit 1e1efdf

Browse files
committed
Align homepage data counter digits
1 parent 1ea2af8 commit 1e1efdf

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

_sass/stylesheets/_blastnet.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ $base0f: #d33682 !default;
6262
text-align:left;
6363
margin-top:-1em;
6464
font-size:1.2em;
65+
66+
@include breakpoint(min-width $mobile){
67+
span.zero {
68+
display:none;
69+
}
70+
}
6571

6672
&#kaggle_size::after {
6773
content:" total data";

assets/js/homepage_stats.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function formatBytes(numBytes) {
88
unitIndex++;
99
}
1010

11-
// Format the output to 3 decimal places
11+
// Format the output to 0 decimal places
1212
return `${numBytes.toFixed(0)} ${units[unitIndex]}`;
1313
}
1414

@@ -27,11 +27,10 @@ async function fetchGistData() {
2727
// Print total bytes downloaded
2828
const formattedNumber = total_bytes.toLocaleString();
2929
const wrappedNumber = Array.from(formattedNumber).map(char => (/\d/.test(char) ? `<span>${char}</span>`:`<em>${char}</em>`)).join('');
30-
document.querySelectorAll("#kaggle_stat")[0].innerHTML = wrappedNumber + " bytes downloaded";
30+
document.getElementById("kaggle_stat").innerHTML = wrappedNumber+" bytes downloaded";
3131

3232
// Print total dataset size
3333
const formattedSize = formatBytes(total_size);
34-
//const wrappedSize = Array.from(formattedSize).map(char => (/\s/.test(char) ? `${char}`:`<span>${char}</span>`)).join('');
3534
const wrappedSize = formattedSize.split(/(\s+)/).map(chunk => {
3635
if (/^\d+$/.test(chunk))
3736
return Array.from(chunk).map(char => `<span>${char}</span>`).join('');
@@ -40,8 +39,24 @@ async function fetchGistData() {
4039
else
4140
return chunk;
4241
}).join('');
43-
document.querySelectorAll("#kaggle_size")[0].innerHTML = wrappedSize;
44-
document.querySelectorAll("#data_size")[0].innerHTML = formattedSize;
42+
document.getElementById("kaggle_size").innerHTML = wrappedSize;
43+
document.getElementById("data_size").innerHTML = formattedSize;
44+
45+
// Extra formatting thanks matthias
46+
let children = Array.from(document.getElementById("kaggle_stat").children);
47+
let firstEmIndex = children.findIndex(child => child.tagName.toLowerCase() === 'em');
48+
let byteCount = firstEmIndex === -1
49+
? children.filter(child => child.tagName.toLowerCase() === 'span').length
50+
: children.slice(0, firstEmIndex).filter(child => child.tagName.toLowerCase() === 'span').length;
51+
let sizeCount = document.querySelectorAll("#kaggle_size span").length-1;
52+
if (sizeCount < byteCount){
53+
let prependZeros = Array(byteCount-sizeCount).fill('<span class="zero">0</span>').join('');
54+
document.getElementById("kaggle_size").innerHTML = prependZeros+wrappedSize;
55+
} else if (sizeCount > byteCount){
56+
let prependZeros = Array(sizeCount-byteCount).fill('<span class="zero">0</span>').join('');
57+
document.getElementById("kaggle_stat").innerHTML = prependZeros+wrappedNumber+" bytes downloaded";
58+
}
59+
4560
} catch (error) {
4661
console.log("Failed to fetch Gist data:", error);
4762
}

0 commit comments

Comments
 (0)