Skip to content

Commit 9d9dd97

Browse files
committed
Merge branch 'as0n-month-position'
2 parents 28b788c + 087a393 commit 9d9dd97

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

lib/index.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,13 @@ GitStats.ansiCalendar = function (data, callback) {
287287
}
288288

289289
var year = []
290-
, months = []
290+
, months = new Array(52) // Stores the months depending on their first week
291291
, cWeek = [" ", " ", " ", " ", " ", " ", " "]
292292
, monthHack = "MM"
293293
, sDay = ""
294294
, cDayObj = null
295295
, strYear = ""
296+
, strMonths = ""
296297
, w = 0
297298
, d = 0
298299
, dataClone = {
@@ -305,9 +306,6 @@ GitStats.ansiCalendar = function (data, callback) {
305306
if (err) { return callback(err); }
306307
GitStats.iterateDays(dataClone, function (cDay, mDay) {
307308
sDay = mDay.format("ddd");
308-
if (mDay.format("D") === "1") {
309-
months.push(mDay.format("MMM"));
310-
}
311309

312310
cDayObj = cal.days[cDay];
313311
if (!cDayObj) return;
@@ -317,6 +315,11 @@ GitStats.ansiCalendar = function (data, callback) {
317315
cWeek = [" ", " ", " ", " ", " ", " ", " "];
318316
}
319317

318+
// Store the new month this week
319+
if (mDay.format("D") === "1") {
320+
months[year.length] = mDay.format("MMM");
321+
}
322+
320323
cWeek[DAYS.indexOf(sDay)] = LEVELS[cDayObj.level];
321324
});
322325

@@ -337,8 +340,19 @@ GitStats.ansiCalendar = function (data, callback) {
337340
return DAYS[i] + c;
338341
}).join("\n");
339342

340-
monthHack = "MMM";
341-
strYear = monthHack + months.join(" ") + "\n" + strYear;
343+
// Months label
344+
monthHack = "MMMM"; //Left padding
345+
346+
for (var i = 0; i < months.length; i++) {
347+
// The length of strMonths should always be 2*(i+1) (at the i-th column)
348+
if (!months[i]) {
349+
strMonths += new Array(2*(i+1)-strMonths.length+1).join(" ");
350+
} else {
351+
strMonths += months[i];
352+
}
353+
}
354+
355+
strYear = monthHack + strMonths + "\n" + strYear;
342356
strYear +=
343357
new Array(5 + 2 * Math.ceil(365 / 7)).join("-")
344358
+ "\n" + "Contributions in the last year: " + cal.total

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"test": "node test"
1111
},
1212
"author": "Ionică Bizău <[email protected]>",
13+
"contributors": [
14+
15+
],
1316
"license": "MIT",
1417
"devDependencies": {},
1518
"repository": {

0 commit comments

Comments
 (0)