React component for heatmap on grid layout
npm install react-heatmap-gridCreated 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.
```
yarn add react-heatmap-grid
or
``
npm install react-heatmap-grid --save
Mandatory fields
| Name | Type | Sample |
| --------- | -------------------------------------------------------------------------- | ----------------------- |
| xLabels | Array of string | ['1am', '2am', '3am'] |yLabels
| | Array of string | ['Sun', 'Mon'] |data
| | 2D Array of numbers having yLabels.length rows and xLabels.length rows | [[2,3,5][5,6,9]] |
`javascript${i}
const xLabels = new Array(24).fill(0).map((_, 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(
document.getElementById("app")
);
`
Configuration
| Name | Type | Description | Default Value |
| ----------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
| background | string | The base color for the heatmap | "#329fff" |30
| height | number | Height of each cell of the heatmap in px | |undefined
| onClick | function | Adds an handler to cell click | |true
| squares | boolean | If set to will render cells as square | false |60
| xLabelWidth | number | Width of the x label area in pixel | |40
| yLabelWidth | number | Width of the y label area in pixel | |"right"
| yLabelTextAlign | string | Text alignment of the yLabels | |"top"
| xLabelsLocation | string | Location of y labels. It can be top or bottom | |[boolean]
| xLabelsVisibility | | 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 | |() => null
| unit | string | Unit to display next to the value on hover | |
| cellRender | function | Render custom content in cell | |${value} ${unit}
| cellStyle | function | To set custom cell style. It is useful for using own colour scheme | |
| title | function | To render custom title in each cell | |
Example
`javascript${i}
const xLabels = new Array(24).fill(0).map((_, 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(
yLabels={yLabels}
xLabelsLocation={"bottom"}
xLabelsVisibility={xLabelsVisibility}
xLabelWidth={50}
data={data}
squares
onClick={(x, y) => alert(Clicked ${x}, ${y})}rgba(66, 86, 244, ${1 - (max - value) / (max - min)})
cellStyle={(background, value, min, max, data, x, y) => ({
background: ,${value}%
fontSize: "11px",
})}
cellRender={(value) => value && }${value}
title={(value, unit) => }`
/>,
document.getElementById("app")
);
New build
``
npm run build
Run dev server
``
npm run dev
Run test
```
npm run test