1.0.7 • Published 1 year ago

@oxth/heatmap v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

heatmap.js

Heatmaps for the Node.js.

This project was fork from heatmap.js to make support only generate heatmap from backend

How to get started

heatmap is also hosted on npm:

npm install @oxth/heatmap

Importing

import Heatmap from '@oxth/heatmap'

Example

const heatmap = new Heatmap({
  width: 640,
  height: 640,
  backgroundImage: 'img_test.jpg',
  radius: 2.2,
  minOpacity: 0.3,
  maxOpacity: 0.5,
});
const points = getCanvasData();
heatmap.setData(points);
await heatmap.save('test.png');

Configurations

ParamTypeDefaultRequiredDescription
rendererstringcanvas2dNoChoose your render type (currently only support 2D canvas)
widthnumber640NoWidth of your image.
heightcanvas2d640NoHeight of image.
minnumbernullNoMax data Value for relative gradient computation. if not set, will be derived from data.
maxnumbernullNoMin data Value for relative gradient computation. if not set, will be derived from data.
radiusnumber20NoRadius of the data point, in pixels.
opacitynumber0NoOpacity factor. (This overrides maxOpacity and minOpacity if greater than 0)
minOpacitynumber0NoMin opacity factor. (will be overridden if opacity set)
maxOpacitynumber1NoMax opacity factor. (will be overridden if opacity set)
intensitynumber0.25NoThe intensity that will be applied to all datapoints. The lower the intensity factor is, the smoother the gradients will be
useGradientOpacitybooleanfalseNoA boolean flag to use opacity of Color Gradient instead of specify opacity
gradients{color: number, number, number, number?, offset: number}[][{ color: 0, 0, 255, offset: 0, }, { color: 0, 0, 255, offset: 0.2, }, { color: 0, 255, 0, offset: 0.45, }, { color: 255, 255, 0, offset: 0.85, }, { color: 255, 0, 0, offset: 1.0, },]NoColor Gradient, an array of objects with color value and offset.
backgroundImagestringNoTo set the background for the heatmap.
pluginsobject{}NoThe plugin support.

Available API

instance.addData([])

Accepts an array of data points with 'x', 'y' and 'value'.

instance.addData([x: , y: , value: ])

instance.setData([])

Accepts an array of data points with 'x', 'y' and 'value'.

instance.setData([x: , y: , value: ])

instance.clearData([])

instance.clearData()

instance.configure({})

Update the configuration

instance.configure({ width: , height: })

instance.toDataURL()

get output to base64 data url

await instance.toDataURL()

instance.toBuffer()

get output to buffer

await instance.toBuffer()

instance.save(filename)

get output to file

await instance.save('test.png')

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago