Skip to content

Commit a70e2b7

Browse files
committed
Add setting to not paint domain label, and control its height
1 parent 5c76f04 commit a70e2b7

File tree

5 files changed

+73
-54
lines changed

5 files changed

+73
-54
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cal-heatmap",
3-
"version": "3.1.0",
3+
"version": "3.1.1",
44
"main": ["./cal-heatmap.js", "./cal-heatmap.css"],
55
"dependencies": {
66
"d3": "~v3.0.6"

cal-heatmap.js

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! cal-heatmap v3.1.0 (Thu Aug 08 2013 01:26:26)
1+
/*! cal-heatmap v3.1.1 (Wed Sep 04 2013 15:37:25)
22
* ---------------------------------------------
33
* Cal-Heatmap is a javascript module to create calendar heatmap to visualize time series data, a la github contribution graph
44
* https://github.com/kamisama/cal-heatmap
@@ -100,7 +100,11 @@ var CalHeatMap = function() {
100100

101101
rotate: null,
102102

103-
width: 100
103+
// Used only on vertical orientation
104+
width: 100,
105+
106+
// Used only on horizontal orientation
107+
height: null
104108
},
105109

106110
// ================================================
@@ -483,9 +487,13 @@ var CalHeatMap = function() {
483487

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

486-
self.domainVerticalLabelHeight = Math.max(25, self.options.cellSize*2);
490+
self.domainVerticalLabelHeight = self.options.label.height === null ? Math.max(25, self.options.cellSize*2) : self.options.label.height;
487491
self.domainHorizontalLabelWidth = 0;
488492

493+
if (self.options.domainLabelFormat === "" && self.options.label.height === null) {
494+
self.domainVerticalLabelHeight = 0;
495+
}
496+
489497
if (!self.verticalDomainLabel) {
490498
self.domainVerticalLabelHeight = 0;
491499
self.domainHorizontalLabelWidth = self.options.label.width;
@@ -730,50 +738,52 @@ var CalHeatMap = function() {
730738
// =========================================================================//
731739
// PAINTING LABEL //
732740
// =========================================================================//
733-
self.svg.append("text")
734-
.attr("class", "graph-label")
735-
.attr("y", function(d) {
736-
var y = self.options.domainMargin[0];
737-
switch(self.options.label.position) {
738-
case "top" : y += self.domainVerticalLabelHeight/2; break;
739-
case "bottom" : y += h(d) + self.domainVerticalLabelHeight/2;
740-
}
741+
if (self.options.domainLabelFormat !== "") {
742+
self.svg.append("text")
743+
.attr("class", "graph-label")
744+
.attr("y", function(d) {
745+
var y = self.options.domainMargin[0];
746+
switch(self.options.label.position) {
747+
case "top" : y += self.domainVerticalLabelHeight/2; break;
748+
case "bottom" : y += h(d) + self.domainVerticalLabelHeight/2;
749+
}
741750

742-
return y + self.options.label.offset.y *
743-
(
744-
((self.options.label.rotate === "right" && self.options.label.position === "right") ||
745-
(self.options.label.rotate === "left" && self.options.label.position === "left")) ?
746-
-1 : 1
747-
);
748-
})
749-
.attr("x", function(d){
750-
var x = self.options.domainMargin[3];
751-
switch(self.options.label.position) {
752-
case "right" : x += w(d); break;
753-
case "bottom" :
754-
case "top" : x += w(d)/2;
755-
}
751+
return y + self.options.label.offset.y *
752+
(
753+
((self.options.label.rotate === "right" && self.options.label.position === "right") ||
754+
(self.options.label.rotate === "left" && self.options.label.position === "left")) ?
755+
-1 : 1
756+
);
757+
})
758+
.attr("x", function(d){
759+
var x = self.options.domainMargin[3];
760+
switch(self.options.label.position) {
761+
case "right" : x += w(d); break;
762+
case "bottom" :
763+
case "top" : x += w(d)/2;
764+
}
756765

757-
if (self.options.label.align === "right") {
758-
return x + self.domainHorizontalLabelWidth - self.options.label.offset.x *
759-
(self.options.label.rotate === "right" ? -1 : 1);
760-
}
761-
return x + self.options.label.offset.x;
766+
if (self.options.label.align === "right") {
767+
return x + self.domainHorizontalLabelWidth - self.options.label.offset.x *
768+
(self.options.label.rotate === "right" ? -1 : 1);
769+
}
770+
return x + self.options.label.offset.x;
762771

763-
})
764-
.attr("text-anchor", function() {
765-
switch(self.options.label.align) {
766-
case "start" :
767-
case "left" : return "start";
768-
case "end" :
769-
case "right" : return "end";
770-
default : return "middle";
771-
}
772-
})
773-
.attr("dominant-baseline", function() { return self.verticalDomainLabel ? "middle" : "top"; })
774-
.text(function(d) { return self.formatDate(new Date(d), self.options.domainLabelFormat); })
775-
.call(domainRotate)
776-
;
772+
})
773+
.attr("text-anchor", function() {
774+
switch(self.options.label.align) {
775+
case "start" :
776+
case "left" : return "start";
777+
case "end" :
778+
case "right" : return "end";
779+
default : return "middle";
780+
}
781+
})
782+
.attr("dominant-baseline", function() { return self.verticalDomainLabel ? "middle" : "top"; })
783+
.text(function(d) { return self.formatDate(new Date(d), self.options.domainLabelFormat); })
784+
.call(domainRotate)
785+
;
786+
}
777787

778788
function domainRotate(selection) {
779789
switch (self.options.label.rotate) {
@@ -804,9 +814,6 @@ var CalHeatMap = function() {
804814
}
805815
}
806816

807-
808-
809-
810817
// =========================================================================//
811818
// PAINTING DOMAIN SUBDOMAIN CONTENT //
812819
// =========================================================================//

cal-heatmap.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cal-heatmap.source-map.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cal-heatmap",
3-
"version": "3.1.0",
3+
"version": "3.1.1",
44
"description": "Cal-Heatmap is a javascript module to create calendar heatmap to visualize time series data, a la github contribution graph",
55
"keywords": [
66
"calendar",
@@ -24,7 +24,19 @@
2424
"grunt-contrib-copy": "~0.4.0",
2525
"grunt-replace": "~0.4.0",
2626
"grunt-contrib-concat": "~0.1.3",
27-
"grunt-qunit-istanbul": "~0.1.3"
27+
"grunt-qunit-istanbul": "~0.1.3",
28+
"karma-script-launcher": "~0.1.0",
29+
"karma-firefox-launcher": "~0.1.0",
30+
"karma-chrome-launcher": "~0.1.0",
31+
"karma-html2js-preprocessor": "~0.1.0",
32+
"karma-jasmine": "~0.1.3",
33+
"karma-requirejs": "~0.1.0",
34+
"karma-coffee-preprocessor": "~0.1.0",
35+
"karma-phantomjs-launcher": "~0.1.0",
36+
"karma": "~0.10.2",
37+
"karma-junit-reporter": "~0.1.0",
38+
"karma-coverage": "~0.1.0",
39+
"karma-qunit": "~0.1.0"
2840
},
2941
"scripts": {
3042
"test": "grunt travis --verbose; ./node_modules/.bin/karma start --single-run --browsers PhantomJS"

0 commit comments

Comments
 (0)