New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-heatmap-grid

Package Overview
Dependencies
Maintainers
0
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-heatmap-grid

React component for heatmap on grid layout

  • 0.9.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.6K
decreased by-11.9%
Maintainers
0
Weekly downloads
 
Created
Source

react-heatmap-grid

Created a new version of this having smaller size and a better interface. Check it out.

A React component for heatmap in grid layout using div.

Live example here.

image

Installation

yarn add react-heatmap-grid

or

npm install react-heatmap-grid --save

Usage

Mandatory fields

NameTypeSample
xLabelsArray of string['1am', '2am', '3am']
yLabelsArray of string['Sun', 'Mon']
data2D Array of numbers having yLabels.length rows and xLabels.length rows[[2,3,5][5,6,9]]
const xLabels = new Array(24).fill(0).map((_, i) => `${i}`);
const yLabels = ["Sun", "Mon", "Tue"];
const data = new Array(yLabels.length)
  .fill(0)
  .map(() =>
    new Array(xLabels.length).fill(0).map(() => Math.floor(Math.random() * 100))
  );

ReactDOM.render(
  <HeatMap xLabels={xLabels} yLabels={yLabels} data={data} />,
  document.getElementById("app")
);

Configuration

NameTypeDescriptionDefault Value
backgroundstringThe base color for the heatmap"#329fff"
heightnumberHeight of each cell of the heatmap in px30
onClickfunctionAdds an handler to cell clickundefined
squaresbooleanIf set to true will render cells as squarefalse
xLabelWidthnumberWidth of the x label area in pixel60
yLabelWidthnumberWidth of the y label area in pixel40
yLabelTextAlignstringText alignment of the yLabels"right"
xLabelsLocationstringLocation of y labels. It can be top or bottom"top"
xLabelsVisibility[boolean]Array of bool conveying which x labels to display. For ex: [true, false, true, false] means the 1st and the 3rd labels will be displayed and the 2nd and 4th will be hidden
unitstringUnit to display next to the value on hover
cellRenderfunctionRender custom content in cell() => null
cellStylefunctionTo set custom cell style. It is useful for using own colour scheme
titlefunctionTo render custom title in each cell${value} ${unit}

Example

const xLabels = new Array(24).fill(0).map((_, i) => `${i}`);

// Display only even labels
const xLabelsVisibility = new Array(24)
  .fill(0)
  .map((_, i) => (i % 2 === 0 ? true : false));

const yLabels = ["Sun", "Mon", "Tue"];
const data = new Array(yLabels.length)
  .fill(0)
  .map(() =>
    new Array(xLabels.length).fill(0).map(() => Math.floor(Math.random() * 100))
  );

ReactDOM.render(
  <HeatMap
    xLabels={xLabels}
    yLabels={yLabels}
    xLabelsLocation={"bottom"}
    xLabelsVisibility={xLabelsVisibility}
    xLabelWidth={50}
    data={data}
    squares
    onClick={(x, y) => alert(`Clicked ${x}, ${y}`)}
    cellStyle={(background, value, min, max, data, x, y) => ({
      background: `rgba(66, 86, 244, ${1 - (max - value) / (max - min)})`,
      fontSize: "11px",
    })}
    cellRender={(value) => value && `${value}%`}
    title={(value, unit) => `${value}`}
  />,
  document.getElementById("app")
);

For developers

New build

npm run build

Run dev server

npm run dev

Run test

npm run test

Buy Me A Coffee

Keywords

FAQs

Package last updated on 09 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc