Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simpleheat",
"version": "0.4.0",
"version": "0.4.1",
"description": "A tiny JavaScript library for drawing heatmaps with Canvas",
"homepage": "https://github.com/mourner/simpleheat",
"keywords": [
Expand Down
11 changes: 8 additions & 3 deletions simpleheat.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ simpleheat.prototype = {
},

clear: function () {
this._ctx.clearRect(0, 0, this._width, this._height);
this._data = [];
return this;
},
Expand Down Expand Up @@ -95,7 +96,7 @@ simpleheat.prototype = {
return this;
},

draw: function (minOpacity) {
draw: function (minOpacity, alpha) {
if (!this._circle) this.radius(this.defaultRadius);
if (!this._grad) this.gradient(this.defaultGradient);

Expand All @@ -112,20 +113,24 @@ simpleheat.prototype = {

// colorize the heatmap, using opacity value of each pixel to get the right color from our gradient
var colored = ctx.getImageData(0, 0, this._width, this._height);
this._colorize(colored.data, this._grad);
this._colorize(colored.data, this._grad, alpha);
ctx.putImageData(colored, 0, 0);

return this;
},

_colorize: function (pixels, gradient) {
_colorize: function (pixels, gradient, alpha) {
for (var i = 0, len = pixels.length, j; i < len; i += 4) {
j = pixels[i + 3] * 4; // get gradient color from opacity value

if (j) {
pixels[i] = gradient[j];
pixels[i + 1] = gradient[j + 1];
pixels[i + 2] = gradient[j + 2];
if (alpha)
{
pixels[i + 3] = pixels[i + 3] * alpha;
}
}
}
},
Expand Down