Created
April 8, 2016 16:01
-
-
Save mathisonian/9ddde94f772c9f903dc265c645245c38 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
var _ = require('lodash'); | |
var d3 = require('d3'); | |
function randomVariable(rate) { | |
rate = rate || 1; | |
var U = Math.random(); | |
return -Math.log(U)/rate; | |
}; | |
var start = 0; | |
var end = 25; | |
var step = 0.01; | |
var eventsPerStep = 5; | |
var generateData = function () { | |
var data = []; | |
_.each(_.range(start, end, step), function(i) { | |
_.each(_.range(Math.random() * eventsPerStep), function() { | |
data.push({ | |
x1: i, | |
x2: i + randomVariable() | |
}); | |
}); | |
}); | |
return data; | |
} | |
var data = generateData(); | |
var width = 800; | |
var height = 600; | |
var x = d3.scale.linear().domain([start, end]).range([0, width]); | |
// var y = d3.scale.linear().domain([start, end]).range([0, width]); | |
var svg = d3.select('body').append('svg') | |
.attr('width', width) | |
.attr('height', height); | |
svg.selectAll('rect') | |
.data(data) | |
.enter() | |
.append('rect') | |
.attr('x', function(d, i) { | |
return x(d.x1); | |
}) | |
.attr('y', function(d, i) { | |
return i; | |
}) | |
.attr('width', function(d) { | |
return x(d.x2) - x(d.x1); | |
}) | |
.attr('height', 1) |
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
{ | |
"name": "duration", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"chroma-js": "^1.1.1", | |
"d3": "^3.5.16", | |
"lodash": "^4.8.2" | |
}, | |
"devDependencies": { | |
"watchify": "^3.7.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment