Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-simple-heatmap

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-simple-heatmap

A simple React component to create responsive heatmap.

  • 2.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-90.32%
Maintainers
1
Weekly downloads
 
Created
Source

react-simple-heatmap

A simple React component to create responsive heatmap. To be rendered, this heatmap only need a dataset (2D Array) and a parent element which have a width and height. There is more customization available.

NPM JavaScript Style Guide

Install

yarn add react-simple-heatmap

or

npm install react-simple-heatmap

Alt text

Demo

Here is a preview.

Obligatory Fields

NameTypedescriptionexampledefault
data2D Array of numbers2D Matrix of numbres[[10,12,33], [2,45,31], [16, 32, 29]]undefined
Basic Example:
import React, { Component } from "react"
import Heatmap from "react-simple-heatmap"

export default class App extends Component {

  render() {
    // 2D array of numbers
    const data = [[10, 12, 33],
                  [21, 45, 31],
                  [16, 32, 29]];
    return (
      <div
        style={{ height: "500px", width: "500px" }}>
        <Heatmap
          data={ data }
        />
      </div>
    );
  }
}

Customization fields

NameTypedescriptionexampledefault
bgColorsArray of 2 colorsMain color using RGB format["rgb(255, 11, 11)", "rgb(255, 255, 0)"]["rgb(24, 144, 255)", "rgb(255, 255, 255)"]
xLabelsArrayDisplay the X-axis labels["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]undefined
yLabelsArrayDisplay the Y-axis labels[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]undefined
showLegendBolleanDisplay the heatmap legend.truefalse
onClickFunctionAdding an handler to cell click(data, x, y) => alert(`Data: ${ data }, X: ${ x }, Y: ${ y }\`)undefined
showDataBolleanDisplay data inside each cells.truefalse
borderedBolleanDisplay a border on the heatmap.falsetrue
xStepLabelNumberShow the label if his index in the xLabels array modulo xStepLabel equals 02undefined
yStepLabelNumberShow the label if his index in the yLabels array modulo yStepLabel equals 02undefined
showTicksBoolean or StringShow the ticks lines of the label. Use true to show X-axis and Y-axis ticks, "y" to show only Y-axis ticks and "x" to show only X-axis ticks."y"false
xLabelsStyleObjectStyle your X-axis labels.{ fontWeight: "bold" }{}
yLabelsStyleObjectStyle your Y-axis labels.{ fontWeight: "bold" }{}
legendStyleObjectStyle your Legeng labels.{ fontWeight: "bold" }{}
borderRadiusStringAdd border radius to the heatmap and legend"4px"0
Customization example
import React, { Component } from 'react'
import Heatmap from 'react-simple-heatmap'

// Creating a 2D array (7 x 24)
const size = 7;
const data = [];
for(let i = 0; i < size; i++){
	const temp = [];
	for(let i = 0; i < 24; i++){
		temp.push(Math.round(Math.random() * 100));
	}
	data.push(temp);
}

export default class App extends Component {

  render() {
		// Create an array of for the Y labels
		const yLabels = [];
		for(let i = 0; i < 24; i++){
			yLabels.push(i+1 + " h");
		}

    return (
      <div className="App">
				<div
					style={{ height: "500px", width: "800px", margin: "4rem auto" }}
				>
					{
						data.length > 0 && (
							<Heatmap
							  data={ data }
								bgColors={ ["rgb(255, 11, 11)", "rgb(255, 255, 0)"] }
								xLabels={ ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"] }
								yLabels={ yLabels }
								showLegend={ true }
								xStepLabel={ 2 }
								yStepLabel={ 2 }
								showTicks={ "x" }
								xLabelsStyle={{ fontWeight: "bold", fontSize: "11px" }}
								yLabelsStyle={{ fontWeight: "bold" }}
								legendStyle={{ fontWeight: "bold" }}
								bordered={ false }
								borderRadius={ "4px" }
								onClick={ (data, x, y) => alert(`Data: ${ data }, X: ${ x }, Y: ${ y }`) }
							/>
						)
					}
				</div>
      </div>
    );
  }
}

License

MIT © Julien Rioux

FAQs

Package last updated on 22 Mar 2019

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