Last active
August 29, 2015 14:05
-
-
Save mef51/eace95a1e9c730014813 to your computer and use it in GitHub Desktop.
Pulsing circles with d3 bro
This file contains 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
var pi = Math.PI, | |
sin = Math.sin, | |
cos = Math.cos | |
var t = 0; | |
setInterval(function(){ | |
var data = [sin(t)+1, cos(t)+1, sin(t)+1, cos(t)+1, sin(t)+1]; | |
// bind circle elements to data | |
var circles = d3.selectAll(".chart") | |
.selectAll("circle") | |
.data(data); | |
// create circles if there aren't any | |
circles.enter().append("circle") | |
.attr("cx", function(d, i){ | |
return 100 + i*100; | |
}) | |
.attr("cy", 100); | |
// change the radius of each circle based on da data | |
circles.attr("r", function(d){ | |
return d*10 + 10; | |
}); | |
t += 0.1; | |
if(t > 2*pi){ | |
t = 0; | |
} | |
}, 10); |
This file contains 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
<style> | |
circle { | |
fill: black; | |
} | |
</style> | |
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> | |
<script src="circles.js"></script> | |
<svg class="chart" width="720" height="200"></svg> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment