Skip to content

Commit

Permalink
Releasing 3.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e committed Aug 1, 2013
1 parent 48102be commit 5aae520
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v3.0.8 [2013-08-01]

* [new] Add `minDate`, `startDate` to limit domain navigation beyond certain dates
* [new] Add `onMaxDomainReached()` and `onMinDomainReached()` events, triggered when navigation is hitting the lower/upper domain limit
* [change] `next()` and `previous()` will now always return `true`, as long as there is more domain to load

## v3.0.7 [2013-07-24]

* [fix] Fix domain month class (`m_x`) beginning at `m_0` insted of `m_1`
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cal-heatmap",
"version": "3.0.7",
"version": "3.0.8",
"main": ["./cal-heatmap.js", "./cal-heatmap.css"],
"dependencies": {
"d3": "~v3.0.6"
Expand Down
129 changes: 119 additions & 10 deletions cal-heatmap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! cal-heatmap v3.0.7 (Wed Jul 24 2013 18:16:30)
/*! cal-heatmap v3.0.8 (Thu Aug 01 2013 14:27:18)
* ---------------------------------------------
* Cal-Heatmap is a javascript module to create calendar heatmap to visualize time series data, a la github contribution graph
* https://github.com/kamisama/cal-heatmap
Expand Down Expand Up @@ -57,6 +57,10 @@ var CalHeatMap = function() {
// @default now
start : new Date(),

minDate : null,

maxDate: null,

// URL, where to fetch the original datas
data : "",

Expand Down Expand Up @@ -212,7 +216,23 @@ var CalHeatMap = function() {
// Used mainly to convert the datas if they're not formatted like expected
// Takes the fetched "data" object as argument, must return a json object
// formatted like {timestamp:count, timestamp2:count2},
afterLoadData : function(data) { return data; }
afterLoadData : function(data) { return data; },

// Callback triggered after calling next().
// The `status` argument is equal to true if there is no
// more next domain to load
//
// This callback is also executed once, after calling previous(),
// only when the max domain is reached
onMaxDomainReached: function(reached) {},

// Callback triggered after calling previous().
// The `status` argument is equal to true if there is no
// more previous domain to load
//
// This callback is also executed once, after calling next(),
// only when the min domain is reached
onMinDomainReached: function(reached) {}
};


Expand Down Expand Up @@ -277,9 +297,8 @@ var CalHeatMap = function() {
case "month" :
if (self.options.verticalOrientation) {
return 6;
} else {
return self.options.domainDynamicDimension ? (self.getWeekNumber(new Date(d.getFullYear(), d.getMonth()+1, 0)) - self.getWeekNumber(d) + 1) : 6;
}
return self.options.domainDynamicDimension ? (self.getWeekNumber(new Date(d.getFullYear(), d.getMonth()+1, 0)) - self.getWeekNumber(d) + 1) : 6;
case "week" : return 1;
}
},
Expand Down Expand Up @@ -387,9 +406,8 @@ var CalHeatMap = function() {
case "month" :
if (!self.options.verticalOrientation) {
return 6;
} else {
return self.options.domainDynamicDimension ? (self.getWeekNumber(new Date(d.getFullYear(), d.getMonth()+1, 0)) - self.getWeekNumber(d) + 1) : 6;
}
return self.options.domainDynamicDimension ? (self.getWeekNumber(new Date(d.getFullYear(), d.getMonth()+1, 0)) - self.getWeekNumber(d) + 1) : 6;
case "week" : return 1;
}
};
Expand All @@ -413,6 +431,9 @@ var CalHeatMap = function() {

this.root = null;

this._maxDomainReached = false;
this._minDomainReached = false;

this.domainPosition = new DomainPosition();

/**
Expand All @@ -437,14 +458,14 @@ var CalHeatMap = function() {
if (self.options.nextSelector !== false) {
d3.select(self.options.nextSelector).on("click." + self.options.itemNamespace, function(d) {
d3.event.preventDefault();
self.loadNextDomain();
return self.loadNextDomain();
});
}

if (self.options.previousSelector !== false) {
d3.select(self.options.previousSelector).on("click." + self.options.itemNamespace, function(d) {
d3.event.preventDefault();
self.loadPreviousDomain();
return self.loadPreviousDomain();
});
}

Expand Down Expand Up @@ -1067,6 +1088,26 @@ CalHeatMap.prototype = {
}
},

onMinDomainReached: function(reached) {
this._minDomainReached = reached;
if (typeof (this.options.onMinDomainReached) === "function") {
return this.options.onMinDomainReached(reached);
} else {
console.log("Provided callback for onMinDomainReached is not a function.");
return false;
}
},

onMaxDomainReached: function(reached) {
this._maxDomainReached = reached;
if (typeof (this.options.onMaxDomainReached) === "function") {
return this.options.onMaxDomainReached(reached);
} else {
console.log("Provided callback for onMaxDomainReached is not a function.");
return false;
}
},

formatNumber: d3.format(",g"),

formatDate: function(d, format) {
Expand All @@ -1085,9 +1126,24 @@ CalHeatMap.prototype = {
// =========================================================================//
// DOMAIN NAVIGATION //
// =========================================================================//

/**
* Shift the calendar one domain forward
*
* The new domain is loaded only if it's not beyond the maxDate
*
* @return bool True if the next domain was loaded, else false
*/
loadNextDomain: function() {

var nextDomainStartTimestamp = this.getNextDomain().getTime();

if (this._maxDomainReached || this.maxDomainIsReached(nextDomainStartTimestamp)) {
return false;
}

var parent = this;
this._domains.push(this.getNextDomain().getTime());
this._domains.push(nextDomainStartTimestamp);
this._domains.shift();

this.paint(this.NAVIGATE_RIGHT);
Expand All @@ -1102,11 +1158,35 @@ CalHeatMap.prototype = {
);

this.afterLoadNextDomain(new Date(this._domains[this._domains.length-1]));

if (this.maxDomainIsReached(this.getNextDomain().getTime())) {
this.onMaxDomainReached(true);
}

// Try to "disengage" the min domain reached setting
if (this._minDomainReached && !this.minDomainIsReached(this._domains[0])) {
this.onMinDomainReached(false);
}

return true;
},

/**
* Shift the calendar one domain backward
*
* The previous domain is loaded only if it's not beyond the minDate
*
* @return bool True if the previous domain was loaded, else false
*/
loadPreviousDomain: function() {
if (this._minDomainReached || this.minDomainIsReached(this._domains[0])) {
return false;
}

var previousDomainStartTimestamp = this.getPreviousDomain().getTime();

var parent = this;
this._domains.unshift(this.getPreviousDomain().getTime());
this._domains.unshift(previousDomainStartTimestamp);
this._domains.pop();

this.paint(this.NAVIGATE_LEFT);
Expand All @@ -1121,6 +1201,35 @@ CalHeatMap.prototype = {
);

this.afterLoadPreviousDomain(new Date(this._domains[0]));

if (this.minDomainIsReached(previousDomainStartTimestamp)) {
this.onMinDomainReached(true);
}

// Try to "disengage" the max domain reached setting
if (this._maxDomainReached && !this.maxDomainIsReached(this._domains[this._domains.length-1])) {
this.onMaxDomainReached(false);
}

return true;
},

/**
* Return whether a date is inside the scope determined by maxDate
*
* @return bool
*/
maxDomainIsReached: function(datetimestamp) {
return (this.options.maxDate !== null && (this.options.maxDate.getTime() < datetimestamp));
},

/**
* Return whether a date is inside the scope determined by minDate
*
* @return bool
*/
minDomainIsReached: function (datetimestamp) {
return (this.options.minDate !== null && (this.options.minDate.getTime() >= datetimestamp));
},

// =========================================================================//
Expand Down
4 changes: 2 additions & 2 deletions cal-heatmap.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cal-heatmap.source-map.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cal-heatmap",
"version": "3.0.7",
"version": "3.0.8",
"description": "Cal-Heatmap is a javascript module to create calendar heatmap to visualize time series data, a la github contribution graph",
"keywords": [
"calendar",
Expand Down

0 comments on commit 5aae520

Please sign in to comment.