From acdb7523001f3e704babe740c24e61669f03b0bb Mon Sep 17 00:00:00 2001 From: Steve McDonald Date: Tue, 10 May 2016 15:04:03 -0400 Subject: [PATCH] #1 add support for rendering all colors with the same opacity added optional config parameter fixedOpacity if not set, the library works as before valid values are between 0 and 255. these values may be considered more awkward than values between 0 and 1. I decided to simply use what was used in the rgba colors. --- simpleheat.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/simpleheat.js b/simpleheat.js index de0fd65..346c9cd 100644 --- a/simpleheat.js +++ b/simpleheat.js @@ -12,6 +12,7 @@ function simpleheat(canvas) { this._height = canvas.height; this._max = 1; + this._fixedOpacity = null; this._data = []; } @@ -37,6 +38,12 @@ simpleheat.prototype = { return this; }, + // value between 0 and 255 + fixedOpacity: function(fixedOpacity) { + this._fixedOpacity = fixedOpacity; + return this; + }, + add: function (point) { this._data.push(point); return this; @@ -126,6 +133,8 @@ simpleheat.prototype = { pixels[i] = gradient[j]; pixels[i + 1] = gradient[j + 1]; pixels[i + 2] = gradient[j + 2]; + if (this._fixedOpacity != null) + pixels[i + 3] = this._fixedOpacity; } } }, @@ -140,3 +149,4 @@ simpleheat.prototype = { } } }; +