Skip to content

Commit

Permalink
Add setting to not paint domain label, and control its height
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e committed Sep 4, 2013
1 parent 5c76f04 commit a70e2b7
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 54 deletions.
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.1.0",
"version": "3.1.1",
"main": ["./cal-heatmap.js", "./cal-heatmap.css"],
"dependencies": {
"d3": "~v3.0.6"
Expand Down
101 changes: 54 additions & 47 deletions cal-heatmap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! cal-heatmap v3.1.0 (Thu Aug 08 2013 01:26:26)
/*! cal-heatmap v3.1.1 (Wed Sep 04 2013 15:37:25)
* ---------------------------------------------
* 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 @@ -100,7 +100,11 @@ var CalHeatMap = function() {

rotate: null,

width: 100
// Used only on vertical orientation
width: 100,

// Used only on horizontal orientation
height: null
},

// ================================================
Expand Down Expand Up @@ -483,9 +487,13 @@ var CalHeatMap = function() {

self.verticalDomainLabel = (self.options.label.position === "top" || self.options.label.position === "bottom");

self.domainVerticalLabelHeight = Math.max(25, self.options.cellSize*2);
self.domainVerticalLabelHeight = self.options.label.height === null ? Math.max(25, self.options.cellSize*2) : self.options.label.height;
self.domainHorizontalLabelWidth = 0;

if (self.options.domainLabelFormat === "" && self.options.label.height === null) {
self.domainVerticalLabelHeight = 0;
}

if (!self.verticalDomainLabel) {
self.domainVerticalLabelHeight = 0;
self.domainHorizontalLabelWidth = self.options.label.width;
Expand Down Expand Up @@ -730,50 +738,52 @@ var CalHeatMap = function() {
// =========================================================================//
// PAINTING LABEL //
// =========================================================================//
self.svg.append("text")
.attr("class", "graph-label")
.attr("y", function(d) {
var y = self.options.domainMargin[0];
switch(self.options.label.position) {
case "top" : y += self.domainVerticalLabelHeight/2; break;
case "bottom" : y += h(d) + self.domainVerticalLabelHeight/2;
}
if (self.options.domainLabelFormat !== "") {
self.svg.append("text")
.attr("class", "graph-label")
.attr("y", function(d) {
var y = self.options.domainMargin[0];
switch(self.options.label.position) {
case "top" : y += self.domainVerticalLabelHeight/2; break;
case "bottom" : y += h(d) + self.domainVerticalLabelHeight/2;
}

return y + self.options.label.offset.y *
(
((self.options.label.rotate === "right" && self.options.label.position === "right") ||
(self.options.label.rotate === "left" && self.options.label.position === "left")) ?
-1 : 1
);
})
.attr("x", function(d){
var x = self.options.domainMargin[3];
switch(self.options.label.position) {
case "right" : x += w(d); break;
case "bottom" :
case "top" : x += w(d)/2;
}
return y + self.options.label.offset.y *
(
((self.options.label.rotate === "right" && self.options.label.position === "right") ||
(self.options.label.rotate === "left" && self.options.label.position === "left")) ?
-1 : 1
);
})
.attr("x", function(d){
var x = self.options.domainMargin[3];
switch(self.options.label.position) {
case "right" : x += w(d); break;
case "bottom" :
case "top" : x += w(d)/2;
}

if (self.options.label.align === "right") {
return x + self.domainHorizontalLabelWidth - self.options.label.offset.x *
(self.options.label.rotate === "right" ? -1 : 1);
}
return x + self.options.label.offset.x;
if (self.options.label.align === "right") {
return x + self.domainHorizontalLabelWidth - self.options.label.offset.x *
(self.options.label.rotate === "right" ? -1 : 1);
}
return x + self.options.label.offset.x;

})
.attr("text-anchor", function() {
switch(self.options.label.align) {
case "start" :
case "left" : return "start";
case "end" :
case "right" : return "end";
default : return "middle";
}
})
.attr("dominant-baseline", function() { return self.verticalDomainLabel ? "middle" : "top"; })
.text(function(d) { return self.formatDate(new Date(d), self.options.domainLabelFormat); })
.call(domainRotate)
;
})
.attr("text-anchor", function() {
switch(self.options.label.align) {
case "start" :
case "left" : return "start";
case "end" :
case "right" : return "end";
default : return "middle";
}
})
.attr("dominant-baseline", function() { return self.verticalDomainLabel ? "middle" : "top"; })
.text(function(d) { return self.formatDate(new Date(d), self.options.domainLabelFormat); })
.call(domainRotate)
;
}

function domainRotate(selection) {
switch (self.options.label.rotate) {
Expand Down Expand Up @@ -804,9 +814,6 @@ var CalHeatMap = function() {
}
}




// =========================================================================//
// PAINTING DOMAIN SUBDOMAIN CONTENT //
// =========================================================================//
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.

16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cal-heatmap",
"version": "3.1.0",
"version": "3.1.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 All @@ -24,7 +24,19 @@
"grunt-contrib-copy": "~0.4.0",
"grunt-replace": "~0.4.0",
"grunt-contrib-concat": "~0.1.3",
"grunt-qunit-istanbul": "~0.1.3"
"grunt-qunit-istanbul": "~0.1.3",
"karma-script-launcher": "~0.1.0",
"karma-firefox-launcher": "~0.1.0",
"karma-chrome-launcher": "~0.1.0",
"karma-html2js-preprocessor": "~0.1.0",
"karma-jasmine": "~0.1.3",
"karma-requirejs": "~0.1.0",
"karma-coffee-preprocessor": "~0.1.0",
"karma-phantomjs-launcher": "~0.1.0",
"karma": "~0.10.2",
"karma-junit-reporter": "~0.1.0",
"karma-coverage": "~0.1.0",
"karma-qunit": "~0.1.0"
},
"scripts": {
"test": "grunt travis --verbose; ./node_modules/.bin/karma start --single-run --browsers PhantomJS"
Expand Down

0 comments on commit a70e2b7

Please sign in to comment.