项目作者: DKirwan

项目描述 :
A d3 heatmap for representing time series data similar to github's contribution chart
高级语言: JavaScript
项目地址: git://github.com/DKirwan/calendar-heatmap.git
创建时间: 2016-02-16T20:54:30Z
项目社区:https://github.com/DKirwan/calendar-heatmap

开源协议:MIT License

下载


This project is not actively maintained

D3 Calendar Heatmap

A d3.js heatmap representing time series data. Inspired by Github’s contribution chart

Reusable D3.js Calendar Heatmap chart

Configuration

Property Usage Default Required
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, can be object for pluralization control ‘contributions’ no
legendEnabled Option to render a legend true no
onClick callback function on day click events (see example below) null no
locale Object to translate every word used, except for tooltipUnit see below no

Default locale object

  1. {
  2. months: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  3. days: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
  4. No: 'No',
  5. on: 'on',
  6. Less: 'Less',
  7. More: 'More'
  8. }

Dependencies

Usage

1: Add d3.js and moment.js

2: Include calendar-heatmap.js and calendar-heatmap.css
<link rel="stylesheet" type="text/css" href="path/tocalendar-heatmap.css">
<script src="path/to/calendar-heatmap.js"></script>

3: Format the data so each array item has a date and count property.
As long as new Date() can parse the date string it’s ok. Note - there all data should be rolled up into daily bucket granularity.

4: Configure the chart and render it

  1. // chart data example
  2. var chartData = [{
  3. date: valid Javascript date object,
  4. count: Number
  5. }];
  6. var chart1 = calendarHeatmap()
  7. .data(chartData)
  8. .selector('#chart-one')
  9. .colorRange(['#D8E6E7', '#218380'])
  10. .tooltipEnabled(true)
  11. .onClick(function (data) {
  12. console.log('onClick callback. Data:', data);
  13. });
  14. chart1(); // render the chart

control unit pluralization

  1. var chart1 = calendarHeatmap()
  2. .data(chartData)
  3. .tooltipUnit(
  4. [
  5. {min: 0, unit: 'contribution'},
  6. {min: 1, max: 1, unit: 'contribution'},
  7. {min: 2, max: 'Infinity', unit: 'contributions'}
  8. ]
  9. );
  10. chart1(); // render the chart

Pull Requests and issues

…are very welcome!