Skip to content

Commit

Permalink
Fix #35
Browse files Browse the repository at this point in the history
Can't load new domain with `next()` when the new domain's timestamp contains more character
  • Loading branch information
wa0x6e committed Sep 17, 2013
1 parent 3ab7cf8 commit 6f80ed1
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 40 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v3.2.1 [2013-09-17]

* [fix] Fix #35: Can't load new domain with `next()` when the new domain's timestamp contains more character

## v3.2.0 [2013-09-12]

* [fix] Fix #33: domain browsing is incrementing the calendar's value when data is a json object
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.2.0",
"version": "3.2.1",
"main": ["./cal-heatmap.js", "./cal-heatmap.css"],
"dependencies": {
"d3": "~v3.0.6"
Expand Down
45 changes: 26 additions & 19 deletions cal-heatmap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! cal-heatmap v3.2.0 (Thu Sep 12 2013 19:22:40)
/*! cal-heatmap v3.2.1 (Tue Sep 17 2013 18:46:03)
* ---------------------------------------------
* 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 @@ -534,7 +534,7 @@ var CalHeatMap = function() {

// Fill the graph with some datas
if (self.options.loadOnInit) {
var domains = self._domains.keys().sort();
var domains = self.getDomainKeys();
self.getDatas(
self.options.data,
new Date(parseInt(domains[0], 10)),
Expand Down Expand Up @@ -586,7 +586,7 @@ var CalHeatMap = function() {
// Painting all the domains
var domainSvg = self.root.select(".graph")
.selectAll(".graph-domain")
.data(self._domains.keys().map(function(d) { return parseInt(d, 10); }), function(d) { return d;})
.data(self.getDomainKeys().map(function(d) { return parseInt(d, 10); }), function(d) { return d;})
;

var enteringDomainDim = 0;
Expand Down Expand Up @@ -646,9 +646,7 @@ var CalHeatMap = function() {
var tmp = 0;
switch(navigationDir) {
case false :
//if (domainIndex > 0) {
tmp = graphDim[axis];
//}
tmp = graphDim[axis];

graphDim[axis] += domainDim;
self.domainPosition.setPosition(domainIndex, tmp);
Expand Down Expand Up @@ -1252,12 +1250,11 @@ CalHeatMap.prototype = {
return {t: parent._domainType[parent.options.subDomain].extractUnit(d), v: null};
})
);
this._domains.remove(this._domains.keys().sort().shift());
var domains = this.getDomainKeys();
this._domains.remove(domains.shift());

this.paint(this.NAVIGATE_RIGHT);

var domains = this._domains.keys().sort();

this.getDatas(
this.options.data,
new Date(parseInt(domains[domains.length-1], 10)),
Expand Down Expand Up @@ -1302,12 +1299,11 @@ CalHeatMap.prototype = {
return {t: parent._domainType[parent.options.subDomain].extractUnit(d), v: null};
})
);
this._domains.remove(this._domains.keys().sort().pop());
var domains = this.getDomainKeys();
this._domains.remove(domains.pop());

this.paint(this.NAVIGATE_LEFT);

var domains = this._domains.keys().sort();

this.getDatas(
this.options.data,
new Date(parseInt(domains[0], 10)),
Expand Down Expand Up @@ -1441,6 +1437,12 @@ CalHeatMap.prototype = {

},

getDomainKeys : function() {
return this._domains.keys().sort(function(a, b) {
return parseInt(a, 10) - parseInt(b, 10);
});
},

// =========================================================================//
// POSITIONNING //
// =========================================================================//
Expand Down Expand Up @@ -1749,11 +1751,11 @@ CalHeatMap.prototype = {
},

getNextDomain: function() {
return this.getDomain(parseInt(this._domains.keys().sort().pop(), 10), 2).pop();
return this.getDomain(parseInt(this.getDomainKeys().pop(), 10), 2).pop();
},

getPreviousDomain: function() {
return this.getDomain(parseInt(this._domains.keys().sort().shift(), 10), -1)[0];
return this.getDomain(parseInt(this.getDomainKeys().shift(), 10), -1)[0];
},

/**
Expand Down Expand Up @@ -1943,7 +1945,7 @@ CalHeatMap.prototype = {
updateMode = this.RESET_ALL_ON_UPDATE;
}

var domains = this._domains.keys().sort();
var domains = this.getDomainKeys();
var self = this;
this.getDatas(
dataSource,
Expand Down Expand Up @@ -2092,12 +2094,12 @@ DomainPosition.prototype.getPosition = function(d) {
};

DomainPosition.prototype.getPositionFromIndex = function(i) {
var domains = this.positions.keys().sort();
var domains = this.getKeys();
return this.positions.get(domains[i]);
};

DomainPosition.prototype.getLast = function() {
var domains = this.positions.keys().sort();
var domains = this.getKeys();
return this.positions.get(domains[domains.length-1]);
};

Expand All @@ -2110,7 +2112,7 @@ DomainPosition.prototype.shiftRightBy = function(exitingDomainDim) {
this.set(key, value - exitingDomainDim);
});

var domains = this.positions.keys().sort();
var domains = this.getKeys();
this.positions.remove(domains[0]);
};

Expand All @@ -2119,10 +2121,15 @@ DomainPosition.prototype.shiftLeftBy = function(enteringDomainDim) {
this.set(key, value + enteringDomainDim);
});

var domains = this.positions.keys().sort();
var domains = this.getKeys();
this.positions.remove(domains[domains.length-1]);
};

DomainPosition.prototype.getKeys = function() {
return this.positions.keys().sort(function(a, b) {
return parseInt(a, 10) - parseInt(b, 10);
});
};

/**
* Sprintf like function
Expand Down
6 changes: 3 additions & 3 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.2.0",
"version": "3.2.1",
"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
39 changes: 24 additions & 15 deletions src/cal-heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ var CalHeatMap = function() {

// Fill the graph with some datas
if (self.options.loadOnInit) {
var domains = self._domains.keys().sort();
var domains = self.getDomainKeys();
self.getDatas(
self.options.data,
new Date(parseInt(domains[0], 10)),
Expand Down Expand Up @@ -578,7 +578,7 @@ var CalHeatMap = function() {
// Painting all the domains
var domainSvg = self.root.select(".graph")
.selectAll(".graph-domain")
.data(self._domains.keys().map(function(d) { return parseInt(d, 10); }), function(d) { return d;})
.data(self.getDomainKeys().map(function(d) { return parseInt(d, 10); }), function(d) { return d;})
;

var enteringDomainDim = 0;
Expand Down Expand Up @@ -1242,12 +1242,11 @@ CalHeatMap.prototype = {
return {t: parent._domainType[parent.options.subDomain].extractUnit(d), v: null};
})
);
this._domains.remove(this._domains.keys().sort().shift());
var domains = this.getDomainKeys();
this._domains.remove(domains.shift());

this.paint(this.NAVIGATE_RIGHT);

var domains = this._domains.keys().sort();

this.getDatas(
this.options.data,
new Date(parseInt(domains[domains.length-1], 10)),
Expand Down Expand Up @@ -1292,12 +1291,11 @@ CalHeatMap.prototype = {
return {t: parent._domainType[parent.options.subDomain].extractUnit(d), v: null};
})
);
this._domains.remove(this._domains.keys().sort().pop());
var domains = this.getDomainKeys();
this._domains.remove(domains.pop());

this.paint(this.NAVIGATE_LEFT);

var domains = this._domains.keys().sort();

this.getDatas(
this.options.data,
new Date(parseInt(domains[0], 10)),
Expand Down Expand Up @@ -1431,6 +1429,12 @@ CalHeatMap.prototype = {

},

getDomainKeys : function() {
return this._domains.keys().sort(function(a, b) {
return parseInt(a, 10) - parseInt(b, 10);
});
},

// =========================================================================//
// POSITIONNING //
// =========================================================================//
Expand Down Expand Up @@ -1739,11 +1743,11 @@ CalHeatMap.prototype = {
},

getNextDomain: function() {
return this.getDomain(parseInt(this._domains.keys().sort().pop(), 10), 2).pop();
return this.getDomain(parseInt(this.getDomainKeys().pop(), 10), 2).pop();
},

getPreviousDomain: function() {
return this.getDomain(parseInt(this._domains.keys().sort().shift(), 10), -1)[0];
return this.getDomain(parseInt(this.getDomainKeys().shift(), 10), -1)[0];
},

/**
Expand Down Expand Up @@ -1933,7 +1937,7 @@ CalHeatMap.prototype = {
updateMode = this.RESET_ALL_ON_UPDATE;
}

var domains = this._domains.keys().sort();
var domains = this.getDomainKeys();
var self = this;
this.getDatas(
dataSource,
Expand Down Expand Up @@ -2082,12 +2086,12 @@ DomainPosition.prototype.getPosition = function(d) {
};

DomainPosition.prototype.getPositionFromIndex = function(i) {
var domains = this.positions.keys().sort();
var domains = this.getKeys();
return this.positions.get(domains[i]);
};

DomainPosition.prototype.getLast = function() {
var domains = this.positions.keys().sort();
var domains = this.getKeys();
return this.positions.get(domains[domains.length-1]);
};

Expand All @@ -2100,7 +2104,7 @@ DomainPosition.prototype.shiftRightBy = function(exitingDomainDim) {
this.set(key, value - exitingDomainDim);
});

var domains = this.positions.keys().sort();
var domains = this.getKeys();
this.positions.remove(domains[0]);
};

Expand All @@ -2109,10 +2113,15 @@ DomainPosition.prototype.shiftLeftBy = function(enteringDomainDim) {
this.set(key, value + enteringDomainDim);
});

var domains = this.positions.keys().sort();
var domains = this.getKeys();
this.positions.remove(domains[domains.length-1]);
};

DomainPosition.prototype.getKeys = function() {
return this.positions.keys().sort(function(a, b) {
return parseInt(a, 10) - parseInt(b, 10);
});
};

/**
* Sprintf like function
Expand Down

0 comments on commit 6f80ed1

Please sign in to comment.