npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-light-heatmap

v0.1.0

Published

React component for heatmap grid layout

Downloads

22

Readme

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

|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]]|

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

|Name |Type|Description|Default Value|
|---|---|---|---|
|components|object|Replace default component|default components |background|string|The base color for the heatmap|"#239a3b"|
|height|number|Height of each cell of the heatmap in px|30|
|onClick|function|Adds an handler to cell click|undefined|
|squares|boolean|If set to true will render cells as square|false|
|xLabelWidth|number|Width of the x label area in pixel|60|
|xLabelsLocation|string|Location of y labels. It can be top or bottom|"top"|
|unit|string|Unit to display next to the value on hover||
|cellStyle|function|To set custom cell style. It is useful for using own colour scheme||
|getValue|function|To get value from provided data|value => 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