Browse files

a package.json and a readme all up in this thing

  • Loading branch information...
1 parent adebfae commit 3338a4f4244cca13f0ab07555984ddebba8bd7c7 @substack committed Jul 29, 2011
Showing with 131 additions and 17 deletions.
  1. +70 −0 README.markdown
  2. +0 −15 ex.js
  3. +16 −0 example/blob.js
  4. 0 { → example/web}/index.html
  5. +1 −1 { → example/web}/main.js
  6. 0 { → example/web}/server.js
  7. +4 −1 index.js
  8. +40 −0 package.json
View
70 README.markdown
@@ -0,0 +1,70 @@
+heatmap
+=======
+
+Heatmaps for node.js and the browser, groovy!
+
+![groovy heatmap, man](http://substack.net/images/heatmap.png)
+
+example
+=======
+
+blob.js
+-------
+
+````javascript
+var heatmap = require('heatmap');
+
+var heat = heatmap(500, 500, { radius : 30 });
+for (var i = 0; i < 5000; i++) {
+ var rho = Math.random() * 2 * Math.PI;
+ var z = Math.pow(Math.random(), 2) * 200;
+
+ var x = 250 + Math.cos(rho) * z;
+ var y = 250 + Math.sin(rho) * z;
+
+ heat.addPoint(x, y);
+}
+heat.draw();
+
+var fs = require('fs');
+fs.writeFileSync('blob.png', heat.canvas.toBuffer());
+````
+
+methods
+=======
+
+var heatmap = require('heatmap');
+
+var heat = heatmap(...)
+-----------------------
+
+Create a new heatmap from an existing canvas element, a numeric width and
+height, or an option object with canvas or width and height fields.
+
+Optionally, you can set the `opts.radius` and `opts.threshold` to control the
+rendering a little.
+
+heat.addPoint(x, y, radius=heat.radius || 20)
+---------------------------------------------
+
+Add a point to the heatmap with a `radius`.
+
+heat.draw()
+-----------
+
+Render all the points onto the canvas element.
+
+heat.canvas
+-----------
+
+The HTML Canvas element.
+
+Protip: with the [https://github.com/LearnBoost/node-canvas](canvas module) for
+node you can `heat.canvas.buffer()` to get a Buffer with a PNG file all up in it.
+
+install
+=======
+
+With [npm](http://npmjs.org), just do:
+
+ npm install heatmap
View
15 ex.js
@@ -1,15 +0,0 @@
-var fs = require('fs');
-var heatmap = require('./');
-
-var heat = heatmap(500, 500, { radius : 50 });
-for (var i = 0; i < 1000; i++) {
- var rho = Math.random() * 2 * Math.PI;
- var z = Math.pow(Math.random(), 2) * 250;
-
- var x = 250 + Math.cos(rho) * z;
- var y = 250 + Math.sin(rho) * z;
-
- heat.addPoint(x, y);
-}
-heat.draw();
-fs.writeFileSync('out.png', heat.canvas.toBuffer());
View
16 example/blob.js
@@ -0,0 +1,16 @@
+var heatmap = require('heatmap');
+
+var heat = heatmap(500, 500, { radius : 30 });
+for (var i = 0; i < 5000; i++) {
+ var rho = Math.random() * 2 * Math.PI;
+ var z = Math.pow(Math.random(), 2) * 200;
+
+ var x = 250 + Math.cos(rho) * z;
+ var y = 250 + Math.sin(rho) * z;
+
+ heat.addPoint(x, y);
+}
+heat.draw();
+
+var fs = require('fs');
+fs.writeFileSync('blob.png', heat.canvas.toBuffer());
View
0 index.html → example/web/index.html
File renamed without changes.
View
2 main.js → example/web/main.js
@@ -1,5 +1,5 @@
var $ = require('jquery-browserify');
-var heatmap = require('./');
+var heatmap = require('heatmap');
$(window).ready(function () {
var canvas = $('<canvas>').attr({
View
0 server.js → example/web/server.js
File renamed without changes.
View
5 index.js
@@ -38,12 +38,15 @@ var exports = module.exports = function (canvas) {
return new Heat(canvas, opts)
};
+exports.Heat = Heat;
+
function Heat (canvas, opts) {
if (!opts) opts = {};
this.canvas = canvas;
this.alphaCanvas = createCanvas(canvas.width, canvas.height);
this.radius = opts.radius || 20;
+ this.threshold = opts.threshold || 0;
}
Heat.prototype.addPoint = function (x, y, radius) {
@@ -72,7 +75,7 @@ Heat.prototype.draw = function () {
for (var i = 0; i < values.data.length; i += 4) {
var v = values.data[i+3];
- if (v > 5) {
+ if (v > this.threshold) {
var theta = (1 - values.data[i+3] / 255) * 270;
var rgb = convert.hsl2rgb(theta, 100, 50);
heat.data[i] = rgb[0];
View
40 package.json
@@ -0,0 +1,40 @@
+{
+ "name" : "heatmap",
+ "version" : "0.0.0",
+ "description" : "canvas heat maps for node and the browser",
+ "main" : "index.js",
+ "directories" : {
+ "lib" : ".",
+ "example" : "example",
+ "test" : "test"
+ },
+ "dependencies" : {
+ "color-convert" : "0.2.x",
+ "canvas" : "0.7.x"
+ },
+ "devDependencies" : {
+ "expresso" : "0.7.x",
+ "jquery-browserify" : "1.6.x",
+ "browserify" : "1.3.x",
+ "uglify-js" : ">=1.0.6 <1.1"
+ },
+ "scripts" : {
+ "test" : "expresso"
+ },
+ "repository" : {
+ "type" : "git",
+ "url" : "http://github.com/substack/node-heatmap.git"
+ },
+ "keywords" : [
+ "heatmap",
+ "canvas",
+ "browser"
+ ],
+ "author" : {
+ "name" : "James Halliday",
+ "email" : "mail@substack.net",
+ "url" : "http://substack.net"
+ },
+ "license" : "MIT/X11",
+ "engine" : { "node" : ">=0.4" }
+}

0 comments on commit 3338a4f

Please sign in to comment.