Created
November 13, 2011 04:06
-
-
Save tclem/1361577 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Histogram</title> | |
<script type="text/javascript" src="../../d3.js"></script> | |
<script type="text/javascript" src="../../d3.layout.js"></script> | |
<script type="text/javascript" src="pseudoMathStats.js"></script> | |
<script type="text/javascript" src="lhc.js"></script> | |
<style type="text/css"> | |
body { | |
font: 10px sans-serif; | |
} | |
rect { | |
fill: steelblue; | |
stroke: white; | |
} | |
line { | |
stroke: black; | |
shape-rendering: crispEdges; | |
} | |
</style> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
var histogram = d3.layout.histogram() | |
(data); | |
var x = d3.scale.ordinal() | |
.domain(histogram.map(function(d) { return d.x; })) | |
.rangeRoundBands([0, w]); | |
var y = d3.scale.linear() | |
.domain([0, d3.max(histogram, function(d) { return d.y; })]) | |
.range([0, h]); | |
var vis = d3.select("body").append("svg:svg") | |
.attr("width", w) | |
.attr("height", h) | |
.append("svg:g") | |
.attr("transform", "translate(.5)"); | |
vis.selectAll("rect") | |
.data(histogram) | |
.enter().append("svg:rect") | |
.attr("transform", function(d) { return "translate(" + x(d.x) + "," + (h - y(d.y)) + ")"; }) | |
.attr("width", x.rangeBand()) | |
.attr("y", function(d) { return y(d.y); }) | |
.attr("height", 0) | |
.transition() | |
.duration(750) | |
.attr("y", 0) | |
.attr("height", function(d) { return y(d.y); }); | |
vis.append("svg:line") | |
.attr("x1", 0) | |
.attr("x2", w) | |
.attr("y1", h) | |
.attr("y2", h); | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function read(path) { | |
// load a whole csv file, and then split it line by line | |
console.log('reading cvs file'); | |
var req = new XMLHttpRequest(); | |
req.open("GET", path, false); | |
req.send(""); | |
return req.responseText.split(/\n/g).map(function(a){return a.split(/\,/g)}); | |
} | |
Array.prototype.project = function(col) { | |
var res = []; | |
var list = this; | |
for(var i=0; i < 1000; i++) { | |
// for(var i=0; i < list.length; i++) { | |
if(i == 0) continue; | |
res.push(list[i][col]); | |
} | |
return res; | |
} | |
Array.prototype.each = function(func) { | |
var list = this; | |
for(var i=0; i < list.length; i++) { | |
list[i] = func(list[i]); | |
} | |
} | |
function normalize(list) { | |
list.each(parseFloat); | |
var std = list.stdDev(); | |
var dev = 2 * std; | |
console.log(dev); | |
return list.filter(function(x){ | |
if(x > dev) { | |
// console.log('filtered out' + x); | |
return false; | |
} | |
return true; | |
}); | |
} | |
// Start Plotting the data | |
var w = 400, | |
h = 400; | |
var raw = read('../../../public_data/dir_dimuon/dimuon.csv'); | |
console.log(raw[0]); | |
var e1 = raw.project(3); | |
console.log('before: ' + e1.length); | |
e1 = normalize(e1); | |
console.log('after: ' + e1.length); | |
//var e2 = raw.project(11); | |
var data = e1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function read(path) { | |
// load a whole csv file, and then split it line by line | |
console.log('reading cvs file'); | |
var req = new XMLHttpRequest(); | |
req.open("GET", path, false); | |
req.send(""); | |
return req.responseText.split(/\n/g).map(function(a){return a.split(/\,/g)}); | |
} | |
Array.prototype.project = function(col) { | |
var res = []; | |
var list = this; | |
for(var i=0; i < 1000; i++) { | |
// for(var i=0; i < list.length; i++) { | |
if(i == 0) continue; | |
res.push(list[i][col]); | |
} | |
return res; | |
} | |
Array.prototype.each = function(func) { | |
var list = this; | |
for(var i=0; i < list.length; i++) { | |
list[i] = func(list[i]); | |
} | |
} | |
function normalize(list) { | |
list.each(parseFloat); | |
var std = list.stdDev(); | |
var dev = 2 * std; | |
console.log(dev); | |
return list.filter(function(x){ | |
if(x > dev) { | |
// console.log('filtered out' + x); | |
return false; | |
} | |
return true; | |
}); | |
} | |
// Start Plotting the data | |
var w = 400, | |
h = 400; | |
var raw = read('../../../public_data/dir_dimuon/dimuon.csv'); | |
console.log(raw[0]); | |
var e1 = raw.project(3); | |
console.log('before: ' + e1.length); | |
e1 = normalize(e1); | |
console.log('after: ' + e1.length); | |
//var e2 = raw.project(11); | |
var data = e1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment