@vx/heatmap

A Heatmap is an arrangement of shapes where the data values are represented as colors.

Example

<HeatmapRect
  data={data}
  xScale={xScale}
  yScale={yScale}
  colorScale={colorScale}
  opacityScale={opacityScale}
  binWidth={bWidth}
  binHeight={bWidth}
  step={dStep}
  gap={0}
/>

Heatmaps generally require structure that has this shape:

[
  {
    bin: 1,
    bins: [
      {
        count: 20,
        bin: 23,
      },
    ],
  },
];

However, you're welcome to use your own structure by defining x, y, z accessors such as:

// Example accessors
const x = d => d.myBin;
const y = d => d.myBins;
const z = d => d.myCount;

// Example scale with an accessors
const xScale = scaleLinear({
  range: [0, xMax],
  domain: extent(data, x),
});

Installation

npm install --save @vx/heatmap

Examples

Components

APIs

#<HeatmapRect />

# HeatmapRect.xScale(columnIndex: number) => numberrequired

Given a column index, returns the x position of a rect cell.

# HeatmapRect.yScale(rowIndex: number) => numberrequired

Given a row index, returns the y position of a rect cell.

# HeatmapRect.binHeightnumber | undefinedoptional

Height of a rect bin.

Default 6

# HeatmapRect.bins((column: ColumnDatum) => BinDatum[]) | undefinedoptional

Accessor that returns an array of cell BinDatums (rows) for the provided ColumnData.

Default (d: any) => d && d.bins

# HeatmapRect.binWidthnumber | undefinedoptional

Width of a rect bin.

Default 6

# HeatmapRect.children((cells: RectCell<ColumnDatum, BinDatum>[][]) => ReactNode) | undefinedoptional

Render function override, provided with heatmap.

# HeatmapRect.classNamestring | undefinedoptional

className to apply to each heatmap rect element.

# HeatmapRect.colorScaleColorScale | undefinedoptional

Given a count value, returns the desired rect fill color.

Default () => undefined

# HeatmapRect.count((bin: BinDatum) => number) | undefinedoptional

Accessor that returns the count for the provided Bin.

Default (d: any) => d && d.count

# HeatmapRect.dataColumnDatum[] | undefinedoptional

Array of column data (one per column desired) for the heatmap.

Default []

# HeatmapRect.gapnumber | undefinedoptional

Pixel gap between heatmap rects.

Default 1

# HeatmapRect.leftnumber | undefinedoptional

Left offset applied to heatmap wrapper g element.

# HeatmapRect.opacityScaleOpacityScale | undefinedoptional

Given a count value, returns the desired rect fill opacity.

Default () => 1

# HeatmapRect.topnumber | undefinedoptional

Top offset applied to heatmap wrapper g element.

# HeatmapRect.x0number | undefinedoptional

Default 0

#<HeatmapCircle />

# HeatmapCircle.xScale(columnIndex: number) => numberrequired

Given a column index, returns the x position of a circle cell.

# HeatmapCircle.yScale(rowIndex: number) => numberrequired

Given a row index, returns the y position of a circle cell.

# HeatmapCircle.bins((column: ColumnDatum) => BinDatum[]) | undefinedoptional

Accessor that returns an array of cell BinDatums (rows) for the provided ColumnData.

Default (column: any) => column && column.bins

# HeatmapCircle.children((cells: CircleCell<ColumnDatum, BinDatum>[][]) => ReactNode) | undefinedoptional

Render function override, provided with heatmap.

# HeatmapCircle.classNamestring | undefinedoptional

className to apply to each heatmap circle element.

# HeatmapCircle.colorScaleColorScale | undefinedoptional

Given a count value, returns the desired circle fill color.

Default () => undefined

# HeatmapCircle.count((bin: BinDatum) => number) | undefinedoptional

Accessor that returns the count for the provided Bin.

Default (cell: any) => cell && cell.count

# HeatmapCircle.dataColumnDatum[] | undefinedoptional

Array of column data (one per column desired) for the heatmap.

Default []

# HeatmapCircle.gapnumber | undefinedoptional

Pixel gap between heatmap circles.

Default 1

# HeatmapCircle.leftnumber | undefinedoptional

Left offset applied to heatmap wrapper g element.

# HeatmapCircle.opacityScaleOpacityScale | undefinedoptional

Given a count value, returns the desired circle fill opacity.

Default () => 1

# HeatmapCircle.radiusnumber | undefinedoptional

Pixel radius of heatmap circles.

Default 6

# HeatmapCircle.topnumber | undefinedoptional

Top offset applied to heatmap wrapper g element.