D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
capitolmuckrakr
Full window
Github gist
I Make Circles
forked from
mbostock
's block:
I Make Circles
<!DOCTYPE html> <style> button { position: absolute; top: 10px; left: 10px; } circle { fill: none; stroke: #000; stroke-width: 1.5px; } </style> <button>Click Me</button> <svg width="960" height="500"></svg> <script src="https://d3js.org/d3.v4.min.js"></script> <script> var svg = d3.select("svg"), margin = {top: 30, right: 30, bottom: 30, left: 30}, width = +svg.attr("width") - margin.left - margin.right, height = +svg.attr("height") - margin.top - margin.bottom, g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")"); var x = d3.scaleTime() .range([0, width]); var xAxis = d3.axisBottom(x); var xAxisG = g.append("g") .attr("transform", "translate(0, " + height + ")"); d3.timer(function() { var now = Date.now(); x.domain([now - 5000, now]); xAxisG.call(xAxis); }); d3.select("button").on("click", function() { var time = Date.now(); var circle = g.append("circle") .attr("r", 80) .attr("stroke-opacity", 0) .attr("cy", Math.random() * height); circle.transition("time") .duration(5000) .ease(d3.easeLinear) .attrTween("cx", function(d) { return function(t) { return x(time); }; }) circle.transition() .duration(750) .ease(d3.easeCubicOut) .attr("r", 3.5) .attr("stroke-opacity", 1) .transition() .delay(5000 - 750 * 2) .ease(d3.easeCubicIn) .attr("r", 80) .attr("stroke-opacity", 0) .remove(); }); </script>
https://d3js.org/d3.v4.min.js