mirror of
https://github.com/IonicaBizau/git-stats.git
synced 2024-12-22 13:22:11 +01:00
Compute squares.
This commit is contained in:
parent
9d829d3068
commit
78082da8c8
1 changed files with 37 additions and 3 deletions
40
lib/index.js
40
lib/index.js
|
@ -7,6 +7,16 @@ var FsExtra = require("fs-extra")
|
|||
// Constants
|
||||
const STORE_PATH = Ul.USER_DIR + "/.git-stats"
|
||||
, LEVELS = 5
|
||||
, SQUARES = ["⬚", "O", "▢", "▤", "▣", "⬛"]
|
||||
, DAYS = {
|
||||
Sun: 0
|
||||
, Mon: 1
|
||||
, Tue: 2
|
||||
, Wed: 3
|
||||
, Thu: 4
|
||||
, Fri: 5
|
||||
, Sat: 6
|
||||
}
|
||||
;
|
||||
|
||||
// Constructor
|
||||
|
@ -96,7 +106,7 @@ GitStats.iterateDays = function (data, callback) {
|
|||
|
||||
while (!start.isAfter(end)) {
|
||||
cDay = start.format(data.format);
|
||||
callback(cDay);
|
||||
callback(cDay, start);
|
||||
start.add(1, "days")
|
||||
}
|
||||
};
|
||||
|
@ -167,10 +177,34 @@ GitStats.ansiCalendar = function (data, callback) {
|
|||
callback = data;
|
||||
data = undefined;
|
||||
}
|
||||
// ⬚ ▢ ▤ ▣ ⬛
|
||||
|
||||
var year = []
|
||||
, cWeek = []
|
||||
, sDay = ""
|
||||
, cDayObj = null
|
||||
;
|
||||
|
||||
|
||||
GitStats.calendar(data, function (err, cal) {
|
||||
if (err) { return callback(err); }
|
||||
GitStats.iterateDays(function (cDay, mDay) {
|
||||
sDay = mDay.format("ddd");
|
||||
cDayObj = cal.days[cDay];
|
||||
|
||||
if (sDay === "Sun" && Object.keys(cWeek).length) {
|
||||
year.push(cWeek);
|
||||
cWeek = []
|
||||
}
|
||||
|
||||
if (!cDayObj) return;
|
||||
|
||||
cWeek[DAYS[sDay]] = SQUARES[cDayObj.level];
|
||||
});
|
||||
|
||||
if (cWeek.length) {
|
||||
year.push(cWeek);
|
||||
}
|
||||
|
||||
|
||||
debugger
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue