D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
tmcw
Full window
Github gist
An inlet to Tributary
<!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 = 500 - 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.json", function(error, data) { var data = d3.entries(data).map(function(d) { return { sec: +d.key, count: +d.value }; }); x.domain([0, d3.max(data, function(d) { return d.sec; })]); y.domain([0, d3.max(data, function(d) { return d.count; })]); 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"); var bars = svg.selectAll(".bar") .data(data); bars.enter().append("rect") .attr("class", "bar") .attr("x", function(d) { return x(d.sec); }) .attr("width", x(data[1].sec)) .attr("y", function(d) { return y(d.count); }) .attr("height", function(d) { return height - y(d.count); }); function draw(offset) { bars .data(data) .transition() .delay(function(d, i) { return i; }) .attr("x", function(d) { return x((d.sec + offset) % 1440); }) .attr("width", x(data[1].sec)) .attr("y", function(d) { return y(d.count); }) .attr("height", function(d) { return height - y(d.count); }); } d3.select('#tz') .on('change', function() { draw(this.value * 60); }) .selectAll('option') .data(d3.range(0, 24)) .enter() .append('option') .text(String) .attr('value', String); }); </script> <br />timezone offset from UTC <select id='tz'> </select>
Modified
http://d3js.org/d3.v3.min.js
to a secure url
https://d3js.org/d3.v3.min.js