A histogram script written in javascript (ripped and made atomic from d3.js)
JavaScript
Switch branches/tags
Nothing to show
Latest commit 8881475 Apr 25, 2014 @eoinmurray Update README.md
Permalink
Failed to load latest commit information.
.gitignore init, need to add tests. Aug 27, 2013
License.md npm publish Sep 6, 2013
README.md Update README.md Apr 25, 2014
histogram.js added test and example Sep 2, 2013
package.json npm publish Sep 6, 2013
test.js added test and example Sep 2, 2013

README.md

Histogram.js

	npm i histogramjs
	var hist = require('histogramjs')

Frequency sort an array of data. Ripped from d3.js. this histogram function is fully self contained and can be dropped easily into project.

It was created originally for use with webworkers.

histogram({
	data : Array,
	bins : Array
})

Example.

	var histogram = require('./histogram')
	
	var linspace = function linspace(a,b,n) {
	    if(typeof n === "undefined") n = Math.max(Math.round(b-a)+1,1);
	    if(n<2) { return n===1?[a]:[]; }
	    var i,ret = Array(n);
	    n--;
	    for(i=n;i>=0;i--) { ret[i] = (i*b+(n-i)*a)/n; }
	    return ret;
	}
	
	var x = linspace(0, 12, 100),
		y = [],
		num;
	
	for(var i = 0; i < 2000; i ++){
		num = - Math.log(Math.random())
		y.push(num)
	}
	
	var data = histogram({
		data : y,
		bins : x
	})
	
	for(var i = 0; i < data.length; i ++){
		console.log('[' + data[i].x + ',' +  data[i].y + '],')
	}

Run in node, it produces this distribution.