forked from mbostock's block: I Make Circles
Created
March 2, 2017 21:22
-
-
Save capitolmuckrakr/c6a22e4476c674f54f55166e0510dfa5 to your computer and use it in GitHub Desktop.
I Make Circles
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
license: gpl-3.0 |
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
<!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> |
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
���� JFIF 8 8 ��@ICC_PROFILE 0appl mntrRGB XYZ � -acspAPPL APPL �� �-appl desc P bdscm � cprt � #wtpt � rXYZ gXYZ bXYZ , rTRC @ aarg L vcgt l 0ndin � >chad � ,mmod (bTRC @ gTRC @ aabg L aagg L desc Display mluc " |