Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Commit 68409d9

Browse files
committed
0.19
1 parent 7c602d6 commit 68409d9

2 files changed

Lines changed: 31 additions & 41 deletions

File tree

stats.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,12 @@ const lang_colors = { /** thanks, @anuraghazra's github-readme-stats **/
552552
"xBase": "#403a40"
553553
}
554554

555+
function sort(arr) {
556+
const len = arr.length - 1;
557+
for (let i = 0; i <= len; i++) {for (let j = 0; j < len - i; j++) {if (arr[j] > arr[j + 1]) {[arr[j], arr[j + 1]] = [arr[j + 1], arr[j]]}}}
558+
return arr
559+
}
560+
555561
function storeConvert(size, idx=0) {
556562
if (size <= 0) {
557563
return "0";
@@ -564,9 +570,10 @@ function storeConvert(size, idx=0) {
564570
return `${size.toFixed(1)} ${store_units[idx]}`;
565571
}
566572

567-
function decConvert(n) {
573+
function decConvert(n, allowed_pre=true) {
568574
let idx = 0;
569-
while (idx < (dec_units.length - 1) && n > 100) { n /= 1000 ; idx ++ }
575+
let condition = allowed_pre ? 100 : 1000;
576+
while (idx < (dec_units.length - 1) && n > condition) { n /= 1000 ; idx ++ }
570577
return idx === 0 ? n : n.toFixed(1) + dec_units[idx];
571578
}
572579

@@ -592,8 +599,8 @@ async function langStatistics(queue) {
592599

593600
function langHandler(langs) {
594601
langs = {...langs}; // 这里有一个很神奇的关于指针的Bug的回忆
595-
// (缓存与操作的Array指向一个列表, 导致了奇妙的事情发生, 有意者可以亲自拉下代码复刻这一[特性])
596-
const val_arr = Object.values(langs).sort().reverse();
602+
// (缓存与操作的对象指向一个Array, 导致了奇妙的事情发生, 有意者可以亲自拉下代码复刻这一[特性])
603+
const val_arr = sort(Object.values(langs)).reverse();
597604
const total = val_arr.reduce((before, after) => before + after);
598605
for (let k in langs) {
599606
langs[langs[k]] = k;
@@ -609,7 +616,7 @@ function langHandler(langs) {
609616
color: lang_colors[lang],
610617
cursor: cursor - ratio,
611618
ratio: ratio,
612-
text: `${(ratio*100).toFixed(0)}% (${decConvert(key)})`,
619+
text: `${lang} ${(ratio * 100).toFixed(0)}% (${decConvert(key, false)})`,
613620
}
614621
});
615622
}

views/repo.ejs

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -143,45 +143,28 @@
143143
<% langs.forEach(function(lang){ %>
144144
<rect mask="url(#rect-mask)" data-testid="lang-progress" x="<%- lang.cursor * 300 %>" y="0" width="<%- lang.ratio * 300 %>" height="8" fill="<%- lang.color %>"/>
145145
<% }); %>
146-
147-
148146
<g transform="translate(0, 25)">
149-
<g transform="translate(0, 0)"><g transform="translate(0, 0)">
150-
<g class="stagger" style="animation-delay: 450ms">
151-
<circle cx="5" cy="6" r="5" fill="#f1e05a"/>
152-
<text data-testid="lang-name" x="15" y="10" class="lang-name">
153-
JavaScript 76.79%
154-
</text>
155-
</g>
156-
</g><g transform="translate(0, 25)">
157-
<g class="stagger" style="animation-delay: 600ms">
158-
<circle cx="5" cy="6" r="5" fill="#e34c26"/>
159-
<text data-testid="lang-name" x="15" y="10" class="lang-name">
160-
HTML 10.18%
161-
</text>
162-
</g>
163-
</g><g transform="translate(0, 50)">
164-
<g class="stagger" style="animation-delay: 750ms">
165-
<circle cx="5" cy="6" r="5" fill="#3178c6"/>
166-
<text data-testid="lang-name" x="15" y="10" class="lang-name">
167-
TypeScript 9.89%
168-
</text>
147+
<% const left = Math.ceil(langs.length / 2) %>
148+
<g transform="translate(0, 0)">
149+
<% langs.splice(0, left).forEach(function (lang, idx) { %>
150+
<g transform="translate(0, <%- idx * 25 %>)">
151+
<g class="stagger" style="animation-delay: <%- 450 + (idx * 150) %>ms">
152+
<circle cx="5" cy="6" r="5" fill="<%- lang.color %>"/>
153+
<text data-testid="lang-name" x="15" y="10" class="lang-name"><%- lang.text %></text>
154+
</g>
169155
</g>
170-
</g></g><g transform="translate(150, 0)"><g transform="translate(0, 0)">
171-
<g class="stagger" style="animation-delay: 450ms">
172-
<circle cx="5" cy="6" r="5" fill="#563d7c"/>
173-
<text data-testid="lang-name" x="15" y="10" class="lang-name">
174-
CSS 2.69%
175-
</text>
176-
</g>
177-
</g><g transform="translate(0, 25)">
178-
<g class="stagger" style="animation-delay: 600ms">
179-
<circle cx="5" cy="6" r="5" fill="#5686a5"/>
180-
<text data-testid="lang-name" x="15" y="10" class="lang-name">
181-
GLSL 0.46%
182-
</text>
156+
<% });%>
157+
</g>
158+
<g transform="translate(150, 0)">
159+
<% langs.splice(0, left).forEach(function (lang, idx) { %>
160+
<g transform="translate(0, <%- idx * 25 %>)">
161+
<g class="stagger" style="animation-delay: <%- 450 + (idx * 150) %>ms">
162+
<circle cx="5" cy="6" r="5" fill="<%- lang.color %>"/>
163+
<text data-testid="lang-name" x="15" y="10" class="lang-name"><%- lang.text %></text>
164+
</g>
183165
</g>
184-
</g></g>
166+
<% });%>
167+
</g>
185168
</g>
186169
</svg>
187170
</g>

0 commit comments

Comments
 (0)