0.9.0 • Published 2 years ago

react-heatmap-grid v0.9.0

Weekly downloads
1,774
License
MIT
Repository
github
Last release
2 years ago

react-heatmap-grid

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

Build Status

A React component for heatmap in grid layout using div.

Live example here.

Screenshot

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

0.9.0

2 years ago

0.8.2

4 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.3

5 years ago

0.7.2

5 years ago

0.7.0

5 years ago

0.6.0

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago