Skip to content

Commit

Permalink
Allow to set start date
Browse files Browse the repository at this point in the history
Before, heatmap always ends today and starts a year ago. Now a
startDate can be set by the user via .startData(Date)
  • Loading branch information
peterdesmet committed Jan 20, 2017
1 parent 57857c4 commit 09e24a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ A [d3.js](https://d3js.org/) heatmap representing time series data. Inspired by
| data | Chart data | none | yes |
| selector | DOM selector to attach the chart to | body | no |
| max | Maximum count | max found in data | no |
| startDate | Date to start heatmap at | 1 year ago | no |
| colorRange | Minimum and maximum chart gradient colors | ['#D8E6E7', '#218380'] | no |
| tooltipEnabled | Option to render a tooltip | true | no |
| tooltipUnit | Unit to render on the tooltip | 'contributions' | no |
Expand Down
8 changes: 8 additions & 0 deletions src/calendar-heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function calendarHeatmap() {
var MONTH_LABEL_PADDING = 6;
var now = moment().endOf('day').toDate();
var yearAgo = moment().startOf('day').subtract(1, 'year').toDate();
var startDate = null;
var data = [];
var max = null;
var colorRange = ['#D8E6E7', '#218380'];
Expand Down Expand Up @@ -40,6 +41,13 @@ function calendarHeatmap() {
return chart;
};

chart.startDate = function (value) {
if (!arguments.length) { return startDate; }
yearAgo = value;
now = moment(value).endOf('day').add(1, 'year').toDate();
return chart;
};

chart.colorRange = function (value) {
if (!arguments.length) { return colorRange; }
colorRange = value;
Expand Down

0 comments on commit 09e24a8

Please sign in to comment.