Skip to content

Commit 9c9d669

Browse files
authored
Merge pull request #28 from yoshi389111/change_logarithmic_height
Change logarithmic height
2 parents c255e86 + 16c8fe9 commit 9c9d669

File tree

5 files changed

+92
-26
lines changed

5 files changed

+92
-26
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,27 @@ e.g.
128128
![](./profile-3d-contrib/profile-green-animate.svg)
129129
```
130130

131+
## How to use (local)
132+
133+
Set the `GITHUB_TOKEN` environment variable to the value of "personal access token".
134+
135+
```shell-session
136+
export GITHUB_TOKEN=XXXXXXXXXXXXXXXXXXXXX
137+
```
138+
139+
Run it with your GitHub user specified.
140+
141+
```shell-session
142+
node_modules/.bin/ts-node src/index.ts USER_NAME
143+
```
144+
145+
or
146+
147+
```shell-session
148+
npm run build
149+
node . USER_NAME
150+
```
151+
131152
## Licence
132153

133154
MIT License

dist/index.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ const create3DContrib = (svg, userInfo, x, y, width, height, settings, isAnimate
346346
const week = Math.floor(diffDate(startTime, cal.date.getTime()) / 7);
347347
const baseX = offsetX + (week - dayOfWeek) * dx;
348348
const baseY = offsetY + (week + dayOfWeek) * dy;
349-
const calHeight = Math.min(50, cal.contributionCount) * 3 + 3;
349+
const calHeight = Math.log10(cal.contributionCount / 20 + 1) * 144 + 3;
350350
const plainLeft = createRightPanelPath(baseX, baseY, calHeight, dxx, dyy);
351351
const pathLeft = group
352352
.append('path')
@@ -722,6 +722,26 @@ const radar = __importStar(__nccwpck_require__(76592));
722722
const width = 1280;
723723
const height = 850;
724724
const toIsoDate = (date) => date.toISOString().substring(0, 10);
725+
// Separate every three digits with a space (SI format)
726+
const inertThousandSeparator = (value) => value.toFixed(0).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1 ');
727+
// Rounding large numbers
728+
const toScale = (value) => {
729+
if (value < 1000) {
730+
// 0 - 999
731+
return value.toFixed(0);
732+
}
733+
else if (value < 10000) {
734+
// 1.0K - 9.9K
735+
return Math.floor(value / 1000).toFixed(1) + 'K';
736+
}
737+
else if (value < 1000000) {
738+
// 10K - 999K
739+
return Math.floor(value / 1000).toFixed(0) + 'K';
740+
}
741+
else {
742+
return '1.0M+';
743+
}
744+
};
725745
const createSvg = (userInfo, settings, isAnimate) => {
726746
const fakeDom = new jsdom_1.JSDOM('<!DOCTYPE html><html><body><div class="container"></div></body></html>');
727747
const container = d3.select(fakeDom.window.document).select('.container');
@@ -759,12 +779,8 @@ const createSvg = (userInfo, settings, isAnimate) => {
759779
.attr('x', positionXContrib)
760780
.attr('y', positionYContrib)
761781
.attr('text-anchor', 'end')
762-
.text(userInfo.totalContributions < 10000
763-
? userInfo.totalContributions
764-
: '9999+')
765-
.attr('fill', settings.strongColor)
766-
.append('title')
767-
.text(userInfo.totalContributions);
782+
.text(inertThousandSeparator(userInfo.totalContributions))
783+
.attr('fill', settings.strongColor);
768784
group
769785
.append('text')
770786
.style('font-size', '24px')
@@ -791,9 +807,7 @@ const createSvg = (userInfo, settings, isAnimate) => {
791807
.attr('x', positionXStar + 10)
792808
.attr('y', positionYStar)
793809
.attr('text-anchor', 'start')
794-
.text(userInfo.totalStargazerCount < 1000
795-
? userInfo.totalStargazerCount
796-
: '999+')
810+
.text(toScale(userInfo.totalStargazerCount))
797811
.attr('fill', settings.foregroundColor)
798812
.append('title')
799813
.text(userInfo.totalStargazerCount);
@@ -814,7 +828,7 @@ const createSvg = (userInfo, settings, isAnimate) => {
814828
.attr('x', positionXFork + 4)
815829
.attr('y', positionYFork)
816830
.attr('text-anchor', 'start')
817-
.text(userInfo.totalForkCount < 1000 ? userInfo.totalForkCount : '999+')
831+
.text(toScale(userInfo.totalForkCount))
818832
.attr('fill', settings.foregroundColor)
819833
.append('title')
820834
.text(userInfo.totalForkCount);

docs/README.ja-jp.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,27 @@ jobs:
128128
![](./profile-3d-contrib/profile-green-animate.svg)
129129
```
130130

131+
## 使い方 (ローカル)
132+
133+
環境変数 `GITHUB_TOKEN` には「personal access token」を指定してください。
134+
135+
```shell-session
136+
export GITHUB_TOKEN=XXXXXXXXXXXXXXXXXXXXX
137+
```
138+
139+
GitHubのユーザを指定して実行してください。
140+
141+
```shell-session
142+
node_modules/.bin/ts-node src/index.ts USER_NAME
143+
```
144+
145+
あるいは
146+
147+
```shell-session
148+
npm run build
149+
node . USER_NAME
150+
```
151+
131152
## Licence
132153

133154
MIT License

src/create-3d-contrib.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export const create3DContrib = (
216216

217217
const baseX = offsetX + (week - dayOfWeek) * dx;
218218
const baseY = offsetY + (week + dayOfWeek) * dy;
219-
const calHeight = Math.min(50, cal.contributionCount) * 3 + 3;
219+
const calHeight = Math.log10(cal.contributionCount / 20 + 1) * 144 + 3;
220220

221221
const plainLeft = createRightPanelPath(
222222
baseX,

src/create-svg.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,26 @@ const height = 850;
1010

1111
const toIsoDate = (date: Date) => date.toISOString().substring(0, 10);
1212

13+
// Separate every three digits with a space (SI format)
14+
const inertThousandSeparator = (value: number) =>
15+
value.toFixed(0).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1 ');
16+
17+
// Rounding large numbers
18+
const toScale = (value: number) => {
19+
if (value < 1_000) {
20+
// 0 - 999
21+
return value.toFixed(0);
22+
} else if (value < 10_000) {
23+
// 1.0K - 9.9K
24+
return Math.floor(value / 1_000).toFixed(1) + 'K';
25+
} else if (value < 1_000_000) {
26+
// 10K - 999K
27+
return Math.floor(value / 1_000).toFixed(0) + 'K';
28+
} else {
29+
return '1.0M+';
30+
}
31+
};
32+
1333
export const createSvg = (
1434
userInfo: type.UserInfo,
1535
settings: type.Settings,
@@ -90,14 +110,8 @@ export const createSvg = (
90110
.attr('x', positionXContrib)
91111
.attr('y', positionYContrib)
92112
.attr('text-anchor', 'end')
93-
.text(
94-
userInfo.totalContributions < 10000
95-
? userInfo.totalContributions
96-
: '9999+'
97-
)
98-
.attr('fill', settings.strongColor)
99-
.append('title')
100-
.text(userInfo.totalContributions);
113+
.text(inertThousandSeparator(userInfo.totalContributions))
114+
.attr('fill', settings.strongColor);
101115

102116
group
103117
.append('text')
@@ -134,11 +148,7 @@ export const createSvg = (
134148
.attr('x', positionXStar + 10)
135149
.attr('y', positionYStar)
136150
.attr('text-anchor', 'start')
137-
.text(
138-
userInfo.totalStargazerCount < 1000
139-
? userInfo.totalStargazerCount
140-
: '999+'
141-
)
151+
.text(toScale(userInfo.totalStargazerCount))
142152
.attr('fill', settings.foregroundColor)
143153
.append('title')
144154
.text(userInfo.totalStargazerCount);
@@ -168,7 +178,7 @@ export const createSvg = (
168178
.attr('x', positionXFork + 4)
169179
.attr('y', positionYFork)
170180
.attr('text-anchor', 'start')
171-
.text(userInfo.totalForkCount < 1000 ? userInfo.totalForkCount : '999+')
181+
.text(toScale(userInfo.totalForkCount))
172182
.attr('fill', settings.foregroundColor)
173183
.append('title')
174184
.text(userInfo.totalForkCount);

0 commit comments

Comments
 (0)