Skip to content

Commit 1b1bbe9

Browse files
committed
Update to support weeks parameter
1 parent b85ff6d commit 1b1bbe9

File tree

6 files changed

+28
-20
lines changed

6 files changed

+28
-20
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,13 @@ Input:
8787
```json
8888
{
8989
"width": 800,
90-
"height": 190,
90+
"height": 400,
9191
"username": "<some_github_username>",
9292
"github_token": "<your_github_personal_access_token>",
93+
"weeks": 40,
9394
"theme": {
9495
"horizontal_padding": 22,
95-
"vertical_padding": 22,
96+
"vertical_padding": 10,
9697
"background_color": "#000",
9798
"font_color": "#fff",
9899
"day_border_color": "#555",
@@ -112,7 +113,7 @@ Output:
112113
{
113114
"canvas": {
114115
"width": 800,
115-
"height": 190,
116+
"height": 400,
116117
"data": "<encoded_rgba_bytes_omitted>"
117118
}
118119
}

example-output-dark.png

193 Bytes
Loading

example-output.png

-136 Bytes
Loading

src/graph.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
background: data.backgroundColor,
1111
}}>
1212
<h2 style={{marginTop: 0, marginBottom: 0, color: data.fontColor}}>{data.totalContributions}</h2>
13-
<p style={{marginTop: 0, marginBottom: 10, color: data.fontColor}}>Contributions in the last year</p>
13+
<p style={{marginTop: 0, marginBottom: 10, color: data.fontColor}}>Contributions in the last {data.weekCount} weeks</p>
1414
<div style={{ display: "flex", flexDirection: "row"}}>
1515
{data.weeks.map((week, weekIdx) => (
1616
<div

src/run.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
* @param {{
44
* width: number,
55
* height: number,
6-
* horizontal_padding: number,
7-
* vertical_padding: number,
8-
* background_color: string,
9-
* font_color: string,
10-
* day_border_color: string,
11-
* day_border_width: number,
12-
* day_palette: string[],
136
* username: string,
14-
* github_token: string
7+
* github_token: string,
8+
* weeks: number,
9+
* theme: {
10+
* horizontal_padding: number,
11+
* vertical_padding: number,
12+
* background_color: string,
13+
* font_color: string,
14+
* day_border_color: string,
15+
* day_border_width: number,
16+
* day_palette: string[],
17+
* }
1518
* }} input
1619
* @returns {Promise<{
1720
* data:{
@@ -31,10 +34,12 @@
3134
* jsx: string,
3235
* }>}
3336
*/
34-
export async function run(input){
37+
export async function run(input) {
38+
let weeks = input.weeks || 52;
3539
let data = await getGitHubContributions(
3640
input.github_token || slipway_host.env('GITHUB_TOKEN'),
3741
input.username,
42+
weeks,
3843
);
3944

4045
let theme = input.theme || {};
@@ -44,8 +49,8 @@ export async function run(input){
4449
const boxVerticalMargin = 1;
4550
const boxHorizontalMargin = 3;
4651
const borderWidth = theme.day_border_width || 1;
47-
const drawWidth = input.width - drawMarginWidth*2;
48-
const drawHeight = input.height - drawMarginHeight*2;
52+
const drawWidth = input.width - drawMarginWidth * 2;
53+
const drawHeight = input.height - drawMarginHeight * 2;
4954
const boxWidth = Math.floor(drawWidth / (data.weeks.length + 1)) - borderWidth - boxHorizontalMargin;
5055
const boxHeight = Math.min(boxWidth, Math.floor(drawHeight / 7) - borderWidth - boxVerticalMargin);
5156

@@ -67,7 +72,8 @@ export async function run(input){
6772
];
6873
data.backgroundColor = theme.background_color || '#ffffff';
6974
data.fontColor = theme.font_color || '#000000';
70-
75+
data.weekCount = weeks;
76+
7177
return {
7278
data,
7379
jsx,
@@ -90,12 +96,12 @@ export async function run(input){
9096
* }[]
9197
* }>}
9298
*/
93-
export async function getGitHubContributions(githubToken, username) {
99+
export async function getGitHubContributions(githubToken, username, weeks) {
94100
const today = new Date();
95-
const oneYearAgo = new Date(today);
96-
oneYearAgo.setFullYear(today.getFullYear() - 1);
101+
const weeksAgo = new Date(today);
102+
weeksAgo.setDate(today.getDate() - weeks * 7);
97103

98-
const from = oneYearAgo.toISOString();
104+
const from = weeksAgo.toISOString();
99105
const to = today.toISOString();
100106

101107
const query = `

src/slipway_component.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"optionalProperties": {
1212
"github_token": { "type": "string" },
13+
"weeks": { "type": "uint32" },
1314
"theme": {
1415
"optionalProperties": {
1516
"horizontal_padding": { "type": "uint32" },

0 commit comments

Comments
 (0)