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

react-date-heatmap

v1.0.6

Published

A React Component that allows you to visualize an array of dates in form of a heatmap.

Downloads

19

Readme

react-date-heatmap

A React Component that allows you to visualize an array of dates in form of a heatmap.

screenshot

Installation

Install react-date-heatmap in your project using the following npm command:

npm install react-date-heatmap

Or with yarn

yarn add react-date-heatmap

After installation, you can use the ReactDateHeatmap component in your React project.

import React from 'react';
import ReactDateHeatmap from 'react-date-heatmap';

const YourComponent = () => {
  const arrayOfDates = /* ... */;

  return (
    <ReactDateHeatmap data={arrayOfDates} />
  );
}

export default YourComponent;

Usage Example

import React, { useState } from "react";
import { DateEntry, ReactDateHeatmap } from "react-date-heatmap";

// generate an array of random dates
function getRandomDateArray(length: number) {
  const startDate = new Date(2023, 9, 7);
  const endDate = new Date(2023, 11, 31);
  const dateArray: Date[] = [];
  for (let i = 0; i < length; i++) {
    const randomTime =
      startDate.getTime() +
      Math.random() * (endDate.getTime() - startDate.getTime());
    const randomDate = new Date(randomTime);
    dateArray.push(randomDate);
  }
  return dateArray;
}

function ExampleApp() {
  const [data, setData] = useState(getRandomDateArray(100));

  // Console log the Entry you clicked on
  const onSquareClick = (entry: DateEntry) => {
    console.log("You Clicked on entry", entry);
  };
  // Create your own content div that shows up when you hover over a square/entry
  const TooltipContent = ({ entry }: { entry: DateEntry }) => {
    return (
      <div style={{ display: "flex", flexDirection: "column" }}>
        <span>{entry.formatted}</span>
        <span>Entries: {entry.quantity}</span>
      </div>
    );
  };

  return (
    <ReactDateHeatmap
      data={data}
      tooltipContent={TooltipContent}
      onSquareClick={onSquareClick}
      squareColor="#ff0000"
    />
  );
}

export default ExampleApp;

List of Props

| Name | Type | Default Value | Description | | ------------------- | -------------------------------------------------- | ------------- | ---------------------------------------------------- | | data | Date[] | - | An array of dates to be visualized in the heatmap. | | startDate | Date | - | The start date for the heatmap range. | | endDate | Date | - | The end date for the heatmap range. | | rows | number | 7 | Number of rows to display in the heatmap grid. | | showMonths | boolean | true | Display month indicators on the heatmap. | | showShades | boolean | true | Display shades indicating the quantity of each date. | | squareSize | number | 32 | Size of each square in the heatmap grid. | | squareColor | string | "#00ff00" | Color of the filled squares in the heatmap. | | textColor | string | #000000 | Color of the months text. | | emptySquareColor | string | "#333333" | Color of empty squares in the heatmap. | | onSquareClick | (entry: DateEntry) => void | - | Callback function triggered on square click. | | hideTooltip | boolean | false | Hide tooltips on square hover. | | tooltipContent | ({ entry }: { entry: DateEntry }) => JSX.Element | - | Custom tooltip content for each square. | | tooltipBackground | string | "#ffffff" | Background color of the tooltip. | | tooltipTextColor | string | "#000000" | Text color of the tooltip. |

Types

DateEntry

| Name | Type | Description | | ----------- | --------- | ---------------------------------------------- | | date | Date | The date represented by the entry. | | formatted | string | A formatted string representation of the date. | | active | boolean | Indicates whether the date is active or not. | | quantity | number | Quantity associated with the date. |