GithubHelp home page GithubHelp logo

rafaelbeckel / heatcanvas Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sunng87/heatcanvas

0.0 1.0 0.0 130 KB

Pixel based heatmap with html5 canvas.

Home Page: http://sunng87.github.com/heatcanvas/

heatcanvas's Introduction

heatcanvas

This is a simple heatmap api based on HTML5 canvas. A heat map is a graphical representation of data where the values taken by a variable in a two-dimensional table are represented as colors, according to Wikipedia.

You can find an interactive demo at http://sunng87.github.com/heatcanvas

Available via bower

bower install heatcanvas

Usage

1. Create the HeatCanvas object

You can pass the canvas element object or its id to the constructor:

var heatmap = new HeatCanvas("canvasId");

2. Add some data

Add value to point (x,y) in canvas coordinate system.

heatmap.add(x, y, value);

3. Render the map

Call the render function on heatmap to draw it.

heatmap.render();

We use a simple formula to determine value of a pixel, by its distance to a point that holds data:

v = f(d)

The first two optional parameters of render define the formula.

  • step

  • degree

    v = Σ(datai - step * ddegree)

A set of constants are predefined for degree:

  • HeatCanvas.LINEAR
  • HeatCanvas.QUAD
  • HeatCanvas.CUBIC

For the third parameter of render, you can define a custom function to define color of pixels. For instance, we can use a mono-hue color scheme by this function:

var colorscheme = function(value){
    return [0.3, 0.75, value, 1];
}
heatmap.render(null, null, colorscheme);

The value for this function is guaranteed in (0,1].

4. Remove everything we just created

Call clear to erase the canvas and remove all data cached in heatmap instance.

heatmap.clear();

GoogleMap extension

HeatCanvas can be used as an OverlayView in GoogleMaps API V3.

Simply use the Map instance to create an HeatCanvasOverlayView

var heatmap = new HeatCanvasOverlayView(map, options);

Additional options available:

  • step, same as described in HeatCanvas.render
  • degree, same as described in HeatCanvas.render
  • colorscheme, same as described in HeatCanvas.render
  • opacity, the opacity of overlay view, [0,1]

Add data to map:

heatmap.pushData(latitude, longitude, value);

The map will be rendered automatically.

OpenLayers extension

Also we have a OpenLayer extension for you to embed heat map in your custom map application and OpenStreetMap.

The usage is still similar to GoogleMaps. First, construct your heat map layer with a name, OpenLayers map instance, layer options and HeatCanvas options:

var heatmap = new OpenLayers.Layer.HeatCanvas("HeatCanvas", map, {},
        {'step':0.3, 'degree':HeatCanvas.QUAD, 'opacity':0.8});

Add data to layer:

heatmap.pushData(latitude, longitude, value);

Add layer to map:

map.addLayer(heatmap);

Other extensions

There are also HeatCanvas extensions for:

  • Baidu Map (demo)
  • Cloudmade Leaflet (demo)

These extensions share similar API mentioned above. You can browse the source code of our demos to get detail.

License

HeatCanvas is released according to MIT License.

Thanks

  • @lbt05 for his patches on GoogleMap extension and BaiduMap implementation
  • @dazuma for his suggestion to speed up canvas rendering.

heatcanvas's People

Contributors

sunng87 avatar qbit avatar bozdoz avatar ktopping avatar

Watchers

Rafael Beckel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.