1.0.6 • Published 1 month ago

react-date-heatmap v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

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

NameTypeDefault ValueDescription
dataDate[]-An array of dates to be visualized in the heatmap.
startDateDate-The start date for the heatmap range.
endDateDate-The end date for the heatmap range.
rowsnumber7Number of rows to display in the heatmap grid.
showMonthsbooleantrueDisplay month indicators on the heatmap.
showShadesbooleantrueDisplay shades indicating the quantity of each date.
squareSizenumber32Size of each square in the heatmap grid.
squareColorstring"#00ff00"Color of the filled squares in the heatmap.
textColorstring#000000Color of the months text.
emptySquareColorstring"#333333"Color of empty squares in the heatmap.
onSquareClick(entry: DateEntry) => void-Callback function triggered on square click.
hideTooltipbooleanfalseHide tooltips on square hover.
tooltipContent({ entry }: { entry: DateEntry }) => JSX.Element-Custom tooltip content for each square.
tooltipBackgroundstring"#ffffff"Background color of the tooltip.
tooltipTextColorstring"#000000"Text color of the tooltip.

Types

DateEntry

NameTypeDescription
dateDateThe date represented by the entry.
formattedstringA formatted string representation of the date.
activebooleanIndicates whether the date is active or not.
quantitynumberQuantity associated with the date.
1.0.6

1 month ago

1.0.5

4 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago