Socket
Socket
Sign inDemoInstall

react-light-heatmap

Package Overview
Dependencies
10
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-light-heatmap

React component for heatmap grid layout


Version published
Weekly downloads
30
increased by20%
Maintainers
1
Install size
86.0 kB
Created
Weekly downloads
 

Readme

Source

react-light-heatmap

NPM JavaScript Style Guide

A React component for heatmap in grid layout using div.

Demo

alt tag

Installation

yarn add react-light-heatmap  

or

npm install react-light-heatmap --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
componentsobjectReplace default componentdefault components
backgroundstringThe base color for the heatmap"#239a3b"
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
xLabelsLocationstringLocation of y labels. It can be top or bottom"top"
unitstringUnit to display next to the value on hover
cellStylefunctionTo set custom cell style. It is useful for using own colour scheme
getValuefunctionTo get value from provided datavalue => value

Example

  
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}  
    xLabelWidth={50}  
    data={data}  
    squares  
    onClick={(x, y) => alert(`Clicked ${x}, ${y}`)}  
    cellStyle={(background, value, min, max, data, x, y) => ({  
      background: `rgb(66, 86, 244, ${1 - (max - value) / (max - min)})`,  
      fontSize: "11px",  
    })}  
    cellRender={value => value && `${value}%`}  
  />,  
  document.getElementById("app")  
);  

Replacing components

Cell Component responsible for displaing a cell in grid. Props:

type = {
    value: number,
    x: number,
    y: number,
    height: number
}

All other props will be passed to the div component

CellContent Component responsible for displaing a content inside cell component. Props:

type = {
    value: number
}

By default display nothing

XLabel Component responsible for displaing X label Props:

type = {
    value: string|number,
    squares: boolean,
    index: number,
    height: number
}

Default render

<div  
  style={{  
	  flex: squares ? 'none' : 1,  
	  textAlign: 'center',  
	  width: squares ? `${height + 1}px` : 'undefined',  
	  ...style  
  }}  
>  
 {value}  
</div>

YLabel Component responsible for displaing Y label Props:

type = {
    value: string|number,
    squares: boolean,
    index: number,
    height: number
}

Default render

<div  
  style={{  
	  textAlign: 'center',  
	  paddingRight: '5px',  
	  paddingTop: `${height / 3.7}px`,  
	  ...style  
  }} 
>  
 {value}  
</div>

For developers

New build

yarn build  

Run dev server

yarn start

Run test

npm run test  

FAQs

Last updated on 21 Jul 2019

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc