@@ -57,6 +57,7 @@ calendar_heatmap.create = function(opts) {
57
57
stroke_color : opts . stroke_color ? opts . stroke_color : "#fff" ,
58
58
discrete_scale : opts . discrete_scale ? opts . discrete_scale : false ,
59
59
num_colors : opts . num_colors ? opts . num_colors : null ,
60
+ on_click : opts . on_click ? opts . on_click : null ,
60
61
//// labels/legend
61
62
title : opts . title ? opts . title : "" ,
62
63
title_size : opts . title_size ? opts . title_size : 18 ,
@@ -129,6 +130,7 @@ calendar_heatmap.create = function(opts) {
129
130
d . dow = options . sunday_start ?
130
131
d . day . weekday ( ) :
131
132
d . day . isoWeekday ( ) - 1 ;
133
+ d . formatted_date = d . day . format ( "dddd MMM DD, YYYY" ) ;
132
134
133
135
// at the start of every week, count a new week and new week within current month
134
136
if ( d . dow === 0 ) {
@@ -217,6 +219,11 @@ calendar_heatmap.create = function(opts) {
217
219
. range ( palette ) ;
218
220
}
219
221
222
+ // add color to data
223
+ _ . map ( options . data , function ( d ) {
224
+ d . fill_color = d [ options . fill_var ] ? color_scale ( d [ options . fill_var ] ) : options . missing_color ;
225
+ } ) ;
226
+
220
227
// margins and sizes
221
228
var margin = {
222
229
top : options . margin_top ,
@@ -582,7 +589,7 @@ calendar_heatmap.create = function(opts) {
582
589
. attr ( "fill" , "#eee" ) ;
583
590
584
591
this_tile . tt_group . append ( "text" )
585
- . text ( d . day . format ( "dddd MMM DD, YYYY" ) )
592
+ . text ( d . formatted_date )
586
593
. style ( "font-size" , "13px" )
587
594
. attr ( "text-anchor" , "middle" )
588
595
. attr ( "x" , options . tooltip_width / 2 )
@@ -639,6 +646,11 @@ calendar_heatmap.create = function(opts) {
639
646
this_tile . tt_group . remove ( ) ;
640
647
} ) ;
641
648
649
+ // click
650
+ if ( options . on_click ) {
651
+ tiles . on ( "click" , options . on_click ) ;
652
+ }
653
+
642
654
// return tick labels to default
643
655
tile_group . on ( "mouseleave" , function ( ) {
644
656
d3 . selectAll ( y_ticks )
0 commit comments