@@ -44,7 +44,7 @@ const GITHUB_DARK = [
4444 *
4545 * @param userName - The GitHub username to fetch contributions for.
4646 * @param githubToken - A GitHub personal access token with appropriate permissions.
47- * @returns A 2D array representing weeks and days, where each element contains the color string or null.
47+ * @returns The default color palette and a 2D array representing weeks and days, where each element contains the color string or null.
4848 * @throws Will throw an error if the API request fails or returns errors.
4949 */
5050function fetchGithubContributionsGraphQL ( userName , githubToken ) {
@@ -58,6 +58,7 @@ function fetchGithubContributionsGraphQL(userName, githubToken) {
5858 contributionDays {
5959 contributionLevel
6060 contributionCount
61+ color
6162 }
6263 }
6364 }
@@ -84,22 +85,34 @@ function fetchGithubContributionsGraphQL(userName, githubToken) {
8485 }
8586 // Format the contribution days into a 2D array of objects (weeks x days)
8687 const weeks = json . data . user . contributionsCollection . contributionCalendar . weeks ;
88+ const defaultColorPalette = {
89+ 0 : "#000" ,
90+ 1 : "#000" ,
91+ 2 : "#000" ,
92+ 3 : "#000" ,
93+ 4 : "#000" ,
94+ } ;
8795 const levels = [ ] ;
8896 for ( let c = 0 ; c < weeks . length ; c ++ ) {
8997 levels [ c ] = [ ] ;
9098 const days = weeks [ c ] . contributionDays ;
9199 for ( let r = 0 ; r < days . length ; r ++ ) {
100+ const level = ( days [ r ] . contributionLevel === "FOURTH_QUARTILE" && 4 ) ||
101+ ( days [ r ] . contributionLevel === "THIRD_QUARTILE" && 3 ) ||
102+ ( days [ r ] . contributionLevel === "SECOND_QUARTILE" && 2 ) ||
103+ ( days [ r ] . contributionLevel === "FIRST_QUARTILE" && 1 ) ||
104+ 0 ;
105+ defaultColorPalette [ level ] = days [ r ] . color ;
92106 levels [ c ] [ r ] = {
93- level : ( days [ r ] . contributionLevel === "FOURTH_QUARTILE" && 4 ) ||
94- ( days [ r ] . contributionLevel === "THIRD_QUARTILE" && 3 ) ||
95- ( days [ r ] . contributionLevel === "SECOND_QUARTILE" && 2 ) ||
96- ( days [ r ] . contributionLevel === "FIRST_QUARTILE" && 1 ) ||
97- 0 ,
107+ level,
98108 contributionCount : days [ r ] . contributionCount ,
99109 } ;
100110 }
101111 }
102- return levels ;
112+ return {
113+ days : levels ,
114+ defaultColorPalette : Object . values ( defaultColorPalette ) ,
115+ } ;
103116 } ) ;
104117}
105118/**
@@ -233,10 +246,10 @@ function minifySVG(svg) {
233246 */
234247function generateSVG ( username_1 , githubToken_1 ) {
235248 return __awaiter ( this , arguments , void 0 , function * ( username , githubToken , options = { } ) {
236- const { enableGhostBricks = true , paddleColor = "#1F6FEB" , ballColor = "#1F6FEB" , bricksColors = "github_light" , } = options ;
249+ const { enableGhostBricks = true , paddleColor = "#1F6FEB" , ballColor = "#1F6FEB" , bricksColors, } = options ;
237250 const colorDays = yield fetchGithubContributionsGraphQL ( username , githubToken ) ;
238251 // The number of columns (weeks) is determined by the API response
239- const brickColumnCount = colorDays . length ;
252+ const brickColumnCount = colorDays . days . length ;
240253 // Calculate canvasWidth and canvasHeight dynamically
241254 const canvasWidth = brickColumnCount * ( BRICK_SIZE + BRICK_GAP ) + PADDING * 2 - BRICK_GAP ; // right edge flush
242255 // Bricks area height
@@ -248,7 +261,7 @@ function generateSVG(username_1, githubToken_1) {
248261 // The ball and paddle should have enough space at the bottom (add a little margin)
249262 const canvasHeight = paddleY + PADDLE_HEIGHT + PADDING ;
250263 // Pick palette
251- let colorPalette = GITHUB_LIGHT ;
264+ let colorPalette = colorDays . defaultColorPalette ;
252265 if ( bricksColors === "github_light" ) {
253266 colorPalette = GITHUB_LIGHT ;
254267 }
@@ -262,7 +275,7 @@ function generateSVG(username_1, githubToken_1) {
262275 const bricks = [ ] ;
263276 for ( let c = 0 ; c < brickColumnCount ; c ++ ) {
264277 for ( let r = 0 ; r < 7 ; r ++ ) {
265- const day = ( colorDays [ c ] && colorDays [ c ] [ r ] ) || null ;
278+ const day = ( colorDays . days [ c ] && colorDays . days [ c ] [ r ] ) || null ;
266279 if ( ! day )
267280 continue ; // skip bricks for missing days
268281 bricks . push ( {
0 commit comments