Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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)
{
"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
You can’t perform that action at this time.