Fixed month labels positions.

Month labels always start on the column (week) of their first day and aren't just randomly spaced.
This commit is contained in:
as0n 2015-02-17 20:11:21 +01:00
parent 4e9258955f
commit a41624ea7a
1 changed files with 15 additions and 6 deletions

View File

@ -287,12 +287,13 @@ GitStats.ansiCalendar = function (data, callback) {
}
var year = []
, months = []
, months = new Array(52) // Stores the months depending on their first week
, cWeek = [" ", " ", " ", " ", " ", " ", " "]
, monthHack = "MM"
, sDay = ""
, cDayObj = null
, strYear = ""
, strMonths = ""
, w = 0
, d = 0
, dataClone = {
@ -305,9 +306,6 @@ GitStats.ansiCalendar = function (data, callback) {
if (err) { return callback(err); }
GitStats.iterateDays(dataClone, function (cDay, mDay) {
sDay = mDay.format("ddd");
if (mDay.format("D") === "1") {
months.push(mDay.format("MMM"));
}
cDayObj = cal.days[cDay];
if (!cDayObj) return;
@ -317,6 +315,11 @@ GitStats.ansiCalendar = function (data, callback) {
cWeek = [" ", " ", " ", " ", " ", " ", " "];
}
// Store the new month this week
if (mDay.format("D") === "1") {
months[year.length] = mDay.format("MMM");
}
cWeek[DAYS.indexOf(sDay)] = LEVELS[cDayObj.level];
});
@ -337,8 +340,14 @@ GitStats.ansiCalendar = function (data, callback) {
return DAYS[i] + c;
}).join("\n");
monthHack = "MMM";
strYear = monthHack + months.join(" ") + "\n" + strYear;
// Months label
monthHack = "MMMM"; //Left padding
for (var i=0; i<months.length; i++) {
// The length of strMonths should always be 2*(i+1) (at the i-th column)
if (months[i] === undefined) strMonths += new Array(2*(i+1)-strMonths.length+1).join(" ");
else strMonths += months[i];
}
strYear = monthHack + strMonths + "\n" + strYear;
strYear +=
new Array(5 + 2 * Math.ceil(365 / 7)).join("-")
+ "\n" + "Contributions in the last year: " + cal.total