npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

calendar-heatmap-mini

v1.3.0

Published

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

Downloads

6

Readme

D3 Calendar Heatmap Mini

This code was originally forked from https://github.com/DKirwan/calendar-heatmap and modified. This serves to publish the package to npm as calendar-heatmap-mini along with a few key differences.

Key Differences

  • Option for singleSelection thanks to @remyvhw.
  • npm installable as well as importable as a module.
  • Update to the latest [email protected]
    • Trim down to specific d3 packages.
  • Data is auto initialized if none is presented.
  • When updating the same instance of a heatmap, previous max size is not used.
  • Use SVG text for tooltips.
  • Move into a non-forked version of the repository.
    • Rework project structure into the appropriate name (calendar-heatmap-mini).

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 | no | | 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 | | singleSelection | Option to only be able to select a single date | false | no | | locale | Object to translate every word used, except for tooltipUnit | see below | no |

Default locale object

{
    months: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
    days: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
    No: 'No',
    on: 'on',
    Less: 'Less',
    More: 'More'
}

Dependencies

Usage

Without npm

1: Add d3.js and moment.js

2: Include calendar-heatmap-mini.js and calendar-heatmap-mini.css.

<link rel="stylesheet" type="text/css" href="path/tocalendar-heatmap-mini.css">
<script src="path/to/calendar-heatmap-mini.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

// chart data example
var chartData = [{
  date: new Date(),
  count: 100
}];

var chart1 = calendarHeatmap()
              .data(chartData)
              .selector('#chart-one')
              .colorRange(['#D8E6E7', '#218380'])
              .tooltipEnabled(true)
              .onClick(function (data) {
                console.log('onClick callback. Data:', data);
              });

// render the chart
chart1();

With npm

1: Add package dependency.

npm install calendar-heatmap-mini --save
  1. Import however desired.
import CalendarHeatMap from 'calendar-heatmap-mini'
  1. Configure and render the chart.
import CalendarHeatMap from 'calendar-heatmap-mini'

// chart data example
var chartData = [{
  date: new Date(),
  count: 100
}];

const chart1 = new CalendarHeatMap()
              .data(chartData)
              .selector('#chart-one')
              .colorRange(['#D8E6E7', '#218380'])
              .tooltipEnabled(true)
              .onClick(function (data) {
                console.log('onClick callback. Data:', data);
              });

// render the chart
chart1();

Control Unit Pluralization

var chart1 = calendarHeatmap()
              .data(chartData)
              .tooltipUnit(
                [
                  {min: 0, unit: 'contribution'},
                  {min: 1, max: 1, unit: 'contribution'},
                  {min: 2, max: 'Infinity', unit: 'contributions'}
                ]
              );
chart1();  // render the chart

Pull Requests and Issues

...are very welcome!