From a41624ea7a7befc4a7d2a166269bcb9e732f5aa9 Mon Sep 17 00:00:00 2001 From: as0n Date: Tue, 17 Feb 2015 20:11:21 +0100 Subject: [PATCH] Fixed month labels positions. Month labels always start on the column (week) of their first day and aren't just randomly spaced. --- lib/index.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/index.js b/lib/index.js index 4f7df67..d98cecf 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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