Skip to content
Open
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
24 changes: 18 additions & 6 deletions simpleheat.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,27 @@ simpleheat.prototype = {
canvas.width = 1;
canvas.height = 256;

for (var i in grad) {
gradient.addColorStop(+i, grad[i]);
}
if (Object.prototype.toString.call(grad) === '[object Object]') {

ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 1, 256);
for (var i in grad) {
gradient.addColorStop(+i, grad[i]);
}

this._grad = ctx.getImageData(0, 0, 1, 256).data;
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 1, 256);

} else if (Object.prototype.toString.call(grad) === '[object Uint8Array]') {

canvas.width = 256;
const imgData = ctx.createImageData(1, 256);
imgData.data.set(grad);
ctx.putImageData(imgData, 0, 0);

} else {
throw new Error('Color Scale is undefined.');
}

this._grad = ctx.getImageData(0, 0, 1, 256).data;
return this;
},

Expand Down