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

@tcs-open-source/simple-d3-heatmap

v1.0.16

Published

This module allows you to create nicely looking heatmap calendars with ease.

Downloads

21

Readme

simple-d3-heatmap

A javascript module to create heatmap calendars
Demo: https://team-centric-software.github.io/simple-d3-heatmap/

Description

This module allows you to create nicely looking heatmap calendars with ease. You can choose between yearly, monthly and weekly format.

Preview

Yearly:

yearly calendar

Monthly:

monthly calendar

Weekly:

weekly calendar

Getting Started

Installation

Embed the d3-heatmap.js as well as d3.js in your HTML

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/d3.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tcs-open-source/simple-d3-heatmap@latest/simple-d3-heatmap.min.js"></script>

Basic Usage

<!-- Create div to append the calendar to -->
<div id="calendarContainer"></div>

<script>
	// time series data with the format `timestamp: value` as object
	const data = {
		1546254000000: 29,
		1546257600000: 41,
		1546261200000: 50,
		1546264800000: 13,
		1546268400000: 5,
	};

	// create a new instance of SimpleD3Heatmap
	const heatmap = new SimpleD3Heatmap();
	
	// create a weekly calendar which we will append to `calendarContainer` with the data `data`
	heatmap.weekly("calendarContainer", data);
</script>

<!-- Styling for the Tooltip -->
<style>
	.d3-calendar-tooltip {
		background-color: white;
		border: 2px solid #111;
		color: black;
		width: max-content;
		padding: 3px 12px;
	}

	.d3-calendar-tooltip::after {
		box-sizing: border-box;
		display: inline;
		font-size: 12px;
		width: 100%;
		line-height: 1;
		color: #111;
		content: "\25BC";
		position: absolute;
		left: 0px;
		top: 24px;
		text-align: center;
	}
</style>

Heatmap calendar live preview and playground: Click here

Documentation

new SimpleD3Heatmap([settings])

Creates an instance of SimpleD3Heatmap.

Parameters

| Name | Type | Description | default | | | ---- | ---- | ----------- | ------- | -------- | | settings | Object | Object which holds all settings for the SimpleD3Heatmap | {} | Optional | | settings.minColor | color | Color of the lowest datapoint in the heatmap - as HEX, RGB or CSS color code | "#ECF5E2" | Optional | | settings.maxColor | color | Color of the highest datapoint in the heatmap - as HEX, RGB or CSS color code | "#222081" | Optional | | settings.colorMode | int | Selects the way the colors are generated (1 => linear, 2 => sqrt or 3 => cubehelix) | 2 | Optional | | settings.gutterSize | float | Defines the space inbetween the square (0 - 1) (not for yearly) | 0.1 | Optional | | settings.outerSize | float | Defines the space inbetween the axis and the square (0 - 1) (not for yearly) | 0.35 | Optional | | settings.scale | float | Defines the size of the heatmap | 1 | Optional | | settings.showLines | boolean | Show axis lines? (not for yearly) | false | Optional | | settings.showTicks | boolean | Show axis ticks? (not for yearly) | true | Optional | | settings.locale | String | Locale - language used for months, weekdays and date formats | "en-US" | Optional | | settings.dayNameLength | String | Defines the weekday format (long => "Friday", short => "Fri" or narrow => "F") | "long" | Optional | | settings.showMonth | boolean | Show the months? | true | Optional | | settings.includeWeekend | boolean | Show saturday and sunday? Only for weekly calendar heatmap | true | Optional | | settings.tooltipClass | String | CSS class for the tooltip | "d3-calendar-tooltip" | Optional | | settings.mobileViewPx | Number | At how many pixels (width) change to mobile view? | 1200 | Optional | | settings.enableAnimations | boolean | Enable animations when rendering the calendar heatmaps | true | Optional |

Example
const heatmap = new SimpleD3Heatmap({
	minColor: "#ECF5E2", // lowest datapoint's color in the heatmap - e.g. rgb(0, 255, 0) or #00ff00
	maxColor: "#222081", // highest datapoint's color in the heatmap - e.g. rgb(255, 255, 0) or #ffff00
	colorMode: 2, // switches between color scales (1: linear, 2: sqrt and 3: cubehelix)
	
	gutterSize: 0.1, // distance inbetween the squares (range: 0-1)
	outerSize: 0.35, // distance inbetween axis x, y and the squares
	scale: 0.8, // scale of the heatmap
	
	showLines: false, // show the axis line
	showTicks: true, // show the axis ticks
	locale: "de-DE", // defines the format of the date in the axis
	dayNameLength: "short", // style of the displayed weekday, options => long: "Friday", short: "Fri", narrow: "F" (uses locale)
	showMonth: true, // displays the months (uses locale)
	includeWeekend: true, // include the weekend in weekly calendar or only monday till friday?

	tooltipClass: "d3-calendar-tooltip", // class of the tooltip
	mobileViewPx: 1200, // at which width change to mobileview?
	enableAnimations: true, // enable animations when rendering calendar?
})
Returns
  • Void

SimpleD3Heatmap.weekly(container_id, data)

Creates a heatmap calendar of one week

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | container_id | String | ID of the container where the heatmap should be appended to |   | | data | heatmapData | Data for the heatmap |   |

Returns
  • Void

SimpleD3Heatmap.monthly(container_id, data)

Creates a heatmap calendar of one month

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | container_id | String | ID of the container where the heatmap should be appended to |   | | data | heatmapData | Data for the heatmap |   |

Returns
  • Void

SimpleD3Heatmap.yearly(container_id, data)

Creates a heatmap calendar of one year

Parameters

| Name | Type | Description | | | ---- | ---- | ----------- | -------- | | container_id | String | ID of the container where the heatmap should be appended to |   | | data | heatmapData | Data for the heatmap |   |

Returns
  • Void

Data Format: heatmapData

{
	timestamp: value,
	...
}