D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
tmcw
Full window
Github gist
OSM Commits by Second by Year
<!DOCTYPE html> <meta charset="utf-8"> <style> body { font: 10px sans-serif; } .axis path, .axis line { fill: none; stroke: #000; shape-rendering: crispEdges; } .bar { fill: steelblue; } .x.axis path { display: none; } </style> <body> <script src="https://d3js.org/d3.v3.min.js"></script> <script> var margin = {top: 20, right: 20, bottom: 30, left: 40}, width = 900 - margin.left - margin.right, height = 400 - margin.top - margin.bottom; var x = d3.scale.linear() .range([0, width]); var y = d3.scale.linear() .range([height, 0]); var xAxis = d3.svg.axis() .scale(x) .ticks(12) .orient("bottom") .tickFormat(function(d) { var hrs = Math.floor(d/60); var mins = d % 60; return hrs + ':' + mins; }); var yAxis = d3.svg.axis() .scale(y) .orient("left"); var svg = d3.select("body").append("svg") .attr("width", width + margin.left + margin.right) .attr("height", height + margin.top + margin.bottom) .append("g") .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); d3.json("timehist_year.json", function(error, data) { var year = 2011; var data = d3.entries(data).map(function(d) { return { key: d.key, value: d3.entries(d.value).map(function(d) { return { sec: +d.key, count: +d.value }; }) }; }); var d = data.filter(function(d) { return d.key == year; })[0].value; x.domain([0, d3.max(d, function(d) { return d.sec; })]); y.domain([0, d3.max(d, function(d) { return d.count; })]); year = 2005; var d = data.filter(function(d) { return d.key == year; })[0].value; svg.append("g") .attr("class", "x axis") .attr("transform", "translate(0," + height + ")") .call(xAxis); svg.append("g") .attr("class", "y axis") .call(yAxis) .append("text") .attr("transform", "rotate(-90)") .attr("y", 6) .attr("dy", ".71em") .style("text-anchor", "end") .text("Commits"); function draw(d) { var bars = svg.selectAll(".bar") .data(d); bars.enter().append("rect") .attr('class', 'bar'); bars .data(d) .transition() .delay(function(d, i) { return i; }) .attr("x", function(d) { return x(d.sec); }) .attr("width", x(d[1].sec)) .attr("y", function(d) { return y(d.count); }) .attr("height", function(d) { return height - y(d.count); }); bars .exit() .remove(); } d3.select('#tz') .on('change', function() { var v = this.value; draw(data.filter(function(d) { return d.key == v; })[0].value); }) .selectAll('option') .data(data.map(function(d) { return d.key; })) .enter() .append('option') .text(String) .attr('value', String); draw(data.filter(function(d) { return d.key == 2005; })[0].value); }); </script> <br />year: <select id='tz'> </select>
Modified
http://d3js.org/d3.v3.min.js
to a secure url
https://d3js.org/d3.v3.min.js