Skip to content

Instantly share code, notes, and snippets.

@mef51
Last active August 29, 2015 14:05
Show Gist options
  • Save mef51/eace95a1e9c730014813 to your computer and use it in GitHub Desktop.
Save mef51/eace95a1e9c730014813 to your computer and use it in GitHub Desktop.
Pulsing circles with d3 bro
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);
<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