From 732664987033eefdec70599b5931e2b093baa394 Mon Sep 17 00:00:00 2001 From: Darragh Kirwan Date: Sun, 15 May 2016 23:31:03 +0100 Subject: [PATCH] Fixed merging of PR's, added spacing to `toolTipUnit` and fixed some JSHint errors --- src/calendar-heatmap.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/calendar-heatmap.js b/src/calendar-heatmap.js index 3c0347b..5c573dd 100644 --- a/src/calendar-heatmap.js +++ b/src/calendar-heatmap.js @@ -15,6 +15,7 @@ function calendarHeatmap() { var data = []; var colorRange = ['#D8E6E7', '#218380']; var tooltipEnabled = true; + var tooltipUnit = 'contributions'; var legendEnabled = true; var onClick = null; @@ -43,6 +44,12 @@ function calendarHeatmap() { return chart; }; + chart.tooltipUnit = function (value) { + if (!arguments.length) { return tooltipUnit; } + tooltipUnit = value; + return chart; + }; + chart.legendEnabled = function (value) { if (!arguments.length) { return legendEnabled; } legendEnabled = value; @@ -110,8 +117,8 @@ function calendarHeatmap() { .append('div') .attr('class', 'day-cell-tooltip') .html(tooltipHTMLForDate(d)) - .style('left', function () { return Math.floor(i / 7) * SQUARE_LENGTH; }) - .style('top', function () { return d.getDay() * (SQUARE_LENGTH + SQUARE_PADDING) + MONTH_LABEL_PADDING * 3; }); + .style('left', function () { return Math.floor(i / 7) * SQUARE_LENGTH + 'px'; }) + .style('top', function () { return d.getDay() * (SQUARE_LENGTH + SQUARE_PADDING) + MONTH_LABEL_PADDING * 3 + 'px'; }); }) .on('mouseout', function (d, i) { tooltip.remove(); @@ -184,7 +191,7 @@ function calendarHeatmap() { function tooltipHTMLForDate(d) { var dateStr = moment(d).format('ddd, MMM Do YYYY'); var count = countForDate(d); - return '' + (count ? count : 'No') + ' contribution' + (count === 1 ? '' : 's') + ' on ' + dateStr + ''; + return '' + (count ? count : 'No') + ' ' + tooltipUnit + (count === 1 ? '' : 's') + ' on ' + dateStr + ''; } function countForDate(d) { @@ -198,10 +205,10 @@ function calendarHeatmap() { return count; } - var daysOfChart = chart.data().map(function (day){ - // use moment to formt it to Do MM YYYY + var daysOfChart = chart.data().map(function (day) { return day.date.toDateString(); }); + dayRects.filter(function (d) { return daysOfChart.indexOf(d.toDateString()) > -1; }).attr('fill', function (d, i) {