Sunng's Canvas based Heatmap API

Thu 11 February 2010
  • ANN
  • 手艺 tags:
  • canvas
  • html
  • javascript
  • visualization
  • web published: true comments: true

Glad to announce my works this morning: A simple heatmap API based on HTML5 canvas. canvas

The programming interface is rather simple now. To create such a heatmap, you just new a heatmap object by:

<canvas width="300" height="215" id="canv"></canvas>
heatmap = new HeatMap("canv");

Then read your dataset and push data into the heatmap:

heatmap.push(x, y, value);

At last, spread the data and get the canvas rendered:

heatmap.spread();
heatmap.render();
Now you got it.

For advanced usage, you can specify the resolution of heatmap by px:

heatmap = new HeatMap("canv", 2);
Large value will gain performance with low image quality.

Also, you can specify a value to define the attenuation value of each px.

heatmap.spread(5);

Finally, there is an option to use your own color schema for heatmap generation.

heatmap.render(function(value, maxValue){
    var light = value / maxValue * 100;
    return "hsl(20, 75%, "+light+"%)";
});
The parameters passed in are current pixel value and max value in whole context.

That's all the toolkit. More functionality and options might be added in future. Grab it from my bitbucket page: http://bitbucket.org/sunng/daily-coding/src/tip/canvas-heatmap/

There is a demo page which you can test the api by clicking canvas: canvas-raw then click heatmap button! canvas2

This is the new year gift for my readers and my dear friends !