Skip to content

Instantly share code, notes, and snippets.

@syntagmatic
Created March 21, 2012 07:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syntagmatic/2145428 to your computer and use it in GitHub Desktop.
Save syntagmatic/2145428 to your computer and use it in GitHub Desktop.
heatmap.js
var defaults = {
dotsize: 5,
gutsize: 1,
totsize: 6
}
function heatmap(id, data, options) {
var self = {};
var options = _.extend(defaults, options);
self.data = data || [];
self.canvas = document.getElementById(id);
self.ctx = self.canvas.getContext('2d');
self.colorize = options.colorize || default_colorize;
self.ctx.clearRect(
0,
0,
_.size(self.data),
_.size(self.data[0])
);
// render heatmap
self.render = function() {
_(self.data).each(function(row,j) {
_(row).each(function(val,i) {
self.ctx.fillStyle = self.colorize(val);
self.ctx.fillRect(options.totsize*i,options.totsize*j,options.dotsize,options.dotsize);
});
});
}
self.update = function(data) {
self.data = data;
};
return self;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment